1 FFmpeg从入门到精通-FFmpeg简介

1 FFmpeg从入门到精通-FFmpeg简介
2 FFmpeg从入门到精通-FFmpeg工具使用基础
3 FFmpeg从入门到精通-FFmpeg转封装
4 FFmpeg从入门到精通-FFmpeg转码
5 FFmpeg从入门到精通-FFmpeg流媒体
6 FFmpeg从入门到精通-FFmpeg滤镜使用
7 FFmpeg从入门到精通-FFmpeg中Linux设备操作
8 FFmpeg从入门到精通-FFmpeg接口libavformat的使用
9 FFmpeg从入门到精通-FFmpeg接口libavcodec的使用
10 FFmpeg从入门到精通-FFmpeg接口libavfilter的使用

1.FFmpeg简介

  1.1 FFmpeg的定义

    FFmpeg既是一款音视频编解码工具,同时也是一组音视频编解码开发套件,作为编解码开发套件,它为开发者提供了丰富的音视频处理的调用接口。
    FFmpeg提供了多种媒体格式的封装和解封装,包括多种音视频编码、多种协议的流媒体、多种色彩格式转换、多种采样率转换、多种码率转换等;FFmpeg框架提供了多种丰富的插件模块,包含封装与解封装的插件、编码与解码的插件等。

  1.2 FFmpeg的历史

    想要深入了解一个软件、一个系统,首先要了解其发展史,下面就来介绍一下FFmpeg的整体发展过程。
    作为一套开源的音视频编解码套件,FFmpeg可以通过互联网自由获取。FFmpeg的源码Git库提供了多站同步的获取方式,具体如下。
    ·git://source.ffmpeg.org/ffmpeg.git
    ·http://git.videolan.org/?p=ffmpeg.git
    ·https://github.com/FFmpeg/FFmpeg
    FFmpeg发展至今,已经被许多开源项目所采用,如ijkplayer、ffmpeg2theora、VLC、MPlayer、HandBrake、Blender、Google Chrome等。DirectShow/VFW的ffdshow(外部工程)和QuickTime的Perian(外部工程)也采用了FFmpeg。由于FFmpeg是在LGPL/GPL协议下发布的(如果使用了GPL协议发布的模块则必须采用GPL协议),任何人都可以自由使用,但必须严格遵守LGPL/GPL协议。

  1.3 FFmpeg的基本组成

    FFmpeg框架的基本组成包含AVFormat、AVCodec、AVFilter、AVDevice、AVUtil等模块库,结构如图1-1所示。
在这里插入图片描述

  1.3.1 FFmpeg的封装模块AVFormat

    AVFormat中实现了目前多媒体领域中的绝大多数媒体封装格式,包括封装和解封装,如MP4、FLV、KV、TS等文件封装格式,RTMP、RTSP、MMS、HLS等网络协议封装格式。FFmpeg是否支持某种媒体封装格式,取决于编译时是否包含了该格式的封装库。根据实际需求,可进行媒体封装格式的扩展,增加自己定制的封装格式,即在AVFormat中增加自己的封装处理模块。

  1.3.2 FFmpeg的编解码模块AVCodec

    AVCodec中实现了目前多媒体领域绝大多数常用的编解码格式,既支持编码,也支持解码。AVCodec除了支持MPEG4、AAC、MJPEG等自带的媒体编解码格式之外,还支持第三方的编解码器,如H.264(AVC)编码,需要使用x264编码器;H.265(HEVC)编码,需要使用x265编码器;MP3(mp3lame)编码,需要使用libmp3lame编码器。如果希望增加自己的编码格式,或者硬件编解码,则需要在AVCodec中增加相应的编解码模块。

  1.3.3 FFmpeg的滤镜模块AVFilter

    AVFilter库提供了一个通用的音频、视频、字幕等滤镜处理框架。在AVFilter中,滤镜框架可以有多个输入和多个输出。我们参考下面这个滤镜处理的例子,如图1-2所示。
在这里插入图片描述
    图1-2所示样例中的滤镜处理将输入的视频切割成了两部分流,一部分流抛给crop滤镜vflip滤镜处理模块进行操作,另一部分保持原样,当crop滤镜vflip滤镜处理操作完成之后,将流合并到原有的overlay图层中,并显示在最上面一层,输出新的视频。对应的命令行如下:

ffmpeg -i INPUT -vf "split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2" OUTPUT
ffmpeg -i 1.jpg -vf "split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2" 2.jpg

    下面看一下具体的执行情况,以验证该命令的可行性:

ffmpeg version 2022-11-23-git-c8e9cc8d20-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57. 43.100 / 57. 43.100
  libavcodec     59. 54.100 / 59. 54.100
  libavformat    59. 34.102 / 59. 34.102
  libavdevice    59.  8.101 / 59.  8.101
  libavfilter     8. 50.101 /  8. 50.101
  libswscale      6.  8.112 /  6.  8.112
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    56.  7.100 / 56.  7.100
Input #0, image2, from '1.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 4804 kb/s
  Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 360x320 [SAR 1:1 DAR 9:8], 25 fps, 25 tbr, 25 tbn
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b1fd6ac0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b1ff2340] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b200d440] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b239cac0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23af840] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23cdf00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23e97c0] deprecated pixel format used, make sure you did set range correctly
    Last message repeated 1 times
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23c5f00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b20018c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b200e8c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b1fd6d00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23900c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b239d080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b1fd6140] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23900c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b239d080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23e97c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23f67c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b2009900] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b1fc7540] [swscaler @ 000001b4b23ba080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b2009900] [swscaler @ 000001b4b1fc7540] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b2009900] [swscaler @ 000001b4b1fd6140] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b2009900] [swscaler @ 000001b4b23e97c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b2009900] [swscaler @ 000001b4b23f67c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b2009900] [swscaler @ 000001b4b1fe3b40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b2009900] [swscaler @ 000001b4b23900c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001b4b2009900] [swscaler @ 000001b4b23a1080] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '2.jpg':
  Metadata:
    encoder         : Lavf59.34.102
  Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown, progressive), 360x320 [SAR 1:1 DAR 9:8], q=2-31, 200 kb/s, 25 fps, 25 tbn
    Metadata:
      encoder         : Lavc59.54.100 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
[image2 @ 000001b4b1f65a40] The specified filename '2.jpg' does not contain an image sequence pattern or a pattern is invalid.
[image2 @ 000001b4b1f65a40] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.
frame=    1 fps=0.0 q=4.7 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=   0x
video:11kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

    以上内容输出完成,该命令将自动退出,生成的视频结果是保留视频的上半部分,同时上半部分会镜像到视频的下半部分,二者合成之后作为输出视频,如图1-3所示。
在这里插入图片描述
    下面详细说明一下规则,具体如下。
    ·相同的Filter线性链之间用逗号分隔
    ·不同的Filter线性链之间用分号分隔
    在以上示例中,crop与vflip使用的是同一个滤镜处理的线性链,split滤镜和overlay滤镜使用的是另外一个线性链,一个线性链与另一个线性链汇合时是通过方括号“[]”括起来的标签进行标示的。在这个例子中,两个流处理后是通过[main]与[flip]进行关联汇合的。
    split滤镜将分割后的视频流的第二部分打上标签[tmp],通过crop滤镜对该部分流进行处理,然后进行纵坐标调换操作,打上标签[flip],然后将[main]标签与[flip]标签进行合并,[flip]标签的视频流从视频的左边最中间的位置开始显示,这样就出现了镜像效果,如上图所示。

  1.3.4 FFmpeg的视频图像转换计算模块swscale

    swscale模块提供了高级别的图像转换API,例如它允许进行图像缩放和像素格式转换,常见于将图像从1080p转换成720p或者480p等的缩放,或者将图像数据从YUV420P转换成YUYV,或者YUV转RGB等图像格式转换。

  1.3.5 FFmpeg的音频转换计算模块swresample

    swresample模块提供了高级别的音频重采样API。例如它允许操作音频采样、音频通道布局转换与布局调整。

  1.4 FFmpeg的编解码工具ffmpeg

    ffmpeg是FFmpeg源代码编译后生成的一个可执行程序,其可以作为命令行工具使用。本节将通过实际的示例分析,对ffmpeg编解码工具的使用方法进行详细的介绍。
    首先列举一个简单的例子:

ffmpeg -i input.mp4 output.avi

    这条命令行执行过程输出如下:

