FFmpeg三大工具--ffmpeg
  TTGEfHowA3iM 2023年11月02日 70 0


一、前言

FFmpeg的Static版本的​​bin​​​文件夹中只有三个​​.exe​​​文件,分别是: ​​ffmpeg.exe​​​、​​ffplay.exe​​​、​​ffprobe.exe​​,这三个是FFmpeg源代码编译后生成的可执行文件,也就是FFmpeg的三大工具,本文章主要介绍ffmpeg。

​ffmpeg​​​工具主要用于编解码,​​ffmpeg​​的主要工作流程相对比较简单,如下所示:

  • 读取输入源
  • 进行音视频的解封装
  • 解码每一帧音视频数据
  • 编码每一帧音视频数据
  • 进行音视频的重写封装
  • 输出到目标

FFmpeg三大工具--ffmpeg_封装


如上图示:

  • ffmpeg首先读取输入源,然后通过Demuxer将音视频包进行解封装,这个动作通过调用libavformat中的接口即可实现;
  • 接下来通过Decoder进行解码,将音视频通过Decoder解包称为YUV或者PCM这样的数据,Decoder通过libavcodec中的接口即可实现;
  • 然后通过Encoder将对应的数据进行编码,编码可以通过libavcodec中的接口来实现;
  • 接下来将编码后的音视频数据包通过Muxer进行封装,Muxer封装通过libavformat中的接口即可实现,输出成为输出流;

二、ffmpeg命令查询解析

通过​​ffmpeg --help​​可以看到ffmpeg常见的命令,大概分为6个部分:

  • ffmpeg信息查询部分
  • 公共操作参数部分
  • 文件主要操作参数部分
  • 视频操作参数部分
  • 音频操作参数部分
  • 字幕操作参数部分
C:\Users\wangjichuan>ffmpeg --help  //输入命令
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
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
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Getting help:
-h -- print basic options //打印基本参数
-h long -- print more options //打印更多参数
-h full -- print all options (including all format and codec specific options, very long) //打印全部参数
-h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter //打印指定模块参数,模块包括解码器、编码器、解封装、封装、滤镜
See man ffmpeg for detailed description of the options.

Print help / information / capabilities: //ffmpeg信息查询部分
-L show license //查询ffmpeg目前所支持的license协议
-h topic show help //查询help
-? topic show help //查询help
-help topic show help //查询help
--help topic show help //查询help
-version show version //查询ffmpeg的版本
-buildconf show build configuration
-formats show available formats //查询ffmpeg支持的文件格式
-muxers show available muxers //查询ffmpeg支持的封装
-demuxers show available demuxers //查询ffmpeg支持的解封装
-devices show available devices //查询ffmpeg支持的
-codecs show available codecs //查询ffmpeg支持的编码格式
-decoders show available decoders //查询ffmpeg支持的解码器
-encoders show available encoders //查询ffmpeg支持的编码器
-bsfs show available bit stream filters
-protocols show available protocols
-filters show available filters //查询ffmpeg支持的滤镜
-pix_fmts show available pixel formats
-layouts show standard channel layouts
-sample_fmts show available audio sample formats
-colors show available color names
-sources device list sources of the input device
-sinks device list sinks of the output device
-hwaccels show available HW acceleration methods

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)

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

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

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

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

三、命令查询示例

ffmpeg -formats

C:\Users\wangjichuan>ffmpeg -formats  //输入命令
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
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
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
File formats:
D. = Demuxing supported
.E = Muxing supported
--
D 3dostr 3DO STR
E 3g2 3GP2 (3GPP2 file format)
E 3gp 3GP (3GPP file format)
......
......
......
  • 第一列是多媒体文件封装格式的Demuxing支持与Muxing支持;
  • 第二列是多媒体文件格式;
  • 第三列是文件格式的详细说明;

ffmpeg -decoders

C:\Users\wangjichuan>ffmpeg -decoders  //输入命令
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
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
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Decoders:
V..... = Video
A..... = Audio
S..... = Subtitle
.F.... = Frame-level multithreading
..S... = Slice-level multithreading
...X.. = Codec is experimental
....B. = Supports draw_horiz_band
.....D = Supports direct rendering method 1
------
V....D 012v Uncompressed 4:2:2 10-bit
V....D 4xm 4X Movie
V....D 8bps QuickTime 8BPS video
......
......
......
  • 第一列包含6个字段:第一个字段用来表示此编码器为音频、视频还是字幕;第二个字段表示帧级别的多线程支持;第三个字段表示分片级别的多线程;第四个字段表示该编码为试验版本;第五个字段吧小时draw horiz band模式支持;第六个字段表示直接渲染模式支持;
  • 第二列是编码格式;
  • 第三列是编码格式的详细说明;

ffmpeg -filters

C:\Users\wangjichuan>ffmpeg -filters
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
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
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Filters:
T.. = Timeline support
.S. = Slice threading
..C = Command support
A = Audio input/output
V = Video input/output
N = Dynamic number and/or type of input/output
| = Source or sink filter
... abench A->A Benchmark part of a filtergraph.
... acompressor A->A Audio compressor.
... acopy A->A Copy the input audio unchanged to the output.
... acrossfade AA->A Cross fade two input audio streams.
... acrusher A->A Reduce audio bit resolution.
T.. adelay A->A Delay one or more audio channels.
... aecho A->A Add echoing to the audio.
... aemphasis A->A Audio emphasis.
... aeval A->A Filter audio signal according to a specified expression.
T.. afade A->A Fade in/out input audio.
... afftfilt A->A Apply arbitrary expressions to samples in frequency domain.
.S. afir AA->A Apply Finite Impulse Response filter with supplied coefficients in 2nd stream.
... aformat A->A Convert the input audio to one of the specified formats.
......
......
......
  • 第一列总共有3个字段:第一个字段是时间轴支持;第二个字段是分片线程处理支持;第三个字段是命令支持;
  • 第二列是滤镜名;
  • 第三列是转换方式,入音频转音频(A->A),视频转视频(V->V),创建音频(|->A),创建视频(|->V)等操作;
  • 第四列是滤镜作用说明;

三、命令测试实例

在此文件夹下按住​​Shift​​​点击​​鼠标右键​​​,选择:​​在此处打开命令行窗口​​:

FFmpeg三大工具--ffmpeg_linux_02


FFmpeg三大工具--ffmpeg_封装_03

输入如下命令:

ffmpeg -i test.mp4 test_out.avi

FFmpeg三大工具--ffmpeg_linux_04


FFmpeg三大工具--ffmpeg_ide_05


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
TTGEfHowA3iM