Ask Your Question
0

How many frames is it when I call videoWriter.write?

asked 2017-12-21 11:21:20 -0600

jsplyy gravatar image

updated 2017-12-21 11:37:27 -0600

berak gravatar image

In constructor function of VideoWriter, I set the fps is 10. But I call videoWriter.write(frame) function more than 10 times per second. So my question is what is the real fps in my saved video and which frames are saved?
Input 100 fps when set fps as 10, what is the result? Will it save 10 fps? which 10 fps in input 100 fps will be saved? videoWriter = cv2.VideoWriter('video_demo.avi', cv2.cv.CV_FOURCC('M', 'J', 'P', 'G'), 10, size)

success, frame = videoCapture.read()  

while success :  
    cv2.imshow("Video demo", frame) 
    videoWriter.write(frame) 
    success, frame = videoCapture.read()  
    if cv2.waitKey(1) == 27: 
        break  # esc to quit
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-12-21 14:15:17 -0600

supra56 gravatar image

updated 2017-12-21 14:26:47 -0600

length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

Then do in loop if length > 10 do something

link: frame count

Btw, I'm on vacation.

edit flag offensive delete link more

Comments

There 2 ways to do this:

[1] for i in range(100):
or 
 [2] time.sleep
supra56 gravatar imagesupra56 ( 2017-12-21 14:36:11 -0600 )edit

Hi supra, thanks for your response, I know what you mean. I am capturing frame from a camera and save into .avi file. Input 100 fps when set fps as 10, what is the result? Will it save 10 fps? which 10 fps in input 100 fps will be saved?

jsplyy gravatar imagejsplyy ( 2017-12-21 21:24:34 -0600 )edit

OOppss! My mistaken...it is for i in range(10):

supra56 gravatar imagesupra56 ( 2017-12-22 03:41:59 -0600 )edit

@supra56, careful, not every webcam supports this !

@jsplyy, if you write 100 frames per second, and had 10fps in your VideoWriter, the final video will be a 10x slower "timelapse" one. please understand, that there is no synchronization between the Capture and the Writer, and no frames will get dropped.

again, please don't abuse any of this, trying to make a video editor, there's better libs for that (e.g. ffmpeg, videolan, gstreamer)

berak gravatar imageberak ( 2017-12-22 11:01:56 -0600 )edit

I haven't test this. Still waiting make j1. for OpenCV 3.4.0

import cv2
cap = cv2.VideoCapture(0)
fps = 10
size = (int(cameraCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),
       (int(cameraCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
out = cv2.VideoWriter('MyOutputVid.avi', cv2.CV_FOURC(('M', 'J', 'P', 'G' '0'), fps,size)
success, frame = cap = read()
        numFrameRemaining = 10 * fps -1
        while success and numFrameRemaining > 0:
            out.write(frame)
:
:
:
supra56 gravatar imagesupra56 ( 2017-12-23 08:08:38 -0600 )edit

Apologized, my mistaken. cv2.CV_FOURC(('M', 'J', 'P', 'G')

supra56 gravatar imagesupra56 ( 2017-12-24 05:12:57 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-21 11:21:20 -0600

Seen: 2,313 times

Last updated: Dec 21 '17