ffmpeg version 2022-11-23-git-c8e9cc8d20-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57. 43.100 / 57. 43.100
  libavcodec     59. 54.100 / 59. 54.100
  libavformat    59. 34.102 / 59. 34.102
  libavdevice    59.  8.101 / 59.  8.101
  libavfilter     8. 50.101 /  8. 50.101
  libswscale      6.  8.112 /  6.  8.112
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    56.  7.100 / 56.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf54.6.100
  Duration: 00:04:13.00, start: 0.000000, bitrate: 511 kb/s
  Stream #0:0[0x1](und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 505 kb/s, 5 fps, 5 tbr, 5 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 3 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, avi, to 'output.avi':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    ISFT            : Lavf59.34.102
  Stream #0:0(und): Video: mpeg4 (FMP4 / 0x34504D46), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 5 fps, 5 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.54.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.54.100 libmp3lame
frame= 1265 fps=426 q=31.0 Lsize=   10729kB time=00:04:12.80 bitrate= 347.7kbits/s speed=85.1x
video:6512kB audio:3950kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.554561%

    这是一条简单的ffmpeg命令,可以看到,ffmpeg通过-i参数将input.mp4作为输入源输入,然后进行转码与转封装操作,输出到output.avi中,这条命令主要做了如下工作。
    1)获得输入源input.mp4。
    2)转码。
    3)输出文件output.avi。
    看似简单的两步主要的工作,其实远远不止是从后缀名为MP4的文件输出成后缀名为AVI的文件,因为在ffmpeg中,MP4与AVI是两种文件封装格式,并不是后缀名就可以决定的,例如上面的命令行同样可以写成这样:

ffmpeg -i input.mp4 -f avi output.dat

    这条命令行执行过程输出如下:

ffmpeg version 2022-11-23-git-c8e9cc8d20-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57. 43.100 / 57. 43.100
  libavcodec     59. 54.100 / 59. 54.100
  libavformat    59. 34.102 / 59. 34.102
  libavdevice    59.  8.101 / 59.  8.101
  libavfilter     8. 50.101 /  8. 50.101
  libswscale      6.  8.112 /  6.  8.112
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    56.  7.100 / 56.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf54.6.100
  Duration: 00:04:13.00, start: 0.000000, bitrate: 511 kb/s
  Stream #0:0[0x1](und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 505 kb/s, 5 fps, 5 tbr, 5 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 3 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, avi, to 'output.dat':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    ISFT            : Lavf59.34.102
  Stream #0:0(und): Video: mpeg4 (FMP4 / 0x34504D46), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 5 fps, 5 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.54.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.54.100 libmp3lame
frame= 1265 fps=431 q=31.0 Lsize=   10729kB time=00:04:12.80 bitrate= 347.7kbits/s speed=86.2x
video:6512kB audio:3950kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.554561%

    这条ffmpeg命令相对于前面的那条命令做了一些改变,加了一个“-f”进行约束,“-f”参数的工作非常重要,它制定了输出文件的容器格式,所以可以看到输出的文件为output.dat,文件后缀名为.dat,但是其主要工作依然与之前的指令相同。
    分析以上两个输出信息中的Output#0部分,可以看到输出的都是AVI,只是输出的文件名不同,其他内容均相同。
    ffmpeg的主要工作流程相对比较简单,具体如下。
    1)解封装(Demuxing)。
    2)解码(Decoding)。
    3)编码(Encoding)。
    4)封装(Muxing)。
    其中需要经过6个步骤,具体如下。
    1)读取输入源。
    2)进行音视频的解封装。
    3)解码每一帧音视频数据。
    4)编码每一帧音视频数据。
    5)进行音视频的重新封装。
    6)输出到目标。
    ffmpeg整体处理的工作流程与步骤如图1-4所示。

在这里插入图片描述
    从图1-4所示的工作流程可以看出,ffmpeg首先读取输入源;然后通过Demuxer将音视频包进行解封装,这个动作通过调用libavformat中的接口即可实现;接下来通过Decoder进行解码,将音视频通过Decoder解包成为YVU或者PCM这样的数据,Decoder通过libavcodec中的接口即可实现;然后通过Encoder将对应的数据进行编码,编码可以通过libavcodec中的接口来实现;接下来将编码后的音视频数据包通过Muxer进行封装,Muxer封装通过libavformat中的接口即可实现,输出成为输出流

  1.5 FFmpeg的播放器ffplay

    FFmpeg不但可以提供转码、转封装等功能,同时还提供了播放器相关功能,使用FFmpeg的avformat与avcodec,可以播放各种媒体文件或者流。如果想要使用ffplay,那么系统首先需要有SDL来进行ffplay的基础支撑。
    ffplay是FFmpeg源代码编译后生成的另一个可执行程序,与ffmpeg在FFmpeg项目中充当的角色基本相同,可以作为测试工具进行使用,ffplay提供了音视频显示和播放相关的图像信息、音频的波形信息等
    注意:
    有时通过源代码编译生成ffplay不一定能够成功,因为ffplay在旧版本时依赖于SDL-1.2,而ffplay在新版本时依赖于SDL-2.0,需要安装对应的SDL才能生成ffplay。

  1.6 FFmpeg的多媒体分析器ffprobe

    ffprobe也是FFmpeg源码编译后生成的一个可执行程序。ffprobe是一个非常强大的多媒体分析工具,可以从媒体文件或者媒体流中获得你想要了解的媒体信息,比如音频的参数、视频的参数、媒体容器的参数信息等
    例如它可以帮助分析某个媒体容器中的音频是什么编码格式、视频是什么编码格式,同时还可以得到媒体文件中媒体的总时长、复合码率等信息。
    使用ffprobe可以分析媒体文件中每个包的长度、包的类型、帧的信息等。后面章节将会对ffprobe进行详细的介绍,下面列举一个简单的例子,以对ffprobe有一个基本的概念:

ffprobe –show_streams input.mp4

    命令行执行之后将会输出如下内容:

[STREAM]
index=0
codec_name=mpeg4
codec_long_name=MPEG-4 part 2
profile=Simple Profile
codec_type=video
codec_tag_string=mp4v
codec_tag=0x7634706d
width=1280
height=720
coded_width=1280
coded_height=720
closed_captions=0
film_grain=0
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=3
color_range=unknown
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=unknown
refs=1
quarter_sample=false
divx_packed=false
id=0x1
r_frame_rate=5/1
avg_frame_rate=5/1
time_base=1/5
start_pts=0
start_time=0.000000
duration_ts=1265
duration=253.000000
bit_rate=505923
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=1265
nb_read_frames=N/A
nb_read_packets=N/A
extradata_size=43
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
TAG:language=und
TAG:handler_name=VideoHandler
TAG:vendor_id=[0][0][0][0]
[/STREAM]
[STREAM]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=LC
codec_type=audio
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=fltp
sample_rate=44100
channels=2
channel_layout=stereo
bits_per_sample=0
initial_padding=0
id=0x2
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/44100
start_pts=0
start_time=0.000000
duration_ts=11146240
duration=252.749206
bit_rate=3101
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=10886
nb_read_frames=N/A
nb_read_packets=N/A
extradata_size=2
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
TAG:language=und
TAG:handler_name=SoundHandler
TAG:vendor_id=[0][0][0][0]
[/STREAM]

    根据输出内容可以看到,使用ffprobe能够查看MP4文件容器中的流的信息,其包含了一个视频流,由于该文件中只有视频流,流相关的信息是通过[STREAM][/STREAM]的方式展现出来的,在[STREAM]与[/STREAM]之间的信息即为该MP4文件的视频流信息。当视频文件容器中包含音频流与视频流或者更多路流时,会通过[STREAM]与[/STREAM]进行多个流的分隔,分隔后采用index来进行流的索引信息的区分。

  1.7 FFmpeg编译

    FFmpeg在官方网站中提供了已经编译好的可执行文件。因为FFmpeg是开源的,所以也可以根据自己的需要进行手动编译。FFmpeg官方建议用户自行编译使用FFmpeg的最新版本,因为对于一些操作系统,比如Linux系统(无论是Ubuntu还是RedHat),如果使用系统提供的软件库安装ffmpeg时会发现其版本相对比较老旧,比如使用apt-get install ffmpeg或者yum install ffmpeg安装ffmpeg,那么默认支持的版本都很老,有些新的功能并不支持,如一些新的封装格式或者通信协议。

  1.7.1 FFmpeg之Windows平台编译

    FFmpeg在Windows平台中的编译需要使用MinGW-w64,如果不希望使用MinGW而使用Visual Studio的话,则需要消耗很多时间来支持Visual Studio平台,感兴趣的读者可以在网上查找一下支持的方法。截至本书结稿之时,官方提供的Windows的开发包是使用MinGW-w64工具链编写的。
