Ffmpeg Arch Guide
Ffmpeg Arch Guide
Summary
This article attempts to walk users through the installation, usage and configuration
of FFmpeg.
Contents
• 1 Introduction
• 2 Package installation
• 3 Encoding examples
• 3.1 VOB to any container
• 3.2 Single-pass x264 (lossless)
• 3.3 Single-pass MPEG-2 (near lossless)
• 3.4 Single-pass x264 (very high-quality)
• 3.5 Two-pass x264 (very high-quality)
• 3.6 Two-pass MPEG-4 (very high-quality)
• 3.6.1 Determining bitrates with fixed output file sizes
• 4 Preset files
• 4.1 Creating presets
• 4.2 Using preset files
• 4.2.1 libavcodec-vhq.ffpreset
• 4.2.1.1 Two-pass MPEG-4 (very high quality)
• 5 Volume gain
• 6 Extracting audio
• 6.1 Stripping audio
• 7 Adding subtitles
• 8 Recording webcam
• 9 Package removal
• 10 Additional resources
1
Introduction
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
• Examples using syntax and recommended options from extra/ffmpeg
20110622-1
• crf=0 produces higher quality visuals versus qp=0 at the same filesize:
2
ffmpeg -i 13.Assassins.VOB -acodec copy -vcodec libx264 -preset placebo
-crf 0 -x264opts frameref=15 13.Assassins.mkv
• qp=0 does not depend on lookahead and can result in a faster encoding
times:
• Drawbacks for both lossless methods include relatively slow encoding speed
and no reasonable way to estimate output filesize.
• tune option should be set to match the type and content of the of media
being encoded:
3
Two-pass x264 (very high-quality)
• Audio deactivated as only video statistics are recorded during the first of
multiple pass runs:
• Container format is automatically detected and muxed into from the output
file extenstion (.mkv):
• Audio deactivated as only video statistics are logged during the first of
multiple pass runs:
• Container format is automatically detected and muxed into from the output
file extenstion (.avi):
4
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
Preset files
Creating presets
File: ~/.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
libavcodec-vhq.ffpreset
5
• ffpreset = FFmpeg preset filetype suffix
• Ratecontrol based on the video statistics logged from the first pass:
Volume gain
• Change the audio volume in multiples of 256 where 256 = 100% (normal)
volume. Additional values such as 400 are also valid options.
6
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:
• 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:
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.
7
$ 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
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.
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
• x264 Settings - MeWiki Documentation
• FFmpeg Documentation - Official Documentation
• Encoding with the x264 Codec - MEncoder Documentation
• H.264 eEcoding Guide - Avidemux Wiki
8
• Using FFmpeg - Linux How To Pages