Parameters
Parameter | Function |
---|---|
$INPUT |
the input video file |
$CRF |
the target quality (33 is a good value, the smaller the better the video quality) |
$THREADS |
the number of threads to use converting the video |
$GOP |
the number of frames after which another inter frame is forced. You can seek between inter frames, so if you want to seek make this something like 5 * $FPS
|
$OUTFILE |
the target video file name |
$WIDTH |
the target width when scaling. When setting the height to -1 the aspect ratio is kept |
Other regulations:
The webm container only supports webvtt subtitles, so if you have embedded subtitle in the video -c:s webvtt
tries to convert them into webvtt.
Converting a single file
With one-pass:
ffmpeg -i $INPUT -c:v libvpx-vp9 -b:v 0 -crf $CRF -threads $THREADS -g $GOP -tile-columns 6 -frame-parallel 1 -c:s webvtt -speed 1 -c:a libopus -b:a 64k -f webm $OUTFILE
When doing a two-pass, the speed value can be changed and the audio conversion can be omitted during 1st pass:
ffmpeg -i $INPUT -pass 1 -passlogfile $PREFIX -c:v libvpx-vp9 -b:v 0 -crf $CRF -threads $THREADS -g $GOP -tile-columns 6 -frame-parallel 1 -speed 4 -an -f webm /dev/null
ffmpeg -i $INPUT -pass 2 -passlogfile $PREFIX -c:v libvpx-vp9 -b:v 0 -crf $CRF -threads $THREADS -g $GOP -tile-columns 6 -frame-parallel 1 -c:s webvtt -speed 1 -c:a libopus -b:a 64k -f webm $OUTFILE
When scaling the video just add the following parameter:
-vf scale=$WIDTH:-1
Merging several files into one
To merge several files into one a "complex filter" has to be used. When this is used, no normal filter can be used (e.g. for scaling). To simply merge two files use the following parameters:
-i $INPUT1 -i $INPUT2 -filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0] concat=n=2:v=1:a=1 [v] [a]" -map '[v]' -map '[a]'
This takes the first video and audio streams from the first file and the first video and audio streams from the second file. It then concats the two (n=2
) streams in one video (v=1
) and audio stream (a=1
) and exports them as [v]
and [a]
. Later it maps them to the output file.
When trying to scale this video you can chain complex filters. This would look like this:
-i $INPUT1 -i $INPUT2 -filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0] concat=n=2:v=1:a=1 [v] [a]; [v]scale=$WIDTH:-1[v2]" -map '[v2]' -map '[a]'
Known Errors and Workarounds
Invalid channel layout 5.1(side) for specified mapping family -1
Either add an audio filter
-af "channelmap=channel_layout=5.1"
or enhance the complex filter with
;[a] channelmap=channel_layout=5.1 [a2]