Ask Your Question

VideoWriter fps parameter

asked 2017-03-24 04:15:51 -0500

Thoth gravatar image

Through the VideoWriter the incoming webcam stream is stored in uncompressed form in a .avi. The opencv VideoWriter has an fps parameter that should be set in the initialization of the object so as to proceed with the video writing. However, the incoming stream may have an fps lower of higher to that defined in the parameter. Also the real fps of the incoming stream may be not constant. My question is how the data are stored into the uncompressed .avi in accordance to the real fps? Is there an up sampling or downsampling so as to meet the VideoWriter fps? I couldnt found a documentation for that explanations or other ones that I could not imagine right now.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-03-24 04:28:10 -0500

berak gravatar image

updated 2017-03-24 04:35:43 -0500

in short: no, there's no (automatic) attempt done, to synchronize the VideoWriter to your input.

all you can do is the reverse: measure your current fps, and adjust e.g. waitKey() or sleep() times. (synchronize your input to the VideoWriter)

edit flag offensive delete link more


@berak thanks for the reply. Is it possible to provide some clarifications on what is happening on the saved video when the parameter fps is different to the real fps? Is there an up-sampling or down-sampling procedure? In other words, how the saved frames are distributed? Thanks again.

Thoth gravatar imageThoth ( 2017-04-02 07:36:41 -0500 )edit

again, the writer does not know anything about "real" fps. there is no magic under the hood. if you say: 25 fps, 25 frames per second will be played later, that's it. no sampling of any kind, uniform distribution.

berak gravatar imageberak ( 2017-04-02 08:09:35 -0500 )edit

Absolutely, berak.

supra56 gravatar imagesupra56 ( 2017-12-04 05:58:28 -0500 )edit

I am also trouble in this issue. I set 10 fps in constructor function of VideoWriter, but I call videoWriter.write(frame) function more than 10 times per second. So what is the real fps in my saved video and which frames are saved?

videoWriter = cv2.VideoWriter('video_demo.avi','M', 'J', 'P', 'G'), 10, size)  

success, frame =  

while success :  
    cv2.imshow("Video demo", frame) 
    success, frame =  
    if cv2.waitKey(1) == 27: 
        break  # esc to quit
jsplyy gravatar imagejsplyy ( 2017-12-21 11:15:25 -0500 )edit

@jsplyy -- please do not post answers on this site, if you have a question or comment, thank you.

( and your video will run at 10 fps, but it will look faster or slower. again, all you can do is 1. make a reasonable assumption, on how fast your processing is, and how many frames you can render per second, and use (slightly less than) that for the fps. 2. adjust the actual framerate, using waitKey(some_millis_left_over) )

berak gravatar imageberak ( 2017-12-21 11:30:57 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-03-24 04:15:51 -0500

Seen: 3,954 times

Last updated: Mar 24 '17