18

FFmpeg 命令行工具 - 帮助和码率、帧率和文件大小

 3 years ago
source link: http://blog.danthought.com/programming/2020/11/14/ffmpeg-tools-help-and-fundamental-characteristics/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

FFmpeg 命令行工具 - 帮助和码率、帧率和文件大小

这篇文章讲解 FFmpeg 命令行工具中如何查看帮助,以及关于码率、帧率和文件大小的概念和用法。

Editing Video

基础帮助和完整帮助

ffmpeg -h
ffmpeg -h full

针对特定主题的帮助,比如编码器

ffmpeg -bsfs
ffmpeg -codecs
ffmpeg -decoders
ffmpeg -encoders
ffmpeg -filters
ffmpeg -formats
ffmpeg -layouts
ffmpeg -L
ffmpeg -pix_fmts
ffmpeg -protocols
ffmpeg -sample_fmts
ffmpeg -version

针对特定条目的帮助,比如 FLV 解码器

ffmpeg -h decoder=flv

码率、帧率和文件大小

帧率是每秒的帧数,决定流畅度,人眼至少需要帧率为 15 才能感知到连续动画。

帧率通过 -r 来指定:

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

码率是每秒的比特数,决定质量。

  • Average bit rate, ABR, 平均码率:每秒处理的平均比特数量。
  • Constant bit rate, CBR, 固定码率:通常用于流媒体,而不是文件。
  • Variable bit rate, VBR, 变化码率:每秒处理的比特数量是变化的,运动画面需要更多的比特数量,静止画面需要较少的比特数量,同样的文件大小,VBR 比 CBR 的画面质量更好,但也需要更多运算时间和运算资源。

码率通过 -b 来指定, -b:a 针对音频,-b:v 针对视频:

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

CBR 设置

-b-minrate-maxrate 三项需要设置相同的值,-maxrate 还需要 -bufsize 来控制缓存大小:

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

输出文件大小通过 -fs 来指定:

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

编码视频的大小计算:

video_size = video_bitrate * time_in_seconds / 8

没有编码音频的大小计算:

audio_size = sampling_rate * bit_depth * channels * time_in_seconds / 8

编码音频的大小计算:

audio_size = bitrate * time_in_seconds / 8

For example to calculate the final size of 10-minutes video clip with the 1500 kbits/s video bit rate and 128 kbits/s audio bitrate, we can use the equations:

file_size = video_size + audio_size
file_size = (video_bitrate + audio_bitrate) * time_in_seconds / 8
file_size = (1500 kbit/s + 128 kbits/s) * 600 s
file_size = 1628 kbit/s * 600 s
file_size = 976800 kb = 976800000 b / 8 = 122100000 B / 1024 = 119238.28125 KB
file_size = 119238.28125 KB / 1024 = 116.443634033203125 MB ≈ 116.44 MB

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK