Ask Your Question
0

changing the fps of a video?

asked 2019-06-16 20:47:25 -0600

prb gravatar image

I have some demo videos with the FPS=60. I would like to change the FPS to 30. I am using OpenCV 3.4.I used the following code. This is just a snippet of the code.

 while True:
        cap = cap.set(cv2.CV_CAP_PROP_FPS, 30) 
        ret,frame = cap.read()
        fps = cap.get(cv2.CAP_PROP_FPS)
        print(fps)

But I am getting the following error:

AttributeError: module 'cv2.cv2' has no attribute 'CV_CAP_PROP_FPS'

I would appreciate any help any help. Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-06-16 21:18:02 -0600

updated 2019-06-16 22:13:19 -0600

You are using two different flags cv2.CV_CAP_PROP_FPS and cv2.CAP_PROP_FPS. The correct flag is cv2.CAP_PROP_FPS and change it to so when setting your cap.

EDIT I

Read this to understand how FPS works. One way of achieving what you want is to simply add a delay in your loop that reads the frames using cv2.waitKey(delay_time). If you set delay_time=50 then FPS will be 1000/50 = 20. So for your case you could set a delay_time = 100 to get 10FPS.

edit flag offensive delete link more

Comments

@eshirima thanks for pointing out the mistake. I just corrected the code. But after checking the fps it does not change after setting it.

while True:
        cap.set(cv2.CAP_PROP_FPS,10) 
        ret,frame = cap.read()
        print(cap.get(cv2.CAP_PROP_FPS))

This still prints FPS=30. I would like to have it 10. Is my approach correct?

prb gravatar imageprb ( 2019-06-16 21:49:19 -0600 )edit

@prb see the edit!

eshirima gravatar imageeshirima ( 2019-06-16 22:09:25 -0600 )edit
1

@eshirima thank you very much for your detailed answer. Actually, this is making my output video very slow. I think I need to skip some frames.

prb gravatar imageprb ( 2019-06-17 00:05:26 -0600 )edit
1

As the name says, CAP_PROP_FPS sets the frame rate of CAPturing. This is in fact a parameter of the camera. Resolution, exposure time are similar: you can change it as a camera parameter, but for a video file, you can't change it. You can only simulate it, for example by resizing the frames you read.

For reading videos, just add the delay, as @eshirima said.

kbarni gravatar imagekbarni ( 2019-06-17 03:01:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-06-16 20:47:25 -0600

Seen: 22,638 times

Last updated: Jun 16 '19