Ask Your Question

Can I change the fps of a video dynamically?

asked 2018-02-05 14:11:30 -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 2018-02-05 14:13:28 -0500

berak gravatar image

updated 2018-02-05 14:17:54 -0500

no, you can't.

(if you're looking for a general video-editing software, you're in the wrong place)

edit flag offensive delete link more


Is there any other way to achieve this, like extracting frames of a video file and carrying out some manipulations with them?

aniket03 gravatar imageaniket03 ( 2018-02-05 16:12:13 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 1,791 times

Last updated: Feb 06 '18