ffmpeg的使用

下载、安装

Windows环境

  • 在浏览器打开 https://github.com/BtbN/FFmpeg-Builds/releases , 下载 ffmpeg-master-latest-win64-gpl.zip
  • 解压, 并把文件夹放到D盘
  • 设置环境变量, 在path中添加文件夹路径 D:\Program Files\ffmpeg\bin
  • 打开命令提示符,输入ffmpeg -version 查看版本信息

Linux环境

  • 下载、解压、编译
# wget https://ffmpeg.org/releases/ffmpeg-6.1.tar.xz --no-check-certificate
# tar xvf ffmpeg-6.1.tar.xz
# cd ffmpeg-6.1
# ./configure --prefix=/usr/local/ffmpeg
nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.libera.chat.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

安装yasm

# cd ~
# wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
# tar zxvf yasm-1.3.0.tar.gz
# cd yasm-1.3.0
# ./configure
# make && make install
# yasm --version
yasm 1.3.0
Compiled on Dec  7 2023.
  • 编译、安装ffmpeg
# cd ~/ffmpeg-6.1
# ./configure --prefix=/usr/local/ffmpeg
# make && make install
  • 配置变量

/etc/profile 文件最后添加环境变量

export PATH=$PATH:/usr/local/ffmpeg/bin

设置生效

# source /etc/profile
  • 查看版本
# ffmpeg -version

使用

1 Synopsis(概要)

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

2 Description(说明)

ffmpeg is a universal media converter. It can read a wide variety of inputs - including live grabbing/recording devices - filter, and transcode them into a plethora of output formats.

ffmpeg是一种通用的媒体转换器。它可以读取各种各样的输入,包括实时抓取/录制设备,过滤并将其转换为过多的输出格式。

ffmpeg reads from an arbitrary number of input “files” (which can be regular files, pipes, network streams, grabbing devices, etc.), specified by the -i option, and writes to an arbitrary number of output “files”, which are specified by a plain output url. Anything found on the command line which cannot be interpreted as an option is considered to be an output url.

ffmpeg读取由-i选项指定的任意数量的输入“文件”(可以是常规文件、管道、网络流、抓取设备等),并写入由纯输出url指定的任意数目的输出“文件”。在命令行上找到的任何不能被解释为选项的内容都被视为输出url。

Each input or output url can, in principle, contain any number of streams of different types (video/audio/subtitle/attachment/data). The allowed number and/or types of streams may be limited by the container format. Selecting which streams from which inputs will go into which output is either done automatically or with the -map option (see the Stream selection chapter).

原则上,每个输入或输出url可以包含任意数量的不同类型的流(视频/音频/字幕/附件/数据)。允许的流的数量和/或类型可能受到容器格式的限制。选择哪些流,哪些输入将进入哪个输出,要么自动完成,要么使用-map选项(请参阅流选择一章)。

To refer to input files in options, you must use their indices (0-based). E.g. the first input file is 0, the second is 1, etc. Similarly, streams within a file are referred to by their indices. E.g. 2:3 refers to the fourth stream in the third input file. Also see the Stream specifiers chapter.

若要引用选项中的输入文件,必须使用它们的索引(基于0)。例如,第一个输入文件是0,第二个是1,等等。类似地,文件内的流通过它们的索引来引用。例如2:3是指第三个输入文件中的第四个流。另请参阅流说明符一章。

As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file. Exceptions from this rule are the global options (e.g. verbosity level), which should be specified first.

通常情况下,选项会应用于下一个指定的文件。因此,顺序很重要,您可以多次在命令行中使用相同的选项。然后,每次出现都会应用到下一个输入或输出文件。此规则的例外情况是全局选项(例如详细级别),应首先指定。

Do not mix input and output files – first specify all input files, then all output files. Also do not mix options which belong to different files. All options apply ONLY to the next input or output file and are reset between files.

不要混合输入和输出文件——首先指定所有输入文件,然后指定所有输出文件。也不要混合属于不同文件的选项。所有选项仅适用于下一个输入或输出文件,并在文件之间重置。

Some simple examples follow.

下面是一些简单的例子。

  • Convert an input media file to a different format, by re-encoding media streams:(通过重新编码媒体流,将输入媒体文件转换为其他格式:)

    # ffmpeg -i input.avi output.mp4
    
  • Set the video bitrate of the output file to 64 kbit/s:(将输出文件的视频比特率设置为64 kbit/s:)

    # ffmpeg -i input.avi -b:v 64k -bufsize 64k output.mp4
    
  • Force the frame rate of the output file to 24 fps:(强制输出文件的帧速率为24 fps:)

    # ffmpeg -i input.avi -r 24 output.mp4
    
  • Force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps:(强制输入文件的帧速率(仅对原始格式有效)为1 fps,强制输出文件的帧率为24 fps:)

    # ffmpeg -r 1 -i input.m2v -r 24 output.mp4
    

The format option may be needed for raw input files.

原始输入文件可能需要格式选项。

3 Detailed description(详细说明)

The transcoding process in ffmpeg for each output can be described by the following diagram:

ffmpeg中针对每个输出的转码过程可以通过下图来描述:

 _______              ______________
|       |            |              |
| input |  demuxer   | encoded data |   decoder
| file  | ---------> | packets      | -----+
|_______|            |______________|      |
                                           v
                                       _________
                                      |         |
                                      | decoded |
                                      | frames  |
                                      |_________|
 ________             ______________       |
|        |           |              |      |
| output | <-------- | encoded data | <----+
| file   |   muxer   | packets      |   encoder
|________|           |______________|

 _______              _________
|       |            |         | 
|  输入 |  解复用器   | 编码后的 |   解码器
|  文件 | ---------> | 数据包   | ---------+
|_______|            |_________|          |
                                          v
                                       _______
                                      |       |
                                      | 解码后 |
                                      | 的帧   |
                                      |_______|
 ______             _________             |
|      |           |         |            |
| 输出 | <-------- | 编码后的 | <----------+
| 文件 | 多路复用器 | 数据包   |      编码器
|___ __|           |_________|

ffmpeg calls the libavformat library (containing demuxers) to read input files and get packets containing encoded data from them. When there are multiple input files, ffmpeg tries to keep them synchronized by tracking lowest timestamp on any active input stream.

ffmpeg调用libavformat库(包含解复用器)来读取输入文件,并从中获取包含编码数据的包。当有多个输入文件时,ffmpeg试图通过跟踪任何活动输入流上的最低时间戳来保持它们的同步。

Encoded packets are then passed to the decoder (unless streamcopy is selected for the stream, see further for a description). The decoder produces uncompressed frames (raw video/PCM audio/…) which can be processed further by filtering (see next section). After filtering, the frames are passed to the encoder, which encodes them and outputs encoded packets. Finally those are passed to the muxer, which writes the encoded packets to the output file.

编码过的包随后被传递到解码器(除非流选择了streamcopy,请参阅进一步的描述)。解码器产生未压缩的帧(原始视频/PCM音频/…),这些帧可以通过过滤进行进一步处理(见下一节)。在过滤之后,帧被传递到编码器,编码器对它们进行编码并输出编码过的包。最后,这些数据被传递给复用器,复用器将编码过的包写入输出文件。

3.1 Filtering(过滤)

Before encoding, ffmpeg can process raw audio and video frames using filters from the libavfilter library. Several chained filters form a filter graph. ffmpeg distinguishes between two types of filtergraphs: simple and complex.

在编码之前,ffmpeg可以使用libavfilter库中的滤镜来处理原始音频和视频帧。几个链式滤镜形成一个滤镜链图。ffmpeg区分了两种类型的滤镜链图:简单的滤镜链图和复杂的滤镜链图。

3.1.1 Simple filtergraphs(简单的滤镜链图)

Simple filtergraphs are those that have exactly one input and output, both of the same type. In the above diagram they can be represented by simply inserting an additional step between decoding and encoding:

简单的滤镜链图是那些只有一个输入和输出的滤镜链图,它们都是相同类型的。在上图中,它们可以通过简单地在解码和编码之间插入附加步骤来表示:

 _________                        ______________
|         |                      |              |
| decoded |                      | encoded data |
| frames  |\                   _ | packets      |
|_________| \                  /||______________|
             \   __________   /
  simple     _\||          | /  encoder
  filtergraph   | filtered |/
                | frames   |
                |__________|


 _____                            _________
|        |                       |         |
| 解码后 |                       | 编码后的 |
| 的帧   |\                    _ | 数据包   |
|______  | \                   /||_________|
            \     ________    /
    简单     _\| |        |  /    编码器
    滤镜链图      | 过滤后 |/
                 | 的帧   |
                 |________|
               

Simple filtergraphs are configured with the per-stream -filter option (with -vf and -af aliases for video and audio respectively). A simple filtergraph for video can look for example like this:

简单的滤镜链图用每个流的-filter选项(视频和音频分别以 -vf-af 为别名)来配置。例如,一个简单的视频滤镜链图可以如下所示:

 _______        _____________        _______        ________
|       |      |             |      |       |      |        |
| input | ---> | deinterlace | ---> | scale | ---> | output |
|_______|      |_____________|      |_______|      |________|

 ______        _______        _________        ______
|      |      |       |      |         |      |      |
| 输入 | ---> | 反交错 | ---> | 改变大小 | ---> | 输出 |
|______|      |_______|      |_________|      |______|

Note that some filters change frame properties but not frame contents. E.g. the fps filter in the example above changes number of frames, but does not touch the frame contents. Another example is the setpts filter, which only sets timestamps and otherwise passes the frames unchanged.

请注意,某些滤镜会更改帧属性,而不更改帧内容。例如,上述示例中的fps 滤镜改变帧数,但不触摸帧内容。另一个例子是setpts 滤镜,它只设置时间戳,否则不更改帧。

3.1.2 Complex filtergraphs(复杂的滤镜链图)

Complex filtergraphs are those which cannot be described as simply a linear processing chain applied to one stream. This is the case, for example, when the graph has more than one input and/or output, or when output stream type is different from input. They can be represented with the following diagram:

复杂的滤镜链图是那些不能简单地描述为应用于一个流的线性处理链的滤镜链图。例如,当图形具有多个输入和/或输出时,或者当输出流类型与输入不同时,就会出现这种情况。它们可以用下图表示:

 _________
|         |
| input 0 |\                    __________
|_________| \                  |          |
             \   _________    /| output 0 |
              \ |         |  / |__________|
 _________     \| complex | /
|         |     |         |/
| input 1 |---->| filter  |\
|_________|     |         | \   __________
               /| graph   |  \ |          |
              / |         |   \| output 1 |
 _________   /  |_________|    |__________|
|         | /
| input 2 |/
|_________|

 _______
|       |
| 输入0 |\                      _______
|_______| \                    |       |
           \     ________     /| 输出0 |
            \   |        |   / |_______|
 _______     \  | 复杂的  | /
|       |       |        |/
| 输入1 |---->  | 滤镜    |\
|_______|       |         | \    _______
               /| 链表    |   \ |       |
              / |         |    \| 输出1 |
 _______    /   |_________|     |_______|
|       | /
| 输入2 |/
|_______|

Complex filtergraphs are configured with the -filter_complex option. Note that this option is global, since a complex filtergraph, by its nature, cannot be unambiguously associated with a single stream or file.

使用 -filter_complex选项配置复杂的滤镜链图。请注意,此选项是全局性的,因为复杂的过滤器图本质上无法明确地与单个流或文件相关联。

The -lavfi option is equivalent to -filter_complex.

-lavfi选项等效于-filter_complex

A trivial example of a complex filtergraph is the overlay filter, which has two video inputs and one video output, containing one video overlaid on top of the other. Its audio counterpart is the amix filter.

复杂的滤镜链图的一个微不足道的例子是overlay 滤镜,它有两个视频输入和一个视频输出,其中包含一个叠加在另一个之上的视频。它的音频相对应的是amix 滤镜。

3.2 Stream copy(流复制)

Stream copy is a mode selected by supplying the copy parameter to the -codec option. It makes ffmpeg omit the decoding and encoding step for the specified stream, so it does only demuxing and muxing. It is useful for changing the container format or modifying container-level metadata. The diagram above will, in this case, simplify to this:

流复制是通过将copy参数提供给-codec选项来选择的模式。它使ffmpeg省略了对指定流的解码和编码步骤,因此只进行解复用和复用。它可用于更改容器格式或修改容器级元数据。在这种情况下,上图将简化为:

 _______              ______________            ________
|       |            |              |          |        |
| input |  demuxer   | encoded data |  muxer   | output |
| file  | ---------> | packets      | -------> | file   |
|_______|            |______________|          |________|

 ______             _________             ______
|      |           |         |           |      |
| 输入 |  解复用器  | 编码后的 | 多路复用器 | 输出 |
| 文件 | --------->| 数据包   | --------> | 文件 |
|______|           |_________|           |______|

Since there is no decoding or encoding, it is very fast and there is no quality loss. However, it might not work in some cases because of many factors. Applying filters is obviously also impossible, since filters work on uncompressed data.

由于没有解码或编码,所以速度非常快,并且没有质量损失。然而,由于多种因素,它在某些情况下可能不起作用。应用滤镜显然也是不可能的,因为滤镜适用于未压缩的数据。

4 Stream selection(流选择)

ffmpeg provides the -map option for manual control of stream selection in each output file. Users can skip -map and let ffmpeg perform automatic stream selection as described below. The -vn / -an / -sn / -dn options can be used to skip inclusion of video, audio, subtitle and data streams respectively, whether manually mapped or automatically selected, except for those streams which are outputs of complex filtergraphs.

ffmpeg提供了-map选项,用于手动控制每个输出文件中的流选择。用户可以跳过-map,让ffmpeg执行自动流选择,如下所述。无论是手动映射还是自动选择, -vn/-an/-sn/-dn选项都可用于分别跳过视频、音频、字幕和数据流,但作为复杂的过滤链图输出的流除外。

4.1 Description(说明)

The sub-sections that follow describe the various rules that are involved in stream selection. The examples that follow next show how these rules are applied in practice.

下面的小节描述了流选择中涉及的各种规则。下面的例子展示了这些规则是如何在实践中应用的。

While every effort is made to accurately reflect the behavior of the program, FFmpeg is under continuous development and the code may have changed since the time of this writing.

虽然我们尽一切努力准确地反映程序的行为,但FFmpeg正在不断开发中,自撰写本文以来,代码可能已经发生了变化。

4.1.1 Automatic stream selection(自动流选择)

In the absence of any map options for a particular output file, ffmpeg inspects the output format to check which type of streams can be included in it, viz. video, audio and/or subtitles. For each acceptable stream type, ffmpeg will pick one stream, when available, from among all the inputs.

在没有特定输出文件的任何映射选项的情况下,ffmpeg会检查输出格式,以检查其中可以包括哪种类型的流,即视频、音频和/或字幕。对于每个可接受的流类型,如果可用,ffmpeg将从所有输入中选择一个流。

It will select that stream based upon the following criteria:

它将根据以下标准选择该流:

  • for video, it is the stream with the highest resolution,(对于视频,它是具有最高分辨率的流,)
  • for audio, it is the stream with the most channels,(对于音频,它是具有最多通道的流,)
  • for subtitles, it is the first subtitle stream found but there’s a caveat. The output format’s default subtitle encoder can be either text-based or image-based, and only a subtitle stream of the same type will be chosen.(对于字幕,这是第一个找到的字幕流,但有一个警告。输出格式的默认字幕编码器可以是基于文本的,也可以是基于图像的,并且只会选择相同类型的字幕流。)

In the case where several streams of the same type rate equally, the stream with the lowest index is chosen.

在相同类型的多个流速率相等的情况下,选择具有最低索引的流。

Data or attachment streams are not automatically selected and can only be included using -map.

数据或附件流不会自动选择,只能使用-map包含。

4.1.2 Manual stream selection(手动流选择)

When -map is used, only user-mapped streams are included in that output file, with one possible exception for filtergraph outputs described below.

当使用-map时,只有用户映射的流包含在该输出文件中,下面描述的滤镜链图输出可能有一个例外。

4.1.3 Complex filtergraphs(复杂的滤镜链图)

If there are any complex filtergraph output streams with unlabeled pads, they will be added to the first output file. This will lead to a fatal error if the stream type is not supported by the output format. In the absence of the map option, the inclusion of these streams leads to the automatic stream selection of their types being skipped. If map options are present, these filtergraph streams are included in addition to the mapped streams.

如果有任何带有未标记端的复杂滤镜链图输出流,它们将被添加到第一个输出文件中。如果输出格式不支持流类型,这将导致致命错误。在没有map选项的情况下,包含这些流会导致跳过其类型的自动流选择。如果存在映射选项,则除了映射的流之外,还包括这些滤镜链图流。

Complex filtergraph output streams with labeled pads must be mapped once and exactly once.

带有标记端的复杂滤波器图输出流必须映射一次,且只能映射一次。

4.1.4 Stream handling(流处理)

Stream handling is independent of stream selection, with an exception for subtitles described below. Stream handling is set via the -codec option addressed to streams within a specific output file. In particular, codec options are applied by ffmpeg after the stream selection process and thus do not influence the latter. If no -codec option is specified for a stream type, ffmpeg will select the default encoder registered by the output file muxer.

流处理独立于流选择,下面描述的字幕除外。流处理是通过-codec选项设置的,该选项寻址到特定输出文件中的流。特别地,codec选项在流选择过程之后由ffmpeg应用,因此不影响后者。如果没有为流类型指定-codec选项,则ffmpeg将选择输出文件复用器注册的默认编码器。

An exception exists for subtitles. If a subtitle encoder is specified for an output file, the first subtitle stream found of any type, text or image, will be included. ffmpeg does not validate if the specified encoder can convert the selected stream or if the converted stream is acceptable within the output format. This applies generally as well: when the user sets an encoder manually, the stream selection process cannot check if the encoded stream can be muxed into the output file. If it cannot, ffmpeg will abort and all output files will fail to be processed.

字幕存在例外。如果为输出文件指定了字幕编码器,则会包括找到的任何类型(文本或图像)的第一个字幕流。ffmpeg不验证指定的编码器是否可以转换所选流,或者转换后的流在输出格式中是否可以接受。这通常也适用:当用户手动设置编码器时,流选择过程无法检查编码流是否可以复用到输出文件中。如果不能,ffmpeg将中止,所有输出文件都将无法处理。

4.2 Examples(示例)

The following examples illustrate the behavior, quirks and limitations of ffmpeg’s stream selection methods.

以下示例说明了ffmpeg的流选择方法的行为、怪癖和局限性。

They assume the following three input files.

它们假设有以下三个输入文件。

input file 'A.avi'
      stream 0: video 640x360
      stream 1: audio 2 channels

input file 'B.mp4'
      stream 0: video 1920x1080
      stream 1: audio 2 channels
      stream 2: subtitles (text)
      stream 3: audio 5.1 channels
      stream 4: subtitles (text)

input file 'C.mkv'
      stream 0: video 1280x720
      stream 1: audio 2 channels
      stream 2: subtitles (image)

Example: automatic stream selection(示例:自动流选择)
# ffmpeg -i A.avi -i B.mp4 out1.mkv out2.wav -map 1:a -c:a copy out3.mov

There are three output files specified, and for the first two, no -map options are set, so ffmpeg will select streams for these two files automatically.

指定了三个输出文件,对于前两个,没有设置任何-map选项,因此ffmpeg将自动为这两个文件选择流。

out1.mkv is a Matroska container file and accepts video, audio and subtitle streams, so ffmpeg will try to select one of each type.

out1.mkv是一个Matroska容器文件,接受视频、音频和字幕流,因此ffmpeg将尝试从每种类型中选择一种。

For video, it will select stream 0 from B.mp4, which has the highest resolution among all the input video streams.

对于视频,它将从B.mp4中选择stream 0,该流在所有输入视频流中具有最高的分辨率。

For audio, it will select stream 3 from B.mp4, since it has the greatest number of channels.

对于音频,它将从B.mp4中选择stream 3,因为它具有最多的通道数。

For subtitles, it will select stream 2 from B.mp4, which is the first subtitle stream from among A.avi and B.mp4.

对于字幕,它将选择B.mp4的stream 2,这是A.avi和B.mp4中的第一个字幕流。

out2.wav accepts only audio streams, so only stream 3 from B.mp4 is selected.

out2.wav只接受音频流,因此只选择B.mp4中的stream 3

For out3.mov, since a -map option is set, no automatic stream selection will occur. The -map 1:a option will select all audio streams from the second input B.mp4. No other streams will be included in this output file.

