0. 前言

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=/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 用于输出时覆盖已有文件。

4. 单个文件相关的配置选项

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 用于设置输出文件帧的数量。

5. 多媒体视频相关的配置选项

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 用于配置相关的滤镜。

6. 多媒体音频相关的配置选项

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 常用于只保留视频数据的场合。

7. 多媒体字幕相关的配置选项

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 设置输出结果中屏蔽字幕信息,只保留音频或视频。


参考资料

[1] ffmpeg Documentation http://ffmpeg.org/ffmpeg-all.html

[2] FFmpeg命令行工具-实用命令 https://www.jianshu.com/p/124aee284a61

[3] ffmpeg常用命令 #32 https://github.com/gnipbao/iblog/issues/32

本文作者 :phillee

发表日期 :2021年5月19日

本文链接https://www.cnblogs.com/phillee/p/14785534.html

版权声明 :自由转载-非商用-非衍生-保持署名(创意共享3.0许可协议/CC BY-NC-SA 3.0)。转载请注明出处!

限于本人水平,如果文章和代码有表述不当之处,还请不吝赐教。

.outter_box { text-align: center }
.button { background-color: rgba(83, 168, 73, 1); border: none; border-radius: 6px; color: rgba(255, 255, 255, 1); padding: 9px 24px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px }
.img_box { border: none; color: rgba(255, 255, 255, 1); text-align: center; vertical-align: middle }
.demo { width: 208px; height: 260px; margin: 0 auto }
.demo img { -webkit-filter: drop-shadow(2px 2px 5px rgba(0,0,0,.5)); filter: drop-shadow(2px 2px 5px rgba(0,0,0,.5)) }

感谢您的支持

¥ 打赏

微信支付

FFmpeg应用实践之命令查询的更多相关文章

  1. Docker 命令查询

    Docker — 从入门到实践 Docker 命令查询 基本语法 Docker 命令有两大类,客户端命令和服务端命令.前者是主要的操作接口,后者用来启动 Docker Daemon. 客户端命令:基本 ...

  2. MongoDb进阶实践之六 MongoDB查询命令详述(补充)

    一.引言         上一篇文章我们已经介绍了MongoDB数据库的查询操作,但是并没有介绍全,随着自己的学习的深入,对查询又有了新的东西,决定补充进来.如果大家想看上一篇有关MongoDB查询的 ...

  3. 浅谈命令查询职责分离(CQRS)模式

    在常用的三层架构中,通常都是通过数据访问层来修改或者查询数据,一般修改和查询使用的是相同的实体.在一些业务逻辑简单的系统中可能没有什么问题,但是随着系统逻辑变得复杂,用户增多,这种设计就会出现一些性能 ...

  4. IDDD 实现领域驱动设计-CQRS(命令查询职责分离)和 EDA(事件驱动架构)

    上一篇:<IDDD 实现领域驱动设计-SOA.REST 和六边形架构> 阅读目录: CQRS-命令查询职责分离 EDA-事件驱动架构 Domin Event-领域事件 Long-Runni ...

  5. 转:浅谈命令查询职责分离(CQRS)模式

    原文来自于:http://www.cnblogs.com/yangecnu/p/Introduction-CQRS.html 在常用的三层架构中,通常都是通过数据访问层来修改或者查询数据,一般修改和查 ...

  6. CQRS(命令查询职责分离)和 EDA(事件驱动架构)

    转载CQRS(命令查询职责分离)和 EDA(事件驱动架构) 上一篇:<IDDD 实现领域驱动设计-SOA.REST 和六边形架构> 阅读目录: CQRS-命令查询职责分离 EDA-事件驱动 ...

  7. 【转】浅谈命令查询职责分离(CQRS)模式

    原文链接:https://www.cnblogs.com/yangecnu/p/Introduction-CQRS.html 在常用的三层架构中,通常都是通过数据访问层来修改或者查询数据,一般修改和查 ...

  8. 命令查询网站是否开启CDN加速

    1.使用ping命令 不一定准确  运行-CMD 直接输入ping  域名 C:\Users\6503>ping www.netnic.com.cn 正在 Ping u999.v.qingcdn ...

  9. Atitit.列表页面and条件查询的实现最佳实践(1)------设置查询条件and提交查询and返回json数据

    Atitit.列表页面and条件查询的实现最佳实践(1)------设置查询条件and提交查询and返回json数据 1. 1. 配置条件字段@Conditional 1 1 2. 2. 配置条件字段 ...

随机推荐

  1. [Azure Devops] 使用 Azure Boards 管理工作

    1. 什么是 Azure Boards 通过 Azure Boards 网络服务,团队可以管理其软件项目.它提供了丰富的功能,包括 Scrum 和看板的本地支持.可定制的仪表板和集成报告.这些工具可以 ...

  2. SDK音频测试流程

    概述 在上篇文章中,给小伙伴们讲述了sdk模板在渲染中的流程,我们简单来回顾一下,主要讲述了数据创建.素材替换.音频.文字等四部分,在上次讲述中也因为时间于原因没有特别仔细的去讲述他们.上次我们说到最 ...

  3. IT培训有哪些坑(二)?

    今天继续给大家分享一下IT培训都有哪些坑?有哪些不靠谱? 做招转的不靠谱.什么是招转?就是招聘转招生,名义上说的是招聘,但实际上做的就是招生.有很多大学刚毕业的计算机相关专业的同学,他们大学毕业之后, ...

  4. PReact10.5.13源码理解之hook

    hook源码其实不多,但是实现的比较精巧:在diff/index.js中会有一些optison.diff这种钩子函数,hook中就用到了这些钩子函数.   在比如options._diff中将curr ...

  5. ubuntu系统编译安装OpenCV 4.4

    内容转载自我的博客 目录 前言 1. 下载源码 2. 安装各种依赖 3. 开始编译安装 4. 配置C++开发环境 5. 程序执行时加载动态库*.so 6. 测试cpp文件 7. 配置python3的o ...

  6. spark未授权RCE漏洞

    Spark简介 spark是一个实现快速通用的集群计算平台.它是由加州大学伯克利分校AMP实验室 开发的通用内存并行计算框架,用来构建大型的.低延迟的数据分析应用程序.它扩展了广泛使用的MapRedu ...

  7. Vue Hello World

    1 Vue介绍 伟大的项目是从Hello World而来的,Hello World尽管没有什么实际性的作用,但是在于意义重大.(哈哈哈哈) 好了不废话了入正题. Vue是一套用于构建用户界面的渐进式J ...

  8. GO-02-helloworld

    package main /** package main表示一个可独立执行的程序,每个Go应用程序都需要包含一个名为main的包, 并且该包包含一个叫main()的函数(该函数是Go可执行程序的执行 ...

  9. 观世音甘泉活树的故事竟然是Java设计模式:备忘录模式

    目录 定义 意图 主要解决问题 何时使用 优缺点 结构 白箱实现 黑箱实现 多重检查点 观世音甘泉活树的故事 定义 备忘录模式是对象的行为型模式,备忘录对象是一个用来存储另外一个对象内部状态的快照的对 ...

  10. kubeadm安装kubernetes1.18.5

    前言 尝试安装helm3,kubernetes1.18,istio1.6是否支持现有集群平滑迁移 版本 Centos7.6 升级内核4.x kubernetes:v1.18.5 helm:v3.2.4 ...