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 © 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu
–incdir=/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 就能获取足够的信息用于调试。

-y 用于输出时覆盖已有文件。

  1. 单个文件相关的配置选项
    Per-file main options:
    -f fmt force format
    -c codec codec name
    -codec codec codec name
    -pre preset preset name
    -map_metadata outfile[,metadata]:infile[,metadata] set metadata information of outfile from infile
    -t duration record or transcode “duration” seconds of audio/video
    -to time_stop record or transcode stop time
    -fs limit_size set the limit file size in bytes
    -ss time_off set the start time offset
    -sseof time_off set the start time offset relative to EOF
    -seek_timestamp enable/disable seeking by timestamp with -ss
    -timestamp time set the recording timestamp (‘now’ to set the current time)
    -metadata string=string add metadata
    -program title=string:st=number… add program with specified streams
    -target type specify target file type (“vcd”, “svcd”, “dvd”, “dv” or “dv50” with optional prefixes “pal-”, “ntsc-” or “film-”)
    -apad audio pad
    -frames number set the number of frames to output
    -filter filter_graph set stream filtergraph
    -filter_script filename read stream filtergraph description from a file
    -reinit_filter reinit filtergraph on input parameter changes
    -discard discard
    -disposition disposition
    -f fmt 用于指定输出或输出文件的格式。

-frames number 用于设置输出文件帧的数量。

  1. 多媒体视频相关的配置选项
    Video options:
    -vframes number set the number of video frames to output
    -r rate set frame rate (Hz value, fraction or abbreviation)
    -s size set frame size (WxH or abbreviation)
    -aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
    -bits_per_raw_sample number set the number of bits per raw sample
    -vn disable video
    -vcodec codec force video codec (‘copy’ to copy stream)
    -timecode hh:mm:ss[:;.]ff set initial TimeCode value.
    -pass n select the pass number (1 to 3)
    -vf filter_graph set video filters
    -ab bitrate audio bitrate (please use -b:a)
    -b bitrate video bitrate (please use -b:v)
    -dn disable data
    -vframes number 用于设置输出视频帧的数量。

-r rate 用于设置输出视频的帧率。

-vn 常用于只保留音频数据的场合。

-vf filter_graph 用于配置相关的滤镜。

  1. 多媒体音频相关的配置选项
    Audio options:
    -aframes number set the number of audio frames to output
    -aq quality set audio quality (codec-specific)
    -ar rate set audio sampling rate (in Hz)
    -ac channels set number of audio channels
    -an disable audio
    -acodec codec force audio codec (‘copy’ to copy stream)
    -vol volume change audio volume (256=normal)
    -af filter_graph set audio filters
    -ac channels 用于设置音频通道数量,单声道、立体声等。

-an 常用于只保留视频数据的场合。

  1. 多媒体字幕相关的配置选项
    Subtitle options:
    -s size set frame size (WxH or abbreviation)
    -sn disable subtitle
    -scodec codec force subtitle codec (‘copy’ to copy stream)
    -stag fourcc/tag force subtitle tag/fourcc
    -fix_sub_duration fix subtitles duration
    -canvas_size size set canvas size (WxH or abbreviation)
    -spre preset set the subtitle options to the indicated preset
    -sn 设置输出结果中屏蔽字幕信息,只保留音频或视频。
    USB Microphone https://www.soft-voice.com/
    Wooden Speakers https://www.zeshuiplatform.com/
    亚马逊测评 www.yisuping.cn
    深圳网站建设www.sz886.com
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值