1. Introduction

The frames per second (FPS) is an important factor because it determines the quality and smoothness of a video. The FPS or frame rate plays an important role in many aspects like video editing, compression of video files, and smoother playback. Thus, knowing the FPS of a video file is important and helpful in all the above-mentioned tasks.

We can find the FPS of a video file using many tools. In this tutorial, we’ll find the FPS of a video file using some of the widely used media tools in the Linux community.

2. Environment Setup

Let’s download a sample video file using wget command. We’ll use the video file in our examples to extract FPS information:

$ wget https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_2mb.mp4

We’ll find the FPS of this downloaded video using FFmpeg and MediaInfo.

3. Using FFmpeg to Extract Frames per Second

FFmpeg is a popular and powerful open-source multimedia framework that supports a wide range of codecs and file formats. We can use FFmpeg for a variety of tasks, such as video and audio editing, retrieving information about video and audio files, streaming, and screen recording.

We can use apt or snap to install FFmpeg on an Ubuntu or Debian machine:

$ sudo apt install ffmpeg

The ffprobe component of FFmpeg can be used to find frames per second of a video file:

$ ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1 big_buck_bunny_720p_2mb.mp4

In the above example,

  • -v error sets the verbosity level to error
  • -select_streams v:0 selects the video stream
  • -show_entries stream=avg_frame_rate tells FFmpeg to display the average frame rate (frames per second) in the format of -of default=noprint_wrappers=1:nokey=1. This output format specifies that the output should be in the default format without any wrappers or key labels, and only the values of the keys should be printed.

Additionally, this command results in the value of avg_frame_rate for a given input video file that is expressed as a fraction like 30/1 or 25/1. The result 25/1 tells the average frame rate of this video file is 25 FPS (frame rate).

Overall, FFmpeg uses two different parameters for reporting the frame rate of video files: avg_frame_rate and r_frame_rate. Typically, we can use avg_frame_rate for constant frame rate videos having the constant frame rate throughout the video. The r_frame_rate is used to find the maximum frame rate in the video, while the actual frame rate may be lower. Let’s try with r_frame_rate option:

$ ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate -of default=noprint_wrappers=1:nokey=1 big_buck_bunny_720p_2mb.mp4

The above command uses r_frame_rate and displays the highest FPS (frame rate) in the video file.

3. Using MediaInfo to Extract Frames per Second

We can install the MediaInfo using snap or apt:

$ sudo apt install mediainfo

MediaInfo provides information in three different sections for the input video file: general, video, and audio. Let’s check out a basic command to retrieve the information of a video file:

$ mediainfo big_buck_bunny_720p_2mb.mp4

The FPS (frame rate) information will be in the video section of the output along with other information like video format, duration, bit rate, width, height, frame rate mode, etc. We can narrow down the output to only FPS or frame rate using grep:

$ mediainfo big_buck_bunny_720p_2mb.mp4 |grep "Frame rate"
Frame rate mode                          : Constant
Frame rate                               : 25.000 FPS
Frame rate                               : 46.875 FPS (1024 SPF)

Frame rate mode tells us whether the video file is with variable frame rate or with constant frame rate.  The following two Frame rate options are for video and audio streams, respectively. Thus, the input video file has 25 FPS with a constant frame rate throughout the video.

4. Conclusion

In this article, we learned how to find the FPS of a video file using FFmpeg and MediaInfo. We also discussed the different frame rate modes for video streams as well as ways to find FPS for each type of video stream from a given input file.

Comments are closed on this article!