MinGW-w64单独使用起来会比较麻烦,但是其可以与MSYS环境配合使用,其主要完成的工作为UNIX on Windows的功能。显而易见,这是一个仿生UNIX环境的Windows工具集,它的详细介绍和使用方法可以参照http://www.mingw.org/wiki/MSYS。
    MinGW-w64+MSYS环境准备好之后,我们就可以正式进入编译的环节了。
    1)进入FFmpeg源码目录,执行“./configure”,如果一切正常,我们会看到如下信息:
    2)configure成功后执行make,在MinGW环境下编译ffmpeg是一个比较漫长的过程。
    3)执行make install,到此为止,FFmpeg在Windows上的编译已全部完成,此时我们可以尝试使用FFmpeg命令行来验证编译结果。执行“./ffmpeg.exe–h”:
    注意:
    以上编译配置方式编译出来的ffmpeg仅仅只是最简易的ffmpeg,并没有H.264、H.265、加字幕等编码支持,如果需要支持更多的模块和参数,还需要进行更加详细的定制,后面会有详细的介绍。也可自行搜索
    附录1.Windows下MSVC编译FFmpeg

  1.7.2 FFmpeg之Linux平台编译

    前面介绍过,很多Linux的发行版本源中已经包含了FFmpeg,如Ubuntu/Fedora的镜像源中包含了FFmpeg的安装包,但是版本相对来说比较老旧,有些甚至还不支持H.264、H.265编码,或者不支持RTMP等,为了支持这些协议格式和编码格式,需要自己手动编译FFmpeg,默认编译FFmpeg的时候,需要用到yasm汇编器对FFmpeg中的汇编部分进行编译。也可自行搜索
    附录2 FFmpeg从入门到精通-Linux下编译FFmpeg

  1.8 FFmpeg编码支持与定制

    FFmpeg本身支持一些音视频编码格式、文件封装格式与流媒体传输协议,但是支持的数量依然有限,FFmpeg所做的只是提供一套基础的框架,所有的编码格式、文件封装格式与流媒体协议均可以作为FFmpeg的一个模块挂载在FFmpeg框架中。这些模块以第三方的外部库的方式提供支持,可以通过FFmpeg源码的configure命令查看FFmpeg所支持的音视频编码格式、文件封装格式与流媒体传输协议,对于FFmpeg不支持的格式,可以通过configure --help查看所需要的第三方外部库,然后通过增加对应的编译参数选项进行支持。帮助信息内容输出如下:

External library support:

  Using any of the following switches will allow FFmpeg to link to the
  corresponding external library. All the components depending on that library
  will become enabled, if all their other dependencies are met and they are not
  explicitly disabled. E.g. --enable-libopus will enable linking to
  libopus and allow the libopus encoder to be built, unless it is
  specifically disabled with --disable-encoder=libopus.

  Note that only the system libraries are auto-detected. All the other external
  libraries must be explicitly enabled.

  Also note that the following help text describes the purpose of the libraries
  themselves, not all their features will necessarily be usable by FFmpeg.

  --disable-alsa           disable ALSA support [autodetect]
  --disable-appkit         disable Apple AppKit framework [autodetect]
  --disable-avfoundation   disable Apple AVFoundation framework [autodetect]
  --enable-avisynth        enable reading of AviSynth script files [no]
  --disable-bzlib          disable bzlib [autodetect]
  --disable-coreimage      disable Apple CoreImage framework [autodetect]
  --enable-chromaprint     enable audio fingerprinting with chromaprint [no]
  --enable-frei0r          enable frei0r video filtering [no]
  --enable-gcrypt          enable gcrypt, needed for rtmp(t)e support
                           if openssl, librtmp or gmp is not used [no]
  --enable-gmp             enable gmp, needed for rtmp(t)e support
                           if openssl or librtmp is not used [no]
  --enable-gnutls          enable gnutls, needed for https support
                           if openssl, libtls or mbedtls is not used [no]
  --disable-iconv          disable iconv [autodetect]
  --enable-jni             enable JNI support [no]
  --enable-ladspa          enable LADSPA audio filtering [no]
  --enable-lcms2           enable ICC profile support via LittleCMS 2 [no]
  --enable-libaom          enable AV1 video encoding/decoding via libaom [no]
  --enable-libaribb24      enable ARIB text and caption decoding via libaribb24 [no]
  --enable-libass          enable libass subtitles rendering,
                           needed for subtitles and ass filter [no]
  --enable-libbluray       enable BluRay reading using libbluray [no]
  --enable-libbs2b         enable bs2b DSP library [no]
  --enable-libcaca         enable textual display using libcaca [no]
  --enable-libcelt         enable CELT decoding via libcelt [no]
  --enable-libcdio         enable audio CD grabbing with libcdio [no]
  --enable-libcodec2       enable codec2 en/decoding using libcodec2 [no]
  --enable-libdav1d        enable AV1 decoding via libdav1d [no]
  --enable-libdavs2        enable AVS2 decoding via libdavs2 [no]
  --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
                           and libraw1394 [no]
  --enable-libfdk-aac      enable AAC de/encoding via libfdk-aac [no]
  --enable-libflite        enable flite (voice synthesis) support via libflite [no]
  --enable-libfontconfig   enable libfontconfig, useful for drawtext filter [no]
  --enable-libfreetype     enable libfreetype, needed for drawtext filter [no]
  --enable-libfribidi      enable libfribidi, improves drawtext filter [no]
  --enable-libglslang      enable GLSL->SPIRV compilation via libglslang [no]
  --enable-libgme          enable Game Music Emu via libgme [no]
  --enable-libgsm          enable GSM de/encoding via libgsm [no]
  --enable-libiec61883     enable iec61883 via libiec61883 [no]
  --enable-libilbc         enable iLBC de/encoding via libilbc [no]
  --enable-libjack         enable JACK audio sound server [no]
  --enable-libjxl          enable JPEG XL de/encoding via libjxl [no]
  --enable-libklvanc       enable Kernel Labs VANC processing [no]
  --enable-libkvazaar      enable HEVC encoding via libkvazaar [no]
  --enable-liblensfun      enable lensfun lens correction [no]
  --enable-libmodplug      enable ModPlug via libmodplug [no]
  --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
  --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
  --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
  --enable-libopencv       enable video filtering via libopencv [no]
  --enable-libopenh264     enable H.264 encoding via OpenH264 [no]
  --enable-libopenjpeg     enable JPEG 2000 de/encoding via OpenJPEG [no]
  --enable-libopenmpt      enable decoding tracked files via libopenmpt [no]
  --enable-libopenvino     enable OpenVINO as a DNN module backend
                           for DNN based filters like dnn_processing [no]
  --enable-libopus         enable Opus de/encoding via libopus [no]
  --enable-libplacebo      enable libplacebo library [no]
  --enable-libpulse        enable Pulseaudio input via libpulse [no]
  --enable-librabbitmq     enable RabbitMQ library [no]
  --enable-librav1e        enable AV1 encoding via rav1e [no]
  --enable-librist         enable RIST via librist [no]
  --enable-librsvg         enable SVG rasterization via librsvg [no]
  --enable-librubberband   enable rubberband needed for rubberband filter [no]
  --enable-librtmp         enable RTMP[E] support via librtmp [no]
  --enable-libshaderc      enable GLSL->SPIRV compilation via libshaderc [no]
  --enable-libshine        enable fixed-point MP3 encoding via libshine [no]
  --enable-libsmbclient    enable Samba protocol via libsmbclient [no]
  --enable-libsnappy       enable Snappy compression, needed for hap encoding [no]
  --enable-libsoxr         enable Include libsoxr resampling [no]
  --enable-libspeex        enable Speex de/encoding via libspeex [no]
  --enable-libsrt          enable Haivision SRT protocol via libsrt [no]
  --enable-libssh          enable SFTP protocol via libssh [no]
  --enable-libsvtav1       enable AV1 encoding via SVT [no]
  --enable-libtensorflow   enable TensorFlow as a DNN module backend
                           for DNN based filters like sr [no]
  --enable-libtesseract    enable Tesseract, needed for ocr filter [no]
  --enable-libtheora       enable Theora encoding via libtheora [no]
  --enable-libtls          enable LibreSSL (via libtls), needed for https support
                           if openssl, gnutls or mbedtls is not used [no]
  --enable-libtwolame      enable MP2 encoding via libtwolame [no]
  --enable-libuavs3d       enable AVS3 decoding via libuavs3d [no]
  --enable-libv4l2         enable libv4l2/v4l-utils [no]
  --enable-libvidstab      enable video stabilization using vid.stab [no]
  --enable-libvmaf         enable vmaf filter via libvmaf [no]
  --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
  --enable-libvorbis       enable Vorbis en/decoding via libvorbis,
                           native implementation exists [no]
  --enable-libvpx          enable VP8 and VP9 de/encoding via libvpx [no]
  --enable-libwebp         enable WebP encoding via libwebp [no]
  --enable-libx264         enable H.264 encoding via x264 [no]
  --enable-libx265         enable HEVC encoding via x265 [no]
  --enable-libxavs         enable AVS encoding via xavs [no]
  --enable-libxavs2        enable AVS2 encoding via xavs2 [no]
  --enable-libxcb          enable X11 grabbing using XCB [autodetect]
  --enable-libxcb-shm      enable X11 grabbing shm communication [autodetect]
  --enable-libxcb-xfixes   enable X11 grabbing mouse rendering [autodetect]
  --enable-libxcb-shape    enable X11 grabbing shape rendering [autodetect]
  --enable-libxvid         enable Xvid encoding via xvidcore,
                           native MPEG-4/Xvid encoder exists [no]
  --enable-libxml2         enable XML parsing using the C library libxml2, needed
                           for dash and imf demuxing support [no]
  --enable-libzimg         enable z.lib, needed for zscale filter [no]
  --enable-libzmq          enable message passing via libzmq [no]
  --enable-libzvbi         enable teletext support via libzvbi [no]
  --enable-lv2             enable LV2 audio filtering [no]
  --disable-lzma           disable lzma [autodetect]
  --enable-decklink        enable Blackmagic DeckLink I/O support [no]
  --enable-mbedtls         enable mbedTLS, needed for https support
                           if openssl, gnutls or libtls is not used [no]
  --enable-mediacodec      enable Android MediaCodec support [no]
  --enable-mediafoundation enable encoding via MediaFoundation [auto]
  --disable-metal          disable Apple Metal framework [autodetect]
  --enable-libmysofa       enable libmysofa, needed for sofalizer filter [no]
  --enable-openal          enable OpenAL 1.1 capture support [no]
  --enable-opencl          enable OpenCL processing [no]
  --enable-opengl          enable OpenGL rendering [no]
  --enable-openssl         enable openssl, needed for https support
                           if gnutls, libtls or mbedtls is not used [no]
  --enable-pocketsphinx    enable PocketSphinx, needed for asr filter [no]
  --disable-sndio          disable sndio support [autodetect]
  --disable-schannel       disable SChannel SSP, needed for TLS support on
                           Windows if openssl and gnutls are not used [autodetect]
  --disable-sdl2           disable sdl2 [autodetect]
  --disable-securetransport disable Secure Transport, needed for TLS support
                           on OSX if openssl and gnutls are not used [autodetect]
  --enable-vapoursynth     enable VapourSynth demuxer [no]
  --disable-vulkan         disable Vulkan code [autodetect]
  --disable-xlib           disable xlib [autodetect]
  --disable-zlib           disable zlib [autodetect]

  The following libraries provide various hardware acceleration features:
  --disable-amf            disable AMF video encoding code [autodetect]
  --disable-audiotoolbox   disable Apple AudioToolbox code [autodetect]
  --enable-cuda-nvcc       enable Nvidia CUDA compiler [no]
  --disable-cuda-llvm      disable CUDA compilation using clang [autodetect]
  --disable-cuvid          disable Nvidia CUVID support [autodetect]
  --disable-d3d11va        disable Microsoft Direct3D 11 video acceleration code [autodetect]
  --disable-dxva2          disable Microsoft DirectX 9 video acceleration code [autodetect]
  --disable-ffnvcodec      disable dynamically linked Nvidia code [autodetect]
  --enable-libdrm          enable DRM code (Linux) [no]
  --enable-libmfx          enable Intel MediaSDK (AKA Quick Sync Video) code via libmfx [no]
  --enable-libvpl          enable Intel oneVPL code via libvpl if libmfx is not used [no]
  --enable-libnpp          enable Nvidia Performance Primitives-based code [no]
  --enable-mmal            enable Broadcom Multi-Media Abstraction Layer (Raspberry Pi) via MMAL [no]
  --disable-nvdec          disable Nvidia video decoding acceleration (via hwaccel) [autodetect]
  --disable-nvenc          disable Nvidia video encoding code [autodetect]
  --enable-omx             enable OpenMAX IL code [no]
  --enable-omx-rpi         enable OpenMAX IL code for Raspberry Pi [no]
  --enable-rkmpp           enable Rockchip Media Process Platform code [no]
  --disable-v4l2-m2m       disable V4L2 mem2mem code [autodetect]
  --disable-vaapi          disable Video Acceleration API (mainly Unix/Intel) code [autodetect]
  --disable-vdpau          disable Nvidia Video Decode and Presentation API for Unix code [autodetect]
  --disable-videotoolbox   disable VideoToolbox code [autodetect]

