Ask Your Question

openCV3+Python3 reducing the FPS of input video file before processing

asked 2018-05-04 13:50:32 -0500

kzmn gravatar image

Hi.. I need to process some raw video files (mp4) on Raspberry Pi. I use cv2.VideoCapture and read functions to process the video frame by frame. The raw files have FPS of 30 which is too high for Raspberry Pi, and as a result when I process and display the video the result is much slower and a 30sec raw video will be now ~90 sec long. In my application I do not need high FPS, but it is very important that the length of the video remains the same. Could you please let me know how can I reduce FPS of raw video in my code before I loop over the frames? Also, is trial and error the only way to find the highest FPS at which Raspberri Pi will be able to process the video and display it in original video length? Thanks.

edit retag flag offensive close merge delete


This sounds like a camera frame rate control question to me, rather than an opencv question - OpenCV doesn't tend to provide camera feature control APIs. Often, an executable or library is available to change the camera settings (for example, picamera).

opalmirror gravatar imageopalmirror ( 2018-05-04 14:09:21 -0500 )edit

Thanks for your message. But I do not have any control on the raw videos, as they have already been recorded by cell phone and I am using them for processing. I need to find a specific approach to process these videos without changing the raw video files manually.

kzmn gravatar imagekzmn ( 2018-05-04 15:06:34 -0500 )edit

Ah, perhaps skipping frames as in the answer would work better.

opalmirror gravatar imageopalmirror ( 2018-05-04 15:11:25 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-05-04 14:44:28 -0500

I think you need to better explain what you want. You set the frame rate of the video you record. Try something like the following to record a video at fps:

fourcc = cv2.VideoWriter_fourcc(*'MJPG')                                    
video_out = cv2.VideoWriter('output.avi', fourcc, fps, img_size)

If you need to display at a frame rate that terminates when the original video would have (but at reduced fps), then keep track of the time and given the original frame rate, just drop frames as necessary.

edit flag offensive delete link more


Thanks for your response. The raw videos are recorded by cell phone and I am just processing them now. I tried to display and process only every 10th frame (and other numbers I tried too) but that did not solve the issue, plus it seems very random to me so I thought there might be a way for me to change the FPS of prerecorded video in openCV, before looping over every frame.

kzmn gravatar imagekzmn ( 2018-05-04 15:04:32 -0500 )edit

But that wouldn't solve anything. You can't process at the original frame rate, right? But you want to display the processed images as if they were processed at the original frame rate? The only way to do that is to save a video of the processed frames at the original frame rate and the play the video. Your only other option is to drop frames by monitoring your processing speed and comparing it to original frame rate, dropping input frames as necessary. Artificially slowing down the video in is moving the target. Why do you want what you say you want?

Der Luftmensch gravatar imageDer Luftmensch ( 2018-05-04 15:30:30 -0500 )edit

Question Tools

1 follower


Asked: 2018-05-04 13:50:32 -0500

Seen: 1,944 times

Last updated: May 04 '18