3281 lines · 133.5 KB · Text
RawDownload
\input texinfo @c -*- texinfo -*-@documentencoding UTF-8 @settitle ffmpeg Documentation@titlepage@center @titlefont{ffmpeg Documentation}@end titlepage @top @contents @chapter Synopsis ffmpeg [@var{global_options}] @{[@var{input_file_options}] -i @file{input_url}@} ... @{[@var{output_file_options}] @file{output_url}@} ... @chapter Description@c man begin DESCRIPTION @command{ffmpeg} is a universal media converter. It can read a wide variety ofinputs - including live grabbing/recording devices - filter, and transcode theminto a plethora of output formats. @command{ffmpeg} reads from an arbitrary number of inputs (which can be regularfiles, pipes, network streams, grabbing devices, etc.), specified by the@code{-i} option, and writes to an arbitrary number of outputs, which arespecified by a plain output url. Anything found on the command line which cannotbe interpreted as an option is considered to be an output url. Each input or output can, in principle, contain any number of elementary streamsof different types (video/audio/subtitle/attachment/data), though the allowedstream counts and/or types may be limited by the container format. Selectingwhich streams from which inputs will go into which output is either doneautomatically or with the @code{-map} option (see the @ref{Stream selection}chapter). To refer to inputs/outputs in options, you must use their indices (0-based).E.g. the first input is @code{0}, the second is @code{1}, etc. Similarly,streams within an input/output are referred to by their indices. E.g. @code{2:3}refers to the fourth stream in the third input or output. Also see the@ref{Stream specifiers} chapter. As a general rule, options are applied to the next specifiedfile. Therefore, order is important, and you can have the sameoption on the command line multiple times. Each occurrence isthen 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 alloutput files. Also do not mix options which belong to different files. Alloptions apply ONLY to the next input or output file and are reset between files. Some simple examples follow. @itemize@itemConvert an input media file to a different format, by re-encoding media streams:@exampleffmpeg -i input.avi output.mp4@end example @itemSet the video bitrate of the output file to 64 kbit/s:@exampleffmpeg -i input.avi -b:v 64k -bufsize 64k output.mp4@end example @itemForce the frame rate of the output file to 24 fps:@exampleffmpeg -i input.avi -r 24 output.mp4@end example @itemForce the frame rate of the input file (valid for raw formats only) to 1 fps andthe frame rate of the output file to 24 fps:@exampleffmpeg -r 1 -i input.m2v -r 24 output.mp4@end example@end itemize The format option may be needed for raw input files. @c man end DESCRIPTION @chapter Detailed description@c man begin DETAILED DESCRIPTION @command{ffmpeg} builds a transcoding pipeline out of the components listedbelow. The program's operation then consists of input data chunks flowing fromthe sources down the pipes towards the sinks, while being transformed by thecomponents they encounter along the way. The following kinds of components are available:@itemize@item@emph{Demuxers} (short for "demultiplexers") read an input source in order toextract @itemize@itemglobal properties such as metadata or chapters;@itemlist of input elementary streams and their properties@end itemize One demuxer instance is created for each @option{-i} option, and sends encoded@emph{packets} to @emph{decoders} or @emph{muxers}. In other literature, demuxers are sometimes called @emph{splitters}, becausetheir main function is splitting a file into elementary streams (though somefiles only contain one elementary stream). A schematic representation of a demuxer looks like this:@verbatim┌──────────┬───────────────────────┐│ demuxer  │                       │ packets for stream 0╞══════════╡ elementary stream 0   ├──────────────────────►│          │                       ││  global  ├───────────────────────┤│properties│                       │ packets for stream 1│   and    │ elementary stream 1   ├──────────────────────►│ metadata │                       ││          ├───────────────────────┤│          │                       ││          │     ...........       ││          │                       ││          ├───────────────────────┤│          │                       │ packets for stream N│          │ elementary stream N   ├──────────────────────►│          │                       │└──────────┴───────────────────────┘     ▲     │     │ read from file, network stream,     │     grabbing device, etc.     │@end verbatim @item@emph{Decoders} receive encoded (compressed) @emph{packets} for an audio, video,or subtitle elementary stream, and decode them into raw @emph{frames} (arrays ofpixels for video, PCM for audio). A decoder is typically associated with (andreceives its input from) an elementary stream in a @emph{demuxer}, but sometimesmay also exist on its own (see @ref{Loopback decoders}). A schematic representation of a decoder looks like this:@verbatim          ┌─────────┐ packets  │         │ raw frames─────────►│ decoder ├────────────►          │         │          └─────────┘@end verbatim @item@emph{Filtergraphs} process and transform raw audio or video @emph{frames}. Afiltergraph consists of one or more individual @emph{filters} linked into agraph. Filtergraphs come in two flavors - @emph{simple} and @emph{complex},configured with the @option{-filter} and @option{-filter_complex} options,respectively. A simple filtergraph is associated with an @emph{output elementary stream}; itreceives the input to be filtered from a @emph{decoder} and sends filteredoutput to that output stream's @emph{encoder}. A simple video filtergraph that performs deinterlacing (using the @code{yadif}deinterlacer) followed by resizing (using the @code{scale} filter) can look likethis:@verbatim              ┌────────────────────────┐             │  simple filtergraph    │ frames from ╞════════════════════════╡ frames for a decoder   │  ┌───────┐  ┌───────┐  │ an encoder────────────►├─►│ yadif ├─►│ scale ├─►│────────────►             │  └───────┘  └───────┘  │             └────────────────────────┘@end verbatim A complex filtergraph is standalone and not associated with any specific stream.It may have multiple (or zero) inputs, potentially of different types (audio orvideo), each of which receiving data either from a decoder or another complexfiltergraph's output. It also has one or more outputs that feed either anencoder or another complex filtergraph's input. The following example diagram represents a complex filtergraph with 3 inputs and2 outputs (all video):@verbatim          ┌─────────────────────────────────────────────────┐          │               complex filtergraph               │          ╞═════════════════════════════════════════════════╡ frames   ├───────┐  ┌─────────┐      ┌─────────┐  ┌────────┤ frames─────────►│input 0├─►│ overlay ├─────►│ overlay ├─►│output 0├────────►          ├───────┘  │         │      │         │  └────────┤ frames   ├───────┐╭►│         │    ╭►│         │           │─────────►│input 1├╯ └─────────┘    │ └─────────┘           │          ├───────┘                 │                       │ frames   ├───────┐ ┌─────┐ ┌─────┬─╯              ┌────────┤ frames─────────►│input 2├►│scale├►│split├───────────────►│output 1├────────►          ├───────┘ └─────┘ └─────┘                └────────┤          └─────────────────────────────────────────────────┘@end verbatimFrames from second input are overlaid over those from the first. Frames from thethird input are rescaled, then the duplicated into two identical streams. One ofthem is overlaid over the combined first two inputs, with the result exposed asthe filtergraph's first output. The other duplicate ends up being thefiltergraph's second output. @item@emph{Encoders} receive raw audio, video, or subtitle @emph{frames} and encodethem into encoded @emph{packets}. The encoding (compression) process istypically @emph{lossy} - it degrades stream quality to make the output smaller;some encoders are @emph{lossless}, but at the cost of much higher output size. Avideo or audio encoder receives its input from some filtergraph's output,subtitle encoders receive input from a decoder (since subtitle filtering is notsupported yet). Every encoder is associated with some muxer's @emph{outputelementary stream} and sends its output to that muxer. A schematic representation of an encoder looks like this:@verbatim             ┌─────────┐ raw frames  │         │ packets────────────►│ encoder ├─────────►             │         │             └─────────┘@end verbatim @item@emph{Muxers} (short for "multiplexers") receive encoded @emph{packets} fortheir elementary streams from encoders (the @emph{transcoding} path) or directlyfrom demuxers (the @emph{streamcopy} path), interleave them (when there is morethan one elementary stream), and write the resulting bytes into the output file(or pipe, network stream, etc.). A schematic representation of a muxer looks like this:@verbatim                       ┌──────────────────────┬───────────┐ packets for stream 0  │                      │   muxer   │──────────────────────►│  elementary stream 0 ╞═══════════╡                       │                      │           │                       ├──────────────────────┤  global   │ packets for stream 1  │                      │properties │──────────────────────►│  elementary stream 1 │   and     │                       │                      │ metadata  │                       ├──────────────────────┤           │                       │                      │           │                       │     ...........      │           │                       │                      │           │                       ├──────────────────────┤           │ packets for stream N  │                      │           │──────────────────────►│  elementary stream N │           │                       │                      │           │                       └──────────────────────┴─────┬─────┘                                                    │                     write to file, network stream, │                         grabbing device, etc.      │                                                    │                                                    ▼@end verbatim @end itemize @section StreamcopyThe simplest pipeline in @command{ffmpeg} is single-stream@emph{streamcopy}, that is copying one @emph{input elementary stream}'s packetswithout decoding, filtering, or encoding them. As an example, consider an inputfile called @file{INPUT.mkv} with 3 elementary streams, from which we take thesecond and write it to file @file{OUTPUT.mp4}. A schematic representation ofsuch a pipeline looks like this:@verbatim┌──────────┬─────────────────────┐│ demuxer  │                     │ unused╞══════════╡ elementary stream 0 ├────────╳│          │                     ││INPUT.mkv ├─────────────────────┤          ┌──────────────────────┬───────────┐│          │                     │ packets  │                      │   muxer   ││          │ elementary stream 1 ├─────────►│  elementary stream 0 ╞═══════════╡│          │                     │          │                      │OUTPUT.mp4 ││          ├─────────────────────┤          └──────────────────────┴───────────┘│          │                     │ unused│          │ elementary stream 2 ├────────╳│          │                     │└──────────┴─────────────────────┘@end verbatim The above pipeline can be constructed with the following commandline:@exampleffmpeg -i INPUT.mkv -map 0:1 -c copy OUTPUT.mp4@end example In this commandline@itemize @itemthere is a single input @file{INPUT.mkv}; @itemthere are no input options for this input; @itemthere is a single output @file{OUTPUT.mp4}; @itemthere are two output options for this output: @itemize@item@code{-map 0:1} selects the input stream to be used - from input with index 0(i.e. the first one) the stream with index 1 (i.e. the second one); @item@code{-c copy} selects the @code{copy} encoder, i.e. streamcopy with no decodingor encoding.@end itemize @end itemize Streamcopy is useful for changing the elementary stream count, container format,or modifying container-level metadata. Since there is no decoding or encoding,it is very fast and there is no quality loss. However, it might not work in somecases because of a variety of factors (e.g. certain information required by thetarget container is not available in the source). Applying filters is obviouslyalso impossible, since filters work on decoded frames. More complex streamcopy scenarios can be constructed - e.g. combining streamsfrom two input files into a single output:@verbatim┌──────────┬────────────────────┐         ┌────────────────────┬───────────┐│ demuxer 0│                    │ packets │                    │   muxer   │╞══════════╡elementary stream 0 ├────────►│elementary stream 0 ╞═══════════╡│INPUT0.mkv│                    │         │                    │OUTPUT.mp4 │└──────────┴────────────────────┘         ├────────────────────┤           │┌──────────┬────────────────────┐         │                    │           ││ demuxer 1│                    │ packets │elementary stream 1 │           │╞══════════╡elementary stream 0 ├────────►│                    │           ││INPUT1.aac│                    │         └────────────────────┴───────────┘└──────────┴────────────────────┘@end verbatimthat can be built by the commandline@exampleffmpeg -i INPUT0.mkv -i INPUT1.aac -map 0:0 -map 1:0 -c copy OUTPUT.mp4@end example The output @option{-map} option is used twice here, creating two streams in theoutput file - one fed by the first input and one by the second. The singleinstance of the @option{-c} option selects streamcopy for both of those streams.You could also use multiple instances of this option together with@ref{Stream specifiers} to apply different values to each stream, as will bedemonstrated in following sections. A converse scenario is splitting multiple streams from a single input intomultiple outputs:@verbatim┌──────────┬─────────────────────┐          ┌───────────────────┬───────────┐│ demuxer  │                     │ packets  │                   │ muxer 0   │╞══════════╡ elementary stream 0 ├─────────►│elementary stream 0╞═══════════╡│          │                     │          │                   │OUTPUT0.mp4││INPUT.mkv ├─────────────────────┤          └───────────────────┴───────────┘│          │                     │ packets  ┌───────────────────┬───────────┐│          │ elementary stream 1 ├─────────►│                   │ muxer 1   ││          │                     │          │elementary stream 0╞═══════════╡└──────────┴─────────────────────┘          │                   │OUTPUT1.mp4│                                            └───────────────────┴───────────┘@end verbatimbuilt with@exampleffmpeg -i INPUT.mkv -map 0:0 -c copy OUTPUT0.mp4 -map 0:1 -c copy OUTPUT1.mp4@end exampleNote how a separate instance of the @option{-c} option is needed for everyoutput file even though their values are the same. This is because non-globaloptions (which is most of them) only apply in the context of the file beforewhich they are placed. These  examples can of course be further generalized into arbitrary remappingsof any number of inputs into any number of outputs. @section Trancoding@emph{Transcoding} is the process of decoding a stream and then encoding itagain. Since encoding tends to be computationally expensive and in most casesdegrades the stream quality (i.e. it is @emph{lossy}), you should only transcodewhen you need to and perform streamcopy otherwise. Typical reasons to transcodeare: @itemize@itemapplying filters - e.g. resizing, deinterlacing, or overlaying video; resamplingor mixing audio; @itemyou want to feed the stream to something that cannot decode the original codec.@end itemizeNote that @command{ffmpeg} will transcode all audio, video, and subtitle streamsunless you specify @option{-c copy} for them. Consider an example pipeline that reads an input file with one audio and onevideo stream, transcodes the video and copies the audio into a single outputfile. This can be schematically represented as follows@verbatim┌──────────┬─────────────────────┐│ demuxer  │                     │       audio packets╞══════════╡ stream 0 (audio)    ├─────────────────────────────────────╮│          │                     │                                     ││INPUT.mkv ├─────────────────────┤ video    ┌─────────┐     raw        ││          │                     │ packets  │  video  │ video frames   ││          │ stream 1 (video)    ├─────────►│ decoder ├──────────────╮ ││          │                     │          │         │              │ │└──────────┴─────────────────────┘          └─────────┘              │ │                                                                     ▼ ▼                                                                     │ │┌──────────┬─────────────────────┐ video    ┌─────────┐              │ ││ muxer    │                     │ packets  │  video  │              │ │╞══════════╡ stream 0 (video)    │◄─────────┤ encoder ├──────────────╯ ││          │                     │          │(libx264)│                ││OUTPUT.mp4├─────────────────────┤          └─────────┘                ││          │                     │                                     ││          │ stream 1 (audio)    │◄────────────────────────────────────╯│          │                     │└──────────┴─────────────────────┘@end verbatimand implemented with the following commandline:@exampleffmpeg -i INPUT.mkv -map 0:v -map 0:a -c:v libx264 -c:a copy OUTPUT.mp4@end exampleNote how it uses stream specifiers @code{:v} and @code{:a} to select inputstreams and apply different values of the @option{-c} option to them; see the@ref{Stream specifiers} section for more details.  @section Filtering When transcoding, audio and video streams can be filtered before encoding, witheither a @emph{simple} or @emph{complex} filtergraph. @subsection Simple filtergraphs Simple filtergraphs are those that have exactly one input and output, both ofthe same type (audio or video). They are configured with the per-stream@option{-filter} option (with @option{-vf} and @option{-af} aliases for@option{-filter:v} (video) and @option{-filter:a} (audio) respectively). Notethat simple filtergraphs are tied to their output stream, so e.g. if you havemultiple audio streams, @option{-af} will create a separate filtergraph for eachone. Taking the trancoding example from above, adding filtering (and omitting audio,for clarity) makes it look like this:@verbatim┌──────────┬───────────────┐│ demuxer  │               │          ┌─────────┐╞══════════╡ video stream  │ packets  │  video  │ frames│INPUT.mkv │               ├─────────►│ decoder ├─────►───╮│          │               │          └─────────┘         │└──────────┴───────────────┘                              │                                  ╭───────────◄───────────╯                                  │   ┌────────────────────────┐                                  │   │  simple filtergraph    │                                  │   ╞════════════════════════╡                                  │   │  ┌───────┐  ┌───────┐  │                                  ╰──►├─►│ yadif ├─►│ scale ├─►├╮                                      │  └───────┘  └───────┘  ││                                      └────────────────────────┘│                                                                │                                                                │┌──────────┬───────────────┐ video    ┌─────────┐               ││ muxer    │               │ packets  │  video  │               │╞══════════╡ video stream  │◄─────────┤ encoder ├───────◄───────╯│OUTPUT.mp4│               │          │         ││          │               │          └─────────┘└──────────┴───────────────┘@end verbatim @subsection Complex filtergraphs Complex filtergraphs are those which cannot be described as simply a linearprocessing chain applied to one stream. This is the case, for example, when thegraph has more than one input and/or output, or when output stream type isdifferent from input. Complex filtergraphs are configured with the@option{-filter_complex} option. Note that this option is global, since acomplex filtergraph, by its nature, cannot be unambiguously associated with asingle stream or file. Each instance of @option{-filter_complex} creates a newcomplex filtergraph, and there can be any number of them. A trivial example of a complex filtergraph is the @code{overlay} filter, whichhas two video inputs and one video output, containing one video overlaid on topof the other. Its audio counterpart is the @code{amix} filter. @anchor{Loopback decoders}@section Loopback decodersWhile decoders are normally associated with demuxer streams, it is also possibleto create "loopback" decoders that decode the output from some encoder and allowit to be fed back to complex filtergraphs. This is done with the @code{-dec}directive, which takes as a parameter the index of the output stream that shouldbe decoded. Every such directive creates a new loopback decoder, indexed withsuccessive integers starting at zero. These indices should then be used to referto loopback decoders in complex filtergraph link labels, as described in thedocumentation for @option{-filter_complex}. Decoding AVOptions can be passed to loopback decoders by placing them before@code{-dec}, analogously to input/output options.

Lines 1–500 of 3281.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t