对于out3.mov,由于设置了-map选项,因此不会发生自动流选择。-map 1:a选项将从第二个输入B.mp4中选择所有音频流。此输出文件中不会包含其他流。

For the first two outputs, all included streams will be transcoded. The encoders chosen will be the default ones registered by each output format, which may not match the codec of the selected input streams.

对于前两个输出,所有包含的流都将进行转码。所选择的编码器将是每个输出格式注册的默认编码器,其可能与所选输入流的编解码器不匹配。

For the third output, codec option for audio streams has been set to copy, so no decoding-filtering-encoding operations will occur, or can occur. Packets of selected streams shall be conveyed from the input file and muxed within the output file.

对于第三个输出,音频流的编解码器选项已设置为copy,因此不会发生可能发生 解码-过滤-编码 操作。所选流的数据包应从输入文件中传输,并在输出文件中进行复用。

Example: automatic subtitles selection(示例:自动字幕选择)
# ffmpeg -i C.mkv out1.mkv -c:s dvdsub -an out2.mkv

Although out1.mkv is a Matroska container file which accepts subtitle streams, only a video and audio stream shall be selected. The subtitle stream of C.mkv is image-based and the default subtitle encoder of the Matroska muxer is text-based, so a transcode operation for the subtitles is expected to fail and hence the stream isn’t selected. However, in out2.mkv, a subtitle encoder is specified in the command and so, the subtitle stream is selected, in addition to the video stream. The presence of -an disables audio stream selection for out2.mkv.

尽管out1.mkv是一个接受字幕流的Matroska容器文件,但只能选择视频和音频流。C.mkv的字幕流是基于图像的,Matroska复用器的默认字幕编码器是基于文本的,因此字幕的转码操作预计会失败,因此未选择该流。然而,在out2.mkv中,在命令中指定了字幕编码器,因此,除了视频流之外,还选择了字幕流。-an的存在将禁用out2.mkv的音频流选择。

Example: unlabeled filtergraph outputs(示例:未标记的滤镜链图输出)
# ffmpeg -i A.avi -i C.mkv -i B.mp4 -filter_complex "overlay" out1.mp4 out2.srt

A filtergraph is setup here using the -filter_complex option and consists of a single video filter. The overlay filter requires exactly two video inputs, but none are specified, so the first two available video streams are used, those of A.avi and C.mkv. The output pad of the filter has no label and so is sent to the first output file out1.mp4. Due to this, automatic selection of the video stream is skipped, which would have selected the stream in B.mp4. The audio stream with most channels viz. stream 3 in B.mp4, is chosen automatically. No subtitle stream is chosen however, since the MP4 format has no default subtitle encoder registered, and the user hasn’t specified a subtitle encoder.

这里使用-filter_complex选项设置了一个滤镜链图,它由一个视频滤镜组成。overlay 滤镜正好需要两个视频输入,但没有指定,因此使用前两个可用的视频流,即A.avi和C.mkv的视频流。滤镜的输出端没有标签,因此被发送到第一个输出文件out1.mp4。因此,跳过视频流的自动选择,这将选择B.mp4中的流。自动选择具有大多数声道的音频流,即B.mp4中的 stream 3。然而,没有选择字幕流,因为MP4格式没有注册默认的字幕编码器,并且用户没有指定字幕编码器。

The 2nd output file, out2.srt, only accepts text-based subtitle streams. So, even though the first subtitle stream available belongs to C.mkv, it is image-based and hence skipped. The selected stream, stream 2 in B.mp4, is the first text-based subtitle stream.

第二个输出文件out2.srt只接受基于文本的字幕流。因此,即使第一个可用的字幕流属于C.mkv,它也是基于图像的,因此被跳过。所选择的流,即B.mp4中的stream 2,是第一个基于文本的字幕流。

Example: labeled filtergraph outputs(示例:标记的滤波器图输出)
# ffmpeg -i A.avi -i B.mp4 -i C.mkv -filter_complex "[1:v]hue=s=0[outv];overlay;aresample" \
       -map '[outv]' -an        out1.mp4 \
                                out2.mkv \
       -map '[outv]' -map 1:a:0 out3.mkv

The above command will fail, as the output pad labelled [outv] has been mapped twice. None of the output files shall be processed.

上述命令将失败,因为标记为[outv]的输出端已映射两次。不得处理任何输出文件。

# ffmpeg -i A.avi -i B.mp4 -i C.mkv -filter_complex "[1:v]hue=s=0[outv];overlay;aresample" \
       -an        out1.mp4 \
                  out2.mkv \
       -map 1:a:0 out3.mkv

This command above will also fail as the hue filter output has a label, [outv], and hasn’t been mapped anywhere.

上面的这个命令也会失败,因为hue 滤镜输出有一个标签[outv],并且没有映射到任何地方。

The command should be modified as follows,

该命令应修改如下,

# ffmpeg -i A.avi -i B.mp4 -i C.mkv -filter_complex "[1:v]hue=s=0,split=2[outv1][outv2];overlay;aresample" \
        -map '[outv1]' -an        out1.mp4 \
                                  out2.mkv \
        -map '[outv2]' -map 1:a:0 out3.mkv

The video stream from B.mp4 is sent to the hue filter, whose output is cloned once using the split filter, and both outputs labelled. Then a copy each is mapped to the first and third output files.

B.mp4的视频流被发送到hue 滤镜,其输出被使用split 滤镜克隆一次,并且两个输出都被标记。然后,每个副本都映射到第一和第三输出文件。

The overlay filter, requiring two video inputs, uses the first two unused video streams. Those are the streams from A.avi and C.mkv. The overlay output isn’t labelled, so it is sent to the first output file out1.mp4, regardless of the presence of the -map option.

overlay 滤镜需要两个视频输入,使用前两个未使用的视频流。这些是来自A.avi和C.mkv的流。overlay输出没有标记,因此无论-map 选项是否存在,它都会被发送到第一个输出文件out1.mp4。

The aresample filter is sent the first unused audio stream, that of A.avi. Since this filter output is also unlabelled, it too is mapped to the first output file. The presence of -an only suppresses automatic or manual stream selection of audio streams, not outputs sent from filtergraphs. Both these mapped streams shall be ordered before the mapped stream in out1.mp4.

aresample 滤镜发送第一个未使用的音频流,即A.avi的音频流。由于该滤镜输出也未标记,因此它也被映射到第一个输出文件。-an的存在仅抑制音频流的自动或手动流选择,而不是从滤镜链图发送的输出。这两个映射流应在out1.mp4中的映射流之前排序。

The video, audio and subtitle streams mapped to out2.mkv are entirely determined by automatic stream selection.

映射到out2.mkv的视频、音频和字幕流完全由自动流选择决定。

out3.mkv consists of the cloned video output from the hue filter and the first audio stream from B.mp4.

out3.mkv由hue 滤镜的克隆视频输出和B.mp4的第一音频流组成。

5 Options(选项)

All the numerical options, if not specified otherwise, accept a string representing a number as input, which may be followed by one of the SI unit prefixes, for example: ’K’, ’M’, or ’G’.

如果未另行指定,则所有数字选项都接受表示数字的字符串作为输入,该字符串后面可以跟一个国际单位前缀,例如:“K”、“M”或“G”。

If ’i’ is appended to the SI unit prefix, the complete prefix will be interpreted as a unit prefix for binary multiples, which are based on powers of 1024 instead of powers of 1000. Appending ’B’ to the SI unit prefix multiplies the value by 8. This allows using, for example: ’KB’, ’MiB’, ’G’ and ’B’ as number suffixes.

如果“i”附加到国际单位前缀,则完整前缀将被解释为二进制倍数的单位前缀,二进制倍数基于1024的幂,而不是1000的幂。在国际单位制前缀后面加上“B”,值将乘以8。例如,这允许使用“KB”、“MiB”、“G”和“B”作为数字后缀。

Options which do not take arguments are boolean options, and set the corresponding value to true. They can be set to false by prefixing the option name with “no”. For example using “-nofoo” will set the boolean option with name “foo” to false.

不带参数的选项是布尔选项,并将相应的值设置为true。通过在选项名称前面加上“no”,可以将它们设置为false。例如,使用“-nofoo”将名称为“foo”的布尔选项设置为false。

5.1 Stream specifiers(流说明符)

Some options are applied per-stream, e.g. bitrate or codec. Stream specifiers are used to precisely specify which stream(s) a given option belongs to.

每个流应用一些选项,例如比特率或编解码器。流说明符用于精确指定给定选项所属的流。

A stream specifier is a string generally appended to the option name and separated from it by a colon. E.g. -codec:a:1 ac3 contains the a:1 stream specifier, which matches the second audio stream. Therefore, it would select the ac3 codec for the second audio stream.

流说明符是一个字符串,通常附加在选项名称后,并用冒号与之隔开。例如-codec:a:1 ac3包含a:1流说明符,其与第二个音频流匹配。因此,它将为第二音频流选择ac3编解码器。

A stream specifier can match several streams, so that the option is applied to all of them. E.g. the stream specifier in -b:a 128k matches all audio streams.

流说明符可以匹配多个流,以便将该选项应用于所有流。例如,-b:a 128k中的流说明符匹配所有音频流。

An empty stream specifier matches all streams. For example, -codec copy or -codec: copy would copy all the streams without reencoding.

空的流说明符匹配所有流。例如,-codec copy-codec: copy 将在不重新编码的情况下复制所有流。

Possible forms of stream specifiers are:

流说明符的可能形式有:

  • stream_index

    Matches the stream with this index. E.g. -threads:1 4 would set the thread count for the second stream to 4. If stream_index is used as an additional stream specifier (see below), then it selects stream number stream_index from the matching streams. Stream numbering is based on the order of the streams as detected by libavformat except when a program ID is also specified. In this case it is based on the ordering of the streams in the program.

    将流与此索引匹配。例如-threads:1 4将第二个流的线程数设置为4。如果stream_index被用作额外的流说明符(见下文),则它从匹配的流中选择流编号stream_index。流编号基于libavformat 检测到的流的顺序,除非还指定了程序ID。在这种情况下,它是基于程序中流的顺序。

  • stream_type[:additional_stream_specifier]

    stream_type is one of following: ’v’ or ’V’ for video, ’a’ for audio, ’s’ for subtitle, ’d’ for data, and ’t’ for attachments. ’v’ matches all video streams, ’V’ only matches video streams which are not attached pictures, video thumbnails or cover arts. If additional_stream_specifier is used, then it matches streams which both have this type and match the additional_stream_specifier. Otherwise, it matches all streams of the specified type.

    stream_type是以下其中之一:“v”或“V”表示视频,“a”表示音频,“s”表示字幕,“d”表示数据,“t”表示附件。v’匹配所有视频流,'V’仅匹配未附加图片、视频缩略图或封面艺术的视频流。如果使用additional_stream_specifer,那么它将匹配具有此类型并与additional_stream_specifier匹配的流。否则,它将匹配指定类型的所有流。

  • p:program_id[:additional_stream_specifier]

    Matches streams which are in the program with the id program_id. If additional_stream_specifier is used, then it matches streams which both are part of the program and match the additional_stream_specifier.

    将程序中的流与id program_id进行匹配。如果使用additional_stream_specifer,那么它将匹配既是程序一部分又与additional_stream_specifier匹配的流。

  • #stream_id or i:stream_id

    Match the stream by stream id (e.g. PID in MPEG-TS container).

    按流id匹配流(例如,MPEG-TS容器中的PID)。

  • m:key[:value]

    Matches streams with the metadata tag key having the specified value. If value is not given, matches streams that contain the given tag with any value.

    将流与具有指定值的元数据标记键相匹配。如果未给定值,则将包含给定标记的流与任何值进行匹配。

  • u

    Matches streams with usable configuration, the codec must be defined and the essential information such as video dimension or audio sample rate must be present.Note that in ffmpeg, matching by metadata will only work properly for input files.

    将流与可用配置相匹配,必须定义编解码器,并且必须提供视频维度或音频采样率等基本信息。请注意,在ffmpeg 中,通过元数据进行匹配仅适用于输入文件。

5.2 Generic options(常规选项)

These options are shared amongst the ff* tools.

  • -L

    Show license.

    显示许可证。

  • -h, -?, -help, --help [arg]

    Show help. An optional parameter may be specified to print help about a specific item. If no argument is specified, only basic (non advanced) tool options are shown.Possible values of arg are:

    显示帮助。可以指定一个可选参数来打印有关特定项目的帮助。如果未指定任何参数,则仅显示基本(非高级)工具选项。参数的可能值为:

    • long

      Print advanced tool options in addition to the basic tool options.

      除了打印基本工具选项外,还打印高级工具选项。

    • full

      Print complete list of options, including shared and private options for encoders, decoders, demuxers, muxers, filters, etc.

      打印完整的选项列表,包括编码器、解码器、解复用器、复用器、滤镜等的共享和专用选项。

    • decoder=decoder_name

      Print detailed information about the decoder named decoder_name. Use the -decoders option to get a list of all decoders.

      打印有关名为decoder_name 的解码器的详细信息。使用-decoders 选项可以获得所有解码器的列表。

    • encoder=encoder_name

      Print detailed information about the encoder named encoder_name. Use the -encoders option to get a list of all encoders.

      打印有关名为encoder_name的编码器的详细信息。使用-encoders 选项可以获得所有编码器的列表。

    • demuxer=demuxer_name

      Print detailed information about the demuxer named demuxer_name. Use the -formats option to get a list of all demuxers and muxers.

      打印有关名为demuxer_name的解复用器的详细信息。使用-formats 选项可以获得所有解复用器和复用器的列表。

    • muxer=muxer_name

      Print detailed information about the muxer named muxer_name. Use the -formats option to get a list of all muxers and demuxers.

      打印有关名为muxer_name 的复用器的详细信息。使用-formats 选项可以获得所有复用器和解复用器的列表。

    • filter=filter_name

      Print detailed information about the filter named filter_name. Use the -filters option to get a list of all filters.

      打印有关名为filter_name的滤镜的详细信息。使用-filters 选项可以获取所有滤镜的列表。

    • bsf=bitstream_filter_name

      Print detailed information about the bitstream filter named bitstream_filter_name. Use the -bsfs option to get a list of all bitstream filters.

      打印有关名为bitstream_filter_name的比特流滤镜的详细信息。使用-bsfs 选项可以获得所有比特流滤镜的列表。

    • protocol=protocol_name

      Print detailed information about the protocol named protocol_name. Use the -protocols option to get a list of all protocols.

      打印名为protocol_name 的协议的详细信息。使用-protocols选项可以获取所有协议的列表。

  • -version

    Show version.

    显示版本。

  • -buildconf

    Show the build configuration, one option per line.

    显示构建配置,每行一个选项。

  • -formats

    Show available formats (including devices).

    显示可用的格式(包括设备)。

  • -demuxers

    Show available demuxers.

    显示可用的解复用器。

  • -muxers

    Show available muxers.

    显示可用的复用器。

  • -devices

    Show available devices.

    显示可用设备。

  • -codecs

    Show all codecs known to libavcodec.Note that the term ’codec’ is used throughout this documentation as a shortcut for what is more correctly called a media bitstream format.

    显示libavcodec 已知的所有编解码器。请注意,“编解码器”一词在本文档中被用作更正确地称为媒体比特流格式的快捷方式。

  • -decoders

    Show available decoders.

    显示可用的解码器。

  • -encoders

    Show all available encoders.

    显示所有可用的编码器。

  • -bsfs

    Show available bitstream filters.

    显示可用的比特流滤镜。

  • -protocols

    Show available protocols.

    显示可用的协议。

  • -filters

    Show available libavfilter filters.

    显示可用的libavfilter 滤镜。

  • -pix_fmts

    Show available pixel formats.

    显示可用的像素格式。

  • -sample_fmts

    Show available sample formats.

    显示可用的采样格式。

  • -layouts

    Show channel names and standard channel layouts.

    显示通道名称和标准通道布局。

  • -dispositions

    Show stream dispositions.

    显示流部署。

  • -colors

    Show recognized color names.

    显示已识别的颜色名称。

  • -sources device[,opt1=val1[,opt2=val2]...]

    Show autodetected sources of the input device. Some devices may provide system-dependent source names that cannot be autodetected. The returned list cannot be assumed to be always complete.ffmpeg -sources pulse,server=192.168.0.4

    显示输入设备的自动检测源。某些设备可能提供无法自动检测的系统相关源名称。不能认为返回的列表总是完整的。ffmpeg -sources pulse,server=192.168.0.4

  • -sinks device[,opt1=val1[,opt2=val2]...]

    Show autodetected sinks of the output device. Some devices may provide system-dependent sink names that cannot be autodetected. The returned list cannot be assumed to be always complete.ffmpeg -sinks pulse,server=192.168.0.4

    显示输出设备的自动检测接收器。某些设备可能提供无法自动检测的系统相关接收器名称。不能假定返回的列表总是完整的。ffmpeg -sinks pulse,server=192.168.0.4

  • -loglevel [flags+]loglevel | -v [flags+]loglevel

    Set logging level and flags used by the library.

    设置日志记录级别和库使用的标志。

    The optional flags prefix can consist of the following values:

    可选 flags 前缀可以由以下值组成:

    • repeat

      Indicates that repeated log output should not be compressed to the first line and the “Last message repeated n times” line will be omitted.

      指示重复的日志输出不应压缩到第一行,并且将忽略“最后一条消息重复n次”的行。

    • level

      Indicates that log output should add a [level] prefix to each message line. This can be used as an alternative to log coloring, e.g. when dumping the log to file.

      指示日志输出应为每条消息行添加[level]前缀。这可以用作日志着色的替代方法,例如在将日志转储到文件时。

    Flags can also be used alone by adding a ’+’/’-’ prefix to set/reset a single flag without affecting other flags or changing loglevel. When setting both flags and loglevel, a ’+’ separator is expected between the last flags value and before loglevel.

    也可以通过添加“+”/“-”前缀单独使用标志来设置/重置单个标志,而不会影响其他 flags 或更改 loglevel。同时设置 flagsloglevel 时,最后一个 flags 值和 loglevel 之前应使用“+”分隔符。

    loglevel is a string or a number containing one of the following values:

    loglevel 是包含以下值之一的字符串或数字:

    • quiet, -8

      Show nothing at all; be silent.

      什么也不表现;保持沉默。

    • panic, 0

      Only show fatal errors which could lead the process to crash, such as an assertion failure. This is not currently used for anything.

      只显示可能导致进程崩溃的致命错误,例如断言失败。这目前没有用于任何用途。

    • fatal, 8

      Only show fatal errors. These are errors after which the process absolutely cannot continue.

      仅显示致命错误。这些都是错误,之后这个过程绝对无法继续。

    • error, 16

      Show all errors, including ones which can be recovered from.

      显示所有错误,包括可以从中恢复的错误。

    • warning, 24

      Show all warnings and errors. Any message related to possibly incorrect or unexpected events will be shown.

      显示所有警告和错误。将显示与可能不正确或意外事件有关的任何消息。

    • info, 32

      Show informative messages during processing. This is in addition to warnings and errors. This is the default value.

      在处理过程中显示信息性消息。除此之外还有警告和错误。这是默认值。

    • verbose, 40

      Same as info, except more verbose.

      与信息相同,只是更详细。

    • debug, 48

      Show everything, including debugging information.

      显示所有内容,包括调试信息。

    • trace, 56

    For example to enable repeated log output, add the level prefix, and set loglevel to verbose:

    例如,要启用重复日志输出,请添加level 前缀,并将日志级别设置为 verbose

    # ffmpeg -loglevel repeat+level+verbose -i input output
    

    Another example that enables repeated log output without affecting current state of level prefix flag or loglevel:

    另一个允许重复日志输出而不影响级别前缀标志或日志level的当前状态的示例:

    # ffmpeg [...] -loglevel +repeat
    

    By default the program logs to stderr. If coloring is supported by the terminal, colors are used to mark errors and warnings. Log coloring can be disabled setting the environment variable AV_LOG_FORCE_NOCOLOR, or can be forced setting the environment variable AV_LOG_FORCE_COLOR.

    默认情况下,程序会记录到stderr。如果终端支持着色,则使用颜色来标记错误和警告。可以禁用日志着色设置环境变量AV_Log_FORCE_NOCOLOR,也可以强制设置环境变量AV_Log_FORCE_COLOR

  • -report

    Dump full command line and log output to a file named program-YYYYMMDD-HHMMSS.log in the current directory. This file can be useful for bug reports. It also implies -loglevel debug.

    将完整的命令行和日志输出转储到当前目录中名为program-YYYYYMMDD-HHMMSS.log的文件中。此文件可用于错误报告。它还意味着-loglevel debug

    Setting the environment variable FFREPORT to any value has the same effect. If the value is a ’:’-separated key=value sequence, these options will affect the report; option values must be escaped if they contain special characters or the options delimiter ’:’ (see the “Quoting and escaping” section in the ffmpeg-utils manual).

    将环境变量FFREPORT设置为任何值都具有相同的效果。如果值是 : 分隔的 键=值 序列,则这些选项将影响报告;如果选项值包含特殊字符或选项分隔符 : ,则必须对其进行转义(请参阅ffmpeg-utils手册中的“引用和转义”部分)。

    The following options are recognized:

    可识别以下选项:

    • file

      set the file name to use for the report; %p is expanded to the name of the program, %t is expanded to a timestamp, %% is expanded to a plain %

      设置要用于报告的文件名;%p扩展为程序名称,%t扩展为时间戳,%%扩展为纯%

    • level

      set the log verbosity level using a numerical value (see -loglevel).

      使用数值设置日志详细级别(请参阅-loglevel)。

    For example, to output a report to a file named ffreport.log using a log level of 32 (alias for log level info):

    例如,要使用32的日志级别(日志级别info的别名)将报告输出到名为ffreport.log的文件,请执行以下操作:

    FFREPORT=file=ffreport.log:level=32 ffmpeg -i input output

    Errors in parsing the environment variable are not fatal, and will not appear in the report.

    分析环境变量时的错误不会致命,也不会出现在报告中。

  • -hide_banner

    Suppress printing banner.

    禁止打印横幅。

    All FFmpeg tools will normally show a copyright notice, build options and library versions. This option can be used to suppress printing this information.

    所有FFmpeg工具通常都会显示版权声明、构建选项和库版本。此选项可用于禁止打印此信息。

  • -cpuflags flags (全局)

    Allows setting and clearing cpu flags. This option is intended for testing. Do not use it unless you know what you’re doing.

    允许设置和清除cpu标志。此选项用于测试。除非你知道自己在做什么,否则不要使用它。

    # ffmpeg -cpuflags -sse+mmx ...
    # ffmpeg -cpuflags mmx ...
    # ffmpeg -cpuflags 0 ...
    

    Possible flags for this option are:

    此选项的可能标志为:

    ‘x86’

    ​ ‘mmx’

    ​ ‘mmxext’

    ​ ‘sse’

    ​ ‘sse2’

    ​ ‘sse2slow’

    ​ ‘sse3’

    ​ ‘sse3slow’

    ​ ‘ssse3’

    ​ ‘atom’

    ​ ‘sse4.1’

    ​ ‘sse4.2’

    ​ ‘avx’

    ​ ‘avx2’

    ​ ‘xop’

    ​ ‘fma3’

    ​ ‘fma4’

    ​ ‘3dnow’

    ​ ‘3dnowext’

    ​ ‘bmi1’

    ​ ‘bmi2’

    ​ ‘cmov’

    ‘ARM’

    ​ ‘armv5te’

    ​ ‘armv6’

    ​ ‘armv6t2’

    ​ ‘vfp’

    ​ ‘vfpv3’

    ​ ‘neon’

    ​ ‘setend’

    ‘AArch64’

    ​ ‘armv8’

    ​ ‘vfp’

    ​ ‘neon’

    ​ ‘PowerPC’

    ​ ‘altivec’

    ‘Specific Processors’

    ​ ‘pentium2’

    ​ ‘pentium3’

    ​ ‘pentium4’

    ​ ‘k6’

    ​ ‘k62’

    ​ ‘athlon’

    ​ ‘athlonxp’

    ​ ‘k8’

  • -cpucount count (全局)

    Override detection of CPU count. This option is intended for testing. Do not use it unless you know what you’re doing.

    覆盖CPU计数的检测。此选项用于测试。除非你知道自己在做什么,否则不要使用它。

    # ffmpeg -cpucount 2
    
  • -max_alloc bytes

    Set the maximum size limit for allocating a block on the heap by ffmpeg’s family of malloc functions. Exercise extreme caution when using this option. Don’t use if you do not understand the full consequence of doing so. Default is INT_MAX.

    通过ffmpeg的malloc函数家族设置在堆上分配块的最大大小限制。使用此选项时要格外小心。如果您不了解这样做的全部后果,请不要使用。默认值为INT_MAX。

