Ask Your Question

Can I change the fps of a video dynamically?

asked 2018-02-05 14:11:30 -0500

aniket03 gravatar image

updated 2020-07-23 04:07:18 -0500

I am using VideoWriter in python with opencv3.4. I wanted to change the fps of a video dynamically. Presently I am using out = cv2.VideoWriter('output.avi',fourcc,60.0, (848,480)) where 60.0 is the fps. Is it possible that at some part of my code , I can change it to 30fps and then back to 60fps or something else at some other part of the code?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2018-02-06 04:01:09 -0500

kbarni gravatar image

You can simulate the other framerates. For example, if you want 30fps stream on a 60fps video, just add each frame twice.

while not endOfMyVideo:
    #get the frame to write...
    if fps==60:
    elif fps==30:

For other frame rates you can duplicate only certain frames:

while not endOfMyVideo:
    #get the frame to write...
   if outputframe-inputframe>1:
        out.write(frame) //we need to duplicate this frame
    inputframe=inputframe+1 #get to the next frame

This is a simple solution, for better results you might interpolate the subsequent frames.

On the other hand, this will be a "pseudo" framerate, it won't really change the real framerate of the AVI file. So you can't change the framerate of a 30fps avi to 60fps just to add some high quality video (but you can downsample the 60fps video to 30fps by taking every second frame. The code above can be adapted to this situation too.)

edit flag offensive delete link more

answered 2020-07-14 08:00:48 -0500

urvi gravatar image

You can go through my code where I have done it using seconds of current time as a dynamic parameter.

Also, keep in mind that fps can't increase beyond its max(for a particular video it's fps is fixed when played in 1x speed).

Hope this helps. <3

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-02-05 14:11:30 -0500

Seen: 3,188 times

Last updated: Jul 14