FFmpeg
Template:Article summary start Template:Article summary text Template:Article summary end
Contents
Introduction
FFmpeg is command-line driven collection of tools which enables the decoding, encoding, conversion and playback of most audio and video streams.
Note: Encoding to Xvid is best accomplished by way of MEncoder as FFmpeg currently does not support all available Xvid-specific options (i.e. -xvidopts).
Package installation
Template:Package Official is part of the official Arch Linux [extra] repository.
Template:Cli
Encoding examples
- Examples using syntax and recommended options from Template:Filename
VOB to any container
- Concatenate the desired VOB files into a single VOB file:
$ cat VTS_01_1.VOB VTS_01_2.VOB VTS_01_3.VOB VTS_01_4.VOB > Transformers.3.Dark.of.the.Moon.VOB
- Or concatenate and then pipe the output VOB to FFmpeg:
$ cat VTS_01_1.VOB VTS_01_2.VOB VTS_01_3.VOB VTS_01_4.VOB > Transformers.3.Dark.of.the.Moon.VOB | ffmpeg -i ...
Single-pass x264 (lossless)
- Template:Codeline=Template:Codeline is the recommended option for x264 lossless encoding.
- Template:Codeline=Template:Codeline produces higher quality visuals versus Template:Codeline=Template:Codeline at the same filesize:
ffmpeg -i 13.Assassins.VOB -acodec copy -vcodec libx264 -preset placebo -crf 0 -x264opts frameref=15 13.Assassins.mkv
- Template:Codeline=Template:Codeline does not depend on lookahead and can result in a faster encoding times:
ffmpeg -i 13.Assassins.VOB -acodec copy -vcodec libx264 -preset placebo -x264opts qp=0:frameref=15 13.Assassins.mkv
- Drawbacks for both lossless methods include relatively slow encoding speed and no reasonable way to estimate output filesize.
Single-pass MPEG-2 (near lossless)
- Allow FFmpeg to automatically set DVD standardized parameters:
- Encode to DVD MPEG-2 at a frame rate of 30 frames/second:
ffmpeg -i 13.Assassins.VOB -target ntsc-dvd -sameq 13.Assassins.mpg
- Encode to DVD MPEG-2 at a frame rate of 24 frames/second:
ffmpeg -i 13.Assassins.VOB -target film-dvd -sameq 13.Assassins.mpg
Single-pass x264 (very high-quality)
- Template:Codeline=Template:Codeline = automatically detect and select the appropriate number of threads:
ffmpeg -i Transformers.3.Dark.of.the.Moon.VOB -acodec libmp3lame -ab 256k -vcodec libx264 -preset veryslow -crf 15 -threads 0 -x264opts frameref=15:fast_pskip=0 Transformers.3.Dark.of.the.Moon.mkv
- Template:Codeline option should be set to match the type and content of the of media being encoded:
ffmpeg -i 13.Assassins.VOB -acodec libmp3lame -ab 256k -vcodec libx264 -preset veryslow -tune film -crf 15 -threads 0 -x264opts frameref=15:fast_pskip=0 13.Assassins.mkv
- libmp3lame is generally recommended over libfaac encoding at all bitrates.
Two-pass x264 (very high-quality)
- Audio deactivated as only video statistics are recorded during the first of multiple pass runs:
ffmpeg -i Transformers.3.Dark.of.the.Moon.VOB -an -vcodec libx264 -pass 1 -preset veryslow -threads 0 -b 3000k -x264opts frameref=15:fast_pskip=0 -f rawvideo -y /dev/null
- Container format is automatically detected and muxed into from the output file extenstion (Template:Codeline):
ffmpeg -i Transformers.3.Dark.of.the.Moon.VOB -acodec libmp3lame -ab 256k -vcodec libx264 -pass 2 -preset veryslow -threads 0 -b 3000k -x264opts frameref=15:fast_pskip=0 Transformers.3.Dark.of.the.Moon.mkv
Two-pass MPEG-4 (very high-quality)
- Audio deactivated as only video statistics are logged during the first of multiple pass runs:
ffmpeg -i Transformers.3.Dark.of.the.Moon.VOB -an -vcodec mpeg4 -pass 1 -mbd 2 -trellis 2 -flags +cbp+mv0 -pre_dia_size 4 -dia_size 4 -precmp 4 -cmp 4 -subcmp 4 -preme 2 -qns 2 -b 3000k -f rawvideo -y /dev/null
- Container format is automatically detected and muxed into from the output file extenstion (Template:Codeline):
ffmpeg -i Transformers.3.Dark.of.the.Moon.VOB -acodec copy -vcodec mpeg4 -vtag DX50 -pass 2 -mbd 2 -trellis 2 -flags +cbp+mv0 -pre_dia_size 4 -dia_size 4 -precmp 4 -cmp 4 -subcmp 4 -preme 2 -qns 2 -b 3000k Transformers.3.Dark.of.the.Moon.avi
- Introducing Template:Codeline=Template:Codeline>Template:Codeline for Template:Codeline may skew the effects of motion estimation and lead to reduced video quality and compression efficiency.
- The two-pass MPEG-4 example above also supports output to the MP4 container (replace Template:Codeline with Template:Codeline).
Determining bitrates with fixed output file sizes
- Desired Filesize in MB x 8192 kb/MB / Length of Media in Seconds (s) = Bitrate in kb/s
- 3900 MB x 8192 kb/MB / 8830 s = 3618 kb/s required to achieve an output file size of 3900 MB
Preset files
Creating presets
- Populate Template:Filename with the default preset files:
$ cp -iR /usr/share/ffmpeg ~/.ffmpeg
- Create new and/or modify the default preset files:
Using preset files
- Enable the Template:Codeline option after declaring the desired Template:Codeline
Template:Filename
- Template:Filename = Name of the vcodec/acodec
- Template:Filename = Name of specific preset to be called out
- Template:Filename = FFmpeg preset filetype suffix
Two-pass MPEG-4 (very high quality)
- First pass of a multipass (bitrate) ratecontrol transcode:
ffmpeg -i 13.Assassins.2010.mpg -an -vcodec mpeg4 -pass 1 -vpre vhq -f rawvideo -y /dev/null
- Ratecontrol based on the video statistics logged from the first pass:
ffmpeg -i 13.Assassins.2010.mpg -acodec libfaac -aq 100 -vcodec mpeg4 -pass 2 -vpre vhq -b 3000k 13.Assassins.2010.mp4
Volume gain
- Change the audio volume in multiples of 256 where 256 = 100% (normal) volume. Additional values such as 400 are also valid options.
-vol 256 = 100% -vol 512 = 200% -vol 768 = 300% -vol 1024 = 400% -vol 2048 = 800%
- To double the volume (512 = 200%) of an MP3 file:
ffmpeg -i example.mp3 -vol 512 loud-example.mp3
- To quadruple the volume (1024 = 400%) of an Ogg file:
ffmpeg -i example.ogg -vol 1024 loud-example.ogg
- Note that gain metadata is only written to the output file.
Adding subtitles
FFmpeg does not currently support muxing subtitle files into existing streams. See MEncoder for subtitle muxing support.
Package removal
- pacman will not remove configuration files outside of the defaults that were created during package installation. This includes user-created preset files.
Additional resources
- FFmpeg Documentation - Official Documentation
- Encoding with the x264 Codec - MEncoder Documentation
- x264 Settings - MeWiki Documentation