Toolchain options:
  --arch=ARCH              select architecture []
  --cpu=CPU                select the minimum required CPU (affects
                           instruction selection, may crash on older CPUs)
  --cross-prefix=PREFIX    use PREFIX for compilation tools []
  --progs-suffix=SUFFIX    program name suffix []
  --enable-cross-compile   assume a cross-compiler is used
  --sysroot=PATH           root of cross-build tree
  --sysinclude=PATH        location of cross-build system headers
  --target-os=OS           compiler targets OS []
  --target-exec=CMD        command to run executables on target
  --target-path=DIR        path to view of build directory on target
  --target-samples=DIR     path to samples directory on target
  --tempprefix=PATH        force fixed dir/prefix instead of mktemp for checks
  --toolchain=NAME         set tool defaults according to NAME
                           (gcc-asan, clang-asan, gcc-msan, clang-msan,
                           gcc-tsan, clang-tsan, gcc-usan, clang-usan,
                           valgrind-massif, valgrind-memcheck,
                           msvc, icl, gcov, llvm-cov, hardened)
  --nm=NM                  use nm tool NM [nm -g]
  --ar=AR                  use archive tool AR [ar]
  --as=AS                  use assembler AS []
  --ln_s=LN_S              use symbolic link tool LN_S [ln -s -f]
  --strip=STRIP            use strip tool STRIP [strip]
  --windres=WINDRES        use windows resource compiler WINDRES [windres]
  --x86asmexe=EXE          use nasm-compatible assembler EXE [nasm]
  --cc=CC                  use C compiler CC [gcc]
  --cxx=CXX                use C compiler CXX [g++]
  --objcc=OCC              use ObjC compiler OCC [gcc]
  --dep-cc=DEPCC           use dependency generator DEPCC [gcc]
  --nvcc=NVCC              use Nvidia CUDA compiler NVCC or clang []
  --ld=LD                  use linker LD []
  --metalcc=METALCC        use metal compiler METALCC [xcrun -sdk macosx metal]
  --metallib=METALLIB      use metal linker METALLIB [xcrun -sdk macosx metallib]
  --pkg-config=PKGCONFIG   use pkg-config tool PKGCONFIG [pkg-config]
  --pkg-config-flags=FLAGS pass additional flags to pkgconf []
  --ranlib=RANLIB          use ranlib RANLIB [ranlib]
  --doxygen=DOXYGEN        use DOXYGEN to generate API doc [doxygen]
  --host-cc=HOSTCC         use host C compiler HOSTCC
  --host-cflags=HCFLAGS    use HCFLAGS when compiling for host
  --host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host
  --host-ld=HOSTLD         use host linker HOSTLD
  --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host
  --host-extralibs=HLIBS   use libs HLIBS when linking for host
  --host-os=OS             compiler host OS []
  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS []
  --extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS []
  --extra-objcflags=FLAGS  add FLAGS to OBJCFLAGS []
  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS []
  --extra-ldexeflags=ELDFLAGS add ELDFLAGS to LDEXEFLAGS []
  --extra-ldsoflags=ELDFLAGS add ELDFLAGS to LDSOFLAGS []
  --extra-libs=ELIBS       add ELIBS []
  --extra-version=STRING   version string suffix []
  --optflags=OPTFLAGS      override optimization-related compiler flags
  --nvccflags=NVCCFLAGS    override nvcc flags []
  --build-suffix=SUFFIX    library name suffix []
  --enable-pic             build position-independent code
  --enable-thumb           compile for Thumb instruction set
  --enable-lto             use link-time optimization
  --env="ENV=override"     override the environment variables

Advanced options (experts only):
  --malloc-prefix=PREFIX   prefix malloc and related names with PREFIX
  --custom-allocator=NAME  use a supported custom allocator
  --disable-symver         disable symbol versioning
  --enable-hardcoded-tables use hardcoded tables instead of runtime generation
  --disable-safe-bitstream-reader
                           disable buffer boundary checking in bitreaders
                           (faster, but may crash)
  --sws-max-filter-size=N  the max filter size swscale uses [256]