5.3 AVOptions(AV选项)

These options are provided directly by the libavformat, libavdevice and libavcodec libraries. To see the list of available AVOptions, use the -help option. They are separated into two categories:

这些选项由libavformat、libavdevice和libavcodec库直接提供。要查看可用的AV选项列表,请使用-help选项。它们分为两类:

  • generic (通用)

    These options can be set for any container, codec or device. Generic options are listed under AVFormatContext options for containers/devices and under AVCodecContext options for codecs.

    可以为任何容器、编解码器或设备设置这些选项。通用选项列在容器/设备的AVFormatContext选项下,以及编解码器的AVCodecContext选项下。

  • private (专用)

    These options are specific to the given container, device or codec. Private options are listed under their corresponding containers/devices/codecs.

    这些选项特定于给定的容器、设备或编解码器。专用选项列在相应的容器/设备/编解码器下。

For example to write an ID3v2.3 header instead of a default ID3v2.4 to an MP3 file, use the id3v2_version private option of the MP3 muxer:

例如,要将ID3v2.3头而不是默认的ID3v2.4写入MP3文件,请使用MP3 muxer的ID3v2_version私有选项:

# ffmpeg -i input.flac -id3v2_version 3 out.mp3

All codec AVOptions are per-stream, and thus a stream specifier should be attached to them:

所有编解码器AV选项都是按流设置的,因此应在其上附加流说明符:

# ffmpeg -i multichannel.mxf -map 0:v:0 -map 0:a:0 -map 0:a:0 -c:a:0 ac3 -b:a:0 640k -ac:a:1 2 -c:a:1 aac -b:2 128k out.mp4

In the above example, a multichannel audio stream is mapped twice for output. The first instance is encoded with codec ac3 and bitrate 640k. The second instance is downmixed to 2 channels and encoded with codec aac. A bitrate of 128k is specified for it using absolute index of the output stream.

在上面的示例中,多声道音频流被映射两次以进行输出。第一个实例用编解码器ac3和比特率640k进行编码。第二个实例被向下混合到2个通道,并使用编解码器aac进行编码。使用输出流的绝对索引为其指定128k的比特率。

Note: the -nooption syntax cannot be used for boolean AVOptions, use -option 0/-option 1.

注意:-nooption 语法不能用于布尔AV选项,请使用-option 0/-option 1

Note: the old undocumented way of specifying per-stream AVOptions by prepending v/a/s to the options name is now obsolete and will be removed soon.

注意:通过在选项名称前加上v/a/s来指定每个流AV选项的旧的未记录方式现在已经过时,很快就会被删除。

5.4 Main options(主要选项)

  • -f fmt (输入/输出)

    Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.

    强制输入或输出文件格式。输入文件的格式通常是自动检测的,并根据输出文件的文件扩展名进行猜测,因此在大多数情况下不需要此选项。

  • -i url (输入)

    input file url

    输入文件url

  • -y (全局)

    Overwrite output files without asking.

    无需询问即可覆盖输出文件。

  • -n (全局)

    Do not overwrite output files, and exit immediately if a specified output file already exists.

    不要覆盖输出文件,如果指定的输出文件已经存在,请立即退出。

  • -stream_loop number (输入)

    Set number of times input stream shall be looped. Loop 0 means no loop, loop -1 means infinite loop.

    设置输入流循环的次数。循环0表示没有循环,循环-1表示无限循环。

  • -recast_media (全局)

    Allow forcing a decoder of a different media type than the one detected or designated by the demuxer. Useful for decoding media data muxed as data streams.

    允许强制使用与解复用器检测或指定的媒体类型不同的媒体类型的解码器。用于解码复用为数据流的媒体数据。

  • -c[:stream_specifier] codec (输入/输出,每个流)

  • -codec[:stream_specifier] codec (输入/输出,每个流)

    Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.

    为一个或多个流选择编码器(在输出文件之前使用时)或解码器(在输入文件之前使用)。codecdecoder/encoder或特殊值copy(仅输出)的名称,用于指示流不进行重新编码。

    For example

    例如

    # ffmpeg -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT
    

    encodes all video streams with libx264 and copies all audio streams.

    使用libx264对所有视频流进行编码,并复制所有音频流。

    For each stream, the last matching c option is applied, so

    对于每个流,应用最后一个匹配的 c 选项,因此

    # ffmpeg -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT
    

    will copy all the streams except the second video, which will be encoded with libx264, and the 138th audio, which will be encoded with libvorbis.

    将复制除第二个视频(将使用libx264编码)和第138个音频(将使用libvorbis编码)之外的所有流。

  • -t duration (输入/输出)

    When used as an input option (before -i), limit the duration of data read from the input file.

    当用作输入选项(在-i之前)时,限制从输入文件读取数据的持续时间。

    When used as an output option (before an output url), stop writing the output after its duration reaches duration.

    当用作输出选项(在输出url之前)时,在其持续时间达到duration后停止写入输出。

    duration must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.

    duration必须是一个持续时间规范,请参阅(ffmpeg-utils)ffmpeg-utils(1)手册中的“持续时间”部分

    -to and -t are mutually exclusive and -t has priority.

    -to-t是互斥的,-t具有优先级。

  • -to position (输入/输出)

    Stop writing the output or reading the input at position. position must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.

    停止在position写入输出或读取输入。position必须是一个持续时间规范,请参阅(ffmpeg-utils)ffmpeg-utils(1)手册中的“持续时间”部分

    -to and -t are mutually exclusive and -t has priority.

    -to-t是互斥的,-t具有优先级。

  • -fs limit_size (输出)

    Set the file size limit, expressed in bytes. No further chunk of bytes is written after the limit is exceeded. The size of the output file is slightly more than the requested file size.

    设置文件大小限制,以字节表示。超过限制后,不会再写入任何字节块。输出文件的大小略大于请求的文件大小。

  • -ss position (输入/输出)

    When used as an input option (before -i), seeks in this input file to position. Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded. When doing stream copy or when -noaccurate_seek is used, it will be preserved.

    当用作输入选项(在-i之前)时,在此输入文件中查找position。请注意,在大多数格式中,不可能精确地进行搜索,因此ffmpeg将在position之前搜索到最近的搜索点。当启用代码转换和-accurate_seek(默认值)时,将解码并丢弃寻道点和position之间的这一额外段。当进行流复制或使用-noaccurate_seek时,它将被保留。

    When used as an output option (before an output url), decodes but discards input until the timestamps reach position.

    当用作输出选项(在输出url之前)时,解码但丢弃输入,直到时间戳到达position

    position must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.

    position 必须是一个持续时间规范,请参阅(ffmpeg-utils)ffmpeg-utils(1)手册中的“持续时间”部分

  • -sseof position (输入)

    Like the -ss option but relative to the “end of file”. That is negative values are earlier in the file, 0 is at EOF.

    类似于-ss选项,但相对于“文件结尾”。也就是说,负值在文件较早的位置,0处于EOF。

  • -isync input_index (输入)

    Assign an input as a sync source.

    将输入指定为同步源。

    This will take the difference between the start times of the target and reference inputs and offset the timestamps of the target file by that difference. The source timestamps of the two inputs should derive from the same clock source for expected results. If copyts is set then start_at_zero must also be set. If either of the inputs has no starting timestamp then no sync adjustment is made.

    这将获得目标和参考输入的开始时间之间的差异,并将目标文件的时间戳偏移该差异。对于预期结果,两个输入的源时间戳应从同一时钟源导出。如果设置了copyts,则还必须设置start_at_zero。如果任何一个输入都没有开始时间戳,则不进行同步调整。

    Acceptable values are those that refer to a valid ffmpeg input index. If the sync reference is the target index itself or -1, then no adjustment is made to target timestamps. A sync reference may not itself be synced to any other input.Default value is -1.

    可接受的值是指那些引用有效的ffmpeg输入索引的值。如果同步引用是目标索引本身或-1,则不调整目标时间戳。同步引用本身可能不会同步到任何其他输入。默认值为-1。

  • -itsoffset offset (输入)

    Set the input time offset.

    设置输入时间偏移。

    offset must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.

    offset必须是一个持续时间规范,请参阅(ffmpeg-utils)ffmpeg-utils(1)手册中的“持续时间”部分

    The offset is added to the timestamps of the input files. Specifying a positive offset means that the corresponding streams are delayed by the time duration specified in offset.

    偏移量将添加到输入文件的时间戳中。指定正偏移意味着相应的流被延迟offset中指定的持续时间。

  • -itsscale scale (输入,每个流)

    Rescale input timestamps. scale should be a floating point number.

    重新缩放输入时间戳。scale应该是一个浮点数。

  • -timestamp date (输出)

    Set the recording timestamp in the container.

    在容器中设置录制时间戳。

    date must be a date specification, see (ffmpeg-utils)the Date section in the ffmpeg-utils(1) manual.

    date必须是日期规范,请参阅(ffmpeg-utils)ffmpeg-utils(1)手册中的date部分

  • -metadata[:metadata_specifier] key=value (输出,每个元数据)

    Set a metadata key/value pair.

    设置元数据键/值对。

    An optional metadata_specifier may be given to set metadata on streams, chapters or programs. See -map_metadata documentation for details.

    可以提供可选的metadata_specifier 来设置流、章节或程序的元数据。有关详细信息,请参阅-map_metadata文档。

    This option overrides metadata set with -map_metadata. It is also possible to delete metadata by using an empty value.

    此选项将覆盖以-map_metadata设置的元数据。也可以使用空值来删除元数据。

    For example, for setting the title in the output file:

    例如,要在输出文件中设置标题:

    # ffmpeg -i in.avi -metadata title="my title" out.flv
    

    To set the language of the first audio stream:

    要设置第一个音频流的语言:

    # ffmpeg -i INPUT -metadata:s:a:0 language=eng OUTPUT
    
  • -disposition[:stream_specifier] value (输出,每个流)

    Sets the disposition for a stream.

    设置流的disposition 。

    By default, the disposition is copied from the input stream, unless the output stream this option applies to is fed by a complex filtergraph - in that case the disposition is unset by default.

    默认情况下,disposition 是从输入流复制的,除非此选项应用于的输出流是由复杂的滤镜链图提供的——在这种情况下,默认情况下disposition 是未设置的。

    value is a sequence of items separated by ’+’ or ’-’. The first item may also be prefixed with ’+’ or ’-’, in which case this option modifies the default value. Otherwise (the first item is not prefixed) this options overrides the default value. A ’+’ prefix adds the given disposition, ’-’ removes it. It is also possible to clear the disposition by setting it to 0.

    value 是由+-分隔的项目序列。第一项也可以以+-为前缀,在这种情况下,此选项将修改默认值。否则(第一项没有前缀),此选项将覆盖默认值。前缀+会添加给定的处置,-会删除它。也可以通过将其设置为 0 来清除处置。

    If no -disposition options were specified for an output file, ffmpeg will automatically set the ’default’ disposition on the first stream of each type, when there are multiple streams of this type in the output file and no stream of that type is already marked as default.

    如果没有为输出文件指定-disposition选项,当输出文件中有多个此类型的流并且没有将该类型的流标记为默认流时,ffmpeg将自动对每个类型的第一个流设置“默认”disposition 。

    The -dispositions option lists the known dispositions.

    -dispositions选项列出已知的 dispositions。

    For example, to make the second audio stream the default stream:

    例如,要使第二音频流成为默认流:

    # ffmpeg -i in.mkv -c copy -disposition:a:1 default out.mkv
    

    To make the second subtitle stream the default stream and remove the default disposition from the first subtitle stream:

    为了使第二字幕流成为默认流并从第一字幕流移除默认配置:

    # ffmpeg -i in.mkv -c copy -disposition:s:0 0 -disposition:s:1 default out.mkv
    

    To add an embedded cover/thumbnail:

    要添加嵌入的封面/缩略图,请执行以下操作:

    # ffmpeg -i in.mp4 -i IMAGE -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic out.mp4
    

    Not all muxers support embedded thumbnails, and those who do, only support a few formats, like JPEG or PNG.

    并不是所有的复用器都支持嵌入缩略图,而那些支持嵌入缩略图的复用器只支持几种格式,如JPEG或PNG。

  • -program [title=title:][program_num=program_num:]st=stream[:st=stream...] (输出)

    Creates a program with the specified title, program_num and adds the specified stream(s) to it.

    创建具有指定 titleprogram_num 的程序,并向其中添加指定的stream

  • -target type (输出)

    Specify target file type (vcd, svcd, dvd, dv, dv50). type may be prefixed with pal-, ntsc- or film- to use the corresponding standard. All the format options (bitrate, codecs, buffer sizes) are then set automatically. You can just type:

    指定目标文件类型(vcdsvcddvddvdv50)。type可以前缀为pal-ntsc-film-以使用相应的标准。然后自动设置所有格式选项(比特率、编解码器、缓冲区大小)。您只需键入:

    # ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
    

    Nevertheless you can specify additional options as long as you know they do not conflict with the standard, as in:

    但是,您可以指定其他选项,只要您知道这些选项与标准不冲突,如:

    # ffmpeg -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg
    

    The parameters set for each target are as follows.

    为每个目标设置的参数如下。

    VCD

    pal:
    -f vcd -muxrate 1411200 -muxpreload 0.44 -packetsize 2324
    -s 352x288 -r 25
    -codec:v mpeg1video -g 15 -b:v 1150k -maxrate:v 1150k -minrate:v 1150k -bufsize:v 327680
    -ar 44100 -ac 2
    -codec:a mp2 -b:a 224k
    
    ntsc:
    -f vcd -muxrate 1411200 -muxpreload 0.44 -packetsize 2324
    -s 352x240 -r 30000/1001
    -codec:v mpeg1video -g 18 -b:v 1150k -maxrate:v 1150k -minrate:v 1150k -bufsize:v 327680
    -ar 44100 -ac 2
    -codec:a mp2 -b:a 224k
    
    film:
    -f vcd -muxrate 1411200 -muxpreload 0.44 -packetsize 2324
    -s 352x240 -r 24000/1001
    -codec:v mpeg1video -g 18 -b:v 1150k -maxrate:v 1150k -minrate:v 1150k -bufsize:v 327680
    -ar 44100 -ac 2
    -codec:a mp2 -b:a 224k
    

    SVCD

    pal:
    -f svcd -packetsize 2324
    -s 480x576 -pix_fmt yuv420p -r 25
    -codec:v mpeg2video -g 15 -b:v 2040k -maxrate:v 2516k -minrate:v 0 -bufsize:v 1835008 -scan_offset 1
    -ar 44100
    -codec:a mp2 -b:a 224k
    
    ntsc:
    -f svcd -packetsize 2324
    -s 480x480 -pix_fmt yuv420p -r 30000/1001
    -codec:v mpeg2video -g 18 -b:v 2040k -maxrate:v 2516k -minrate:v 0 -bufsize:v 1835008 -scan_offset 1
    -ar 44100
    -codec:a mp2 -b:a 224k
    
    film:
    -f svcd -packetsize 2324
    -s 480x480 -pix_fmt yuv420p -r 24000/1001
    -codec:v mpeg2video -g 18 -b:v 2040k -maxrate:v 2516k -minrate:v 0 -bufsize:v 1835008 -scan_offset 1
    -ar 44100
    -codec:a mp2 -b:a 224k
    

    DVD

    pal:
    -f dvd -muxrate 10080k -packetsize 2048
    -s 720x576 -pix_fmt yuv420p -r 25
    -codec:v mpeg2video -g 15 -b:v 6000k -maxrate:v 9000k -minrate:v 0 -bufsize:v 1835008
    -ar 48000
    -codec:a ac3 -b:a 448k
    
    ntsc:
    -f dvd -muxrate 10080k -packetsize 2048
    -s 720x480 -pix_fmt yuv420p -r 30000/1001
    -codec:v mpeg2video -g 18 -b:v 6000k -maxrate:v 9000k -minrate:v 0 -bufsize:v 1835008
    -ar 48000
    -codec:a ac3 -b:a 448k
    
    film:
    -f dvd -muxrate 10080k -packetsize 2048
    -s 720x480 -pix_fmt yuv420p -r 24000/1001
    -codec:v mpeg2video -g 18 -b:v 6000k -maxrate:v 9000k -minrate:v 0 -bufsize:v 1835008
    -ar 48000
    -codec:a ac3 -b:a 448k
    

    DV

    pal:
    -f dv
    -s 720x576 -pix_fmt yuv420p -r 25
    -ar 48000 -ac 2
    
    ntsc:
    -f dv
    -s 720x480 -pix_fmt yuv411p -r 30000/1001
    -ar 48000 -ac 2
    
    film:
    -f dv
    -s 720x480 -pix_fmt yuv411p -r 24000/1001
    -ar 48000 -ac 2
    

    The dv50 target is identical to the dv target except that the pixel format set is yuv422p for all three standards.

    dv50目标与dv目标相同,不同之处在于针对所有三个标准设置的像素格式是yuv422p

    Any user-set value for a parameter above will override the target preset value. In that case, the output may not comply with the target standard.

    上述参数的任何用户设置值都将覆盖目标预设值。在这种情况下,输出可能不符合目标标准。

  • -dn (输入/输出)

    As an input option, blocks all data streams of a file from being filtered or being automatically selected or mapped for any output. See -discard option to disable streams individually.

    作为一个输入选项,阻止文件的所有数据流被过滤或自动选择或映射用于任何输出。请参阅-discard选项以单独禁用流。

    As an output option, disables data recording i.e. automatic selection or mapping of any data stream. For full manual control see the -map option.

    作为输出选项,禁用数据记录,即自动选择或映射任何数据流。有关完全手动控制,请参阅-map选项。

  • -dframes number (输出)

    Set the number of data frames to output. This is an obsolete alias for -frames:d, which you should use instead.

    设置要输出的数据帧数。这是-frames:d(您应该使用)的一个过时别名。

  • -frames[:stream_specifier] framecount (输出,每个流)

    Stop writing to the stream after framecount frames.

    framecount帧之后停止向流写入。

  • -q[:stream_specifier] q (输出,每个流)

  • -qscale[:stream_specifier] q (输出,每个流)

    Use fixed quality scale (VBR). The meaning of q/qscale is codec-dependent. If qscale is used without a stream_specifier then it applies only to the video stream, this is to maintain compatibility with previous behavior and as specifying the same codec specific value to 2 different codecs that is audio and video generally is not what is intended when no stream_specifier is used.

    使用固定质量等级(VBR)。q/qscale的含义取决于编解码器。如果在没有stream_specifier的情况下使用qscale,则它仅适用于视频流,这是为了保持与之前行为的兼容性,并且当不使用stream_specificer时,通常不会为音频和视频的两个不同编解码器指定相同的编解码器特定值。

  • -filter[:stream_specifier] filtergraph (输出,每个流)

    Create the filtergraph specified by filtergraph and use it to filter the stream.

    创建filteragraph指定的滤镜图,并使用它来筛选流。

    filtergraph is a description of the filtergraph to apply to the stream, and must have a single input and a single output of the same type of the stream. In the filtergraph, the input is associated to the label in, and the output to the label out. See the ffmpeg-filters manual for more information about the filtergraph syntax.

    filtergraph是要应用于流的滤镜图的描述,并且必须具有相同流类型的单个输入和单个输出。在滤镜图中,输入与标签in相关联,输出与标签out相关联。有关滤镜图语法的更多信息,请参阅ffmpeg滤镜手册。

    See the -filter_complex option if you want to create filtergraphs with multiple inputs and/or outputs.

    如果要创建具有多个输入和/或输出的滤镜图,请参见-filter_complex选项

  • -filter_script[:stream_specifier] filename (输出,每个流)

    This option is similar to -filter, the only difference is that its argument is the name of the file from which a filtergraph description is to be read.

    此选项类似于-filter,唯一的区别在于其参数是要从中读取滤镜图描述的文件的名称。

  • -reinit_filter[:stream_specifier] integer (输入,每个流)

    This boolean option determines if the filtergraph(s) to which this stream is fed gets reinitialized when input frame parameters change mid-stream. This option is enabled by default as most video and all audio filters cannot handle deviation in input frame properties. Upon reinitialization, existing filter state is lost, like e.g. the frame count n reference available in some filters. Any frames buffered at time of reinitialization are lost. The properties where a change triggers reinitialization are, for video, frame resolution or pixel format; for audio, sample format, sample rate, channel count or channel layout.

    当输入帧参数更改中间流时,此布尔选项确定,此流所馈送到的滤镜图是否会重新初始化。默认情况下启用此选项,因为大多数视频和所有音频滤镜无法处理输入帧属性的偏差。在重新初始化时,现有的滤镜状态丢失,例如在一些滤镜中可用的帧计数n参考。在重新初始化时缓冲的任何帧都将丢失。更改触发重新初始化的属性是,对于视频,帧分辨率或像素格式;用于音频、采样格式、采样率、通道计数或通道布局。

  • -filter_threads nb_threads (全局)

    Defines how many threads are used to process a filter pipeline. Each pipeline will produce a thread pool with this many threads available for parallel processing. The default is the number of available CPUs.

    定义用于处理滤镜管道的线程数。每个管道将产生一个线程池,其中有这么多线程可用于并行处理。默认值是可用CPU的数量。

  • -pre[:stream_specifier] preset_name (输出,每个流)

    Specify the preset for matching stream(s).

    指定匹配流的预设。

  • -stats (全局)

    Print encoding progress/statistics. It is on by default, to explicitly disable it you need to specify -nostats.

    打印编码进度/统计信息。默认情况下,它处于启用状态,要显式禁用它,需要指定-nostats

  • -stats_period time (全局)

    Set period at which encoding progress/statistics are updated. Default is 0.5 seconds.

    设置更新编码进度/统计信息的周期。默认值为0.5秒。

  • -progress url (全局)

    Send program-friendly progress information to url.

    将程序友好的进度信息发送到url

    Progress information is written periodically and at the end of the encoding process. It is made of “key=value” lines. key consists of only alphanumeric characters. The last key of a sequence of progress information is always “progress”.

    进度信息会定期写入,并在编码过程结束时写入。它由key=value行组成。key仅由字母数字字符组成。一系列进度信息的最后一个key始终是progress

    The update period is set using -stats_period.

    更新周期是使用-stats_period设置的。

  • -stdin

    Enable interaction on standard input. On by default unless standard input is used as an input. To explicitly disable interaction you need to specify -nostdin.

    启用对标准输入的交互。默认情况下启用,除非将标准输入用作输入。要显式禁用交互,您需要指定-nostdin

    Disabling interaction on standard input is useful, for example, if ffmpeg is in the background process group. Roughly the same result can be achieved with ffmpeg ... < /dev/null but it requires a shell.

    禁用对标准输入的交互是有用的,例如,如果ffmpeg在后台进程组中。使用ffmpeg ...</dev/null可以获得大致相同的结果,但它需要一个shell。

  • -debug_ts (全局)

    Print timestamp information. It is off by default. This option is mostly useful for testing and debugging purposes, and the output format may change from one version to another, so it should not be employed by portable scripts.

    打印时间戳信息。默认情况下处于禁用状态。此选项主要用于测试和调试,并且输出格式可能会从一个版本更改为另一个版本,因此不应被可移植脚本使用。

    See also the option -fdebug ts.

    另请参阅选项-fdebug ts

  • -attach filename (输出)

    Add an attachment to the output file. This is supported by a few formats like Matroska for e.g. fonts used in rendering subtitles. Attachments are implemented as a specific type of stream, so this option will add a new stream to the file. It is then possible to use per-stream options on this stream in the usual way. Attachment streams created with this option will be created after all the other streams (i.e. those created with -map or automatic mappings).

    向输出文件添加附件。这得到了一些格式的支持,例如Matroska,用于渲染字幕的字体。附件是作为特定类型的流实现的,因此此选项将向文件中添加一个新流。然后可以以通常的方式在此流上使用每个流的选项。使用此选项创建的附件流将在所有其他流(即使用-map或自动映射创建的流)之后创建。

    Note that for Matroska you also have to set the mimetype metadata tag:

    请注意,对于Matroska,您还必须设置mimetype元数据标记:

    # ffmpeg -i INPUT -attach DejaVuSans.ttf -metadata:s:2 mimetype=application/x-truetype-font out.mkv
    

    (assuming that the attachment stream will be third in the output file).

    (假设附件流将在输出文件中排名第三)。

  • -dump_attachment[:stream_specifier] filename (输入,每个流)

    Extract the matching attachment stream into a file named filename. If filename is empty, then the value of the filename metadata tag will be used.

    将匹配的附件流提取到名为filename的文件中。如果filename为空,则将使用filename元数据标记的值。

    E.g. to extract the first attachment to a file named ’out.ttf’:

    例如,要提取名为“out.ttf”的文件的第一个附件:

    # ffmpeg -dump_attachment:t:0 out.ttf -i INPUT
    

    To extract all attachments to files determined by the filename tag:

    要提取由filename标记确定的文件的所有附件,请执行以下操作:

    # ffmpeg -dump_attachment:t "" -i INPUT
    

    Technical note – attachments are implemented as codec extradata, so this option can actually be used to extract extradata from any stream, not just attachments.

    技术说明——附件被实现为编解码器外部数据,因此该选项实际上可以用于从任何流中提取外部数据,而不仅仅是附件。

