# How to modify the FPS of a video when using cv::VideoCapture to read frames

**URL:** <https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430>\
**Category:** C++\
**Tags:** videoio\
**Created:** [May 19, 2021, 10:43pm UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430 "2021-05-19T22:43:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephane\_Charette](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/stephane_charette/32/1369_2.png) [@Stephane\_Charette](https://forum.opencv.org/u/Stephane_Charette)\
**Post date:** [May 19, 2021, 10:43pm UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430/1 "2021-05-19T22:43:44Z")

</div>

Using cv::VideoCapture to process videos. Wondering what the technique is for changing the frame rate when I write out a new video. I assume I could do something simple like drop every 2nd frame to cut from 60 FPS to 30 FPS.

But is that the right way to do it?  
Does that mean if I want to go from 30 FPS to 20 FPS I drop every 3rd frame?

Seems too simple. Is there any interpolation or re-interpretation of the frames that needs to happen between frames to make sure everything is smooth?

---

<div class="post-metadata">

**Author:** ![Stephane\_Charette](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/stephane_charette/32/1369_2.png) [@Stephane\_Charette](https://forum.opencv.org/u/Stephane_Charette)\
**Post date:** [May 20, 2021, 3:11am UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430/3 "2021-05-20T03:11:32Z")

</div>

So explain to me how it works then, if 2/3 \* 30 != 20.

But regardless of the number, I suspect that simply dropping every Nth frame is not the way to do it. What is the correct way to resample or change the FPS for video files?

---

<div class="post-metadata">

**Author:** ![mshabunin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mshabunin/32/15_2.png) [@mshabunin](https://forum.opencv.org/u/mshabunin)\
**Post date:** [May 20, 2021, 12:16pm UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430/4 "2021-05-20T12:16:20Z")

</div>

There are different approaches, simpler where frames are dropped or duplicated and more complex where frames can be interpolated. This functionality is built in many specialized video-processing libraries (e.g. FFmpeg - [ChangingFrameRate – FFmpeg](https://trac.ffmpeg.org/wiki/ChangingFrameRate), [https://www.reddit.com/r/ffmpeg/comments/dai5f1/smart\_resampling\_with\_ffmpeg/](https://www.reddit.com/r/ffmpeg/comments/dai5f1/smart_resampling_with_ffmpeg/)).

There are no ready-to-use functions for this in the OpenCV, but I believe it is possible to implement it using existing functionality.

---

<div class="post-metadata">

**Author:** ![matti.vuori](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@matti.vuori](https://forum.opencv.org/u/matti.vuori)\
**Post date:** [May 20, 2021, 3:09pm UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430/5 "2021-05-20T15:09:22Z")

</div>

I guess it should be noted that OpenCV is a CV tool and the idea is not to produce things that are nice to watch for humans, but video frames that are easy for computers to do things with - and any interpolation might not help with that

---

<div class="post-metadata">

**Author:** ![Stephane\_Charette](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/stephane_charette/32/1369_2.png) [@Stephane\_Charette](https://forum.opencv.org/u/Stephane_Charette)\
**Post date:** [May 20, 2021, 3:47pm UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430/6 "2021-05-20T15:47:47Z")

</div>

To be very clear: I wasn’t in any way expecting OpenCV to do this for me. I just happen to use OpenCV for most of my image manipulation, and I’m decently good at it. Since I do use the `cv::VideoCapture` class to read video files, I figured I would ask if anyone happened to know the name or the technique used to alter the FPS.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [May 20, 2021, 8:12pm UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430/7 "2021-05-20T20:12:32Z")

</div>

> [@Stephane\_Charette](#):
>
> the name or the technique used to alter the FPS.

depends on what effect you want to achieve.

say you have _one_ minute of video at _30 fps_.

do you want

- _two_ minutes at 15 fps: same number of frames, just played slower
- one minute at _15 fps_: same duration but half the frames are dropped (not shown)
- _two_ minutes at _30 fps_: double the frame count, interpolated frames are inserted

?

---

<div class="post-metadata">

**Author:** ![Stephane\_Charette](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/stephane_charette/32/1369_2.png) [@Stephane\_Charette](https://forum.opencv.org/u/Stephane_Charette)\
**Post date:** [May 20, 2021, 8:14pm UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430/8 "2021-05-20T20:14:21Z")

</div>

Let’s say I want my 1 minute @ 30 FPS video to be converted to 1 minute @ 25 FPS.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [May 20, 2021, 8:17pm UTC](https://forum.opencv.org/t/how-to-modify-the-fps-of-a-video-when-using-cv-videocapture-to-read-frames/3430/9 "2021-05-20T20:17:00Z")

</div>

> [@Stephane\_Charette](#):
>
> 1 minute @ 30 FPS video to be converted to 1 minute @ 25 FPS

okay, you have the choice of

- keeping 5 of every 6 frames, and dropping the 6th, which looks jittery/jerky
- interpolating new frames at precise times, taking “adjacent” frames from the source and interpolating linearly, which causes time-varying exposure, i.e. weird motion blur
- interpolating, but using using optical flow to calculate the frames (“state of the art”)
