yading@10: =head1 NAME yading@10: yading@10: ffmpeg - ffmpeg video converter yading@10: yading@10: =head1 SYNOPSIS yading@10: yading@10: yading@10: ffmpeg [I] {[I] -i F} ... {[I] F} ... yading@10: yading@10: yading@10: =head1 DESCRIPTION yading@10: yading@10: yading@10: B is a very fast video and audio converter that can also grab from yading@10: a live audio/video source. It can also convert between arbitrary sample yading@10: rates and resize video on the fly with a high quality polyphase filter. yading@10: yading@10: B reads from an arbitrary number of input "files" (which can be regular yading@10: files, pipes, network streams, grabbing devices, etc.), specified by the yading@10: C<-i> option, and writes to an arbitrary number of output "files", which are yading@10: specified by a plain output filename. Anything found on the command line which yading@10: cannot be interpreted as an option is considered to be an output filename. yading@10: yading@10: Each input or output file can, in principle, contain any number of streams of yading@10: different types (video/audio/subtitle/attachment/data). The allowed number and/or yading@10: types of streams may be limited by the container format. Selecting which yading@10: streams from which inputs will go into which output is either done automatically yading@10: or with the C<-map> option (see the Stream selection chapter). yading@10: yading@10: To refer to input files in options, you must use their indices (0-based). E.g. yading@10: the first input file is C<0>, the second is C<1>, etc. Similarly, streams yading@10: within a file are referred to by their indices. E.g. C<2:3> refers to the yading@10: fourth stream in the third input file. Also see the Stream specifiers chapter. yading@10: yading@10: As a general rule, options are applied to the next specified yading@10: file. Therefore, order is important, and you can have the same yading@10: option on the command line multiple times. Each occurrence is yading@10: then applied to the next input or output file. yading@10: Exceptions from this rule are the global options (e.g. verbosity level), yading@10: which should be specified first. yading@10: yading@10: Do not mix input and output files -- first specify all input files, then all yading@10: output files. Also do not mix options which belong to different files. All yading@10: options apply ONLY to the next input or output file and are reset between files. yading@10: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item * yading@10: yading@10: To set the video bitrate of the output file to 64 kbit/s: yading@10: yading@10: ffmpeg -i input.avi -b:v 64k -bufsize 64k output.avi yading@10: yading@10: yading@10: yading@10: =item * yading@10: yading@10: To force the frame rate of the output file to 24 fps: yading@10: yading@10: ffmpeg -i input.avi -r 24 output.avi yading@10: yading@10: yading@10: yading@10: =item * yading@10: yading@10: To force the frame rate of the input file (valid for raw formats only) yading@10: to 1 fps and the frame rate of the output file to 24 fps: yading@10: yading@10: ffmpeg -r 1 -i input.m2v -r 24 output.avi yading@10: yading@10: yading@10: =back yading@10: yading@10: yading@10: The format option may be needed for raw input files. yading@10: yading@10: yading@10: yading@10: =head1 DETAILED DESCRIPTION yading@10: yading@10: yading@10: The transcoding process in B for each output can be described by yading@10: the following diagram: yading@10: yading@10: yading@10: _______ ______________ _________ ______________ ________ yading@10: | | | | | | | | | | yading@10: | input | demuxer | encoded data | decoder | decoded | encoder | encoded data | muxer | output | yading@10: | file | ---------> | packets | ---------> | frames | ---------> | packets | -------> | file | yading@10: |_______| |______________| |_________| |______________| |________| yading@10: yading@10: yading@10: yading@10: B calls the libavformat library (containing demuxers) to read yading@10: input files and get packets containing encoded data from them. When there are yading@10: multiple input files, B tries to keep them synchronized by yading@10: tracking lowest timestamp on any active input stream. yading@10: yading@10: Encoded packets are then passed to the decoder (unless streamcopy is selected yading@10: for the stream, see further for a description). The decoder produces yading@10: uncompressed frames (raw video/PCM audio/...) which can be processed further by yading@10: filtering (see next section). After filtering, the frames are passed to the yading@10: encoder, which encodes them and outputs encoded packets. Finally those are yading@10: passed to the muxer, which writes the encoded packets to the output file. yading@10: yading@10: yading@10: =head2 Filtering yading@10: yading@10: Before encoding, B can process raw audio and video frames using yading@10: filters from the libavfilter library. Several chained filters form a filter yading@10: graph. B distinguishes between two types of filtergraphs: yading@10: simple and complex. yading@10: yading@10: yading@10: =head3 Simple filtergraphs yading@10: yading@10: Simple filtergraphs are those that have exactly one input and output, both of yading@10: the same type. In the above diagram they can be represented by simply inserting yading@10: an additional step between decoding and encoding: yading@10: yading@10: yading@10: _________ __________ ______________ yading@10: | | | | | | yading@10: | decoded | simple filtergraph | filtered | encoder | encoded data | yading@10: | frames | -------------------> | frames | ---------> | packets | yading@10: |_________| |__________| |______________| yading@10: yading@10: yading@10: yading@10: Simple filtergraphs are configured with the per-stream B<-filter> option yading@10: (with B<-vf> and B<-af> aliases for video and audio respectively). yading@10: A simple filtergraph for video can look for example like this: yading@10: yading@10: yading@10: _______ _____________ _______ _____ ________ yading@10: | | | | | | | | | | yading@10: | input | ---> | deinterlace | ---> | scale | ---> | fps | ---> | output | yading@10: |_______| |_____________| |_______| |_____| |________| yading@10: yading@10: yading@10: yading@10: Note that some filters change frame properties but not frame contents. E.g. the yading@10: C filter in the example above changes number of frames, but does not yading@10: touch the frame contents. Another example is the C filter, which yading@10: only sets timestamps and otherwise passes the frames unchanged. yading@10: yading@10: yading@10: =head3 Complex filtergraphs yading@10: yading@10: Complex filtergraphs are those which cannot be described as simply a linear yading@10: processing chain applied to one stream. This is the case, for example, when the graph has yading@10: more than one input and/or output, or when output stream type is different from yading@10: input. They can be represented with the following diagram: yading@10: yading@10: yading@10: _________ yading@10: | | yading@10: | input 0 |\ __________ yading@10: |_________| \ | | yading@10: \ _________ /| output 0 | yading@10: \ | | / |__________| yading@10: _________ \| complex | / yading@10: | | | |/ yading@10: | input 1 |---->| filter |\ yading@10: |_________| | | \ __________ yading@10: /| graph | \ | | yading@10: / | | \| output 1 | yading@10: _________ / |_________| |__________| yading@10: | | / yading@10: | input 2 |/ yading@10: |_________| yading@10: yading@10: yading@10: yading@10: Complex filtergraphs are configured with the B<-filter_complex> option. yading@10: Note that this option is global, since a complex filtergraph, by its nature, yading@10: cannot be unambiguously associated with a single stream or file. yading@10: yading@10: The B<-lavfi> option is equivalent to B<-filter_complex>. yading@10: yading@10: A trivial example of a complex filtergraph is the C filter, which yading@10: has two video inputs and one video output, containing one video overlaid on top yading@10: of the other. Its audio counterpart is the C filter. yading@10: yading@10: yading@10: =head2 Stream copy yading@10: yading@10: Stream copy is a mode selected by supplying the C parameter to the yading@10: B<-codec> option. It makes B omit the decoding and encoding yading@10: step for the specified stream, so it does only demuxing and muxing. It is useful yading@10: for changing the container format or modifying container-level metadata. The yading@10: diagram above will, in this case, simplify to this: yading@10: yading@10: yading@10: _______ ______________ ________ yading@10: | | | | | | yading@10: | input | demuxer | encoded data | muxer | output | yading@10: | file | ---------> | packets | -------> | file | yading@10: |_______| |______________| |________| yading@10: yading@10: yading@10: yading@10: Since there is no decoding or encoding, it is very fast and there is no quality yading@10: loss. However, it might not work in some cases because of many factors. Applying yading@10: filters is obviously also impossible, since filters work on uncompressed data. yading@10: yading@10: yading@10: yading@10: =head1 STREAM SELECTION yading@10: yading@10: yading@10: By default, B includes only one stream of each type (video, audio, subtitle) yading@10: present in the input files and adds them to each output file. It picks the yading@10: "best" of each based upon the following criteria: for video, it is the stream yading@10: with the highest resolution, for audio, it is the stream with the most channels, for yading@10: subtitles, it is the first subtitle stream. In the case where several streams of yading@10: the same type rate equally, the stream with the lowest index is chosen. yading@10: yading@10: You can disable some of those defaults by using the C<-vn/-an/-sn> options. For yading@10: full manual control, use the C<-map> option, which disables the defaults just yading@10: described. yading@10: yading@10: yading@10: yading@10: =head1 OPTIONS yading@10: yading@10: yading@10: All the numerical options, if not specified otherwise, accept a string yading@10: representing a number as input, which may be followed by one of the SI yading@10: unit prefixes, for example: 'K', 'M', or 'G'. yading@10: yading@10: If 'i' is appended to the SI unit prefix, the complete prefix will be yading@10: interpreted as a unit prefix for binary multiplies, which are based on yading@10: powers of 1024 instead of powers of 1000. Appending 'B' to the SI unit yading@10: prefix multiplies the value by 8. This allows using, for example: yading@10: 'KB', 'MiB', 'G' and 'B' as number suffixes. yading@10: yading@10: Options which do not take arguments are boolean options, and set the yading@10: corresponding value to true. They can be set to false by prefixing yading@10: the option name with "no". For example using "-nofoo" yading@10: will set the boolean option with name "foo" to false. yading@10: yading@10: yading@10: yading@10: =head2 Stream specifiers yading@10: yading@10: Some options are applied per-stream, e.g. bitrate or codec. Stream specifiers yading@10: are used to precisely specify which stream(s) a given option belongs to. yading@10: yading@10: A stream specifier is a string generally appended to the option name and yading@10: separated from it by a colon. E.g. C<-codec:a:1 ac3> contains the yading@10: C stream specifier, which matches the second audio stream. Therefore, it yading@10: would select the ac3 codec for the second audio stream. yading@10: yading@10: A stream specifier can match several streams, so that the option is applied to all yading@10: of them. E.g. the stream specifier in C<-b:a 128k> matches all audio yading@10: streams. yading@10: yading@10: An empty stream specifier matches all streams. For example, C<-codec copy> yading@10: or C<-codec: copy> would copy all the streams without reencoding. yading@10: yading@10: Possible forms of stream specifiers are: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item I yading@10: yading@10: Matches the stream with this index. E.g. C<-threads:1 4> would set the yading@10: thread count for the second stream to 4. yading@10: yading@10: =item IB<[:>IB<]> yading@10: yading@10: I is one of following: 'v' for video, 'a' for audio, 's' for subtitle, yading@10: 'd' for data, and 't' for attachments. If I is given, then it matches yading@10: stream number I of this type. Otherwise, it matches all yading@10: streams of this type. yading@10: yading@10: =item BIB<[:>IB<]> yading@10: yading@10: If I is given, then it matches the stream with number I yading@10: in the program with the id I. Otherwise, it matches all streams in the yading@10: program. yading@10: yading@10: =item B<#>I yading@10: yading@10: Matches the stream by a format-specific ID. yading@10: yading@10: =back yading@10: yading@10: yading@10: yading@10: =head2 Generic options yading@10: yading@10: yading@10: These options are shared amongst the ff* tools. yading@10: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: yading@10: =item B<-L> yading@10: yading@10: Show license. yading@10: yading@10: yading@10: =item B<-h, -?, -help, --help [>IB<]> yading@10: yading@10: Show help. An optional parameter may be specified to print help about a specific yading@10: item. yading@10: yading@10: Possible values of I are: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item BI yading@10: yading@10: Print detailed information about the decoder named I. Use the yading@10: B<-decoders> option to get a list of all decoders. yading@10: yading@10: yading@10: =item BI yading@10: yading@10: Print detailed information about the encoder named I. Use the yading@10: B<-encoders> option to get a list of all encoders. yading@10: yading@10: yading@10: =item BI yading@10: yading@10: Print detailed information about the demuxer named I. Use the yading@10: B<-formats> option to get a list of all demuxers and muxers. yading@10: yading@10: yading@10: =item BI yading@10: yading@10: Print detailed information about the muxer named I. Use the yading@10: B<-formats> option to get a list of all muxers and demuxers. yading@10: yading@10: yading@10: =item BI yading@10: yading@10: Print detailed information about the filter name I. Use the yading@10: B<-filters> option to get a list of all filters. yading@10: yading@10: yading@10: =back yading@10: yading@10: yading@10: yading@10: =item B<-version> yading@10: yading@10: Show version. yading@10: yading@10: yading@10: =item B<-formats> yading@10: yading@10: Show available formats. yading@10: yading@10: yading@10: =item B<-codecs> yading@10: yading@10: Show all codecs known to libavcodec. yading@10: yading@10: Note that the term 'codec' is used throughout this documentation as a shortcut yading@10: for what is more correctly called a media bitstream format. yading@10: yading@10: yading@10: =item B<-decoders> yading@10: yading@10: Show available decoders. yading@10: yading@10: yading@10: =item B<-encoders> yading@10: yading@10: Show all available encoders. yading@10: yading@10: yading@10: =item B<-bsfs> yading@10: yading@10: Show available bitstream filters. yading@10: yading@10: yading@10: =item B<-protocols> yading@10: yading@10: Show available protocols. yading@10: yading@10: yading@10: =item B<-filters> yading@10: yading@10: Show available libavfilter filters. yading@10: yading@10: yading@10: =item B<-pix_fmts> yading@10: yading@10: Show available pixel formats. yading@10: yading@10: yading@10: =item B<-sample_fmts> yading@10: yading@10: Show available sample formats. yading@10: yading@10: yading@10: =item B<-layouts> yading@10: yading@10: Show channel names and standard channel layouts. yading@10: yading@10: yading@10: =item B<-loglevel [repeat+]>I B<| -v [repeat+]>I yading@10: yading@10: Set the logging level used by the library. yading@10: Adding "repeat+" indicates that repeated log output should not be compressed yading@10: to the first line and the "Last message repeated n times" line will be yading@10: omitted. "repeat" can also be used alone. yading@10: If "repeat" is used alone, and with no prior loglevel set, the default yading@10: loglevel will be used. If multiple loglevel parameters are given, using yading@10: 'repeat' will not change the loglevel. yading@10: I is a number or a string containing one of the following values: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item B yading@10: yading@10: Show nothing at all; be silent. yading@10: yading@10: =item B yading@10: yading@10: Only show fatal errors which could lead the process to crash, such as yading@10: and assert failure. This is not currently used for anything. yading@10: yading@10: =item B yading@10: yading@10: Only show fatal errors. These are errors after which the process absolutely yading@10: cannot continue after. yading@10: yading@10: =item B yading@10: yading@10: Show all errors, including ones which can be recovered from. yading@10: yading@10: =item B yading@10: yading@10: Show all warnings and errors. Any message related to possibly yading@10: incorrect or unexpected events will be shown. yading@10: yading@10: =item B yading@10: yading@10: Show informative messages during processing. This is in addition to yading@10: warnings and errors. This is the default value. yading@10: yading@10: =item B yading@10: yading@10: Same as C, except more verbose. yading@10: yading@10: =item B yading@10: yading@10: Show everything, including debugging information. yading@10: yading@10: =back yading@10: yading@10: yading@10: By default the program logs to stderr, if coloring is supported by the yading@10: terminal, colors are used to mark errors and warnings. Log coloring yading@10: can be disabled setting the environment variable yading@10: B or B, or can be forced setting yading@10: the environment variable B. yading@10: The use of the environment variable B is deprecated and yading@10: will be dropped in a following FFmpeg version. yading@10: yading@10: yading@10: =item B<-report> yading@10: yading@10: Dump full command line and console output to a file named yading@10: C-I-I.log> in the current yading@10: directory. yading@10: This file can be useful for bug reports. yading@10: It also implies C<-loglevel verbose>. yading@10: yading@10: Setting the environment variable C to any value has the yading@10: same effect. If the value is a ':'-separated key=value sequence, these yading@10: options will affect the report; options values must be escaped if they yading@10: contain special characters or the options delimiter ':' (see the yading@10: ``Quoting and escaping'' section in the ffmpeg-utils manual). The yading@10: following option is recognized: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item B yading@10: yading@10: set the file name to use for the report; C<%p> is expanded to the name yading@10: of the program, C<%t> is expanded to a timestamp, C<%%> is expanded yading@10: to a plain C<%> yading@10: yading@10: =back yading@10: yading@10: yading@10: Errors in parsing the environment variable are not fatal, and will not yading@10: appear in the report. yading@10: yading@10: yading@10: =item B<-cpuflags flags (>IB<)> yading@10: yading@10: Allows setting and clearing cpu flags. This option is intended yading@10: for testing. Do not use it unless you know what you're doing. yading@10: yading@10: ffmpeg -cpuflags -sse+mmx ... yading@10: ffmpeg -cpuflags mmx ... yading@10: ffmpeg -cpuflags 0 ... yading@10: yading@10: Possible flags for this option are: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B<3dnow> yading@10: yading@10: yading@10: =item B<3dnowext> yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =back yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =back yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =back yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =item B yading@10: yading@10: yading@10: =back yading@10: yading@10: yading@10: =back yading@10: yading@10: yading@10: yading@10: =item B<-opencl_options options (>IB<)> yading@10: yading@10: Set OpenCL environment options. This option is only available when yading@10: FFmpeg has been compiled with C<--enable-opencl>. yading@10: yading@10: I must be a list of I=I option pairs yading@10: separated by ':'. See the ``OpenCL Options'' section in the yading@10: ffmpeg-utils manual for the list of supported options. yading@10: yading@10: =back yading@10: yading@10: yading@10: yading@10: =head2 AVOptions yading@10: yading@10: yading@10: These options are provided directly by the libavformat, libavdevice and yading@10: libavcodec libraries. To see the list of available AVOptions, use the yading@10: B<-help> option. They are separated into two categories: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: =item B yading@10: yading@10: These options can be set for any container, codec or device. Generic options yading@10: are listed under AVFormatContext options for containers/devices and under yading@10: AVCodecContext options for codecs. yading@10: yading@10: =item B yading@10: yading@10: These options are specific to the given container, device or codec. Private yading@10: options are listed under their corresponding containers/devices/codecs. yading@10: yading@10: =back yading@10: yading@10: yading@10: For example to write an ID3v2.3 header instead of a default ID3v2.4 to yading@10: an MP3 file, use the B private option of the MP3 yading@10: muxer: yading@10: yading@10: ffmpeg -i input.flac -id3v2_version 3 out.mp3 yading@10: yading@10: yading@10: All codec AVOptions are obviously per-stream, so the chapter on stream yading@10: specifiers applies to them yading@10: yading@10: Note B<-nooption> syntax cannot be used for boolean AVOptions, yading@10: use B<-option 0>/B<-option 1>. yading@10: yading@10: Note2 old undocumented way of specifying per-stream AVOptions by prepending yading@10: v/a/s to the options name is now obsolete and will be removed soon. yading@10: yading@10: yading@10: =head2 Main options yading@10: yading@10: yading@10: yading@10: =over 4 yading@10: yading@10: yading@10: yading@10: =item B<-f> I B<(>IB<)> yading@10: yading@10: Force input or output file format. The format is normally auto detected for input yading@10: files and guessed from the file extension for output files, so this option is not yading@10: needed in most cases. yading@10: yading@10: yading@10: =item B<-i> I B<(>IB<)> yading@10: yading@10: input file name yading@10: yading@10: yading@10: =item B<-y (>IB<)> yading@10: yading@10: Overwrite output files without asking. yading@10: yading@10: yading@10: =item B<-n (>IB<)> yading@10: yading@10: Do not overwrite output files, and exit immediately if a specified yading@10: output file already exists. yading@10: yading@10: yading@10: =item B<-c[:>IB<]> I B<(>IB<)> yading@10: yading@10: yading@10: =item B<-codec[:>IB<]> I B<(>IB<)> yading@10: yading@10: Select an encoder (when used before an output file) or a decoder (when used yading@10: before an input file) for one or more streams. I is the name of a yading@10: decoder/encoder or a special value C (output only) to indicate that yading@10: the stream is not to be re-encoded. yading@10: yading@10: For example yading@10: yading@10: ffmpeg -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT yading@10: yading@10: encodes all video streams with libx264 and copies all audio streams. yading@10: yading@10: For each stream, the last matching C option is applied, so yading@10: yading@10: ffmpeg -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT yading@10: yading@10: will copy all the streams except the second video, which will be encoded with yading@10: libx264, and the 138th audio, which will be encoded with libvorbis. yading@10: yading@10: yading@10: =item B<-t> I B<(>IB<)> yading@10: yading@10: Stop writing the output after its duration reaches I. yading@10: I may be a number in seconds, or in C form. yading@10: yading@10: -to and -t are mutually exclusive and -t has priority. yading@10: yading@10: yading@10: =item B<-to> I B<(>IB<)> yading@10: yading@10: Stop writing the output at I. yading@10: I may be a number in seconds, or in C form. yading@10: yading@10: -to and -t are mutually exclusive and -t has priority. yading@10: yading@10: yading@10: =item B<-fs> I B<(>IB<)> yading@10: yading@10: Set the file size limit, expressed in bytes. yading@10: yading@10: yading@10: =item B<-ss> I B<(>IB<)> yading@10: yading@10: When used as an input option (before C<-i>), seeks in this input file to yading@10: I. When used as an output option (before an output filename), yading@10: decodes but discards input until the timestamps reach I. This is yading@10: slower, but more accurate. yading@10: yading@10: I may be either in seconds or in C form. yading@10: yading@10: yading@10: =item B<-itsoffset> I B<(>IB<)> yading@10: yading@10: Set the input time offset in seconds. yading@10: C<[-]hh:mm:ss[.xxx]> syntax is also supported. yading@10: The offset is added to the timestamps of the input files. yading@10: Specifying a positive offset means that the corresponding yading@10: streams are delayed by I seconds. yading@10: yading@10: yading@10: =item B<-timestamp> I