Save Output to Video format#126
Conversation
|
|
||
| if FLAGS.demo: | ||
| tfnet.camera(FLAGS.demo) | ||
| tfnet.camera(FLAGS.demo,FLAGS.saveVideo) |
There was a problem hiding this comment.
I suggest a space coming after the comma
| self.sess.run(op, {plh: val}) | ||
|
|
||
| def camera(self, file): | ||
| def camera(self, file,SaveVideo): |
There was a problem hiding this comment.
I suggest a space coming after the comma
| fps = get_fps(self,frame) | ||
| height, width, _ = frame.shape | ||
| videoWriter = cv2.VideoWriter('video.avi', fourcc, fps, (width,height)) | ||
| if(SaveVideo): |
| fourcc = cv2.VideoWriter_fourcc(*'XVID') | ||
| fps = get_fps(self,frame) | ||
| height, width, _ = frame.shape | ||
| videoWriter = cv2.VideoWriter('video.avi', fourcc, fps, (width,height)) |
| videoWriter = cv2.VideoWriter('video.avi', fourcc, fps, (width,height)) | ||
| while camera.isOpened(): | ||
| _, frame = camera.read() | ||
| if (frame is None): |
There was a problem hiding this comment.
if frame is None: (no need parantheses)
There was a problem hiding this comment.
not mine, will change it anyway :)
| net_out = self.sess.run(self.out,feed_dict)[0] | ||
| processed = self.framework.postprocess(net_out, frame, False) | ||
| videoWriter.write(processed) | ||
| if (SaveVideo): |
| if(SaveVideo): | ||
| _, frame = camera.read() | ||
| fourcc = cv2.VideoWriter_fourcc(*'XVID') | ||
| fps = get_fps(self,frame) |
|
Thanks! I suggest:
|
|
I tested on an mpeg4 codec video, and i get the following error, and the video is not saved. [mpeg4 @ 0x3714460] framerate not set fps printed from your get_fps() is 0.249... |
|
I am no expert on codec, so waiting for people to come help ... |
|
@thtrieu the problem is not with codec here.. the problem is with the fps.. like i said, i put 25 manually in the Update After testing on various video codec, i can confirm it's not the codec that's the problem, it's the incorrect fps. FPS should be the same as the input video. not calculated by the processed time of single frame. |
|
@borasy, MPEG4 or mp4 is only container name (aka extension), can you mention codec name? make sure u have installed codec pack from here or here for camera demo, we have to set the same fps as you get output (Note: for camera if you set fps as 25 & record video at lower resolution like 0.5, then playback will be extremely fast) |
|
@Prakash19921206 yes, i understand what you mean. At this point we can declare that the codec is not the problem. Sorry my first comment made this confusion. The problem is with the FPS indeed. I think the simplest solution is to just get the FPS from the input video and set it into VideoWriter(), there's no need of calculation. I used this |
|
@borasy , sure please create PR, i'm slightly occupied now.. i think, for webcam we have to calculate fps.. or else it video playback might be faster or slower.. also change this line to this will avoid one error message, in case if user do not want to save video... |
|
@Prakash19921206 My webcam is broken at the moment. After i got a new one, i'll test on the webcam, too. I also fixed your mentioned bug and created a PR already. Have a nice weekend. |
|
but it works for video input |
|
@Prakash19921206 I see the problem. This should fix it. |
|
i think for webcam, the method i have given to calculate fps is proper (what you see is what you record) i tried above method, it showed 13fps only change we need to do is to set |
|
hmm.. i see. You're right. We should use your get_fps() for camera/webcam. But we also need one more change. Your method is calculating the X time it takes for 1 frame to be processed, right? So if we want to know how many frames it can process in 1 second. then fps should be equals to 1/X. Then it should be |
|
yeah i had missed it..thanks for pointing it out.. what i noticed is, opencv had a bug. there was code conflict in PR, after that 1 function was missed from my fork! |
|
Cool. for now that's the way to do it. Awesome job. |
|
Well done, guys! It works like a charm! |
Tested and working fine.
along with
--demo,user need to provide--saveVideo 1(1 means True, 0 means False which is default )i'm writing video to the same input resolution provided.
i'm calling
get_fps(self,frame)because for cpu it will be around 0.4fps for gpu will be around 30 fpsalso i have added namedWindow, so that output window can be resized (full screen or whichever size)