FFmpeg Bit Rate and Frame Rate

A good understanding of the frame rate and the bit rate is important in the work with FFmpeg, frame rate and bit rate are the fundamental characteristics of the video and their proper setting is very important for the overall video quality.

FFmpeg version used in this tutorial :

ffmpeg version N-88555-g6ea7711532 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil      56.  0.100 / 56.  0.100
libavcodec     58.  1.100 / 58.  1.100
libavformat    58.  0.102 / 58.  0.102
libavdevice    58.  0.100 / 58.  0.100
libavfilter     7.  0.101 /  7.  0.101
libswscale      5.  0.101 /  5.  0.101
libswresample   3.  0.101 /  3.  0.101
libpostproc    55.  0.100 / 55.  0.100

 

Frame (frequency) rate

The frame rate is a number of frames per second (FPS or fps) encoded into a video file, the Frame rate is also called frame frequency and it’s unit is the Hertz (Hz), LCD displays have usually 60 Hz frequency.

There are 2 types of frame rates :

Interlaced (denoted as i after FPS number) :

  • NTSC standard used 60i fps, what means 60 interlaced fields (30 frames) per second
  • PAL and SECAM standards use 50i fps what means 50 interlaced fields, equals to 25 frames per second

progressive (denoted as p after FPS number) :

Progressive frame rates of 24p, 25p, and 30p are used in the film industry. Newer frame frequency 50p/60p is used in the High-end HDTV products.

Frame rate setting

Using -r Option

to set the video frame rate we use the -r option before the output file. the syntax is :

ffmpeg -i input -r fps output

So to change the frame rate of the film.avi file from 25 to 30 fps value, we use the command:

ffmpeg -i input.avi -r 30 output.mp4

Note: the -r option can be used also before the input.

Using fps video filter

Another way to set a frame rate is to use an fps filter, what is useful especially in the filterchains.

  • Syntax : fps=fps=number_of_frames

For example, to change the input frame rate of the clip.mpg file to the value 25, we use the command

ffmpeg -i clip.mpg -vf fps=fps=25 clip.webm

Predefined values for frame rate

beside numeric values, both methods for setting the frame rate accept also predefined values

AbbreviationExact valueCorresponding FPS
ntsc-film24000/100123.97
film24/124
pal,qpal,spal25/125
ntsc, qntsc, sntsc3000029.97

for example, to set the frame rate 25 fps, the next 3 commands give the same result:

ffmpeg -i input.avi -r 25 output.mpg
ffmpeg -i input.avi -r 25/1 output.mpg
ffmpeg -i input.avi -r pal output.mpg

Difference between -r and the fps filter

The algorithm of -r is different from video filter “fps”, which means ffmpeg will drop/duplicate different frames depending whether -r or video filter “fps” or both are in use. In constant frame rate, only certain length is allowed for a given frame rate; which means whenever the frame rate conversion occurs, inevitably there will be changes in video length as well; the change of video length is due to frame quantization or rounding in calculation. Video filter “fps”, unlike -r, cannot be used to specify the frame rate for a series of still images sequence; it is meant for frame rate conversion from a video with a given frame rate to another. by Werner Robitza

Bit (data) rate

Bit rate (also bitrate or data rate) it specifies the number of bits processed per time unit, in FFmpeg the bit rate is expressed in bits per second. and is a parameter that determines overall audio or video quality.

Setting bit rate

Bit rate determines how many bits are used to store 1 second of encoded streams, it is set with -b option, to differentiate audio and video stream it is recommended to use -b:a or -b:v forms. For example, to set an overall 1.5 Mbit per second-bit¶ rate, we can use the command:

ffmpeg -i video.avi -b 1.6M video.mp4

This command changes the input bitrate to 1600 kilobits per second.

Constant bit rate (CBR) setting

The constant bit rate is used for instance for live video streams, where the transferred data cannot be buffered. To set the constant bit rate for the output, three parameters must have the same value: bitrate (-b option), minimal rate (-minrate) and maximal rate (-maxrate). To minrate and maxrate options can be added a stream specifier, the maxrate option requires a setting of a -bufsize option. For example, to set the CBR of 0.5 Mbit/s, we can use the command:

ffmpeg -i input.avi -b 0.5M -minrate 0.5M -maxrate 0.5M -bufsize 1M output.mkv

What does -bufsize do?

Based on the -bufsize option, ffmpeg will calculate and correct the average bit rate produced. If we didn’t specify -bufsize, these intervals could be significantly longer than we would want. This would cause the current bit rate to frequently jump a lot over and below the specified average bit rate and would cause an unsteady output bit rate. read more (source ffmpeg.org)

Conclusion

The bit rate and frame rate are very important. Because if we know the bit rate and duration of all included media streams, we can calculate the final size of the output file.

Published by

qoraiche

Codecs Lover

Leave a Reply