Table of Contents
ffmpeg
ffmpeg
is a powerful tool for video conversion.
Recording Screencasts
Screencasts are basically animated screenshots and therefore a very nice way of illustrating things. Here is how to record them using ffmpeg
:
ffmpeg -f x11grab -r 25 -s 1024x768 -i :1.0 -c:v huffyuv screencast.mkv
Encoding Videos
This is rather a howto than some detailed illustration of what ffmpeg does or what one may do with it. Actually, this is how I currently encode DVDs:
Input Files
For quicker access, data from DVD should be ripped to disk first, e.g. using vobcopy -m
. Since ffmpeg
expects input to consist of a single file, DVD tracks contained in multiple VOB files have to be combined - which is actually pretty simple:
cat VIDEO_TS/VTS_NN_{1..Y}.VOB >input.vob
Single-Pass Encoding
In case output size is not as important, single-pass encoding is the way to go. Output quality may be adjusted by specifying different presets. In general, the command looks like this:
ffmpeg -i input.vob [magic options here] output.mkv
My choice of video codec is x264
, using a preset of slower
or veryslow
. Tuning for film
should not hurt, and a quality setting of 20
is decent:
-c:v libx264 -preset veryslow -tune film -crf 20
For audio, I use AAC
with variable bit rate. Setting VBR mode to 3
results in 48-56 kbps/channel (man ffmpeg-codecs
for details):
-c:a libfdk_aac -vbr 3
Extracting subtitles is easy, the MKV format allows for embedded subtitle streams just as VOB does:
-c:s copy
In order to have the right subs being displayed by default, mkvpropedit
comes in handy. For instance, use the following to set the default flag of track 3:
mkvpropedit --edit track:3 --set flag-default=yes output.mkv
Simple Encoding to Webm
ffmpeg -ss 00:37:30 -i input.mp4 -to 00:01:55 -codec:v libvpx -vf scale=-1:480 -an output.webm
This will:
- skip to offset 37m30s in input.mp4
- encode for 1m55s
- encode to VPX codec (usually used for webm)
- scale to yres of 480, keeping aspect ratio (-1)
- drop audio input (-an)
Concatenating Videos
A quick and easy way to concat videos without re-encoding is to use the
concat
format specifier:
$ cat mylist.txt file '/path/to/file1' file '/path/to/file2' file '/path/to/file3' $ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
Encoding MP3s
While this is about transcoding from FLAC to MP3, the same command should do for about any supported source format:
ffmpeg -i input.flac -q:a 0 -map a output.mp3
By default, ffmpeg will write an ID3 version 2.4 section based on FLAC tags.
Though since hardly any ID3-related tool seems to support them, it is advisable
to pass -id3v2_version 3
so version 2.3 is being used. To increase
compatibility, -write_id3v1 1
enables additional ID3 version 1 tags.