Optimization options (experts only):
  --disable-asm            disable all assembly optimizations
  --disable-altivec        disable AltiVec optimizations
  --disable-vsx            disable VSX optimizations
  --disable-power8         disable POWER8 optimizations
  --disable-amd3dnow       disable 3DNow! optimizations
  --disable-amd3dnowext    disable 3DNow! extended optimizations
  --disable-mmx            disable MMX optimizations
  --disable-mmxext         disable MMXEXT optimizations
  --disable-sse            disable SSE optimizations
  --disable-sse2           disable SSE2 optimizations
  --disable-sse3           disable SSE3 optimizations
  --disable-ssse3          disable SSSE3 optimizations
  --disable-sse4           disable SSE4 optimizations
  --disable-sse42          disable SSE4.2 optimizations
  --disable-avx            disable AVX optimizations
  --disable-xop            disable XOP optimizations
  --disable-fma3           disable FMA3 optimizations
  --disable-fma4           disable FMA4 optimizations
  --disable-avx2           disable AVX2 optimizations
  --disable-avx512         disable AVX-512 optimizations
  --disable-avx512icl      disable AVX-512ICL optimizations
  --disable-aesni          disable AESNI optimizations
  --disable-armv5te        disable armv5te optimizations
  --disable-armv6          disable armv6 optimizations
  --disable-armv6t2        disable armv6t2 optimizations
  --disable-vfp            disable VFP optimizations
  --disable-neon           disable NEON optimizations
  --disable-inline-asm     disable use of inline assembly
  --disable-x86asm         disable use of standalone x86 assembly
  --disable-mipsdsp        disable MIPS DSP ASE R1 optimizations
  --disable-mipsdspr2      disable MIPS DSP ASE R2 optimizations
  --disable-msa            disable MSA optimizations
  --disable-mipsfpu        disable floating point MIPS optimizations
  --disable-mmi            disable Loongson MMI optimizations
  --disable-lsx            disable Loongson LSX optimizations
  --disable-lasx           disable Loongson LASX optimizations
  --disable-rvv            disable RISC-V Vector optimizations
  --disable-fast-unaligned consider unaligned accesses slow

Developer options (useful when working on FFmpeg itself):
  --disable-debug          disable debugging symbols
  --enable-debug=LEVEL     set the debug level []
  --disable-optimizations  disable compiler optimizations
  --enable-extra-warnings  enable more compiler warnings
  --disable-stripping      disable stripping of executables and shared libraries
  --assert-level=level     0(default), 1 or 2, amount of assertion testing,
                           2 causes a slowdown at runtime.
  --enable-memory-poisoning fill heap uninitialized allocated space with arbitrary data
  --valgrind=VALGRIND      run "make fate" tests through valgrind to detect memory
                           leaks and errors, using the specified valgrind binary.
                           Cannot be combined with --target-exec
  --enable-ftrapv          Trap arithmetic overflows
  --samples=PATH           location of test samples for FATE, if not set use
                           $FATE_SAMPLES at make invocation time.
  --enable-neon-clobber-test check NEON registers for clobbering (should be
                           used only for debugging purposes)
  --enable-xmm-clobber-test check XMM registers for clobbering (Win64-only;
                           should be used only for debugging purposes)
  --enable-random          randomly enable/disable components
  --disable-random
  --enable-random=LIST     randomly enable/disable specific components or
  --disable-random=LIST    component groups. LIST is a comma-separated list
                           of NAME[:PROB] entries where NAME is a component
                           (group) and PROB the probability associated with
                           NAME (default 0.5).
  --random-seed=VALUE      seed value for --enable/disable-random
  --disable-valgrind-backtrace do not print a backtrace under Valgrind
                           (only applies to --disable-optimizations builds)
  --enable-ossfuzz         Enable building fuzzer tool
  --libfuzzer=PATH         path to libfuzzer
  --ignore-tests=TESTS     comma-separated list (without "fate-" prefix
                           in the name) of tests whose result is ignored
  --enable-linux-perf      enable Linux Performance Monitor API
  --enable-macos-kperf     enable macOS kperf (private) API
  --disable-large-tests    disable tests that use a large amount of memory
  --disable-ptx-compression don't compress CUDA PTX code even when possible

    通过以上帮助信息的输出内容可以看到,FFmpeg所支持的外部库相对来说比较多,主要包含如下列表:

bzip2 1.0.6 <http://bzip.org/>
Fontconfig 2.11.94 <http://freedesktop.org/wiki/Software/fontconfig>
Frei0r 20130909-git-10d8360 <http://frei0r.dyne.org/>
GnuTLS 3.3.15 <http://gnutls.org/>
libiconv 1.14 <http://gnu.org/software/libiconv/>
libass 0.12.2 <http://code.google.com/p/libass/>
libbluray 0.8.1 <http://videolan.org/developers/libbluray.html>
libbs2b 3.1.0 <http://bs2b.sourceforge.net/>
libcaca 0.99.beta18 <http://caca.zoy.org/wiki/libcaca>
dcadec 20150506-git-98fb3b6 <https://github.com/foo86/dcadec>
FreeType 2.5.5 <http://freetype.sourceforge.net/>
Game Music Emu 0.6.0 <http://code.google.com/p/game-music-emu/>
GSM 1.0.13-4 <http://packages.debian.org/source/squeeze/libgsm>
iLBC 20141214-git-ef04ebe <https://github.com/dekkers/libilbc/>
Modplug-XMMS 0.8.8.5 <http://modplug-xmms.sourceforge.net/>
LAME 3.99.5 <http://lame.sourceforge.net/>
OpenCORE AMR 0.1.3 <http://sourceforge.net/projects/opencore-amr/>
OpenJPEG 1.5.2 <http://www.openjpeg.org/>
Opus 1.1 <http://opus-codec.org/>
RTMPDump 20140707-git-a1900c3 <http://rtmpdump.mplayerhq.hu/>
Schroedinger 1.0.11 <http://diracvideo.org/>
libsoxr 0.1.1 <http://sourceforge.net/projects/soxr/>
Speex 1.2rc2 <http://speex.org/>
Theora 1.1.1 <http://theora.org/>
TwoLAME 0.3.13 <http://twolame.org/>
vid.stab 0.98 <http://public.hronopik.de/vid.stab/>
VisualOn AAC 0.1.3 <https://github.com/mstorsjo/vo-aacenc>
VisualOn AMR-WB 0.1.2 <https://github.com/mstorsjo/vo-amrwbenc>
Vorbis 1.3.5 <http://vorbis.com/>
vpx 1.4.0 <http://webmproject.org/>
WavPack 4.75.0 <http://wavpack.com/>
WebP 0.4.3 <https://developers.google.com/speed/webp/>
x264 20150223-git-121396c <http://videolan.org/developers/x264.html>
x265 1.7 <http://x265.org/>
XAVS svn-r55 <http://xavs.sourceforge.net/>
Xvid 1.3.3 <http://xvid.org/>
XZ Utils 5.2.1 <http://tukaani.org/xz>
zlib 1.2.8 <http://zlib.net/>

    这些外部库可以通过configure进行定制,在编译好的FFmpeg可执行程序中也可以看到编译时定制的FFmpeg的外部库:

ffmpeg version n3.3.2 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.1.0 (clang-802.0.42)
    configuration: --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libspeex --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-version3 --cc='ccache gcc' --enable-nonfree --enable-videotoolbox --enable-audiotoolbox
    libavutil      55. 58.100 / 55. 58.100
    libavcodec     57. 89.100 / 57. 89.100
    libavformat    57. 71.100 / 57. 71.100
    libavdevice    57.  6.100 / 57.  6.100
    libavfilter      6. 82.100 /  6. 82.100
    libswscale      4.  6.100 /  4.  6.100
    libswresample   2.  7.100 /  2.  7.100
    libpostproc    54.  5.100 / 54.  5.100

    例如需要自己配置FFmpeg支持哪些格式,比如仅支持H.264视频与AAC音频编码,可以调整配置项将其简化如下:

configure --enable-libx264 --enable-libfdk-aac --enable-gpl --enable-nonfree

    命令行执行后的输出内容如下:

install prefix            /usr/local
source path               .
C compiler                gcc
C library                 glibc
ARCH                      x86 (generic)
big-endian                no
runtime cpu detection     yes
standalone assembly       yes
x86 assembler             nasm
MMX enabled               yes
MMXEXT enabled            yes
3DNow! enabled            yes
3DNow! extended enabled   yes
SSE enabled               yes
SSSE3 enabled             yes
AESNI enabled             yes
AVX enabled               yes
AVX2 enabled              yes
AVX-512 enabled           yes
AVX-512ICL enabled        yes
XOP enabled               yes
FMA3 enabled              yes
FMA4 enabled              yes
i686 features enabled     yes
CMOV is fast              yes
EBX available             yes
EBP available             yes
debug symbols             yes
strip symbols             yes
optimize for size         no
optimizations             yes
static                    yes
shared                    no
postprocessing support    yes
network support           yes
threading support         pthreads
safe bitstream reader     yes
texi2html enabled         no
perl enabled              yes
pod2man enabled           yes
makeinfo enabled          no
makeinfo supports HTML    no
xmllint enabled           yes

    如果需要支持H.265编码,则只需要增加–enable-libx265即可,其与支持H.264基本类似,从前面的help信息中可以看到,其他对应的编码与此类似。
    注意:
    从2016年年初开始,FFmpeg资深的AAC编码器质量逐步好转,至2016年年底,libfaac已经从FFmpeg源代码中剔除
    FFmpeg默认支持的音视频编码格式、文件封装格式和流媒体传输协议相对来说比较多,因此编译出来的FFmpeg体积比较大,在有些应用场景中,并不需要FFmpeg所支持的一些编码、封装或者协议,可以通过configure --help查看一些有用的裁剪操作:
    可以通过这些选项关闭不需要用到的编码、封装与协议等模块,验证方法如下:

configure --disable-encoders --disable-decoders --disable-hwaccels --disable-muxers --disable-demuxers --disable-parsers --disable-bsfs --disable-protocols --disable-indevs --disable-devices --disable-filters

    关闭所有的模块之后,可以看到FFmpeg的编译配置项输出信息几乎为空,输出信息具体如下:

Libraries:
avcodec                 avfilter                avutil                  swscale
avdevice                avformat                swresample

Programs:
ffmpeg                  ffprobe

Enabled decoders:

Enabled encoders:

Enabled hwaccels:

Enabled parsers:

Enabled demuxers:

Enabled muxers:

Enabled protocols:

Enabled filters:
aformat                 atrim                   hflip                   transpose               vflip
anull                   format                  null                    trim

Enabled bsfs:

Enabled indevs:

Enabled outdevs:

License: LGPL version 2.1 or later
libavutil/avconfig.h is unchanged

    而且在关闭所有的模块之后,可以根据定制支持自己所需要的模块,例如希望支持H.264视频编码、AAC音频编码、封装为MP4,可以通过如下方式进行支持:

External libraries:
bzlib                   iconv                   libfdk_aac              libx264                 zlib

External libraries providing hardware acceleration:

Libraries:
avcodec                 avfilter                avutil                  swresample
avdevice                avformat                postproc                swscale

Programs:
ffmpeg                  ffprobe

Enabled decoders:

Enabled encoders:

Enabled hwaccels:

Enabled parsers:
ac3

Enabled demuxers:

Enabled muxers:
mov                     mp4

Enabled protocols:

Enabled filters:
aformat                 atrim                   hflip                   transpose               vflip
anull                   format                  null                    trim

Enabled bsfs:
aac_adtstoasc           vp9_superframe

Enabled indevs:

Enabled outdevs:

    从以上的输出内容可以看到,FFmpeg已经支持了H.264编码、AAC编码与MP4封装格式。这样通过编译之后生成的FFmpeg即是配置裁剪过的FFmpeg,体积会比默认编译的FFmpeg小很多

  1.8.1 FFmpeg的编码器支持

    FFmpeg源代码中可以包含的编码非常多,常见的和不常见的都可以在编译配置列表中见到,可以通过使用编译配置命令./configure–list-encoders参数来查看:

a64multi                eac3                    libshine                pcm_f64le               sbc
a64multi5               exr                     libspeex                pcm_mulaw               sgi
aac                     ffv1                    libsvtav1               pcm_mulaw_at            smc
aac_at                  ffvhuff                 libtheora               pcm_s16be               snow
aac_mf                  fits                    libtwolame              pcm_s16be_planar        sonic
ac3                     flac                    libvo_amrwbenc          pcm_s16le               sonic_ls
ac3_fixed               flashsv                 libvorbis               pcm_s16le_planar        speedhq
ac3_mf                  flashsv2                libvpx_vp8              pcm_s24be               srt
adpcm_adx               flv                     libvpx_vp9              pcm_s24daud             ssa
adpcm_argo              g723_1                  libwebp                 pcm_s24le               subrip
adpcm_g722              gif                     libwebp_anim            pcm_s24le_planar        sunrast
adpcm_g726              h261                    libx262                 pcm_s32be               svq1
adpcm_g726le            h263                    libx264                 pcm_s32le               targa
adpcm_ima_alp           h263_v4l2m2m            libx264rgb              pcm_s32le_planar        text
adpcm_ima_amv           h263p                   libx265                 pcm_s64be               tiff
adpcm_ima_apm           h264_amf                libxavs                 pcm_s64le               truehd
adpcm_ima_qt            h264_mf                 libxavs2                pcm_s8                  tta
adpcm_ima_ssi           h264_nvenc              libxvid                 pcm_s8_planar           ttml
adpcm_ima_wav           h264_omx                ljpeg                   pcm_u16be               utvideo
adpcm_ima_ws            h264_qsv                magicyuv                pcm_u16le               v210
adpcm_ms                h264_v4l2m2m            mjpeg                   pcm_u24be               v308
adpcm_swf               h264_vaapi              mjpeg_qsv               pcm_u24le               v408
adpcm_yamaha            h264_videotoolbox       mjpeg_vaapi             pcm_u32be               v410
alac                    hap                     mlp                     pcm_u32le               vbn
alac_at                 hevc_amf                movtext                 pcm_u8                  vc2
alias_pix               hevc_mf                 mp2                     pcm_vidc                vorbis
amv                     hevc_nvenc              mp2fixed                pcx                     vp8_v4l2m2m
apng                    hevc_qsv                mp3_mf                  pfm                     vp8_vaapi
aptx                    hevc_v4l2m2m            mpeg1video              pgm                     vp9_qsv
aptx_hd                 hevc_vaapi              mpeg2_qsv               pgmyuv                  vp9_vaapi
ass                     hevc_videotoolbox       mpeg2_vaapi             phm                     wavpack
asv1                    huffyuv                 mpeg2video              png                     webvtt
asv2                    ilbc_at                 mpeg4                   ppm                     wmav1
avrp                    jpeg2000                mpeg4_omx               prores                  wmav2
avui                    jpegls                  mpeg4_v4l2m2m           prores_aw               wmv1
ayuv                    libaom_av1              msmpeg4v2               prores_ks               wmv2
bitpacked               libcodec2               msmpeg4v3               prores_videotoolbox     wrapped_avframe
bmp                     libfdk_aac              msvideo1                qoi                     xbm
cfhd                    libgsm                  nellymoser              qtrle                   xface
cinepak                 libgsm_ms               opus                    r10k                    xsub
cljr                    libilbc                 pam                     r210                    xwd
comfortnoise            libjxl                  pbm                     ra_144                  y41p
dca                     libkvazaar              pcm_alaw                rawvideo                yuv4
dfpwm                   libmp3lame              pcm_alaw_at             roq                     zlib
dnxhd                   libopencore_amrnb       pcm_bluray              roq_dpcm                zmbv
dpx                     libopenh264             pcm_dvd                 rpza
dvbsub                  libopenjpeg             pcm_f32be               rv10
dvdsub                  libopus                 pcm_f32le               rv20
dvvideo                 librav1e                pcm_f64be               s302m

    从上面的输出信息中可以看出,FFmpeg支持的编码器比较全面,比如AAC、AC3、H.264、H.265、MPEG4、MPEG2VIDEO、PCM、FLV1的编码器支持

  1.8.2 FFmpeg的解码器支持

    FFmpeg源代码本身包含了很多的解码支持,解码主要是在输入的时候进行解码,也可以理解为将压缩过的编码进行解压缩,关于解码的支持,可以通过./configure–list-decoders命令来进行查看:

aac                     cdgraphics              imm5                    nellymoser              speedhq
aac_at                  cdtoons                 indeo2                  notchlc                 speex
aac_fixed               cdxl                    indeo3                  nuv                     srgc
aac_latm                cfhd                    indeo4                  on2avc                  srt
aasc                    cinepak                 indeo5                  opus                    ssa
ac3                     clearvideo              interplay_acm           paf_audio               stl
ac3_at                  cljr                    interplay_dpcm          paf_video               subrip
ac3_fixed               cllc                    interplay_video         pam                     subviewer
acelp_kelvin            comfortnoise            ipu                     pbm                     subviewer1
adpcm_4xm               cook                    jacosub                 pcm_alaw                sunrast
adpcm_adx               cpia                    jpeg2000                pcm_alaw_at             svq1
adpcm_afc               cri                     jpegls                  pcm_bluray              svq3
adpcm_agm               cscd                    jv                      pcm_dvd                 tak
adpcm_aica              cyuv                    kgv1                    pcm_f16le               targa
adpcm_argo              dca                     kmvc                    pcm_f24le               targa_y216
adpcm_ct                dds                     lagarith                pcm_f32be               tdsc
adpcm_dtk               derf_dpcm               libaom_av1              pcm_f32le               text
adpcm_ea                dfa                     libaribb24              pcm_f64be               theora
adpcm_ea_maxis_xa       dfpwm                   libcelt                 pcm_f64le               thp
adpcm_ea_r1             dirac                   libcodec2               pcm_lxf                 tiertexseqvideo
adpcm_ea_r2             dnxhd                   libdav1d                pcm_mulaw               tiff
adpcm_ea_r3             dolby_e                 libdavs2                pcm_mulaw_at            tmv
adpcm_ea_xas            dpx                     libfdk_aac              pcm_s16be               truehd
adpcm_g722              dsd_lsbf                libgsm                  pcm_s16be_planar        truemotion1
adpcm_g726              dsd_lsbf_planar         libgsm_ms               pcm_s16le               truemotion2
adpcm_g726le            dsd_msbf                libilbc                 pcm_s16le_planar        truemotion2rt
adpcm_ima_acorn         dsd_msbf_planar         libjxl                  pcm_s24be               truespeech
adpcm_ima_alp           dsicinaudio             libopencore_amrnb       pcm_s24daud             tscc
adpcm_ima_amv           dsicinvideo             libopencore_amrwb       pcm_s24le               tscc2
adpcm_ima_apc           dss_sp                  libopenh264             pcm_s24le_planar        tta
adpcm_ima_apm           dst                     libopenjpeg             pcm_s32be               twinvq
adpcm_ima_cunning       dvaudio                 libopus                 pcm_s32le               txd
adpcm_ima_dat4          dvbsub                  librsvg                 pcm_s32le_planar        ulti
adpcm_ima_dk3           dvdsub                  libspeex                pcm_s64be               utvideo
adpcm_ima_dk4           dvvideo                 libuavs3d               pcm_s64le               v210
adpcm_ima_ea_eacs       dxa                     libvorbis               pcm_s8                  v210x
adpcm_ima_ea_sead       dxtory                  libvpx_vp8              pcm_s8_planar           v308
adpcm_ima_iss           dxv                     libvpx_vp9              pcm_sga                 v408
adpcm_ima_moflex        eac3                    libzvbi_teletext        pcm_u16be               v410
adpcm_ima_mtf           eac3_at                 loco                    pcm_u16le               vb
adpcm_ima_oki           eacmv                   lscr                    pcm_u24be               vble
adpcm_ima_qt            eamad                   m101                    pcm_u24le               vbn
adpcm_ima_qt_at         eatgq                   mace3                   pcm_u32be               vc1
adpcm_ima_rad           eatgv                   mace6                   pcm_u32le               vc1_crystalhd
adpcm_ima_smjpeg        eatqi                   magicyuv                pcm_u8                  vc1_cuvid
adpcm_ima_ssi           eightbps                mdec                    pcm_vidc                vc1_mmal
adpcm_ima_wav           eightsvx_exp            metasound               pcx                     vc1_qsv
adpcm_ima_ws            eightsvx_fib            microdvd                pfm                     vc1_v4l2m2m
adpcm_ms                escape124               mimic                   pgm                     vc1image
adpcm_mtaf              escape130               mjpeg                   pgmyuv                  vcr1
adpcm_psx               evrc                    mjpeg_cuvid             pgssub                  vmdaudio
adpcm_sbpro_2           exr                     mjpeg_qsv               pgx                     vmdvideo
adpcm_sbpro_3           fastaudio               mjpegb                  phm                     vmnc
adpcm_sbpro_4           ffv1                    mlp                     photocd                 vorbis
adpcm_swf               ffvhuff                 mmvideo                 pictor                  vp3
adpcm_thp               ffwavesynth             mobiclip                pixlet                  vp4
adpcm_thp_le            fic                     motionpixels            pjs                     vp5
adpcm_vima              fits                    movtext                 png                     vp6
adpcm_xa                flac                    mp1                     ppm                     vp6a
adpcm_yamaha            flashsv                 mp1_at                  prores                  vp6f
adpcm_zork              flashsv2                mp1float                prosumer                vp7
agm                     flic                    mp2                     psd                     vp8
aic                     flv                     mp2_at                  ptx                     vp8_cuvid
alac                    fmvc                    mp2float                qcelp                   vp8_mediacodec
alac_at                 fourxm                  mp3                     qdm2                    vp8_qsv
alias_pix               fraps                   mp3_at                  qdm2_at                 vp8_rkmpp
als                     frwu                    mp3adu                  qdmc                    vp8_v4l2m2m
amr_nb_at               g2m                     mp3adufloat             qdmc_at                 vp9
amrnb                   g723_1                  mp3float                qdraw                   vp9_cuvid
amrwb                   g729                    mp3on4                  qoi                     vp9_mediacodec
amv                     gdv                     mp3on4float             qpeg                    vp9_qsv
anm                     gem                     mpc7                    qtrle                   vp9_rkmpp
ansi                    gif                     mpc8                    r10k                    vp9_v4l2m2m
ape                     gremlin_dpcm            mpeg1_cuvid             r210                    vplayer
apng                    gsm                     mpeg1_v4l2m2m           ra_144                  vqa
aptx                    gsm_ms                  mpeg1video              ra_288                  wavpack
aptx_hd                 gsm_ms_at               mpeg2_crystalhd         ralf                    wcmv
arbc                    h261                    mpeg2_cuvid             rasc                    webp
argo                    h263                    mpeg2_mediacodec        rawvideo                webvtt
ass                     h263_v4l2m2m            mpeg2_mmal              realtext                wmalossless
asv1                    h263i                   mpeg2_qsv               rl2                     wmapro
asv2                    h263p                   mpeg2_v4l2m2m           roq                     wmav1
atrac1                  h264                    mpeg2video              roq_dpcm                wmav2
atrac3                  h264_crystalhd          mpeg4                   rpza                    wmavoice
atrac3al                h264_cuvid              mpeg4_crystalhd         rscc                    wmv1
atrac3p                 h264_mediacodec         mpeg4_cuvid             rv10                    wmv2
atrac3pal               h264_mmal               mpeg4_mediacodec        rv20                    wmv3
atrac9                  h264_qsv                mpeg4_mmal              rv30                    wmv3_crystalhd
aura                    h264_rkmpp              mpeg4_v4l2m2m           rv40                    wmv3image
aura2                   h264_v4l2m2m            mpegvideo               s302m                   wnv1
av1                     hap                     mpl2                    sami                    wrapped_avframe
av1_cuvid               hca                     msa1                    sanm                    ws_snd1
av1_qsv                 hcom                    mscc                    sbc                     xan_dpcm
avrn                    hevc                    msmpeg4_crystalhd       scpr                    xan_wc3
avrp                    hevc_cuvid              msmpeg4v1               screenpresso            xan_wc4
avs                     hevc_mediacodec         msmpeg4v2               sdx2_dpcm               xbin
avui                    hevc_qsv                msmpeg4v3               sga                     xbm
ayuv                    hevc_rkmpp              msnsiren                sgi                     xface
bethsoftvid             hevc_v4l2m2m            msp2                    sgirle                  xl
bfi                     hnm4_video              msrle                   sheervideo              xma1
bink                    hq_hqa                  mss1                    shorten                 xma2
binkaudio_dct           hqx                     mss2                    simbiosis_imx           xpm
binkaudio_rdft          huffyuv                 msvideo1                sipr                    xsub
bintext                 hymt                    mszh                    siren                   xwd
bitpacked               iac                     mts2                    smackaud                y41p
bmp                     idcin                   mv30                    smacker                 ylc
bmv_audio               idf                     mvc1                    smc                     yop
bmv_video               iff_ilbm                mvc2                    smvjpeg                 yuv4
brender_pix             ilbc                    mvdv                    snow                    zero12v
c93                     ilbc_at                 mvha                    sol_dpcm                zerocodec
cavs                    imc                     mwsc                    sonic                   zlib
ccaption                imm4                    mxpeg                   sp5x                    zmbv

    从上面的输出信息中可以看到FFmpeg所支持的解码器模块decoders支持了MPEG4、H.264、H.265(HEVC)、MP3等格式。

  1.8.3 FFmpeg的封装支持

    FFmpeg的封装(Muxing)是指将压缩后的编码封装到一个容器格式中,如果要查看FFmpeg源代码中都可以支持哪些容器格式,可以通过命令./configure --list-muxers来查看:

