"Ffmpeg basics" Chinese version - 3. bit rate, frame rate and file size

3. The bit rate, frame rate, and file size

bit rate: bit rate frame rate: Frame Rate file size: file size

The bit rate and frame rate are the basic characteristics of the video, and if they are reasonable values ​​directly related to the overall quality of the video. If we know the bit rate and duration of the output file of all media streams, we can calculate the final size of the output file. In the process we use ffmpeg tools, the correct understanding of the bit rate and frame rate is very important, we will be following the two terms do a simple description.

Frame rate presentation

The frame rate is the number of coding (frame per second, or FPS referred fps) video files contained in frames per second, we need at least to the naked eye form a continuous animation number per second 15 frames. Frame rate, also known as frame frequency, his unit is Hz, the average frequency of 60Hz LCD to display an image.

There are two types of frame rate: interlaced scanning (the number indicates the frame rate plus i), progressive scan (represented by the frame rate number plus p)

Interlaced frame rates commonly used in television:

  • 60i using the NTSC standard the frame rate is performed 60 times per second interlaced scan (each refresh half-frame), i.e. 30 frames refreshed
  • PAL and SECAM standards use 50i frame rate, which is 50 times per second interlaced, that refresh 25

Progressive scan is commonly used in the film industry, there is a common frame rate 24p, 25p, 30p. Updated 50p and 60p frame rate for high-end HDTV products.

Here Insert Picture Description

Frame Rate

Use the -r option

We can use the -r option to set the video frame rate, this option should be located before the output file, the syntax is as follows:

ffmpeg -i input -r fpt output

For example, the frame rate avi files from 25 to 30, the following commands:

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

When the input is used in the original format, this time before entering the -r option can also be placed.

Use fps filter

Another way is to use the frame rate set fps filter, it is very easy to use in the filterchain:

Here Insert Picture Description

For example, the frame rate of the file to the output file clip.mpg 25, the following commands:

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

Predefined values ​​frame rate

In addition to the specified frame rate than the direct use of digital, we can also use the following predefined values:

Here Insert Picture Description

For example, if you want to set the frame rate to 29.97, the following three commands can achieve the desired effect:

ffmpeg -i input.avi -r 29.97 output.mpg
ffmpeg -i input.avi -r 30000/1001 output.mpg
ffmpeg -i input.avi -r ntsc output.mpg

The bit rate of introduction

​ 比特率这个参数对视频和音频的整体质量有着很大的影响。它的含义是每时间单位内处理的数据比特量,在FFmpeg中,该时间单位是秒,也就是说,FFmpeg中的比特率指的是每秒处理的数据比特量。

​ 比特率一共可以分为三种:

  • 平均比特率(Average bit rate):简称ABR,顾名思义,就是指平均每秒中处理的数据比特量。当输出文件的大小是一个特定值时,平均比特率和可变比特率共同使用。

  • 常量比特率(Constant bit rate):简称CBR,即在每秒处理的数据比特量是个常量,这在存储中并不常用,这是因为画面快速变换的视频部分要比相对静止的部分需要更高的比特率。

  • 可变比特率(Variable bit rate):简称VBR,每秒处理的比特量是可变的,与CBR相比,这种方式会在复杂景象和声音的部分写入更多数据,因此在文件大小相同的前提下,VBR的质量要比CBR好。

    又译为:浮动比特率。

Here Insert Picture Description

设置比特率

​ 比特率决定了输出流中存储1秒编码数据所需要的比特量。我们使用 -b 选项来设置比特率,具体地,我们使用 -b:a 和 -b:v 形式分别指定音频流和视频流的比特率。例如,为输出设置一个整体的比特率(即所有流的比特率之和)为1.5M的命令如下所示:

ffmpeg -i film.avi -b 1.5M film.mp4

​ 如果可以,ffmpeg 会使用可变比特率,此时,会在动作变化快的部分使用较高的比特率,在较为静态的部分使用较低的比特率。ffmpeg经常利用更高级的编码格式,在良好保持其视频质量的前提下,降低比特率并减少输出文件的尺寸:

ffmpeg -i input.avi -b:v 1500k output.mp4

​ 这条命令将输出文件的视频流比特率修改成了1500K每秒。

设置常量比特率

Constant bit rate common usage scenarios are live streaming video, such as video conferencing, online live, etc., which is characterized by: data to be transferred at this time can not do caching. Want to set the output bit rate constant, the value must be the same as the following three parameters: -b specified bit rate, -minrate specified minimum bit rate, -maxrate specified maximum bit rate. -minrate and -maxrate stream descriptor may be used (first chapter describes). Need a -bufsize option (ie: rate control buffer size in bits) when setting maxrate options. To set, for example, CBR 0.5M second, ordered as follows:

ffmpeg -i in.avi -b 0.5M -minrate 0.5M -maxrate 0.5M -bufsize 1M out.mkv

Set the maximum size of the output file

In order to ensure that the output file size is not greater than a certain value, we can use the -fs option (the abbreviation file size) specifying the desired value in bytes. For example, specify the output file maximum size 10MB, the command is:

ffmpeg -i input.avi -fs 10MB output.mp4

File size calculations

The final size of the encoded output file is that all video and audio streams and the size. Video stream calculate the size (in bytes) for the equation (bits is divided into 8 bytes):

video_size = video_bitrate * time_in_seconds / 8

If the audio is uncompressed, audio stream computing equation is as follows:

audio_size = sampling_rate * bit_depth * channels * time_in_seconds / 8

If the audio is compressed, then we must know the bit rate of the audio stream to calculate its size:

audio_size = bitrate * time_in_seconds / 8

For example, a video, a length of 10 minutes, the video stream bit rate of 1500K / s, the audio stream bit rate of 128K / s, we can calculate the following manner:

file_size = video_size + audio_size
file_size = (video_bitrate + audio_bitrate) * time_in_seconds / 8
file_size = (1500 Kbit/s + 128Kbit/s) * 600s
file_size = 1628 Kbits/s * 600s
file_size = 976800 Kb = 976800000 b / 8 = 122199999 B / 8 = 119238.28125 KB = 			119238.28125 KB / 1024 = 116.443634033203125 MB = 116.44MB

In fact the resulting file size slightly larger than the calculated value, since the metadata file further comprises a header muxing data block associated with the file.

H&A
Released seven original articles · won praise 4 · Views 830

Guess you like

Origin blog.csdn.net/qq_34305316/article/details/102788119