Difference between revisions of "FFmpeg"

From ArchWiki
Jump to: navigation, search
(Single-pass x264 (lossless): qp and crf make no difference in lossless (unless 10-bit which x264 from repo is not). placebo is a joke.)
(use new templates)
Line 6: Line 6:
 
{{Article summary end}}
 
{{Article summary end}}
  
== Introduction ==
 
 
[http://www.ffmpeg.org/ FFmpeg] is command-line driven collection of tools which enables the decoding, encoding, conversion and playback of [http://ffmpeg.org/general.html#Supported-File-Formats-and-Codecs most audio and video streams].
 
[http://www.ffmpeg.org/ FFmpeg] is command-line driven collection of tools which enables the decoding, encoding, conversion and playback of [http://ffmpeg.org/general.html#Supported-File-Formats-and-Codecs most audio and video streams].
  
 
== Package installation ==
 
== Package installation ==
{{Package Official|FFmpeg}} is part of the [[Official_repositories#.5Bextra.5D|official Arch Linux [extra] repository]].
+
{{Pkg|FFmpeg}} is part of the [[Official_repositories#.5Bextra.5D|official Arch Linux [extra] repository]].
  
  {{Cli|# pacman -S ffmpeg}}
+
  {{bc|# pacman -S ffmpeg}}
  
 
== Encoding examples ==
 
== Encoding examples ==
Line 24: Line 23:
 
=== x264 Lossless ===
 
=== x264 Lossless ===
 
The ''ultrafast'' preset will provide the fastest encoding and is useful for quick capturing (such as screencasting):
 
The ''ultrafast'' preset will provide the fastest encoding and is useful for quick capturing (such as screencasting):
<pre style='overflow:auto'>
+
{{bc|ffmpeg -i input -vcodec libx264 -preset ultrafast -qp 0 -acodec copy output.mkv}}
ffmpeg -i input -vcodec libx264 -preset ultrafast -qp 0 -acodec copy output.mkv
+
</pre>
+
 
On the opposite end of the preset spectrum is ''veryslow'' and will encode slower than ''ultrafast'' but provide a smaller output file size:
 
On the opposite end of the preset spectrum is ''veryslow'' and will encode slower than ''ultrafast'' but provide a smaller output file size:
<pre style='overflow:auto'>
+
{{bc|ffmpeg -i input -vcodec libx264 -preset veryslow -qp 0 -acodec copy output.mkv}}
ffmpeg -i input -vcodec libx264 -preset veryslow -qp 0 -acodec copy output.mkv
+
</pre>
+
 
Both examples will provide the same quality output.
 
Both examples will provide the same quality output.
  
Line 43: Line 38:
  
 
=== Single-pass x264 (very high-quality) ===
 
=== Single-pass x264 (very high-quality) ===
{{Codeline|threads}}={{Codeline|0}} '''=''' automatically detect and select the appropriate number of threads:  
+
{{ic|threads}}={{ic|0}} '''=''' automatically detect and select the appropriate number of threads:  
<pre style='overflow:auto'>
+
{{bc|1=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 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
+
{{ic|tune}} option should be set to [http://forum.doom9.org/showthread.php?t=149394 match the type and content of the of media being encoded]:
</pre>
+
{{bc|1=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}}
{{Codeline|tune}} option should be set to [http://forum.doom9.org/showthread.php?t=149394 match the type and content of the of media being encoded]:
+
<pre style='overflow:auto'>
+
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
+
</pre>
+
  
 
* [http://lame.sourceforge.net/ libmp3lame] is generally recommended over [http://www.audiocoding.com/faac.html libfaac] encoding at all bitrates.
 
* [http://lame.sourceforge.net/ libmp3lame] is generally recommended over [http://www.audiocoding.com/faac.html libfaac] encoding at all bitrates.
Line 56: Line 47:
 
=== Two-pass x264 (very high-quality) ===
 
=== Two-pass x264 (very high-quality) ===
 
Audio deactivated as only video statistics are recorded during the first of multiple pass runs:  
 
Audio deactivated as only video statistics are recorded during the first of multiple pass runs:  
<pre style='overflow:auto'>
+
{{bc|1=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}}
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 ({{ic|.mkv}}):
</pre>
+
{{bc|1=ffmpeg -i Transformers.3.Dark.of.the.Moon.VOB -acodec libvo-aacenc -ab 256k -ar 96000 -vcodec libx264 -pass 2 -preset veryslow -threads 0 -b 3000k -x264opts frameref=15:fast_pskip=0 Transformers.3.Dark.of.the.Moon.mkv}}
Container format is automatically detected and muxed into from the output file extenstion ({{Codeline|.mkv}}):
+
<pre style='overflow:auto'>
+
ffmpeg -i Transformers.3.Dark.of.the.Moon.VOB -acodec libvo-aacenc -ab 256k -ar 96000 -vcodec libx264 -pass 2 -preset veryslow -threads 0 -b 3000k -x264opts frameref=15:fast_pskip=0 Transformers.3.Dark.of.the.Moon.mkv
+
</pre>
+
  
 
=== Two-pass MPEG-4 (very high-quality) ===
 
=== Two-pass MPEG-4 (very high-quality) ===
 
Audio deactivated as only video statistics are logged during the first of multiple pass runs:  
 
Audio deactivated as only video statistics are logged during the first of multiple pass runs:  
<pre style='overflow:auto'>
+
{{bc|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}}
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
+
</pre>
+
  
Container format is automatically detected and muxed into from the output file extenstion ({{Codeline|.avi}}):
+
Container format is automatically detected and muxed into from the output file extenstion ({{ic|.avi}}):
<pre style='overflow:auto'>
+
{{bc|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}}
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 {{ic|threads}}={{ic|n}}>{{ic|1}} for {{ic|-vcodec mpeg4}} may skew the effects of [[Wikipedia:Motion_estimation|motion estimation]] and lead to [http://ffmpeg.org/faq.html#SEC16 reduced video quality] and compression efficiency.
</pre>
+
* The two-pass MPEG-4 example above also supports output to the [[Wikipedia:MPEG-4_Part_14|MP4]] container (replace {{ic|.avi}} with {{ic|.mp4}}).
* Introducing {{Codeline|threads}}={{Codeline|n}}>{{Codeline|1}} for {{Codeline|-vcodec mpeg4}} may skew the effects of [[Wikipedia:Motion_estimation|motion estimation]] and lead to [http://ffmpeg.org/faq.html#SEC16 reduced video quality] and compression efficiency.
+
* The two-pass MPEG-4 example above also supports output to the [[Wikipedia:MPEG-4_Part_14|MP4]] container (replace {{Codeline|.avi}} with {{Codeline|.mp4}}).
+
  
 
==== Determining bitrates with fixed output file sizes ====
 
==== Determining bitrates with fixed output file sizes ====
Line 84: Line 67:
 
=== Creating presets ===
 
=== Creating presets ===
  
Populate {{Filename|~/.ffmpeg}} with the default [http://ffmpeg.org/ffmpeg-doc.html#SEC13 preset files]:  
+
Populate {{ic|~/.ffmpeg}} with the default [http://ffmpeg.org/ffmpeg-doc.html#SEC13 preset files]:  
  
 
  $ cp -iR /usr/share/ffmpeg ~/.ffmpeg
 
  $ cp -iR /usr/share/ffmpeg ~/.ffmpeg
Line 90: Line 73:
 
Create new and/or modify the default preset files:
 
Create new and/or modify the default preset files:
  
{{File|~/.ffmpeg/libavcodec-vhq.ffpreset|<nowiki>
+
{{hc|~/.ffmpeg/libavcodec-vhq.ffpreset|<nowiki>
 
  vtag=DX50
 
  vtag=DX50
 
  mbd=2
 
  mbd=2
Line 105: Line 88:
 
=== Using preset files ===
 
=== Using preset files ===
  
Enable the {{Codeline|-vpre}} option after declaring the desired  {{Codeline|-vcodec}}
+
Enable the {{ic|-vpre}} option after declaring the desired  {{ic|-vcodec}}
  
==== {{filename|libavcodec-vhq.ffpreset}} ====
+
==== {{ic|libavcodec-vhq.ffpreset}} ====
  
* {{filename|libavcodec}} '''=''' Name of the vcodec/acodec
+
* {{ic|libavcodec}} '''=''' Name of the vcodec/acodec
* {{filename|vhq}} '''=''' Name of specific preset to be called out
+
* {{ic|vhq}} '''=''' Name of specific preset to be called out
* {{filename|ffpreset}} '''=''' FFmpeg preset filetype suffix  
+
* {{ic|ffpreset}} '''=''' FFmpeg preset filetype suffix  
  
 
===== Two-pass MPEG-4 (very high quality) =====
 
===== Two-pass MPEG-4 (very high quality) =====
  
 
First pass of a multipass (bitrate) ratecontrol transcode:
 
First pass of a multipass (bitrate) ratecontrol transcode:
<pre style='overflow:auto'>
+
{{bc|ffmpeg -i 13.Assassins.2010.mpg -an -vcodec mpeg4 -pass 1 -vpre vhq -f rawvideo -y /dev/null}}
ffmpeg -i 13.Assassins.2010.mpg -an -vcodec mpeg4 -pass 1 -vpre vhq -f rawvideo -y /dev/null
+
</pre>
+
 
Ratecontrol based on the video statistics logged from the first pass:  
 
Ratecontrol based on the video statistics logged from the first pass:  
<pre style='overflow:auto'>
+
{{bc|ffmpeg -i 13.Assassins.2010.mpg -acodec libvorbis -aq 8 -ar 48000 -vcodec mpeg4 -pass 2 -vpre vhq -b 3000k 13.Assassins.2010.mp4}}
ffmpeg -i 13.Assassins.2010.mpg -acodec libvorbis -aq 8 -ar 48000 -vcodec mpeg4 -pass 2 -vpre vhq -b 3000k 13.Assassins.2010.mp4
+
</pre>
+
  
 
* '''libvorbis quality settings (VBR)'''
 
* '''libvorbis quality settings (VBR)'''
Line 152: Line 131:
 
== Extracting audio ==
 
== Extracting audio ==
  
{{Cli|$ ffmpeg -i The.Kings.Speech.mpg<br>
+
{{bc|$ ffmpeg -i The.Kings.Speech.mpg<br>
 
Input #0, avi, from 'The.Kings.Speech.2010.mpg':<br>  Duration: 01:58:28.96, start: 0.000000, bitrate: 3000 kb/s<br>    Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 1:1 DAR 16:9], 29.97 tbr, 29.97 tbn, 29.97 tbc<br>    Stream #0.1: Audio: ac3, 48000 Hz, stereo, s16, 384 kb/s<br>    Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s<br>    Stream #0.3: Audio: dts, 48000 Hz, 5.1 768 kb/s}}
 
Input #0, avi, from 'The.Kings.Speech.2010.mpg':<br>  Duration: 01:58:28.96, start: 0.000000, bitrate: 3000 kb/s<br>    Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 1:1 DAR 16:9], 29.97 tbr, 29.97 tbn, 29.97 tbc<br>    Stream #0.1: Audio: ac3, 48000 Hz, stereo, s16, 384 kb/s<br>    Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s<br>    Stream #0.3: Audio: dts, 48000 Hz, 5.1 768 kb/s}}
  
Extract the first ({{codeline|-map 0:1}}) [[Wikipedia:Dolby_Digital|AC-3]] encoded audio stream exactly as it was multiplexed into the file:  
+
Extract the first ({{ic|-map 0:1}}) [[Wikipedia:Dolby_Digital|AC-3]] encoded audio stream exactly as it was multiplexed into the file:  
<pre style='overflow:auto'>
+
{{bc|ffmpeg -i The.Kings.Speech.mpg -map 0:1 -acodec copy -vn The.Kings.Speech.ac3}}
ffmpeg -i The.Kings.Speech.mpg -map 0:1 -acodec copy -vn The.Kings.Speech.ac3
+
Convert the third ({{ic|-map 0:3}}) [[Wikipedia:DTS_(sound_system)|DTS]] audio stream to an [[Wikipedia:Advanced_Audio_Coding|AAC]] file with a bitrate of 192 kb/s and a [[Wikipedia:Sampling_rate|sampling rate]] of 96000 Hz:
</pre>
+
{{bc|ffmpeg -i The.Kings.Speech.mpg -map 0:3 -acodec libvo-aacenc -ab 192k -ar 96000 -vn The.Kings.Speech.aac}}
Convert the third ({{codeline|-map 0:3}}) [[Wikipedia:DTS_(sound_system)|DTS]] audio stream to an [[Wikipedia:Advanced_Audio_Coding|AAC]] file with a bitrate of 192 kb/s and a [[Wikipedia:Sampling_rate|sampling rate]] of 96000 Hz:
+
{{ic|-vn}} disables the processing of the video stream.
<pre style='overflow:auto'>
+
ffmpeg -i The.Kings.Speech.mpg -map 0:3 -acodec libvo-aacenc -ab 192k -ar 96000 -vn The.Kings.Speech.aac
+
</pre>
+
{{codeline|-vn}} disables the processing of the video stream.
+
  
 
=== Stripping audio ===
 
=== Stripping audio ===
  
# Copy the first video stream ({{codeline|-map 0:0}}) along with the second AC-3 audio stream ({{codeline|-map 0:2}}).
+
# Copy the first video stream ({{ic|-map 0:0}}) along with the second AC-3 audio stream ({{ic|-map 0:2}}).
 
# Convert the AC-3 audio stream to two-channel MP3 with a bitrate of 128 kb/s and a sampling rate of 48000 Hz.
 
# Convert the AC-3 audio stream to two-channel MP3 with a bitrate of 128 kb/s and a sampling rate of 48000 Hz.
<pre style='overflow:auto'>
+
{{bc|ffmpeg -i The.Kings.Speech.mpg -map 0:0 -map 0:2 -vcodec copy -acodec libmp3lame -ab 128k -ar 48000 -ac 2 The.Kings.Speech.mkv}}
ffmpeg -i The.Kings.Speech.mpg -map 0:0 -map 0:2 -vcodec copy -acodec libmp3lame -ab 128k -ar 48000 -ac 2 The.Kings.Speech.mkv
+
{{bc|$ ffmpeg -i The.Kings.Speech.mkv<br>
</pre>
+
{{Cli|$ ffmpeg -i The.Kings.Speech.mkv<br>
+
 
Input #0, avi, from 'The.Kings.Speech.2010.mpg':<br>  Duration: 01:58:28.96, start: 0.000000, bitrate: 3000 kb/s<br>    Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 1:1 DAR 16:9], 29.97 tbr, 29.97 tbn, 29.97 tbc<br>    Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s}}
 
Input #0, avi, from 'The.Kings.Speech.2010.mpg':<br>  Duration: 01:58:28.96, start: 0.000000, bitrate: 3000 kb/s<br>    Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 1:1 DAR 16:9], 29.97 tbr, 29.97 tbn, 29.97 tbc<br>    Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s}}
 
{{Note|Removing undesired audio streams allows for additional bits to be allocated towards improving video quality.}}
 
{{Note|Removing undesired audio streams allows for additional bits to be allocated towards improving video quality.}}

Revision as of 13:56, 17 November 2011

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 – فارسی

Summary help replacing me
This article attempts to walk users through the installation, usage and configuration of FFmpeg.

FFmpeg is command-line driven collection of tools which enables the decoding, encoding, conversion and playback of most audio and video streams.

Package installation

FFmpeg is part of the official Arch Linux [extra] repository.

# pacman -S ffmpeg

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

x264 Lossless

The ultrafast preset will provide the fastest encoding and is useful for quick capturing (such as screencasting):

ffmpeg -i input -vcodec libx264 -preset ultrafast -qp 0 -acodec copy output.mkv

On the opposite end of the preset spectrum is veryslow and will encode slower than ultrafast but provide a smaller output file size:

ffmpeg -i input -vcodec libx264 -preset veryslow -qp 0 -acodec copy output.mkv

Both examples will provide the same quality output.

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)

threads=0 = 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

tune 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

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 (.mkv):

ffmpeg -i Transformers.3.Dark.of.the.Moon.VOB -acodec libvo-aacenc -ab 256k -ar 96000 -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 (.avi):

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 threads=n>1 for -vcodec mpeg4 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 .avi with .mp4).

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

Populate ~/.ffmpeg with the default preset files:

$ cp -iR /usr/share/ffmpeg ~/.ffmpeg

Create new and/or modify the default preset files:

~/.ffmpeg/libavcodec-vhq.ffpreset
 vtag=DX50
 mbd=2
 trellis=2
 flags=+cbp+mv0
 pre_dia_size=4
 dia_size=4
 precmp=4
 cmp=4
 subcmp=4
 preme=2
 qns=2

Using preset files

Enable the -vpre option after declaring the desired -vcodec

libavcodec-vhq.ffpreset

  • libavcodec = Name of the vcodec/acodec
  • vhq = Name of specific preset to be called out
  • ffpreset = 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 libvorbis -aq 8 -ar 48000 -vcodec mpeg4 -pass 2 -vpre vhq -b 3000k 13.Assassins.2010.mp4
  • libvorbis quality settings (VBR)
  • -aq 4 = 128 kb/s
  • -aq 5 = 160 kb/s
  • -aq 6 = 192 kb/s
  • -aq 7 = 224 kb/s
  • -aq 8 = 256 kb/s

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. Unlike mp3gain or ogggain, the source sound file is untouched.

Extracting audio

$ ffmpeg -i The.Kings.Speech.mpg
Input #0, avi, from 'The.Kings.Speech.2010.mpg':
Duration: 01:58:28.96, start: 0.000000, bitrate: 3000 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 1:1 DAR 16:9], 29.97 tbr, 29.97 tbn, 29.97 tbc
Stream #0.1: Audio: ac3, 48000 Hz, stereo, s16, 384 kb/s
Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
Stream #0.3: Audio: dts, 48000 Hz, 5.1 768 kb/s

Extract the first (-map 0:1) 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 (-map 0:3) DTS audio stream to an AAC file with a bitrate of 192 kb/s and a sampling rate of 96000 Hz:

ffmpeg -i The.Kings.Speech.mpg -map 0:3 -acodec libvo-aacenc -ab 192k -ar 96000 -vn The.Kings.Speech.aac

-vn disables the processing of the video stream.

Stripping audio

  1. Copy the first video stream (-map 0:0) along with the second AC-3 audio stream (-map 0:2).
  2. Convert the AC-3 audio stream to two-channel MP3 with a bitrate of 128 kb/s and a sampling rate of 48000 Hz.
ffmpeg -i The.Kings.Speech.mpg -map 0:0 -map 0:2 -vcodec copy -acodec libmp3lame -ab 128k -ar 48000 -ac 2 The.Kings.Speech.mkv
$ ffmpeg -i The.Kings.Speech.mkv
Input #0, avi, from 'The.Kings.Speech.2010.mpg':
Duration: 01:58:28.96, start: 0.000000, bitrate: 3000 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 1:1 DAR 16:9], 29.97 tbr, 29.97 tbn, 29.97 tbc
Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s
Note: Removing undesired audio streams allows for additional bits to be allocated towards improving video quality.

Adding subtitles

FFmpeg does not currently support muxing subtitle files into existing streams. See MEncoder for subtitle muxing support.

Recording webcam

With FFmpeg it is very easy to record a video from the webcam and including audio sources from an additional microphone. This following example uses pulseaudio with the alsa backend for the microphone and assumes that the webcam is correctly recognised under /dev/video0.

$ ffmpeg -f alsa -i pulse -f video4linux2 -s 640x480 -i /dev/video0 out.mpg

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