FFmpeg应用实践之命令查询

FFmpeg 中常用的工具有三个,分别是多媒体编解码工具ffmpeg、多媒体内容分析工具ffprobe和多媒体播放器ffplay。本文介绍的指令都是与编解码工具 ffmpeg 相关的。

学会查询内置文档能够解决我们遇到的很多参数设置问题,也可以避免因为网上各种版本不同、质量参差不齐的答案而困惑。

1. ffmpeg 帮助信息

ffmpeg 命令行指令语法格式如下

ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...

ffmpeg 命令行应用中,最基础的操作就是查询一些诸如版本、支持的编码方式/编解码器/滤镜等信息。

首先我们要学会使用的是最最基本的一个命令 -help,有了它我们就可以更愉快地学习与之相关的各种功能了。

执行 ffmpeg -h 后,在终端会打印出与当前使用版本相关的帮助信息。通常在 Linux 系统下使用时可以用如下所示的命令行指令,利用管道加上 less 后可以使用 /match_template 来快速匹配定位到自己关心的部分。

~$ ffmpeg -h full | less ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04) configuration: --prefix=http://www.likecs.com/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=http://www.likecs.com/usr/lib/x86_64-linux-gnu --incdir=http://www.likecs.com/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100 ...

除了上述最基本的使用方法外,使用 -h type=name 参数可以用来查看指定名称的编/解码器、复用/解复用器、滤镜等的详细信息,非常实用。比如下面的示例中查看 H.264(AVC) 编码器的配置参数。

~$ ffmpeg -h encoder=h264 | less ... Encoder libx264 [libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]: General capabilities: delay threads Threading capabilities: auto Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p nv12 nv16 nv21 libx264 AVOptions: ...

从 ffmpeg -h 输出信息中可以看到,ffmpeg 常见命令大概分为六类,分别是

ffmpeg 信息查询部分

全局配置参数部分

文件主要配置参数部分

视频配置参数部分

音频配置参数部分

字幕配置参数部分

2. ffmpeg 信息查询指令

可以通过本小节的参数来查询 ffmpeg 支持的封装或者编解码格式等。

-L 显示ffmpeg目前所支持的License协议 -version 显示版本信息 -buildconf 显示编译配置 -formats 显示可用的格式 -muxers 显示可用的复用器 -demuxers 显示可用的解复用器 -devices 显示可用的设备 -codecs 显示可用的编解码器,包括编码器和解码器 -decoders 显示可用的解码器 -encoders 显示可用的编码器 -bsfs 显示可用的比特流滤镜 -protocols 显示可用的协议 -filters 显示可用的滤镜 -pix_fmts 显示可用的像素格式 -layouts 显示标准声道名称 -sample_fmts 显示可用的音频采样格式 -colors 显示可用的颜色名称 -sources device 列出输入设备的来源 -sinks device 列出输出设备的接收器 -hwaccels 显示可用的HW加速方法

比如使用 -version 参数可以查看 ffmepg 的版本,包括子模块如libavutil、libavcodec、libavformat、libavdevice、libavfilter、libavresample、libswscale、libswresample、libpostproc等的详细版本信息。

使用 -formats 参数可以查看当前使用的 ffmpeg 是否支持对应文件的视频格式。这样当我们使用 ffmpeg 转码时如果遇到报错提示不支持生成对应的视频文件,就可以进行相应的调整。

如下示例是使用 -devices 参数列出可用设备的输出结果。

~$ ffmpeg -devices ... Devices: D. = Demuxing supported .E = Muxing supported -- DE alsa ALSA audio output E caca caca (color ASCII art) output device DE fbdev Linux framebuffer D iec61883 libiec61883 (new DV1394) A/V input device D jack JACK Audio Connection Kit D lavfi Libavfilter virtual input device D libcdio D libdc1394 dc1394 v.2 A/V grab D openal OpenAL audio capture device E opengl OpenGL output DE oss OSS (Open Sound System) playback DE pulse Pulse audio output E sdl,sdl2 SDL2 output device DE sndio sndio audio playback E v4l2 Video4Linux2 output device D video4linux2,v4l2 Video4Linux2 device grab D x11grab X11 screen capture, using XCB E xv XV (XVideo) output device 3. 全局相关的配置选项 Global options (affect whole program instead of just one file: -loglevel loglevel set logging level -v loglevel set logging level -report generate a report -max_alloc bytes set maximum size of a single allocated block -y overwrite output files -n never overwrite output files -ignore_unknown Ignore unknown stream types -filter_threads number of non-complex filter threads -filter_complex_threads number of threads for -filter_complex -stats print progress report during encoding -max_error_rate ratio of errors (0.0: no errors, 1.0: 100% error maximum error rate -bits_per_raw_sample number set the number of bits per raw sample -vol volume change audio volume (256=normal)

-v loglevel 用于设置日志输出级别,不同的等级输出的信息密度和重要程度有所区别,一般设置成 info 就能获取足够的信息用于调试。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zydfyz.html