FFmpeg Documentation
Table of Contents
- 1. Introduction
- 2. Quick Start
- 3. Invocation
- 4. Tips
- 5. external libraries
- 6. Supported File Formats and Codecs
- 7. Platform Specific information
- 8. Developers Guide
FFmpeg Documentation
1. Introduction
FFmpeg is a very fast video and audio converter. It can also grab from a live audio/video source.
The command line interface is designed to be intuitive, in the sense that FFmpeg tries to figure out all parameters that can possibly be derived automatically. You usually only have to specify the target bitrate you want.
FFmpeg can also convert from any sample rate to any other, and resize video on the fly with a high quality polyphase filter.
2. Quick Start
2.1 Video and Audio grabbing
FFmpeg can use a video4linux compatible video source and any Open Sound System audio source:
ffmpeg /tmp/out.mpg
Note that you must activate the right video source and channel before launching FFmpeg with any TV viewer such as xawtv (http://bytesex.org/xawtv/) by Gerd Knorr. You also have to set the audio recording levels correctly with a standard mixer.
2.2 X11 grabbing
FFmpeg can grab the X11 display.
ffmpeg -f x11grab -vd x11:0.0 /tmp/out.mpg
0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable.
ffmpeg -f x11grab -vd x11: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.
2.3 Video and Audio file format conversion
* FFmpeg can use any supported file format and protocol as input:
Examples:
* You can use YUV files as input:
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.
* You can input from a raw YUV420P file:
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.
* You can output to a raw YUV420P file:
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.
* 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 22050Hz sample rate.
* 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 -ab 64 /tmp/a.mp2 -ab 128 /tmp/b.mp2 -map 0:0 -map 0:0
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.
* You can transcode decrypted VOBs
ffmpeg -i snatch_1.vob -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec mp3 -ab 128 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-mp3lame
to configure. The mapping is particularly useful for DVD transcoding to get the desired audio language.
NOTE: To see the supported input formats, use ffmpeg -formats
.
3. Invocation
3.1 Syntax
The generic syntax is:
ffmpeg [[infile options][`-i' infile]]... {[outfile options] outfile}...
If no input file is given, audio/video grabbing is done.
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.
* To set the video bitrate of the output file to 64kbit/s:
ffmpeg -i input.avi -b 64k output.avi
* To force the frame rate of the input and output file to 24 fps:
ffmpeg -r 24 -i input.avi output.avi
* To force the frame rate of the output file to 24 fps:
ffmpeg -i input.avi -r 24 output.avi
* To force the frame rate of input file to 1 fps and the output file to 24 fps:
ffmpeg -r 1 -i input.avi -r 24 output.avi
The format option may be needed for raw input files.
By default, FFmpeg tries to convert as losslessly as possible: It uses the same audio and video parameters for the outputs as the one specified for the inputs.
3.2 Main options
-
`-L'
- Show license. `-h'
- Show help. `-version'
- Show version. `-formats'
- Show available formats, codecs, protocols, ... `-f fmt'
- Force format. `-i filename'
- input filename `-y'
- Overwrite output files. `-t duration'
-
Set the recording time in seconds.
hh:mm:ss[.xxx]
syntax is also supported.
`-fs limit_size'
- Set the file size limit. `-ss position'
-
Seek to given time position in seconds.
hh:mm:ss[.xxx]
syntax is also supported.
`-itsoffset offset'
-
Set the input time offset in seconds.
[-]hh:mm:ss[.xxx]
syntax is also supported. This option affects all the input files that follow it. The offset is added to the timestamps of the input files. Specifying a positive offset means that the corresponding streams are delayed by 'offset' seconds.
`-title string'
- Set the title. `-timestamp time'
- Set the timestamp. `-author string'
- Set the author. `-copyright string'
- Set the copyright. `-comment string'
- Set the comment. `-album string'
- Set the album. `-track number'
- Set the track. `-year number'
- Set the year. `-v verbose'
- Control amount of logging. `-target type'
-
Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ... ). All the format options (bitrate, codecs, buffer sizes) are then set automatically. You can just type:
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
`-dframes number'
- Set the number of data frames to record. `-scodec codec'
- Force subtitle codec ('copy' to copy stream). `-newsubtitle'
- Add a new subtitle stream to the current output stream. `-slang code'
- Set the ISO 639 language code (3 letters) of the current subtitle stream.
3.3 Video Options
-
`-b bitrate'
- Set the video bitrate in bit/s (default = 200 kb/s). `-vframes number'
- Set the number of video frames to record. `-r fps'
- Set frame rate (Hz value, fraction or abbreviation), (default = 25). `-s size'
-
Set frame size. The format is
`wxh' (default = 160x128). The following abbreviations are recognized:
-
`sqcif'
- 128x96 `qcif'
- 176x144 `cif'
- 352x288 `4cif'
- 704x576
`-aspect aspect'
- Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777). `-croptop size'
- Set top crop band size (in pixels). `-cropbottom size'
- Set bottom crop band size (in pixels). `-cropleft size'
- Set left crop band size (in pixels). `-cropright size'
- Set right crop band size (in pixels). `-padtop size'
- Set top pad band size (in pixels). `-padbottom size'
- Set bottom pad band size (in pixels). `-padleft size'
- Set left pad band size (in pixels). `-padright size'
- Set right pad band size (in pixels). `-padcolor (hex color)'
- Set color of padded bands. The value for padcolor is expressed as a six d