5.5 Video Options(视频选项)

  • -vframes number (输出)

    Set the number of video frames to output. This is an obsolete alias for -frames:v, which you should use instead.

    设置要输出的视频帧数。这是-frames:v(您应该使用)的一个过时别名。

  • -r[:stream_specifier] fps (输入/输出,每个流)

    Set frame rate (Hz value, fraction or abbreviation).

    设置帧速率(Hz值、片段或缩略)。

    As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps. This is not the same as the -framerate option used for some input formats like image2 or v4l2 (it used to be the same in older versions of FFmpeg). If in doubt use -framerate instead of the input option -r.

    作为一个输入选项,忽略文件中存储的任何时间戳,而是在假定恒定帧速率fps的情况下生成时间戳。这与用于某些输入格式(如image2或v4l2)的-framerate选项不同(以前在旧版本的FFmpeg中也是如此)。如果有疑问,请使用-framerate代替输入选项-r

    As an output option:

    作为输出选项:

    • video encoding(视频编码)

      ​Duplicate or drop frames right before encoding them to achieve constant output frame rate fps.

      ​在对帧进行编码之前立即复制或丢弃帧,以实现恒定的输出帧速率fps

    • video streamcopy(视频流复制)

      ​Indicate to the muxer that fps is the stream frame rate. No data is dropped or duplicated in this case. This may produce invalid files if fps does not match the actual stream frame rate as determined by packet timestamps. See also the setts bitstream filter.

      ​向复用器指示fps是流帧速率。在这种情况下,不会丢弃或复制任何数据。如果fps与由分组时间戳确定的实际流帧速率不匹配,则这可能产生无效文件。另请参阅setts比特流过滤器。

  • -fpsmax[:stream_specifier] fps (输出,每个流)

    Set maximum frame rate (Hz value, fraction or abbreviation).

    设置最大帧速率(Hz值、片段或缩略)。

    Clamps output frame rate when output framerate is auto-set and is higher than this value. Useful in batch processing or when input framerate is wrongly detected as very high. It cannot be set together with -r. It is ignored during streamcopy.

    当输出帧速率是自动设置的并且高于此值时,严格管制输出帧速。在批处理中或当输入帧速率被错误地检测为非常高时有用。它不能与-r一起设置。在流媒体复制过程中会忽略它。

  • -s[:stream_specifier] size (输入/输出,每个流)

    Set frame size.

    设置帧大小。

    As an input option, this is a shortcut for the video_size private option, recognized by some demuxers for which the frame size is either not stored in the file or is configurable – e.g. raw video or video grabbers.

    作为输入选项,这是video_size专用选项的快捷方式,可由一些帧大小未存储在文件中或可配置的解复用器识别,例如原始视频或视频抓取器。

    As an output option, this inserts the scale video filter to the end of the corresponding filtergraph. Please use the scale filter directly to insert it at the beginning or some other place.

    作为输出选项,这会将scale 视频滤镜插入到相应的过滤镜图的末尾。请直接使用scale 滤镜将其插入开头或其他位置。

    The format is ‘wxh’ (default - same as source).

    格式为wxh(默认值——与source相同)。

  • -aspect[:stream_specifier] aspect (输出,每个流)

    Set the video display aspect ratio specified by aspect.

    设置由aspect指定的视频显示纵横比。

    aspect can be a floating point number string, or a string of the form num:den, where num and den are the numerator and denominator of the aspect ratio. For example “4:3”, “16:9”, “1.3333”, and “1.7777” are valid argument values.

    aspect可以是浮点数字字符串,也可以是num:den形式的字符串,其中numden是纵横比的分子和分母。例如,“4:3”、“16:9”、“1.3333”和“1.7777”是有效的参数值。

    If used together with -vcodec copy, it will affect the aspect ratio stored at container level, but not the aspect ratio stored in encoded frames, if it exists.

    如果与-vcodec copy一起使用,它将影响存储在容器级别的纵横比,但不会影响存储在编码帧中的纵横比(如果存在的话)。

  • -display_rotation[:stream_specifier] rotation (输入,每个流)

    Set video rotation metadata.

    设置视频旋转元数据。

    rotation is a decimal number specifying the amount in degree by which the video should be rotated counter-clockwise before being displayed.

    rotation是一个十进制数,指定视频在显示前应逆时针旋转的程度。

    This option overrides the rotation/display transform metadata stored in the file, if any. When the video is being transcoded (rather than copied) and -autorotate is enabled, the video will be rotated at the filtering stage. Otherwise, the metadata will be written into the output file if the muxer supports it.

    此选项将覆盖存储在文件中的旋转/显示变换元数据(如果有的话)。当视频被转码(而不是复制)并且启用了-autorotate时,视频将在过滤阶段旋转。否则,如果复用器支持,元数据将被写入输出文件。

    If the -display_hflip and/or -display_vflip options are given, they are applied after the rotation specified by this option.

    如果给定-display_hflip和/或-display_vflip选项,则在该选项指定的旋转之后应用它们。

  • -display_hflip[:stream_specifier] (输入,每个流)

    Set whether on display the image should be horizontally flipped.See the -display_rotation option for more details.

    设置是否在显示器上水平翻转图像。有关详细信息,请参阅-display_rotation选项。

  • -display_vflip[:stream_specifier] (输入,每个流)

    Set whether on display the image should be vertically flipped.See the -display_rotation option for more details.

    设置是否在显示器上垂直翻转图像。有关详细信息,请参阅-display_rotation 选项。

  • -vn (输入/输出)

    As an input option, blocks all video streams of a file from being filtered or being automatically selected or mapped for any output. See -discard option to disable streams individually.

    作为输入选项,阻止文件的所有视频流被过滤或自动选择或映射用于任何输出。请参阅-discard选项以单独禁用流。

    As an output option, disables video recording i.e. automatic selection or mapping of any video stream. For full manual control see the -map option.

    作为输出选项,禁用视频录制,即自动选择或映射任何视频流。有关完全手动控制,请参阅-map选项。

  • -vcodec codec (输出)

    Set the video codec. This is an alias for -codec:v.

    设置视频编解码器。这是 -codec:v的别名。

  • -pass[:stream_specifier] n (输出,每个流)

    Select the pass number (1 or 2). It is used to do two-pass video encoding. The statistics of the video are recorded in the first pass into a log file (see also the option -passlogfile), and in the second pass that log file is used to generate the video at the exact requested bitrate. On pass 1, you may just deactivate audio and set output to null, examples for Windows and Unix:

    选择pass编号(1或2)。它用于进行 two-pass(一种算法)视频编码。视频的统计信息在第一次pass记录到日志文件中(另请参阅选项-passlogfile),在第二次pass中,该日志文件用于以准确的请求比特率生成视频。在步骤1中,您可以只停用音频并将输出设置为null,例如Windows和Unix:

    # ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y NUL
    # ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y /dev/null
    
  • -passlogfile[:stream_specifier] prefix (输出,每个流)

    Set two-pass log file name prefix to prefix, the default file name prefix is “ffmpeg2pass”. The complete file name will be PREFIX-N.log, where N is a number specific to the output stream

    将two-pass日志文件名前缀设置为prefix,默认文件名前缀为“ffmpeg2pass”。完整的文件名将是PREFIX-N.log,其中N是特定于输出流的数字

  • -vf filtergraph (输出)

    Create the filtergraph specified by filtergraph and use it to filter the stream.

    创建filteragraph指定的滤镜图,并使用它来过滤流。

    This is an alias for -filter:v, see the -filter option.

    这是-filter:v的别名,请参阅-filter选项

  • -autorotate

    Automatically rotate the video according to file metadata. Enabled by default, use -noautorotate to disable it.

    根据文件元数据自动旋转视频。默认情况下已启用,请使用-noautorotate 将其禁用。

  • -autoscale

    Automatically scale the video according to the resolution of first frame. Enabled by default, use -noautoscale to disable it. When autoscale is disabled, all output frames of filter graph might not be in the same resolution and may be inadequate for some encoder/muxer. Therefore, it is not recommended to disable it unless you really know what you are doing. Disable autoscale at your own risk.

    根据第一帧的分辨率自动缩放视频。默认情况下已启用,请使用-noautoscale 禁用它。禁用自动缩放时,滤镜图的所有输出帧可能不在同一分辨率,并且可能不适合某些编码器/复用器。因此,除非你真的知道自己在做什么,否则不建议禁用它。禁用自动缩放,风险自负。