a64                     dirac                   ircam                   oga                     sbc
ac3                     dnxhd                   ismv                    ogg                     scc
adts                    dts                     ivf                     ogv                     segafilm
adx                     dv                      jacosub                 oma                     segment
aiff                    eac3                    kvag                    opus                    smjpeg
alp                     f4v                     latm                    pcm_alaw                smoothstreaming
amr                     ffmetadata              lrc                     pcm_f32be               sox
amv                     fifo                    m4v                     pcm_f32le               spdif
apm                     fifo_test               matroska                pcm_f64be               spx
apng                    filmstrip               matroska_audio          pcm_f64le               srt
aptx                    fits                    md5                     pcm_mulaw               stream_segment
aptx_hd                 flac                    microdvd                pcm_s16be               streamhash
argo_asf                flv                     mjpeg                   pcm_s16le               sup
argo_cvg                framecrc                mkvtimestamp_v2         pcm_s24be               swf
asf                     framehash               mlp                     pcm_s24le               tee
asf_stream              framemd5                mmf                     pcm_s32be               tg2
ass                     g722                    mov                     pcm_s32le               tgp
ast                     g723_1                  mp2                     pcm_s8                  truehd
au                      g726                    mp3                     pcm_u16be               tta
avi                     g726le                  mp4                     pcm_u16le               ttml
avif                    gif                     mpeg1system             pcm_u24be               uncodedframecrc
avm2                    gsm                     mpeg1vcd                pcm_u24le               vc1
avs2                    gxf                     mpeg1video              pcm_u32be               vc1t
avs3                    h261                    mpeg2dvd                pcm_u32le               voc
bit                     h263                    mpeg2svcd               pcm_u8                  w64
caf                     h264                    mpeg2video              pcm_vidc                wav
cavsvideo               hash                    mpeg2vob                psp                     webm
chromaprint             hds                     mpegts                  rawvideo                webm_chunk
codec2                  hevc                    mpjpeg                  rm                      webm_dash_manifest
codec2raw               hls                     mxf                     roq                     webp
crc                     ico                     mxf_d10                 rso                     webvtt
dash                    ilbc                    mxf_opatom              rtp                     wsaud
data                    image2                  null                    rtp_mpegts              wtv
daud                    image2pipe              nut                     rtsp                    wv
dfpwm                   ipod                    obu                     sap                     yuv4mpegpipe

    从封装(又称复用)格式所支持的信息中可以看到,FFmpeg支持生成裸流文件,如H.264、AAC、PCM,也支持一些常见的格式,如MP3、MP4、FLV、M3U8、WEBM等。

  1.8.4 FFmpeg的解封装支持

    FFmpeg的解封装(Demuxing)是指将读入的容器格式拆解开,将里面压缩的音频流、视频流、字幕流、数据流等提取出来,如果要查看FFmpeg的源代码中都可以支持哪些输入的容器格式,可以通过命令./configure --list-demuxers来查看:

aa                      dhav                    image_pgm_pipe          msnwc_tcp               segafilm
aac                     dirac                   image_pgmyuv_pipe       msp                     ser
aax                     dnxhd                   image_pgx_pipe          mtaf                    sga
ac3                     dsf                     image_phm_pipe          mtv                     shorten
ace                     dsicin                  image_photocd_pipe      musx                    siff
acm                     dss                     image_pictor_pipe       mv                      simbiosis_imx
act                     dts                     image_png_pipe          mvi                     sln
adf                     dtshd                   image_ppm_pipe          mxf                     smacker
adp                     dv                      image_psd_pipe          mxg                     smjpeg
ads                     dvbsub                  image_qdraw_pipe        nc                      smush
adx                     dvbtxt                  image_qoi_pipe          nistsphere              sol
aea                     dxa                     image_sgi_pipe          nsp                     sox
afc                     ea                      image_sunrast_pipe      nsv                     spdif
aiff                    ea_cdata                image_svg_pipe          nut                     srt
aix                     eac3                    image_tiff_pipe         nuv                     stl
alp                     epaf                    image_vbn_pipe          obu                     str
amr                     ffmetadata              image_webp_pipe         ogg                     subviewer
amrnb                   filmstrip               image_xbm_pipe          oma                     subviewer1
amrwb                   fits                    image_xpm_pipe          paf                     sup
anm                     flac                    image_xwd_pipe          pcm_alaw                svag
apc                     flic                    imf                     pcm_f32be               svs
ape                     flv                     ingenient               pcm_f32le               swf
apm                     fourxm                  ipmovie                 pcm_f64be               tak
apng                    frm                     ipu                     pcm_f64le               tedcaptions
aptx                    fsb                     ircam                   pcm_mulaw               thp
aptx_hd                 fwse                    iss                     pcm_s16be               threedostr
aqtitle                 g722                    iv8                     pcm_s16le               tiertexseq
argo_asf                g723_1                  ivf                     pcm_s24be               tmv
argo_brp                g726                    ivr                     pcm_s24le               truehd
argo_cvg                g726le                  jacosub                 pcm_s32be               tta
asf                     g729                    jv                      pcm_s32le               tty
asf_o                   gdv                     kux                     pcm_s8                  txd
ass                     genh                    kvag                    pcm_u16be               ty
ast                     gif                     libgme                  pcm_u16le               v210
au                      gsm                     libmodplug              pcm_u24be               v210x
av1                     gxf                     libopenmpt              pcm_u24le               vag
avi                     h261                    live_flv                pcm_u32be               vapoursynth
avisynth                h263                    lmlm4                   pcm_u32le               vc1
avr                     h264                    loas                    pcm_u8                  vc1t
avs                     hca                     lrc                     pcm_vidc                vividas
avs2                    hcom                    luodat                  pjs                     vivo
avs3                    hevc                    lvf                     pmp                     vmd
bethsoftvid             hls                     lxf                     pp_bnk                  vobsub
bfi                     hnm                     m4v                     pva                     voc
bfstm                   ico                     matroska                pvf                     vpk
bink                    idcin                   mca                     qcp                     vplayer
binka                   idf                     mcc                     r3d                     vqf
bintext                 iff                     mgsts                   rawvideo                w64
bit                     ifv                     microdvd                realtext                wav
bitpacked               ilbc                    mjpeg                   redspark                wc3
bmv                     image2                  mjpeg_2000              rl2                     webm_dash_manifest
boa                     image2_alias_pix        mlp                     rm                      webvtt
brstm                   image2_brender_pix      mlv                     roq                     wsaud
c93                     image2pipe              mm                      rpl                     wsd
caf                     image_bmp_pipe          mmf                     rsd                     wsvqa
cavsvideo               image_cri_pipe          mods                    rso                     wtv
cdg                     image_dds_pipe          moflex                  rtp                     wv
cdxl                    image_dpx_pipe          mov                     rtsp                    wve
cine                    image_exr_pipe          mp3                     s337m                   xa
codec2                  image_gem_pipe          mpc                     sami                    xbin
codec2raw               image_gif_pipe          mpc8                    sap                     xmv
concat                  image_j2k_pipe          mpegps                  sbc                     xvag
dash                    image_jpeg_pipe         mpegts                  sbg                     xwma
data                    image_jpegls_pipe       mpegtsraw               scc                     yop
daud                    image_jpegxl_pipe       mpegvideo               scd                     yuv4mpegpipe
dcstr                   image_pam_pipe          mpjpeg                  sdp
derf                    image_pbm_pipe          mpl2                    sdr2
dfa                     image_pcx_pipe          mpsub                   sds
dfpwm                   image_pfm_pipe          msf                     sdx

    从解封装(Demuxer,又称解复用)格式支持信息中可以看到,FFmpeg源代码中已经支持的demuxer非常多,包含图片(image)、MP3、FLV、MP4、MOV、AVI等

  1.8.5 FFmpeg的通信协议支持

    FFmpeg不仅仅支持本地的多媒体处理,而且还支持网络流媒体的处理,支持的网络流媒体协议相对来说也很全面,可以通过命令./configure --list-protocols查看:

async                   gopher                  librtmp                 mmst                    srtp
bluray                  gophers                 librtmpe                pipe                    subfile
cache                   hls                     librtmps                prompeg                 tcp
concat                  http                    librtmpt                rtmp                    tee
concatf                 httpproxy               librtmpte               rtmpe                   tls
crypto                  https                   libsmbclient            rtmps                   udp
data                    icecast                 libsrt                  rtmpt                   udplite
ffrtmpcrypt             ipfs                    libssh                  rtmpte                  unix
ffrtmphttp              ipns                    libzmq                  rtmpts
file                    libamqp                 md5                     rtp
ftp                     librist                 mmsh                    sctp

    从协议的相关信息列表中可以看到,FFmpeg支持的流媒体协议比较多,包括MMS、HTTP、HTTPS、HLS(M3U8)、RTMP、RTP,甚至支持TCP、UDP,其也支持使用file协议的本地文件操作和使用concat协议支持的多个文件串流操作,后面的章节中会有详细的介绍。

  1.9 小结

    本章重点介绍了FFmpeg的获取、安装、容器封装与解封装的格式支持、音视频编码与解码的格式支持,以及流媒体传输协议的支持。综合来说,FFmpeg所支持的容器、编解码、协议相对来说比较全面,是一款功能强大的多媒体处理工具和开发套件。

猜你喜欢

转载自blog.csdn.net/migu123/article/details/129300701