FFmpeg

From ArchWiki
Revision as of 23:28, 19 July 2011 by Adamlau (Talk | contribs)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Article summary start Template:Article summary text Template:Article summary end

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

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)

ffmpeg -i 13.Assassins.VOB -acodec copy -vcodec libx264 -preset placebo -crf 0 -x264opts frameref=15 13.Assassins.mkv
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)

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
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

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

Determining bitrates with fixed output file sizes

  • (Desired File Size in MB - Audio File Size in MB) x 8192 kb/MB / Length of Media in Seconds (s) = Bitrate in kb/s
  • (3900 MB - 275 MB) = 3625 MB x 8192 kb/MB / 8830 s = 3363 kb/s required to achieve an approximate total output file size of 3900 MB

Preset files

Creating presets

$ cp -iR /usr/share/ffmpeg ~/.ffmpeg
  • Create new and/or modify the default preset files:

Template:File

Using preset files

Template:Filename

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.

Extracting audio

Template:Cli

  • Extract the first (mapped) AC-3 encoded audio stream exactly as it was multiplexed into the file:
ffmpeg -i The.Kings.Speech.mpg -map 0:1 acodec copy -vn The.Kings.Speech.ac3
  • Convert the third (mapped) audio stream to an MP3 file with a bitrate of 256 kb/s and a sampling rate of 96000 Hz:
ffmpeg -i The.Kings.Speech.mpg -map 0:3 -acodec libmp3lame -ab 256k -ar 96000 -vn The.Kings.Speech.mp3

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