5.6 Advanced Video options(高级视频选项)

  • -pix_fmt[:stream_specifier] format (输入/输出,每个流)

    Set pixel format. Use -pix_fmts to show all the supported pixel formats. If the selected pixel format can not be selected, ffmpeg will print a warning and select the best pixel format supported by the encoder. If pix_fmt is prefixed by a +, ffmpeg will exit with an error if the requested pixel format can not be selected, and automatic conversions inside filtergraphs are disabled. If pix_fmt is a single +, ffmpeg selects the same pixel format as the input (or graph output) and automatic conversions are disabled.

    设置像素格式。使用-pix_fmts显示所有支持的像素格式。如果无法选择所选的像素格式,ffmpeg将打印警告并选择编码器支持的最佳像素格式。如果pix_fmt的前缀为+,则如果无法选择所请求的像素格式,则ffmpeg将退出并返回错误,并且禁用了滤镜链图内部的自动转换。如果pix_fmt是单个+,则ffmpeg会选择与输入(或图形输出)相同的像素格式,并禁用自动转换。

  • -sws_flags flags (输入/输出)

    Set default flags for the libswscale library. These flags are used by automatically inserted scale filters and those within simple filtergraphs, if not overridden within the filtergraph definition.

    设置libswscale 库的默认标志。这些标志由自动插入的scale过滤器和简单滤镜链图中的滤镜使用,如果没有在滤镜链图定义中重写的话。

    See the (ffmpeg-scaler)ffmpeg-scaler manual for a list of scaler options.

    有关缩放器选项的列表,请参阅(ffmpeg scaler)ffmpeg缩放器手册

  • -rc_override[:stream_specifier] override (输出,每个流)

    Rate control override for specific intervals, formatted as “int,int,int” list separated with slashes. Two first values are the beginning and end frame numbers, last one is quantizer to use if positive, or quality factor if negative.

    特定间隔的速率控制覆盖,格式为用斜线分隔的“int,int,int”列表。前两个值是开始帧号和结束帧号,最后一个值是要使用的量化器(如果为正),或者质量因子(如果为负)。

  • -psnr

    Calculate PSNR of compressed frames. This option is deprecated, pass the PSNR flag to the encoder instead, using -flags +psnr.

    计算压缩帧的PSNR。此选项已弃用,请改用 -flags +psnr将PSNR标志传递给编码器。

  • -vstats

    Dump video coding statistics to vstats_HHMMSS.log. See the vstats file format section for the format description.

    将视频编码统计信息转储到vstats_HHMMSS.log。有关格式描述,请参阅vstats文件格式部分。

  • -vstats_file file

    Dump video coding statistics to file. See the vstats file format section for the format description.

    将视频编码统计信息转储到文件中。有关格式说明,请参阅vstats文件格式部分。

  • -vstats_version file

    Specify which version of the vstats format to use. Default is 2. See the vstats file format section for the format description.

    指定要使用的vstats格式的版本。默认值为2。有关格式说明,请参阅vstats文件格式部分。

  • -vtag fourcc/tag (输出)

    Force video tag/fourcc. This is an alias for -tag:v.

    强制视频tag/fourcc。这是-tag:v的别名。

  • -vbsf bitstream_filter

    Deprecated see -bsf

    不推荐,参见-bsf

  • -force_key_frames[:stream_specifier] time[,time...] (输出,每个流)

  • -force_key_frames[:stream_specifier] expr:expr (输出,每个流)

  • -force_key_frames[:stream_specifier] source (输出,每个流)

    force_key_frames can take arguments of the following form:

    force_key_frames可以采用以下形式的参数:

    • time[,time...]

      If the argument consists of timestamps, ffmpeg will round the specified times to the nearest output timestamp as per the encoder time base and force a keyframe at the first frame having timestamp equal or greater than the computed timestamp. Note that if the encoder time base is too coarse, then the keyframes may be forced on frames with timestamps lower than the specified time. The default encoder time base is the inverse of the output framerate but may be set otherwise via -enc_time_base.

      如果参数由时间戳组成,则ffmpeg将根据编码器时基将指定的时间四舍五入到最接近的输出时间戳,并强制第一帧处的关键帧具有等于或大于计算的时间戳的时间戳。请注意,如果编码器时基过于粗略,则可能会在时间戳低于指定时间的帧上强制使用关键帧。默认编码器时基是输出帧速率的倒数,但可以通过-enc_time_base进行其他设置。

      If one of the times is “chapters[delta]”, it is expanded into the time of the beginning of all chapters in the file, shifted by delta, expressed as a time in seconds. This option can be useful to ensure that a seek point is present at a chapter mark or any other designated place in the output file.

      如果其中一个时间是chapters[delta],则将其扩展为文件中所有章节开始的时间,按delta移位,表示为以秒为单位的时间。此选项可用于确保查找点位于章节标记或输出文件中的任何其他指定位置。

      For example, to insert a key frame at 5 minutes, plus key frames 0.1 second before the beginning of every chapter:

      例如,要在5分钟插入一个关键帧,再加上每章开始前0.1秒的关键帧:

      -force_key_frames 0:05:00,chapters-0.1
      
    • expr:expr

      If the argument is prefixed with expr:, the string expr is interpreted like an expression and is evaluated for each frame. A key frame is forced in case the evaluation is non-zero.

      如果参数以expr:为前缀,则字符串expr将像表达式一样进行解释,并针对每个帧进行计算。如果评估值为非零,则强制使用关键帧。

      The expression in expr can contain the following constants:

      expr中的表达式可以包含以下常量:

      • n

        the number of current processed frame, starting from 0

        当前处理的帧数,从0开始

      • n_forced

        the number of forced frames

        强制帧的数量

      • prev_forced_n

        the number of the previous forced frame, it is NAN when no keyframe was forced yet

        上一个强制帧的编号,当尚未强制关键帧时为NAN

      • prev_forced_t

        the time of the previous forced frame, it is NAN when no keyframe was forced yet

        上一个强制帧的时间,当尚未强制关键帧时为NAN

      • t

        the time of the current processed frame

        当前处理帧的时间

      For example to force a key frame every 5 seconds, you can specify:

      例如,要每隔5秒强制一个关键帧,可以指定:

      -force_key_frames expr:gte(t,n_forced*5)
      

      To force a key frame 5 seconds after the time of the last forced one, starting from second 13:

      要在最后一个强制关键帧的时间后5秒强制关键帧(从13秒开始):

      -force_key_frames expr:if(isnan(prev_forced_t),gte(t,13),gte(t,prev_forced_t+5))
      
    • source

      If the argument is source, ffmpeg will force a key frame if the current frame being encoded is marked as a key frame in its source. In cases where this particular source frame has to be dropped, enforce the next available frame to become a key frame instead.

      如果参数为source,则如果当前编码的帧在其源中标记为关键帧,则ffmpeg将强制使用关键帧。在必须删除此特定源帧的情况下,强制下一个可用帧成为关键帧。

    Note that forcing too many keyframes is very harmful for the lookahead algorithms of certain encoders: using fixed-GOP options or similar would be more efficient.

    请注意,强制使用过多的关键帧对某些编码器的前瞻性算法非常有害:使用fixed-GOP选项或类似选项会更有效。

  • -copyinkf[:stream_specifier] (输出,每个流)

    When doing stream copy, copy also non-key frames found at the beginning.

    进行流复制时,还复制在开头找到的非关键帧。

  • -init_hw_device type[=name][:device[,key=value...]]

    Initialise a new hardware device of type type called name, using the given device parameters. If no name is specified it will receive a default name of the form “type%d”.

    使用给定的设备参数初始化typename的新硬件设备。如果没有指定名称,它将接收一个默认名称,格式为type%d

    The meaning of device and the following arguments depends on the device type:

    device和以下参数的含义取决于设备类型:

    • cuda

      device is the number of the CUDA device.

      device是CUDA设备的编号。

      The following options are recognized:

      可识别以下选项:

      • primary_ctx

        If set to 1, uses the primary device context instead of creating a new one.

        如果设置为1,则使用主设备上下文,而不是创建新的设备上下文。

      Examples:

      -init_hw_device cuda:1

      ​ Choose the second device on the system.

      ​ 选择系统上的第二个设备。

      -init_hw_device cuda:0,primary_ctx=1

      ​ Choose the first device and use the primary device context.

      ​ 选择第一个设备并使用主设备上下文。

    • dxva2

      device is the number of the Direct3D 9 display adapter.

      device是Direct3D 9显示适配器的编号。

    • d3d11va

      device is the number of the Direct3D 11 display adapter. If not specified, it will attempt to use the default Direct3D 11 display adapter or the first Direct3D 11 display adapter whose hardware VendorId is specified by ‘vendor_id’.

      device是Direct3D11显示适配器的编号。如果未指定,它将尝试使用默认的Direct3D 11显示适配器或硬件VendorId由vendor_id指定的第一个Direct3D 11显示器适配器。

      Examples:

      -init_hw_device d3d11va

      ​ Create a d3d11va device on the default Direct3D 11 display adapter.

      ​ 在默认的Direct3D 11显示适配器上创建一个d3d11va设备。

      -init_hw_device d3d11va:1

      ​ Create a d3d11va device on the Direct3D 11 display adapter specified by index 1.

      ​ 在索引1指定的Direct3D 11显示适配器上创建d3d11va设备。

      -init_hw_device d3d11va:,vendor_id=0x8086

      ​ Create a d3d11va device on the first Direct3D 11 display adapter whose hardware VendorId is 0x8086.

      ​ 在硬件VendorId为0x8086的第一个Direct3D 11显示适配器上创建一个d3d11va设备。

    • vaapi

      device is either an X11 display name, a DRM render node or a DirectX adapter index. If not specified, it will attempt to open the default X11 display ($DISPLAY) and then the first DRM render node (/dev/dri/renderD128), or the default DirectX adapter on Windows.

      device是X11显示器名称、DRM渲染节点或DirectX适配器索引。如果未指定,它将尝试打开默认的X11显示器($DISPLAY),然后打开第一个DRM渲染节点(/dev/dri/renderD128),或者打开Windows上的默认DirectX适配器。

    • vdpau

      device is an X11 display name. If not specified, it will attempt to open the default X11 display ($DISPLAY).

      device是X11显示器名称。如果没有指定,它将尝试打开默认的X11显示器($DISPLAY)。

    • qsv

      device selects a value in ‘MFX_IMPL_*’. Allowed values are:

      deviceMFX_IMPL_*中选择一个值。允许的值为:

      • auto
      • sw
      • hw
      • auto_any
      • hw_any
      • hw2
      • hw3
      • hw4

      If not specified, ‘auto_any’ is used. (Note that it may be easier to achieve the desired result for QSV by creating the platform-appropriate subdevice (‘dxva2’ or ‘d3d11va’ or ‘vaapi’) and then deriving a QSV device from that.)

      如果未指定,则使用auto_any。(请注意,通过创建适合平台的子设备(dxva2d3d11vavaapi),然后从中导出QSV设备,可能更容易实现QSV的期望结果。)

      Alternatively, ‘child_device_type’ helps to choose platform-appropriate subdevice type. On Windows ‘d3d11va’ is used as default subdevice type.

      或者,child_device_type有助于选择适合平台的子设备类型。在Windows上,d3d11va被用作默认的子设备类型。

      Examples:

      -init_hw_device qsv:hw,child_device_type=d3d11va

      ​ Choose the GPU subdevice with type ‘d3d11va’ and create QSV device with ‘MFX_IMPL_HARDWARE’.

      ​ 选择类型为d3d11va的GPU子设备,并创建类型为MFX_IMPL_HARDWARE的QSV设备。

      -init_hw_device qsv:hw,child_device_type=dxva2

      ​ Choose the GPU subdevice with type ‘dxva2’ and create QSV device with ‘MFX_IMPL_HARDWARE’.

      ​ 选择类型为dxva2的GPU子设备,并创建类型为MFX_IMPL_HARDWARE的QSV设备。

    • opencl

      device selects the platform and device as platform_index.device_index.

      device选择平台和设备作为platform_index.device_index

      The set of devices can also be filtered using the key-value pairs to find only devices matching particular platform or device strings.

      也可以使用键值对来过滤设备集合,以仅找到与特定平台或设备字符串匹配的设备。

      The strings usable as filters are:

      可用作过滤器的字符串有:

      • platform_profile
      • platform_version
      • platform_name
      • platform_vendor
      • platform_extensions
      • device_name
      • device_vendor
      • driver_version
      • device_version
      • device_profile
      • device_extensions
      • device_type

      The indices and filters must together uniquely select a device.

      索引和筛选器必须一起唯一地选择一个设备。

      Examples:

      示例:

      -init_hw_device opencl:0.1

      ​ Choose the second device on the first platform.

      ​ 在第一个平台上选择第二个设备。

      -init_hw_device opencl:,device_name=Foo9000

      ​ Choose the device with a name containing the string Foo9000.

      ​ 选择名称包含字符串Foo9000的设备。

      -init_hw_device opencl:1,device_type=gpu,device_extensions=cl_khr_fp16

      ​ Choose the GPU device on the second platform supporting the cl_khr_fp16 extension.

      ​ 在支持cl_khr_fp16扩展的第二个平台上选择GPU设备。

    • vulkan

      If device is an integer, it selects the device by its index in a system-dependent list of devices. If device is any other string, it selects the first device with a name containing that string as a substring.

      如果device是一个整数,它会根据系统相关设备列表中的索引来选择设备。如果device是任何其他字符串,它会选择具有包含该字符串的名称的第一个设备作为子字符串。

      The following options are recognized:

      可识别以下选项:

      • debug

        If set to 1, enables the validation layer, if installed.

        如果设置为1,则启用验证层(如果已安装)。

      • linear_images

        If set to 1, images allocated by the hwcontext will be linear and locally mappable.

        如果设置为1,则hwcontext分配的图像将是线性的并且可本地映射。

      • instance_extensions

        A plus separated list of additional instance extensions to enable.

        要启用的附加实例扩展的加号分隔列表。

      • device_extensions

        A plus separated list of additional device extensions to enable.

        要启用的附加设备扩展名的加分隔列表。

      Examples:

      示例:

      -init_hw_device vulkan:1

      ​ Choose the second device on the system.

      ​ 选择系统上的第二个设备。

      -init_hw_device vulkan:RADV

      ​ Choose the first device with a name containing the string RADV.

      ​ 选择第一个名称包含字符串RADV的设备。

      -init_hw_device vulkan:0,instance_extensions=VK_KHR_wayland_surface+VK_KHR_xcb_surface

      ​ Choose the first device and enable the Wayland and XCB instance extensions.

      ​ 选择第一个设备并启用WaylandXCB实例扩展。

  • -init_hw_device type[=name]@source

    Initialise a new hardware device of type type called name, deriving it from the existing device with the name source.

    初始化名为nametype类型的新硬件设备,从具有名称source的现有设备派生。

  • -init_hw_device list

    List all hardware device types supported in this build of ffmpeg.

    列出此版本的ffmpeg中支持的所有硬件设备类型。

  • -filter_hw_device name

    Pass the hardware device called name to all filters in any filter graph. This can be used to set the device to upload to with the hwupload filter, or the device to map to with the hwmap filter. Other filters may also make use of this parameter when they require a hardware device. Note that this is typically only required when the input is not already in hardware frames - when it is, filters will derive the device they require from the context of the frames they receive as input.

    将名为name的硬件设备传递给任何滤镜图中的所有滤镜。这可以用于设置要使用hwupload 滤镜上传到的设备,或者使用hwmap 滤镜映射到的设备。当其他滤镜需要硬件设备时,它们也可以使用该参数。请注意,这通常只在输入不在硬件帧中时才需要——当输入不在时,滤镜将从作为输入接收的帧的上下文中导出所需的设备。

    This is a global setting, so all filters will receive the same device.

    这是一个全局设置,因此所有滤镜都将接收相同的设备。

  • -hwaccel[:stream_specifier] hwaccel (输入,每个流)

    Use hardware acceleration to decode the matching stream(s). The allowed values of hwaccel are:

    使用硬件加速对匹配的流进行解码。hwccel的允许值为:

    • none

      Do not use any hardware acceleration (the default).

      不要使用任何硬件加速(默认设置)。

    • auto

      Automatically select the hardware acceleration method.

      自动选择硬件加速方法。

    • vdpau

      Use VDPAU (Video Decode and Presentation API for Unix) hardware acceleration.

      使用VDPAU(Unix的视频解码和演示API)硬件加速。

    • dxva2

      Use DXVA2 (DirectX Video Acceleration) hardware acceleration.

      使用DXVA2(DirectX视频加速)硬件加速。

    • d3d11va

      Use D3D11VA (DirectX Video Acceleration) hardware acceleration.

      使用D3D11VA(DirectX视频加速)硬件加速。

    • vaapi

      Use VAAPI (Video Acceleration API) hardware acceleration.

      使用VAAPI(视频加速API)硬件加速。

    • qsv

      Use the Intel QuickSync Video acceleration for video transcoding.

      使用“英特尔快速同步视频”加速进行视频转码。

      Unlike most other values, this option does not enable accelerated decoding (that is used automatically whenever a qsv decoder is selected), but accelerated transcoding, without copying the frames into the system memory.

      与大多数其他值不同,此选项不启用加速解码(无论何时选择qsv解码器都会自动使用),而是启用加速转码,而无需将帧复制到系统内存中。

      For it to work, both the decoder and the encoder must support QSV acceleration and no filters must be used.

      为了使其工作,解码器和编码器都必须支持QSV加速,并且不必使用滤镜。

    This option has no effect if the selected hwaccel is not available or not supported by the chosen decoder.

    如果所选的hwaccel不可用或不受所选解码器支持,则此选项无效。

    Note that most acceleration methods are intended for playback and will not be faster than software decoding on modern CPUs. Additionally, ffmpeg will usually need to copy the decoded frames from the GPU memory into the system memory, resulting in further performance loss. This option is thus mainly useful for testing.

    请注意,大多数加速方法都是用于播放的,不会比现代CPU上的软件解码更快。此外,ffmpeg通常需要将解码的帧从GPU内存复制到系统内存中,从而导致进一步的性能损失。因此,此选项主要用于测试。

  • -hwaccel_device[:stream_specifier] hwaccel_device (输入,每个流)

    Select a device to use for hardware acceleration.

    选择用于硬件加速的设备。

    This option only makes sense when the -hwaccel option is also specified. It can either refer to an existing device created with -init_hw_device by name, or it can create a new device as if ‘-init_hw_device’ type:hwaccel_device were called immediately before.

    只有在同时指定了-hwaccel选项时,此选项才有意义。它可以按名称引用使用-init_hw_device创建的现有设备,也可以创建一个新设备,就好像之前调用了-init_hw _device type:hwaccel_device一样。

  • -hwaccels

    List all hardware acceleration components enabled in this build of ffmpeg. Actual runtime availability depends on the hardware and its suitable driver being installed.

    列出此版本的ffmpeg中启用的所有硬件加速组件。实际的运行时可用性取决于所安装的硬件及其合适的驱动程序。

  • -fix_sub_duration_heartbeat[:stream_specifier]

    Set a specific output video stream as the heartbeat stream according to which to split and push through currently in-progress subtitle upon receipt of a random access packet.

    将特定的输出视频流设置为心跳流,根据该心跳流在接收到随机访问分组时分割和推送当前正在进行的字幕。

    This lowers the latency of subtitles for which the end packet or the following subtitle has not yet been received. As a drawback, this will most likely lead to duplication of subtitle events in order to cover the full duration, so when dealing with use cases where latency of when the subtitle event is passed on to output is not relevant this option should not be utilized.

    这降低了尚未接收到结束分组或后续字幕的字幕的延迟。作为一个缺点,这很可能会导致字幕事件的重复,以覆盖整个持续时间,因此在处理字幕事件传递到输出的延迟不相关的用例时,不应使用此选项。

    Requires -fix_sub_duration to be set for the relevant input subtitle stream for this to have any effect, as well as for the input subtitle stream having to be directly mapped to the same output in which the heartbeat stream resides.

    需要为相关的输入字幕流设置-fix_sub_duration,这样才能产生任何效果,也需要将输入字幕流直接映射到心跳流所在的同一输出。

5.7 Audio Options(音频选项)

  • -aframes number (输出)

    Set the number of audio frames to output. This is an obsolete alias for -frames:a, which you should use instead.

    设置要输出的音频帧数。这是-frames:a(您应该使用)的一个过时别名。

  • -ar[:stream_specifier] freq (输入/输出,每个流)

    Set the audio sampling frequency. For output streams it is set by default to the frequency of the corresponding input stream. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options.

    设置音频采样频率。对于输出流,它默认设置为相应输入流的频率。对于输入流,此选项仅对音频获取设备和原始解复用器有意义,并映射到相应的解复用器选项。

  • -aq q (输出)

    Set the audio quality (codec-specific, VBR). This is an alias for -q:a.

    设置音频质量(特定于编解码器,VBR)。这是 -q:a的别名。

  • -ac[:stream_specifier] channels (输入/输出,每个流)

    Set the number of audio channels. For output streams it is set by default to the number of input audio channels. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options.

    设置音频通道的数量。对于输出流,它默认设置为输入音频通道的数量。对于输入流,此选项仅对音频获取设备和原始解复用器有意义,并映射到相应的解复用器选项。

  • -an (输入/输出)

    As an input option, blocks all audio streams of a file from being filtered or being automatically selected or mapped for any output. See -discard option to disable streams individually.

    作为输入选项,阻止文件的所有音频流被过滤或自动选择或映射用于任何输出。请参阅-discard选项以单独禁用流。

    As an output option, disables audio recording i.e. automatic selection or mapping of any audio stream. For full manual control see the -map option.

    作为输出选项,禁用音频录制,即自动选择或映射任何音频流。有关完全手动控制,请参阅-map选项。

  • -acodec codec (输入/输出)

    Set the audio codec. This is an alias for -codec:a.

    设置音频编解码器。这是-codec:a的别名。

  • -sample_fmt[:stream_specifier] sample_fmt (输出,每个流)

    Set the audio sample format. Use -sample_fmts to get a list of supported sample formats.

    设置音频采样格式。使用-sample_fmts 获取支持的采样格式列表。

  • -af filtergraph (输出)

    Create the filtergraph specified by filtergraph and use it to filter the stream.This is an alias for -filter:a, see the -filter option.

    创建filteragraph指定的滤镜图,并使用它来过滤流。这是-filter:a的别名,请参阅-filter选项

5.8 Advanced Audio options(高级音频选项)

  • -atag fourcc/tag (输出)

    Force audio tag/fourcc. This is an alias for -tag:a.

    强制音频 tag/fourcc。这是-tag:a的别名。

  • -absf bitstream_filter

    Deprecated, see -bsf

    已弃用,请参阅-bsf

  • -guess_layout_max channels (输入,每个流)

    If some input channel layout is not known, try to guess only if it corresponds to at most the specified number of channels. For example, 2 tells to ffmpeg to recognize 1 channel as mono and 2 channels as stereo but not 6 channels as 5.1. The default is to always try to guess. Use 0 to disable all guessing.

    如果某些输入通道布局未知,就尝试猜测它是否最多对应于指定数量的通道。例如,2告诉ffmpeg将1个声道识别为单声道,将2个声道识别成立体声,但不将6个声道识别出5.1。默认情况是总是尝试猜测。使用0可禁用所有猜测。

