Ask Your Question
0

VideoWriter fps parameter

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

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.

Thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

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

berak gravatar image

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

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

Comments

@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 -0600 )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 -0600 )edit

Absolutely, berak.

supra56 gravatar imagesupra56 ( 2017-12-04 05:58:28 -0600 )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', 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
jsplyy gravatar imagejsplyy ( 2017-12-21 11:15:25 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 12,660 times

Last updated: Mar 24 '17