﻿ How to Find the Frames Per Second in a Video in Python using OpenCV ﻿

How to Find the Frames Per Second in a Video in Python using OpenCV

In this article, we show how to find the frames per second in a video in Python using the OpenCV module.

OpenCV has a number of built-in features that allow us to extract data from a video.

One of the features we can get is the frames per second (FPS) there are in a video.

Frames are the images that make up a video. A video is a series of images shown in sequence. The frames per second tells us how many images there are per second of video.

To find the frames per second of a video using OpenCV, we use the following statement, cv2.CAP_PROP_FPS

This will get the frames per second in a video using OpenCV.

To see this in actual code, see the code below.

First we create a cap variable, which connects us to the video that we want to process.

Next, we create a variable, framespersecond, which will store the frames per second of this video, princess.mp4.

Next, we print out the frames per second in the video.

The frames per second is a very important piece of data because it is related to the speed that the video needs to played at in order to played at a rate that is human watchable. The frames per second represents the frequency, meaning the number of images that appear per second. Going back to the classic science formula, the time period, T= 1/f. So using this formula, we can calculate how much delay we need to insert into a video based on the frames per second of the video. This is the real usefulness of frames per second. Knowing this, we can do this simple calculation to find out how much delay we need to give a video in order to slow it down enough to make it human watchable.

Going over some examples let's say that a certain video has a FPS of 20.

Doing the math, this gives a time period, T= 1/f = 1/20= 0.05 seconds

Let's say another video has a FPS of 50.

Doing the math, this gives a time period, T= 1/f= 1/50= 0.02 seconds.

So you can see that if a video has a greater FPS, there is less time delay needed.

So you can see how the frames per second of a video factors in to let us know how fast to play a video. Based on the FPS, we can figure out the time period needed for each package of frames per second in order to play a video smoothly.

The reason that we need to introduce a time delay is because computers can play videos fast, very fast, much faster than our eyes can watch a video. In order to make a video human watchable, we need to introduce time delay to slow it down. To know the time delay needed, we calculate it based off the FPS, which can be found according to the formula, T= 1/f. That's why all of this is important.

And this is how we can find the frames per second of a video in Python using the OpenCV module.

Related Resources