5.9 Subtitle options(字幕选项)

  • -scodec codec (输入/输出)

    Set the subtitle codec. This is an alias for -codec:s.

    设置字幕编解码器。这是-codec:s的别名。

  • -sn (输入/输出)

    As an input option, blocks all subtitle streams of a file from being filtered or being automatically selected or mapped for any output. See -discard option to disable streams individually.

    作为输入选项,阻止文件的所有字幕流被过滤或自动选择或映射用于任何输出。请参阅-discard选项以单独禁用流。

    As an output option, disables subtitle recording i.e. automatic selection or mapping of any subtitle stream. For full manual control see the -map option.

    作为输出选项,禁用字幕录制,即自动选择或映射任何字幕流。有关完全手动控制,请参阅-map选项。

  • -sbsf bitstream_filter

    Deprecated, see -bsf

    已弃用,请参阅-bsf

5.10 Advanced Subtitle options(高级字幕选项)

  • -fix_sub_duration

    Fix subtitles durations. For each subtitle, wait for the next packet in the same stream and adjust the duration of the first to avoid overlap. This is necessary with some subtitles codecs, especially DVB subtitles, because the duration in the original packet is only a rough estimate and the end is actually marked by an empty subtitle frame. Failing to use this option when necessary can result in exaggerated durations or muxing failures due to non-monotonic timestamps.

    修复字幕持续时间。对于每个字幕,等待同一流中的下一个数据包,并调整第一个数据包的持续时间以避免重叠。这对于一些字幕编解码器是必要的,尤其是DVB字幕,因为原始数据包中的持续时间只是粗略估计,并且结束实际上由空字幕帧标记。如果在必要时不使用此选项,可能会由于非单调时间戳而导致持续时间过长或复用失败。

    Note that this option will delay the output of all data until the next subtitle packet is decoded: it may increase memory consumption and latency a lot.

    请注意,此选项将延迟所有数据的输出,直到下一个字幕包被解码:这可能会大大增加内存消耗和延迟。

  • -canvas_size size

    Set the size of the canvas used to render subtitles.

    设置用于渲染字幕的画布的大小。

5.11 Advanced options(高级选项)

  • -map [-]input_file_id[:stream_specifier][?] | [linklabel] (输出)

    Create one or more streams in the output file. This option has two forms for specifying the data source(s): the first selects one or more streams from some input file (specified with -i), the second takes an output from some complex filtergraph (specified with -filter_complex or -filter_complex_script).

    在输出文件中创建一个或多个流。此选项有两种形式用于指定数据源:第一种形式从某个输入文件(用-i指定)中选择一个或多个流,第二种形式从某种复杂的滤镜图(用-filter_complex-filter_complex_script指定)中获取输出。

    In the first form, an output stream is created for every stream from the input file with the index input_file_id. If stream_specifier is given, only those streams that match the specifier are used (see the Stream specifiers section for the stream_specifier syntax).

    在第一种形式中,为索引为input_file_id的输入文件中的每个流创建一个输出流。如果给定stream_specifier,则仅使用与说明符匹配的流(有关stream_specificer语法,请参阅流说明符部分)。

    A - character before the stream identifier creates a “negative” mapping. It disables matching streams from already created mappings.

    流标识符前面的 - 字符会创建一个“负”映射。它禁用已创建映射的匹配流。

    A trailing ? after the stream index will allow the map to be optional: if the map matches no streams the map will be ignored instead of failing. Note the map will still fail if an invalid input file index is used; such as if the map refers to a non-existent input.

    在流索引后的 ?,将允许映射是可选的:如果映射不匹配任何流,则映射将被忽略,而不是失败。请注意,如果使用了无效的输入文件索引,则映射仍将失败;例如如果映射指的是不存在的输入。

    An alternative [linklabel] form will map outputs from complex filter graphs (see the -filter_complex option) to the output file. linklabel must correspond to a defined output link label in the graph.

    另一种[linklabel]形式将把复杂滤镜图的输出(请参阅-filter_complex选项)映射到输出文件。linklabel必须与图中定义的输出链接标签相对应。

    This option may be specified multiple times, each adding more streams to the output file. Any given input stream may also be mapped any number of times as a source for different output streams, e.g. in order to use different encoding options and/or filters. The streams are created in the output in the same order in which the -map options are given on the commandline.

    此选项可以指定多次,每次都会向输出文件添加更多的流。任何给定的输入流也可以被映射任意次数作为不同输出流的源,例如为了使用不同的编码选项和/或滤镜。流在输出中的创建顺序与在命令行上提供-map选项的顺序相同。

    Using this option disables the default mappings for this output file.

    使用此选项将禁用此输出文件的默认映射。

    Examples:

    示例:

    • map everything(映射所有)

      To map ALL streams from the first input file to output

      将第一个输入文件的所有流映射到输出

      # ffmpeg -i INPUT -map 0 output
      
    • select specific stream(选择特定流)

      If you have two audio streams in the first input file, these streams are identified by 0:0 and 0:1. You can use -map to select which streams to place in an output file. For example:

      如果在第一个输入文件中有两个音频流,则这些流由0:0和0:1标识。您可以使用-map来选择要放置在输出文件中的流。例如:

      # ffmpeg -i INPUT -map 0:1 out.wav
      

      will map the second input stream in INPUT to the (single) output stream in out.wav.

      INPUT 中的第二个输入流映射到 out.wav 中的(单个)输出流。

    • create multiple streams(创建多个流)

      To select the stream with index 2 from input file a.mov (specified by the identifier 0:2), and stream with index 6 from input b.mov (specified by the identifier 1:6), and copy them to the output file out.mov:

      要从输入文件 a.mov(由标识符0:2指定)中选择索引为2的流,并从输入b.mov(通过标识符1:6指定)中选取索引为6的流,然后将它们复制到输出文件out.mov

      # ffmpeg -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov
      
    • create multiple streams 2(创建多个流 2)

      To select all video and the third audio stream from an input file:

      要从输入文件中选择所有视频和第三个音频流,请执行以下操作:

      # ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT
      
    • negative map(负映射)

      To map all the streams except the second audio, use negative mappings

      要映射除第二个音频之外的所有流,请使用负映射

      # ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT
      
    • optional map(可选映射)

      To map the video and audio streams from the first input, and using the trailing ?, ignore the audio mapping if no audio streams exist in the first input:

      要从第一个输入映射视频和音频流,并使用 ? 尾,如果在所述第一输入中不存在音频流,则忽略所述音频映射:

      # ffmpeg -i INPUT -map 0:v -map 0:a? OUTPUT
      
    • map by language(按语言映射)

      To pick the English audio stream:

      要选择英语音频流:

      # ffmpeg -i INPUT -map 0:m:language:eng OUTPUT
      
  • -ignore_unknown

    Ignore input streams with unknown type instead of failing if copying such streams is attempted.

    如果尝试复制未知类型的输入流,则忽略这些流,而不是失败。

  • -copy_unknown

    Allow input streams with unknown type to be copied instead of failing if copying such streams is attempted.

    如果尝试复制未知类型的输入流,则允许复制此类流,而不是失败。

  • -map_channel [input_file_id.stream_specifier.channel_id|-1][?][:output_file_id.stream_specifier]

    This option is deprecated and will be removed. It can be replaced by the pan filter. In some cases it may be easier to use some combination of the channelsplit, channelmap, or amerge filters.

    此选项已弃用,将被删除。它可以用pan滤镜代替。在某些情况下,使用某些channelsplitchannelmapamerge 的滤镜组合可能更容易。

    Map an audio channel from a given input to an output. If output_file_id.stream_specifier is not set, the audio channel will be mapped on all the audio streams.

    将音频通道从给定的输入映射到输出。如果未设置output_file_id.stream_specifier,则音频通道将映射到所有音频流上。

    Using “-1” instead of input_file_id.stream_specifier.channel_id will map a muted channel.

    使用“-1”而不是input_file_id.stream_specifier.channel_id将映射静音频道。

    A trailing ? will allow the map_channel to be optional: if the map_channel matches no channel the map_channel will be ignored instead of failing.

    后随?将允许map_channel是可选的:如果map_channnel不匹配任何通道,则map_channal将被忽略而不是失败。

    For example, assuming INPUT is a stereo audio file, you can switch the two audio channels with the following command:

    例如,假设INPUT是立体声音频文件,可以使用以下命令切换两个音频通道:

    # ffmpeg -i INPUT -map_channel 0.0.1 -map_channel 0.0.0 OUTPUT
    

    If you want to mute the first channel and keep the second:

    如果要将第一个频道静音并保留第二个频道:

    # ffmpeg -i INPUT -map_channel -1 -map_channel 0.0.1 OUTPUT
    

    The order of the “-map_channel” option specifies the order of the channels in the output stream. The output channel layout is guessed from the number of channels mapped (mono if one “-map_channel”, stereo if two, etc.). Using “-ac” in combination of “-map_channel” makes the channel gain levels to be updated if input and output channel layouts don’t match (for instance two “-map_channel” options and “-ac 6”).

    -map_channel选项的顺序指定输出流中通道的顺序。输出通道布局是根据映射的通道数猜测的(如果是一个-map_channel 则是单声道、两个则是立体声等)。如果输入和输出通道布局不匹配(例如两个-map_channel选项和-ac 6),将-ac-map_channel组合使用会更新通道增益级别。

    You can also extract each channel of an input to specific outputs; the following command extracts two channels of the INPUT audio stream (file 0, stream 0) to the respective OUTPUT_CH0 and OUTPUT_CH1 outputs:

    您还可以将输入的每个通道提取为特定的输出;以下命令将INPUT音频流(文件0、流0)的两个通道提取到各自的OUTPUT_CH0OUTPUT_CH1输出:

    # ffmpeg -i INPUT -map_channel 0.0.0 OUTPUT_CH0 -map_channel 0.0.1 OUTPUT_CH1
    

    The following example splits the channels of a stereo input into two separate streams, which are put into the same output file:

    以下示例将立体声输入的通道拆分为两个独立的流,这些流被放入同一输出文件中:

    # ffmpeg -i stereo.wav -map 0:0 -map 0:0 -map_channel 0.0.0:0.0 -map_channel 0.0.1:0.1 -y out.ogg
    

    Note that currently each output stream can only contain channels from a single input stream; you can’t for example use “-map_channel” to pick multiple input audio channels contained in different streams (from the same or different files) and merge them into a single output stream. It is therefore not currently possible, for example, to turn two separate mono streams into a single stereo stream. However splitting a stereo stream into two single channel mono streams is possible.

    注意,当前每个输出流只能包含来自单个输入流的通道;例如,您不能使用-map_channel来拾取包含在不同流(来自相同或不同文件)中的多个输入音频通道,并将它们合并为一个输出流。因此,例如,目前不可能将两个单独的单声道流转换为单个立体声流。然而,将立体声流分割成两个单声道单声道流是可能的。

    If you need this feature, a possible workaround is to use the amerge filter. For example, if you need to merge a media (here input.mkv) with 2 mono audio streams into one single stereo channel audio stream (and keep the video stream), you can use the following command:

    如果您需要此功能,一个可能的解决方法是使用amerge 滤镜。例如,如果需要将具有2个单声道音频流的媒体(此处为input.mkv)合并为一个立体声声道音频流(并保留视频流),可以使用以下命令:

    # ffmpeg -i input.mkv -filter_complex "[0:1] [0:2] amerge" -c:a pcm_s16le -c:v copy output.mkv
    

    To map the first two audio channels from the first input, and using the trailing ?, ignore the audio channel mapping if the first input is mono instead of stereo:

    要从第一个输入映射前两个音频通道,并使用尾随的?,如果第一输入是单声道而不是立体声,则忽略音频通道映射:

    # ffmpeg -i INPUT -map_channel 0.0.0 -map_channel 0.0.1? OUTPUT
    
  • -map_metadata[:metadata_spec_out] infile[:metadata_spec_in] (输出,每个元数据)

    Set metadata information of the next output file from infile. Note that those are file indices (zero-based), not filenames. Optional metadata_spec_in/out parameters specify, which metadata to copy. A metadata specifier can have the following forms:

    infile设置下一个输出文件的元数据信息。请注意,这些是文件索引(从零开始),而不是文件名。可选的metadata_spec_in/out参数指定要复制的元数据。元数据说明符可以具有以下形式:

    • g

      global metadata, i.e. metadata that applies to the whole file

      全局元数据,即应用于整个文件的元数据

    • s[:stream_spec]

      per-stream metadata. stream_spec is a stream specifier as described in the Stream specifiers chapter. In an input metadata specifier, the first matching stream is copied from. In an output metadata specifier, all matching streams are copied to.

      每个流元数据。stream_spec是流说明符,如流说明符一章中所述。在输入元数据说明符中,从第一个匹配流复制。在输出元数据说明符中,所有匹配的流都被复制到。

    • c:chapter_index

      per-chapter metadata. chapter_index is the zero-based chapter index.

      每章元数据。chapter_index是基于零的章节索引。

    • p:program_index

      per-program metadata. program_index is the zero-based program index.

      每个程序元数据。program_index是基于零的程序索引。

    If metadata specifier is omitted, it defaults to global.

    如果省略元数据说明符,则默认为全局。

    By default, global metadata is copied from the first input file, per-stream and per-chapter metadata is copied along with streams/chapters. These default mappings are disabled by creating any mapping of the relevant type. A negative file index can be used to create a dummy mapping that just disables automatic copying.

    默认情况下,全局元数据从第一个输入文件中复制,每个流和每个章节的元数据与流/章节一起复制。通过创建相关类型的任何映射,可以禁用这些默认映射。负文件索引可用于创建仅禁用自动复制的伪映射。

    For example to copy metadata from the first stream of the input file to global metadata of the output file:

    例如,要将元数据从输入文件的第一个流复制到输出文件的全局元数据:

    # ffmpeg -i in.ogg -map_metadata 0:s:0 out.mp3
    

    To do the reverse, i.e. copy global metadata to all audio streams:

    要执行相反的操作,即将全局元数据复制到所有音频流:

    # ffmpeg -i in.mkv -map_metadata:s:a 0:g out.mkv
    

    Note that simple 0 would work as well in this example, since global metadata is assumed by default.

    请注意,在本例中,简单的0也可以工作,因为默认情况下假定全局元数据。

  • -map_chapters input_file_index (输出)

    Copy chapters from input file with index input_file_index to the next output file. If no chapter mapping is specified, then chapters are copied from the first input file with at least one chapter. Use a negative file index to disable any chapter copying.

    将具有索引input_file_index的输入文件中的章节复制到下一个输出文件。如果没有指定章节映射,则从第一个输入文件中复制至少有一个章节的章节。使用负文件索引可以禁用任何章节复制。

  • -benchmark (全局)

    Show benchmarking information at the end of an encode. Shows real, system and user time used and maximum memory consumption. Maximum memory consumption is not supported on all systems, it will usually display as 0 if not supported.

    在编码结束时显示基准分析信息。显示实际、系统和用户使用的时间以及最大内存消耗量。并非所有系统都支持最大内存消耗,如果不支持,通常会显示为0。

  • -benchmark_all (全局)

    Show benchmarking information during the encode. Shows real, system and user time used in various steps (audio/video encode/decode).

    在编码过程中显示基准分析信息。显示各种步骤(音频/视频编码/解码)中使用的真实时间、系统时间和用户时间。

  • -timelimit duration (全局)

    Exit after ffmpeg has been running for duration seconds in CPU user time.

    在CPU用户时间内,ffmpeg已运行duration秒后退出。

  • -dump (全局)

    Dump each input packet to stderr.

    将每个输入数据包转储到stderr。

  • -hex (全局)

    When dumping packets, also dump the payload.

    转储数据包时,还要转储有效负载。

  • -readrate speed (输入)

    Limit input read speed.

    限制输入读取速度。

    Its value is a floating-point positive number which represents the maximum duration of media, in seconds, that should be ingested in one second of wallclock time. Default value is zero and represents no imposed limitation on speed of ingestion. Value 1 represents real-time speed and is equivalent to -re.

    它的值是一个浮点正数,表示应在墙时钟时间的一秒内摄入的媒体的最大持续时间(以秒为单位)。默认值为零,表示没有对摄取速度施加限制。值1表示实时速度,相当于-re

    Mainly used to simulate a capture device or live input stream (e.g. when reading from a file). Should not be used with a low value when input is an actual capture device or live stream as it may cause packet loss.

    主要用于模拟捕获设备或实时输入流(例如,从文件中读取时)。当输入是实际捕获设备或直播流时,不应使用低值,因为这可能会导致数据包丢失。

    It is useful for when flow speed of output packets is important, such as live streaming.

    当输出数据包的流速度很重要时,例如直播时,它很有用。

  • -re (输入)

    Read input at native frame rate. This is equivalent to setting -readrate 1.

    以本机帧速率读取输入。这相当于设置 -readrate 1

  • -readrate_initial_burst seconds

    Set an initial read burst time, in seconds, after which -re/-readrate will be enforced.

    设置初始读取突发时间(以秒为单位),之后将强制执行-re/-readrate

  • -vsync parameter (全局)

  • -fps_mode[:stream_specifier] parameter (输出,每个流)

    Set video sync method / framerate mode. vsync is applied to all output video streams but can be overridden for a stream by setting fps_mode. vsync is deprecated and will be removed in the future.

    设置视频同步方式/帧速率模式。vsync应用于所有输出视频流,但可以通过设置fps_mode来覆盖流。vsync已弃用,将来将被删除。

    For compatibility reasons some of the values for vsync can be specified as numbers (shown in parentheses in the following table).

    出于兼容性原因,vsync的一些值可以指定为数字(如下表中的括号所示)。

    • passthrough (0)

      Each frame is passed with its timestamp from the demuxer to the muxer.

      每个帧与其时间戳一起从解复用器传递到复用器。

    • cfr (1)

      Frames will be duplicated and dropped to achieve exactly the requested constant frame rate.

      帧将被复制和丢弃,以达到所要求的恒定帧速率。

    • vfr (2)

      Frames are passed through with their timestamp or dropped so as to prevent 2 frames from having the same timestamp.

      帧以其时间戳通过或丢弃,以防止两个帧具有相同的时间戳。

    • drop

      As passthrough but destroys all timestamps, making the muxer generate fresh timestamps based on frame-rate.

      作为通过但破坏所有时间戳,使复用器基于帧速率生成新的时间戳。

    • auto (-1)

      Chooses between cfr and vfr depending on muxer capabilities. This is the default method.

      根据复用器能力在cfrvfr之间进行选择。这是默认方法。

    Note that the timestamps may be further modified by the muxer, after this. For example, in the case that the format option avoid_negative_ts is enabled.

    注意,在这之后,时间戳可以由复用器进一步修改。例如,在启用格式选项avoid_negative_ts的情况下。

    With -map you can select from which stream the timestamps should be taken. You can leave either video or audio unchanged and sync the remaining stream(s) to the unchanged one.

    使用-map,您可以选择从哪个流中获取时间戳。您可以保持视频或音频不变,并将剩余的流同步到不变的流。

  • -frame_drop_threshold parameter

    Frame drop threshold, which specifies how much behind video frames can be before they are dropped. In frame rate units, so 1.0 is one frame. The default is -1.1. One possible usecase is to avoid framedrops in case of noisy timestamps or to increase frame drop precision in case of exact timestamps.

    帧丢弃阈值,指定视频帧在丢弃之前可以落后多少。因此在帧速率单位中,1.0是一帧。默认值为-1.1。一种可能的使用情况是在有噪声的时间戳的情况下避免掉帧,或者在精确的时间戳情况下增加掉帧精度。

  • -apad parameters (输出,每个流)

    Pad the output audio stream(s). This is the same as applying -af apad. Argument is a string of filter parameters composed the same as with the apad filter. -shortest must be set for this output for the option to take effect.

    填充输出音频流。这与应用-af apad相同。命令行参数是一个滤镜参数字符串,其组成与apad滤镜相同。必须为此输出设置-shortest,选项才能生效。

  • -copyts

    Do not process input timestamps, but keep their values without trying to sanitize them. In particular, do not remove the initial start time offset value.

    不要处理输入时间戳,而是保留它们的值,而不尝试净化它们。特别是,不要删除最初的开始时间偏移值。

    Note that, depending on the vsync option or on specific muxer processing (e.g. in case the format option avoid_negative_ts is enabled) the output timestamps may mismatch with the input timestamps even when this option is selected.

    注意,根据vsync选项或特定的复用器处理(例如,在启用格式选项avoid_negative_ts的情况下),即使选择了该选项,输出时间戳也可能与输入时间戳不匹配。

  • -start_at_zero

    When used with copyts, shift input timestamps so they start at zero.

    当与副本一起使用时,移动输入时间戳,使其从零开始。

    This means that using e.g. -ss 50 will make output timestamps start at 50 seconds, regardless of what timestamp the input file started at.

    这意味着使用例如-ss 50将使输出时间戳从50秒开始,而不管输入文件从什么时间戳开始。

  • -copytb mode

    Specify how to set the encoder timebase when stream copying. mode is an integer numeric value, and can assume one of the following values:

    指定流复制时如何设置编码器时基。mode是一个整数值,可以采用以下值之一:

    • 1

      Use the demuxer timebase.

      使用解复用器时基。

      The time base is copied to the output encoder from the corresponding input demuxer. This is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate.

      时基从相应的输入解复用器复制到输出编码器。这有时是为了避免在复制具有可变帧速率的视频流时非单调增加的时间戳而需要的。

    • 0

      Use the decoder timebase.

      使用解码器时基。

      The time base is copied to the output encoder from the corresponding input decoder.

      时基从相应的输入解码器复制到输出编码器。

    • -1

      Try to make the choice automatically, in order to generate a sane output.

      尝试自动做出选择,以便生成合理的输出。

    Default value is -1.

    默认值为 -1

  • -enc_time_base[:stream_specifier] timebase (输出,每个流)

    Set the encoder timebase. timebase can assume one of the following values:

    设置编码器时基。timebase可以采用以下值之一:

    • 0

      Assign a default value according to the media type.

      根据媒体类型指定默认值。

      For video - use 1/framerate, for audio - use 1/samplerate.

      对于视频——使用1/帧速率,对于音频——使用1/采样率。

    • demux

      Use the timebase from the demuxer.

      使用解复用器中的时基。

    • filter

      Use the timebase from the filtergraph.

      使用滤镜图中的时基。

    • a positive number

      Use the provided number as the timebase.

      使用提供的数字作为时基。

      This field can be provided as a ratio of two integers (e.g. 1:24, 1:48000) or as a decimal number (e.g. 0.04166, 2.0833e-5)

      该字段可以提供为两个整数的比率(例如1:24、1:48000)或十进制数(例如0.04166、2.0833e-5)

    Default value is 0.

    默认值为0。

  • -bitexact (输入/输出)

    Enable bitexact mode for (de)muxer and (de/en)coder

    为(解)复用器和(解/编)码器启用位精确模式

  • -shortest (输出)

    Finish encoding when the shortest output stream ends.

    当最短的输出流结束时,完成编码。

    Note that this option may require buffering frames, which introduces extra latency. The maximum amount of this latency may be controlled with the -shortest_buf_duration option.

    请注意,此选项可能需要缓冲帧,这会带来额外的延迟。此延迟的最大数量可以使用-shortest_buf_duration选项进行控制。

  • -shortest_buf_duration duration (输出)

    The -shortest option may require buffering potentially large amounts of data when at least one of the streams is “sparse” (i.e. has large gaps between frames – this is typically the case for subtitles).

    当至少有一个流是“稀疏的”(即帧之间有很大的间隙——字幕通常是这样)时,-shortest选项可能需要缓冲潜在的大量数据。

    This option controls the maximum duration of buffered frames in seconds. Larger values may allow the -shortest option to produce more accurate results, but increase memory use and latency.

    此选项控制缓冲帧的最大持续时间(以秒为单位)。较大的值可能允许-shortest选项产生更准确的结果,但会增加内存使用和延迟。

    The default value is 10 seconds.

    默认值为10秒。

  • -dts_delta_threshold threshold

    Timestamp discontinuity delta threshold, expressed as a decimal number of seconds.

    时间戳不连续delta阈值,以十进制秒数表示。

    The timestamp discontinuity correction enabled by this option is only applied to input formats accepting timestamp discontinuity (for which the AV_FMT_DISCONT flag is enabled), e.g. MPEG-TS and HLS, and is automatically disabled when employing the -copy_ts option (unless wrapping is detected).

    此选项启用的时间戳不连续性校正仅适用于接受时间戳不一致性的输入格式(AV_FMT_DISCONT 标志已启用),例如MPEG-TS和HLS,并且在使用-copy_ts选项时自动禁用(除非检测到换行)。

    If a timestamp discontinuity is detected whose absolute value is greater than threshold, ffmpeg will remove the discontinuity by decreasing/increasing the current DTS and PTS by the corresponding delta value.

    如果检测到绝对值大于threshold的时间戳不连续,则ffmpeg将通过将当前DTS和PTS减少/增加相应的delta值来去除该不连续性。

    The default value is 10.

    默认值为10。

  • -dts_error_threshold threshold

    Timestamp error delta threshold, expressed as a decimal number of seconds.

    时间戳错误delta阈值,以十进制秒数表示。

    The timestamp correction enabled by this option is only applied to input formats not accepting timestamp discontinuity (for which the AV_FMT_DISCONT flag is not enabled).

    此选项启用的时间戳校正仅适用于不接受时间戳不连续的输入格式(未启用AV_FMT_DISCONT 标志)。

    If a timestamp discontinuity is detected whose absolute value is greater than threshold, ffmpeg will drop the PTS/DTS timestamp value.

    如果检测到绝对值大于threshold的时间戳不连续,则ffmpeg将丢弃PTS/DTS时间戳值。

    The default value is 3600*30 (30 hours), which is arbitrarily picked and quite conservative.

    默认值为3600*30(30小时),这是任意选择的,非常保守。

  • -muxdelay seconds (输出)

    Set the maximum demux-decode delay.

    设置最大解复用解码延迟。

  • -muxpreload seconds (输出)

    Set the initial demux-decode delay.

    设置初始解复用解码延迟。

  • -streamid output-stream-index:new-value (输出)

    Assign a new stream-id value to an output stream. This option should be specified prior to the output filename to which it applies. For the situation where multiple output files exist, a streamid may be reassigned to a different value.

    为输出流分配一个新的流id值。应在应用该选项的输出文件名之前指定该选项。对于存在多个输出文件的情况,流ID可能会重新分配给不同的值。

    For example, to set the stream 0 PID to 33 and the stream 1 PID to 36 for an output mpegts file:

    例如,要将输出mpegts文件的流0 PID设置为33,将流1 PID设置为36:

    # ffmpeg -i inurl -streamid 0:33 -streamid 1:36 out.ts
    
  • -bsf[:stream_specifier] bitstream_filters (输出,每个流)

    Apply bitstream filters to matching streams.

    将比特流滤镜应用于匹配的流。

    bitstream_filters is a comma-separated list of bitstream filter specifications. The specified bitstream filters are applied to coded packets in the order they are written in. Each bitstream filter specification is of the form

    bitstream_filters是以逗号分隔的比特流过滤器规范列表。指定的比特流滤镜按写入顺序应用于编码的数据包。每个比特流滤镜规范的形式如下

    filter[=optname0=optval0:optname1=optval1:...]
    

    Any of the ’,=:’ characters that are to be a part of an option value need to be escaped with a backslash.

    要成为选项值一部分的任何 ,=: 字符都需要使用反斜杠进行转义。

    Use the -bsfs option to get the list of bitstream filters.

    使用-bsfs选项可以获取比特流滤镜的列表。

    # ffmpeg -i h264.mp4 -c:v copy -bsf:v h264_mp4toannexb -an out.h264
    
    # ffmpeg -i file.mov -an -vn -bsf:s mov2textsub -c:s copy -f rawvideo sub.txt
    
  • -tag[:stream_specifier] codec_tag (输入/输出,每个流)

    Force a tag/fourcc for matching streams.

    为匹配的流强制 tag/fourcc。

  • -timecode hh:mm:ssSEPff

    Specify Timecode for writing. SEP is ’:’ for non drop timecode and ’;’ (or ’.’) for drop.

    指定写入的时间代码。SEP:表示非丢弃时间码,;(或.)表示丢弃。

    # ffmpeg -i input.mpg -timecode 01:02:03.04 -r 30000/1001 -s ntsc output.mpg
    
  • -filter_complex filtergraph (全局)

    Define a complex filtergraph, i.e. one with arbitrary number of inputs and/or outputs. For simple graphs – those with one input and one output of the same type – see the -filter options. filtergraph is a description of the filtergraph, as described in the “Filtergraph syntax” section of the ffmpeg-filters manual.

    定义一个复杂的滤镜链图,即具有任意数量的输入和/或输出的滤镜链图。对于简单的图(具有相同类型的一个输入和一个输出的图),请参阅-filter选项。filtergraph是对滤镜图的描述,如ffmpeg过滤器手册的“滤镜图语法”部分所述。

    Input link labels must refer to input streams using the [file_index:stream_specifier] syntax (i.e. the same as -map uses). If stream_specifier matches multiple streams, the first one will be used. An unlabeled input will be connected to the first unused input stream of the matching type.

    输入链接标签必须使用[file_index:stream_specifer]语法(即与-map使用的语法相同)引用输入流。如果stream_specifier匹配多个流,则将使用第一个流。未标记的输入将连接到匹配类型的第一未使用的输入流。

    Output link labels are referred to with -map. Unlabeled outputs are added to the first output file.

    输出链接标签与-map一起引用。未标记的输出被添加到第一个输出文件中。

    Note that with this option it is possible to use only lavfi sources without normal input files.

    请注意,使用此选项可以仅使用lavfi源,而不使用正常的输入文件。

    For example, to overlay an image over video

    例如,将图像覆盖在视频上

    # ffmpeg -i video.mkv -i image.png -filter_complex '[0:v][1:v]overlay[out]' -map
    '[out]' out.mkv
    

    Here [0:v] refers to the first video stream in the first input file, which is linked to the first (main) input of the overlay filter. Similarly the first video stream in the second input is linked to the second (overlay) input of overlay.

    这里[0:v]是指第一输入文件中的第一视频流,其链接到overlay 滤镜的第一(主)输入。类似地,第二输入中的第一视频流被链接到overlay的第二(overlay)输入。

    Assuming there is only one video stream in each input file, we can omit input labels, so the above is equivalent to

    假设每个输入文件中只有一个视频流,我们可以省略输入标签,因此上述内容等效于

    # ffmpeg -i video.mkv -i image.png -filter_complex 'overlay[out]' -map
    '[out]' out.mkv
    

    Furthermore we can omit the output label and the single output from the filter graph will be added to the output file automatically, so we can simply write

    此外,我们可以省略输出标签,滤镜图中的单个输出将自动添加到输出文件中,因此我们可以简单地编写

    # ffmpeg -i video.mkv -i image.png -filter_complex 'overlay' out.mkv
    

    As a special exception, you can use a bitmap subtitle stream as input: it will be converted into a video with the same size as the largest video in the file, or 720x576 if no video is present. Note that this is an experimental and temporary solution. It will be removed once libavfilter has proper support for subtitles.

    作为一个特殊的例外,您可以使用位图字幕流作为输入:它将被转换为与文件中最大视频大小相同的视频,如果没有视频,则转换为720x576。请注意,这是一个实验性的临时解决方案。一旦libavfilter对字幕有了适当的支持,它就会被删除。

    For example, to hardcode subtitles on top of a DVB-T recording stored in MPEG-TS format, delaying the subtitles by 1 second:

    例如,要在以MPEG-TS格式存储的DVB-T记录上硬编码字幕,将字幕延迟1秒:

    # ffmpeg -i input.ts -filter_complex \
      '[#0x2ef] setpts=PTS+1/TB [sub] ; [#0x2d0] [sub] overlay' \
      -sn -map '#0x2dc' output.mkv
    

    (0x2d0, 0x2dc and 0x2ef are the MPEG-TS PIDs of respectively the video, audio and subtitles streams; 0:0, 0:3 and 0:7 would have worked too)

    (0x2d0、0x2dc和0x2ef分别是视频、音频和字幕流的MPEG-TS PID;0:0、0:3和0:7也可以工作)

    To generate 5 seconds of pure red video using lavfi color source:

    要使用lavfi color 源 生成5秒的纯红色视频,请执行以下操作:

    # ffmpeg -filter_complex 'color=c=red' -t 5 out.mkv
    
  • -filter_complex_threads nb_threads (全局)

    Defines how many threads are used to process a filter_complex graph. Similar to filter_threads but used for -filter_complex graphs only. The default is the number of available CPUs.

    定义用于处理filter_complex图的线程数。类似于filter_threads,但仅用于-filter_complex图。默认值是可用CPU的数量。

  • -lavfi filtergraph (全局)

    Define a complex filtergraph, i.e. one with arbitrary number of inputs and/or outputs. Equivalent to -filter_complex.

    定义一个复杂的滤镜图,即具有任意数量的输入和/或输出的滤镜图。等效于-filter_complex

  • -filter_complex_script filename (全局)

    This option is similar to -filter_complex, the only difference is that its argument is the name of the file from which a complex filtergraph description is to be read.

    此选项类似于-filter_complex,唯一的区别在于其参数是要从中读取复杂滤镜图描述的文件的名称。

  • -accurate_seek (输入)

    This option enables or disables accurate seeking in input files with the -ss option. It is enabled by default, so seeking is accurate when transcoding. Use -noaccurate_seek to disable it, which may be useful e.g. when copying some streams and transcoding the others.

    此选项使用-ss选项启用或禁用输入文件中的精确查找。它是默认启用的,因此在转码时查找是准确的。使用-noaccurate_seek禁用它,这可能很有用,例如在复制某些流和对其他流进行转码时。

  • -seek_timestamp (输入)

    This option enables or disables seeking by timestamp in input files with the -ss option. It is disabled by default. If enabled, the argument to the -ss option is considered an actual timestamp, and is not offset by the start time of the file. This matters only for files which do not start from timestamp 0, such as transport streams.

    此选项使用-ss选项在输入文件中启用或禁用按时间戳搜索。默认情况下,它处于禁用状态。如果启用,-ss选项的参数将被视为实际的时间戳,并且不会被文件的开始时间偏移。这只适用于不从时间戳0开始的文件,如传输流。

  • -thread_queue_size size (输入/输出)

    For input, this option sets the maximum number of queued packets when reading from the file or device. With low latency / high rate live streams, packets may be discarded if they are not read in a timely manner; setting this value can force ffmpeg to use a separate input thread and read packets as soon as they arrive. By default ffmpeg only does this if multiple inputs are specified.

    对于输入,此选项设置从文件或设备读取时排队数据包的最大数量。对于低延迟/高速率实时流,如果没有及时读取数据包,则可能会丢弃数据包;设置此值可以强制ffmpeg使用单独的输入线程,并在数据包到达时立即读取数据包。默认情况下,只有在指定了多个输入时,ffmpeg才会执行此操作。

    For output, this option specified the maximum number of packets that may be queued to each muxing thread.

    对于输出,此选项指定了可以排队到每个复用线程的最大数据包数。

  • -sdp_file file (全局)

    Print sdp information for an output stream to file. This allows dumping sdp information when at least one output isn’t an rtp stream. (Requires at least one of the output formats to be rtp).

    将输出流的 sdp 信息打印到file中。这允许在至少一个输出不是rtp流时转储 sdp 信息。(要求至少有一种输出格式是rtp)。

  • -discard (输入)

    Allows discarding specific streams or frames from streams. Any input stream can be fully discarded, using value all whereas selective discarding of frames from a stream occurs at the demuxer and is not supported by all demuxers.

    允许丢弃流中的特定流或帧。任何输入流都可以使用值all被完全丢弃,而流中帧的选择性丢弃发生在解复用器处,并且不是所有解复用器都支持。

    • none

      Discard no frame.

      不丢弃任何帧。

    • default

      Default, which discards no frames.

      默认设置,不丢弃任何帧。

    • noref

      Discard all non-reference frames.

      放弃所有非引用帧。

    • bidir

      Discard all bidirectional frames.

      放弃所有双向帧。

    • nokey

      Discard all frames excepts keyframes.

      丢弃除关键帧之外的所有帧。

    • all

      Discard all frames.

      丢弃所有帧。

  • -abort_on flags (全局)

    Stop and abort on various conditions. The following flags are available:

    在各种情况下停止和中止。以下标志可用:

    • empty_output

      No packets were passed to the muxer, the output is empty.

      没有数据包传递到多路复用器,输出为空。

    • empty_output_stream

      No packets were passed to the muxer in some of the output streams.

      在一些输出流中,没有数据包被传递到多路复用器。

  • -max_error_rate (全局)

    Set fraction of decoding frame failures across all inputs which when crossed ffmpeg will return exit code 69. Crossing this threshold does not terminate processing. Range is a floating-point number between 0 to 1. Default is 2/3.

    在所有输入上设置解码帧失败的分数,当越过ffmpeg时将返回退出代码69。超过此阈值不会终止处理。范围是一个介于0到1之间的浮点数。默认值为2/3。

  • -xerror (全局)

    Stop and exit on error

    出现错误时停止并退出

  • -max_muxing_queue_size packets (输出,每个流)

    When transcoding audio and/or video streams, ffmpeg will not begin writing into the output until it has one packet for each such stream. While waiting for that to happen, packets for other streams are buffered. This option sets the size of this buffer, in packets, for the matching output stream.

    当对音频和/或视频流进行转码时,ffmpeg将不会开始写入输出,直到它为每个这样的流具有一个数据包。在等待发生这种情况时,会缓冲其他流的数据包。此选项为匹配的输出流设置此缓冲区的大小(以数据包为单位)。

    The default value of this option should be high enough for most uses, so only touch this option if you are sure that you need it.

    此选项的默认值应该足够高,以用于大多数用途,因此只有在确定需要时才涉及此选项。

  • -muxing_queue_data_threshold bytes (输出,每个流)

    This is a minimum threshold until which the muxing queue size is not taken into account. Defaults to 50 megabytes per stream, and is based on the overall size of packets passed to the muxer.

    这是不考虑复用队列大小的最小阈值。默认为每个流50兆字节,并且基于传递给多路复用器的数据包的总体大小。

  • -auto_conversion_filters (全局)

    Enable automatically inserting format conversion filters in all filter graphs, including those defined by -vf, -af, -filter_complex and -lavfi. If filter format negotiation requires a conversion, the initialization of the filters will fail. Conversions can still be performed by inserting the relevant conversion filter (scale, aresample) in the graph. On by default, to explicitly disable it you need to specify -noauto_conversion_filters.

    启用在所有滤镜图中自动插入格式转换滤镜,包括由-vf-af-filter_complex-lavfi定义的滤镜。如果滤镜格式协商需要转换,则滤镜的初始化将失败。转换仍然可以通过在图中插入相关的转换滤镜(scalearesample)来执行。默认情况下,要显式禁用它,您需要指定noauto_conversion_filters

  • -bits_per_raw_sample[:stream_specifier] value (输出,每个流)

    Declare the number of bits per raw sample in the given output stream to be value. Note that this option sets the information provided to the encoder/muxer, it does not change the stream to conform to this value. Setting values that do not match the stream properties may result in encoding failures or invalid output files.

    将给定输出流中每个原始样本的位数声明为value。请注意,此选项设置提供给编码器/复用器的信息,它不会更改流以符合此值。设置与流属性不匹配的值可能会导致编码失败或输出文件无效。

  • -stats_enc_pre[:stream_specifier] path (输出,每个流)

  • -stats_enc_post[:stream_specifier] path (输出,每个流)

  • -stats_mux_pre[:stream_specifier] path (输出,每个流)

    Write per-frame encoding information about the matching streams into the file given by path.

    将有关匹配流的每帧编码信息写入path给定的文件中。

    -stats_enc_pre writes information about raw video or audio frames right before they are sent for encoding, while -stats_enc_post writes information about encoded packets as they are received from the encoder. -stats_mux_pre writes information about packets just as they are about to be sent to the muxer. Every frame or packet produces one line in the specified file. The format of this line is controlled by -stats_enc_pre_fmt / -stats_enc_post_fmt / -stats_mux_pre_fmt.

    -stats_enc_pre 在原始视频或音频帧被发送进行编码之前立即写入关于它们的信息,而-stats_enc_post在从编码器接收到编码包时写入关于编码包的信息。-stats_mux_pre在分组即将被发送到复用器时写入关于分组的信息。每个帧或数据包在指定的文件中产生一行。此行的格式由-stats_enc_pre_fmt / -stats_enc_post_fmt / -stats_mux_pre_fmt控制。

    When stats for multiple streams are written into a single file, the lines corresponding to different streams will be interleaved. The precise order of this interleaving is not specified and not guaranteed to remain stable between different invocations of the program, even with the same options.

    当多个流的统计数据被写入单个文件时,与不同流对应的行将被交错。这种交错的精确顺序没有指定,也不能保证在程序的不同调用之间保持稳定,即使使用相同的选项也是如此。

  • -stats_enc_pre_fmt[:stream_specifier] format_spec (输出,每个流)

  • -stats_enc_post_fmt[:stream_specifier] format_spec (输出,每个流)

  • -stats_mux_pre_fmt[:stream_specifier] format_spec (输出,每个流)

    Specify the format for the lines written with -stats_enc_pre / -stats_enc_post / -stats_mux_pre.

    指定使用-stats_enc_pre / -stats_enc_post / -stats_mux_pre写入的行的格式。

    format_spec is a string that may contain directives of the form {fmt}. format_spec is backslash-escaped — use \{, \}, and \\ to write a literal {, }, or , respectively, into the output.

    format_spec是一个字符串,它可能包含形式为{fmt}的指令。format_spec是反斜杠转义的–使用\{\}\\分别将字面{}\写入输出中。

    The directives given with fmt may be one of the following:

    fmt提供的指令可以是以下指令之一:

    • fidx

      Index of the output file.

      输出文件的索引。

    • sidx

      Index of the output stream in the file.

      文件中输出流的索引。

    • n

      Frame number. Pre-encoding: number of frames sent to the encoder so far. Post-encoding: number of packets received from the encoder so far. Muxing: number of packets submitted to the muxer for this stream so far.

      帧编号。预编码:到目前为止发送到编码器的帧数。后编码:到目前为止从编码器接收到的数据包数。复用:到目前为止,提交给该流的复用器的数据包数。

    • ni

      Input frame number. Index of the input frame (i.e. output by a decoder) that corresponds to this output frame or packet. -1 if unavailable.

      输入帧编号。与该输出帧或数据包相对应的输入帧(即解码器输出)的索引。如果不可用则为-1

    • tb

      Timebase in which this frame/packet’s timestamps are expressed, as a rational number num/den. Note that encoder and muxer may use different timebases.

      表示此帧/数据包的时间戳的时基,表示为有理数num/den。请注意,编码器和多路复用器可以使用不同的时基。

    • tbi

      Timebase for ptsi, as a rational number num/den. Available when ptsi is available, 0/1 otherwise.

      ptsi的时基,作为有理数num/denptsi可用时可用,否则为0/1

    • pts

      Presentation timestamp of the frame or packet, as an integer. Should be multiplied by the timebase to compute presentation time.

      帧或数据包的表示时间戳,作为整数。应该乘以时基来计算演示时间。

    • ptsi

      Presentation timestamp of the input frame (see ni), as an integer. Should be multiplied by tbi to compute presentation time. Printed as (2^63 - 1 = 9223372036854775807) when not available.

      输入帧的表示时间戳(请参见ni),作为一个整数。应该乘以tbi来计算演示时间。不可用时打印为 (2^63 - 1 = 9223372036854775807)

    • t

      Presentation time of the frame or packet, as a decimal number. Equal to pts multiplied by tb.

      帧或数据包的显示时间,以十进制数表示。等于pts乘以tb

    • ti

      Presentation time of the input frame (see ni), as a decimal number. Equal to ptsi multiplied by tbi. Printed as inf when not available.

      输入帧的显示时间(见ni),以十进制数表示。等于ptsi乘以tbi。不可用时打印为inf

    • dts (数据包)

      Decoding timestamp of the packet, as an integer. Should be multiplied by the timebase to compute presentation time.

      将数据包的时间戳解码为整数。应该乘以时基来计算演示时间。

    • dt (数据包)

      Decoding time of the frame or packet, as a decimal number. Equal to dts multiplied by tb.

      帧或数据包的解码时间,如十进制数。等于dts乘以tb

    • sn (帧,音频)

      Number of audio samples sent to the encoder so far.

      到目前为止发送到编码器的音频样本数。

    • samp (帧,音频)

      Number of audio samples in the frame.

      帧中的音频采样数。

    • size (数据包)

      Size of the encoded packet in bytes.

      编码数据包的大小(以字节为单位)。

    • br (数据包)

      Current bitrate in bits per second. Post-encoding only.

      当前比特率(以比特每秒为单位)。仅后编码。

    • abr (数据包)

      Average bitrate for the whole stream so far, in bits per second, -1 if it cannot be determined at this point. Post-encoding only.

      到目前为止,整个流的平均比特率,以比特每秒为单位,如果此时无法确定,则为-1。仅后编码。

    Directives tagged with packet may only be used with -stats_enc_post_fmt and -stats_mux_pre_fmt.

    packet标记的指令只能与-stats_enc_post_fmt-stats_mux_pre_fmt一起使用。

    Directives tagged with frame may only be used with -stats_enc_pre_fmt.

    frame标记的指令只能与-stats_enc_pre_fmt一起使用。

    Directives tagged with audio may only be used with audio streams.

    标记有audio的指令只能与音频流一起使用。

    The default format strings are:

    默认格式字符串为:

    • pre-encoding(预编码)

      {fidx} {sidx} {n} {t}

    • post-encoding(后编码)

      {fidx} {sidx} {n} {t}

    In the future, new items may be added to the end of the default formatting strings. Users who depend on the format staying exactly the same, should prescribe it manually.

    将来,新项目可能会添加到默认格式字符串的末尾。依赖于格式保持不变的用户应该手动指定格式。

    Note that stats for different streams written into the same file may have different formats.

    请注意,写入同一文件的不同流的统计数据可能具有不同的格式。

5.12 Preset files(预设文件)

A preset file contains a sequence of option=value pairs, one for each line, specifying a sequence of options which would be awkward to specify on the command line. Lines starting with the hash (’#’) character are ignored and are used to provide comments. Check the presets directory in the FFmpeg source tree for examples.

预设文件包含一系列 选项=值 对,每行一个,指定一系列选项,这在命令行上很难指定。以hash(‘#’)字符开头的行将被忽略,并用于提供注释。查看FFmpeg源代码树中的presets目录以获取示例。

There are two types of preset files: ffpreset and avpreset files.

预设文件有两种类型:ffpresetavpreset文件。

5.12.1 ffpreset files(ffpreset文件)

ffpreset files are specified with the vpre, apre, spre, and fpre options. The fpre option takes the filename of the preset instead of a preset name as input and can be used for any kind of codec. For the vpre, apre, and spre options, the options specified in a preset file are applied to the currently selected codec of the same type as the preset option.

ffpreset文件是用vpreapresprefpre选项指定的。fpre选项以预设的文件名而不是预设名称作为输入,可用于任何类型的编解码器。对于vpreaprespre选项,在预设文件中指定的选项将应用于当前选择的与预设选项类型相同的编解码器。

The argument passed to the vpre, apre, and spre preset options identifies the preset file to use according to the following rules:

传递给vpreaprespre预设选项的参数根据以下规则标识要使用的预设文件:

First ffmpeg searches for a file named arg.ffpreset in the directories $FFMPEG_DATADIR (if set), and $HOME/.ffmpeg, and in the datadir defined at configuration time (usually PREFIX/share/ffmpeg) or in a ffpresets folder along the executable on win32, in that order. For example, if the argument is libvpx-1080p, it will search for the file libvpx-1080p.ffpreset.

首先,ffmpeg搜索一个名为arg的文件。在目录$FFMPEG_DATADIR(如果设置)和$HOME/.ffmpeg中的ffpreset,以及在配置时定义的datadir(通常为PREFIX/share/ffmpeg)中或在win32上可执行文件的ffpresets文件夹中,按此顺序。例如,如果参数是libvpx-1080p,它将搜索文件libvpx-1080p.ffpreset

If no such file is found, then ffmpeg will search for a file named codec_name-arg.ffpreset in the above-mentioned directories, where codec_name is the name of the codec to which the preset file options will be applied. For example, if you select the video codec with -vcodec libvpx and use -vpre 1080p, then it will search for the file libvpx-1080p.ffpreset.

如果没有找到这样的文件,则ffmpeg将在上述目录中搜索名为codec_name-arg.ffpreset的文件,其中codec_name是将应用预设文件选项的编解码器的名称。例如,如果选择带有-vcodec libvpx的视频编解码器并使用-vpre 1080p,则它将搜索文件libvpx-1080p.ffpreset

5.12.2 avpreset files(avpreset文件)

avpreset files are specified with the pre option. They work similar to ffpreset files, but they only allow encoder- specific options. Therefore, an option=value pair specifying an encoder cannot be used.

avpreset文件是用pre选项指定的。它们的工作方式类似于ffpreset文件,但只允许编码器特定的选项。因此,不能使用指定编码器的 选项=值 对。

When the pre option is specified, ffmpeg will look for files with the suffix .avpreset in the directories $AVCONV_DATADIR (if set), and $HOME/.avconv, and in the datadir defined at configuration time (usually PREFIX/share/ffmpeg), in that order.

当指定了pre选项时,ffmpeg将在目录$AVCONV_DATADIR (如果设置)和$HOME/.avconv中,以及在配置时定义的datadir(通常为PREFIX/share/ffmeg)中,按顺序查找后缀为.avpreset的文件。

First ffmpeg searches for a file named codec_name-arg.avpreset in the above-mentioned directories, where codec_name is the name of the codec to which the preset file options will be applied. For example, if you select the video codec with -vcodec libvpx and use -pre 1080p, then it will search for the file libvpx-1080p.avpreset.

首先,ffmpeg在上述目录中搜索名为codec_name-arg.avpreset 的文件,其中codec_name是将应用预设文件选项的编解码器的名称。例如,如果选择带有 -vcodec libvpx 的视频编解码器并使用 -pre 1080p,则它将搜索文件libvpx-1080p.avpreset

If no such file is found, then ffmpeg will search for a file named arg.avpreset in the same directories.

如果没有找到这样的文件,那么ffmpeg将在相同的目录中搜索名为arg.avpreset的文件。

5.13 vstats file format(vstats文件格式)

The -vstats and -vstats_file options enable generation of a file containing statistics about the generated video outputs.

-vstats-vstats_file选项允许生成一个文件,该文件包含有关生成的视频输出的统计信息。

The -vstats_version option controls the format version of the generated file.

-vstats_version选项控制生成文件的格式版本。

With version 1 the format is:

对于版本1,格式为:

frame= FRAME q= FRAME_QUALITY PSNR= PSNR f_size= FRAME_SIZE s_size= STREAM_SIZEkB time= TIMESTAMP br= BITRATEkbits/s avg_br= AVERAGE_BITRATEkbits/s

With version 2 the format is:

对于版本2,格式为:

out= OUT_FILE_INDEX st= OUT_FILE_STREAM_INDEX frame= FRAME_NUMBER q= FRAME_QUALITYf PSNR= PSNR f_size= FRAME_SIZE s_size= STREAM_SIZEkB time= TIMESTAMP br= BITRATEkbits/s avg_br= AVERAGE_BITRATEkbits/s

The value corresponding to each key is described below:

每个键对应的值如下所述:

  • avg_br

    average bitrate expressed in Kbits/s

    以Kbits/s表示的平均比特率

  • br

    bitrate expressed in Kbits/s

    以Kbits/s表示的比特率

  • frame

    number of encoded frame

    编码帧数

  • out

    out file index

    输出文件索引

  • PSNR

    Peak Signal to Noise Ratio

    峰值信噪比

  • q

    quality of the frame

    帧质量

  • f_size

    encoded packet size expressed as number of bytes

    以字节数表示的编码数据包大小

  • s_size

    stream size expressed in KiB

    以KiB表示的流大小

  • st

    out file stream index

    输出文件流索引

  • time

    time of the packet

    数据包的时间

  • type

    picture type

    图片类型

See also the -stats_enc options for an alternative way to show encoding statistics.

另请参阅-stats_enc选项,以获取显示编码统计信息的替代方式。

6 Examples(示例)

6.1 Video and Audio grabbing(视频和音频抓取)

If you specify the input format and device then ffmpeg can grab video and audio directly.

如果指定输入格式和设备,那么ffmpeg可以直接获取视频和音频。

# ffmpeg -f oss -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg

Or with an ALSA audio source (mono input, card id 1) instead of OSS:

或者使用ALSA音频源(单声道输入,卡id 1)而不是OSS:

# ffmpeg -f alsa -ac 1 -i hw:1 -f video4linux2 -i /dev/video0 /tmp/out.mpg

Note that you must activate the right video source and channel before launching ffmpeg with any TV viewer such as xawtv by Gerd Knorr. You also have to set the audio recording levels correctly with a standard mixer.

请注意,在使用任何电视观看器(如Gerd Knorr的xawtv)启动ffmpeg之前,必须激活正确的视频源和频道。您还必须使用标准混合器正确设置音频录制级别。

6.2 X11 grabbing(X11抓取)

Grab the X11 display with ffmpeg via

使用ffmpeg获取X11显示

# ffmpeg -f x11grab -video_size cif -framerate 25 -i :0.0 /tmp/out.mpg

0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable.

0.0是X11服务器的display.screen编号,与DISPLAY环境变量相同。

# ffmpeg -f x11grab -video_size cif -framerate 25 -i :0.0+10,20 /tmp/out.mpg

0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. 10 is the x-offset and 20 the y-offset for the grabbing.

0.0是X11服务器的display.screen编号,与DISPLAY环境变量相同。10是抓取的x偏移,20是抓取的y偏移。

6.3 Video and Audio file format conversion(视频和音频文件格式转换)

Any supported file format and protocol can serve as input to ffmpeg:

任何支持的文件格式和协议都可以作为ffmpeg的输入:

Examples:

示例:

  • You can use YUV files as input (可以使用YUV文件作为输入):

    # ffmpeg -i /tmp/test%d.Y /tmp/out.mpg
    

    It will use the files:

    它将使用以下文件:

    /tmp/test0.Y, /tmp/test0.U, /tmp/test0.V,
    /tmp/test1.Y, /tmp/test1.U, /tmp/test1.V, etc...
    

    The Y files use twice the resolution of the U and V files. They are raw files, without header. They can be generated by all decent video decoders. You must specify the size of the image with the -s option if ffmpeg cannot guess it.

    Y文件使用的分辨率是U文件和V文件的两倍。它们是原始文件,没有头。它们可以由所有适当的视频解码器生成。如果ffmpeg无法猜测,则必须使用-s选项指定图像的大小。

  • You can input from a raw YUV420P file (您可以从原始YUV420P文件进行输入):

    # ffmpeg -i /tmp/test.yuv /tmp/out.avi
    

    test.yuv is a file containing raw YUV planar data. Each frame is composed of the Y plane followed by the U and V planes at half vertical and horizontal resolution.

    test.yuv是一个包含原始YUV平面数据的文件。每个帧由Y平面和U平面和V平面组成,它们的垂直和水平分辨率各为一半。

  • You can output to a raw YUV420P file (可以输出到原始YUV420P文件):

    # ffmpeg -i mydivx.avi hugefile.yuv
    
  • You can set several input files and output files (可以设置多个输入文件和输出文件):

    # ffmpeg -i /tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg
    

    Converts the audio file a.wav and the raw YUV video file a.yuv to MPEG file a.mpg.

    将音频文件a.wav和原始YUV视频文件a.yuv转换为MPEG文件a.mpg

  • You can also do audio and video conversions at the same time (您还可以同时进行音频和视频转换):

    # ffmpeg -i /tmp/a.wav -ar 22050 /tmp/a.mp2
    

    Converts a.wav to MPEG audio at 22050 Hz sample rate.

    以22050 Hz的采样率将a.wav转换为MPEG音频。

  • You can encode to several formats at the same time and define a mapping from input stream to output streams (您可以同时编码为多种格式,并定义从输入流到输出流的映射):

    # ffmpeg -i /tmp/a.wav -map 0:a -b:a 64k /tmp/a.mp2 -map 0:a -b:a 128k /tmp/b.mp2
    

    Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. ’-map file:index’ specifies which input stream is used for each output stream, in the order of the definition of output streams.

    a.wav转换为64 kbits 的a.mp2和128kbits 的b.mp2-map file:index按照输出流定义的顺序,指定每个输出流使用哪个输入流。

  • You can transcode decrypted VOBs (您可以对解密的VOB进行转码):

    # ffmpeg -i snatch_1.vob -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a libmp3lame -b:a 128k snatch.avi
    

    This is a typical DVD ripping example; the input is a VOB file, the output an AVI file with MPEG-4 video and MP3 audio. Note that in this command we use B-frames so the MPEG-4 stream is DivX5 compatible, and GOP size is 300 which means one intra frame every 10 seconds for 29.97fps input video. Furthermore, the audio stream is MP3-encoded so you need to enable LAME support by passing --enable-libmp3lame to configure. The mapping is particularly useful for DVD transcoding to get the desired audio language.

    这是一个典型的DVD翻录示例;输入是VOB文件,输出是具有MPEG-4视频和MP3音频的AVI文件。请注意,在该命令中,我们使用B帧,因此MPEG-4流与DivX5兼容,GOP大小为300,这意味着对于29.97fps的输入视频,每10秒一个帧内帧。此外,音频流是MP3编码的,因此您需要通过传递--enable-libmp3lame进行配置来启用LAME支持。映射对于DVD转码以获得所需的音频语言特别有用。

    NOTE: To see the supported input formats, use ffmpeg -demuxers.

    注意:要查看支持的输入格式,请使用ffmpeg -demuxers

  • You can extract images from a video, or create a video from many images (您可以从视频中提取图像,也可以从多个图像创建视频):

    For extracting images from a video:

    要从视频中提取图像,请执行以下操作:

    # ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
    

    This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.

    这将每秒从视频中提取一个视频帧,并将其输出到名为foo-001.jpeg、foo-002.jpeg等的文件中。将重新缩放图像以适应新的WxH值。

    If you want to extract just a limited number of frames, you can use the above command in combination with the -frames:v or -t option, or in combination with -ss to start extracting from a certain point in time.

    如果只想提取有限数量的帧,可以将上述命令与-frames:v-t选项结合使用,或者与-ss结合使用,从某个时间点开始提取。

    For creating a video from many images:

    要从多个图像创建视频,请执行以下操作:

    # ffmpeg -f image2 -framerate 12 -i foo-%03d.jpeg -s WxH foo.avi
    

    The syntax foo-%03d.jpeg specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.

    语法 foo-%03d.jpeg 指定使用一个由三位数字组成的十进制数字来表示序列号。它与C printf函数支持的语法相同,但只有接受正常整数的格式才适用。

    When importing an image sequence, -i also supports expanding shell-like wildcard patterns (globbing) internally, by selecting the image2-specific -pattern_type glob option.

    导入图像序列时,-i还支持通过选择特定于image2的-pattern_type glob选项在内部展开类似外壳的通配符模式(globbing)。

    For example, for creating a video from filenames matching the glob pattern foo-*.jpeg:

    例如,要从与glob模式foo-*.jpeg匹配的文件名创建视频,请执行以下操作:

    # ffmpeg -f image2 -pattern_type glob -framerate 12 -i 'foo-*.jpeg' -s WxH foo.avi
    
  • You can put many streams of the same type in the output (您可以在输出中放入许多相同类型的流):

    # ffmpeg -i test1.avi -i test2.avi -map 1:1 -map 1:0 -map 0:1 -map 0:0 -c copy -y test12.nut
    

    The resulting output file test12.nut will contain the first four streams from the input files in reverse order.

    生成的输出文件test12.nut将以相反的顺序包含来自输入文件的前四个流。

  • To force CBR video output (强制CBR视频输出):

    # ffmpeg -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v
    
  • The four options lmin, lmax, mblmin and mblmax use ’lambda’ units, but you may use the QP2LAMBDA constant to easily convert from ’q’ units (四个选项lminlmaxmblminmblmax使用lambda单位,但您可以使用QP2LAMBDA常量轻松地从q单位转换):

    # ffmpeg -i src.ext -lmax 21*QP2LAMBDA dst.ext
    

7 See Also(另见)

ffmpeg-all, ffplay, ffprobe, ffmpeg-utils, ffmpeg-scaler, ffmpeg-resampler, ffmpeg-codecs, ffmpeg-bitstream-filters, ffmpeg-formats, ffmpeg-devices, ffmpeg-protocols, ffmpeg-filters

参考

音视频基础知识 https://blog.csdn.net/weixin_41101173/article/details/118067547

linux下安装ffmpeg的详细教程 https://blog.csdn.net/qq_36437693/article/details/133976644

ffmpeg Documentation https://ffmpeg.org/ffmpeg.html

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值