The basis of these commands needs to call FFmpeg, specify the input file and then the video codec which is
ffmpeg -i in.mp4 -c:v libvpx-vp9
Bitrate control modes
The main part is the rate control mode, there are multiple with some being more specific and controlling in the outcome.
This mode will try and achieve close to a set bitrate throughout the whole video, which means it is not an efficient choice.
ffmpeg -i in.mp4 -c:v libvpx-vp9 -b:v 1.5M output.webm
The example is for a target bitrate of 1.5MBit/s
This mode is recommended, with the method being a target bitrate is set and targeted twice for max effectivness by using
-pass 1 and
ffmpeg -i in.mp4 -c:v libvpx-vp9 -b:v 1.5M -pass 1 -f null /dev/null && \ ffmpeg -i in.mp4 -c:v libvpx-vp9 -b:v 1.5M -pass 2 out.webm
ffmpeg -i in.mp4 -c:v libvpx-vp9 -b:v 0 -crf 28 -pass 1 -f null /dev/null && \ ffmpeg -i in.mp4 -c:v libvpx-vp9 -b:v 0 -crf 28 -pass 2 out.webm
Pass 1 can skip audio encoding with
A popular option from h264 encoding, a quality value is given between 0 and 63 with lower values meaning higher quality. It is recommended to use a value between 15 and 35. To use constant quality
-b:v must be set and at zero:
ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 28 -b:v 0 out.webm
This mode uses the quality value from constant quality but also keeps the bitrate below a specified upper bound. This method is said as a best case for consistency when bulk encoding.
ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 28 -b:v 1500k out.webm
Min and max:
ffmpeg -i in.mp4 -c:v libvpx-vp9 -minrate 400k -b:v 1500k -maxrate 2200k out.webm
Encodes your video to a set bitrate
ffmpeg -i in.mp4 -c:v libvpx-vp9 -minrate 1.5M -maxrate 1.5M -b:v 1.5M out.webm
Lossless encoding can be achieved with
ffmpeg -i in.mp4 -c:v libvpx-vp9 -lossless 1 out.webm
Speed and quality
-deadline is the main option for VP9 encoding speed, as per media encoding lore the slower options do a more efficient encode.
good(default) is the recommended.
besthas the finest compression (slow).
realtimelive and fast encoding.
-cpu-used is how efficient the compression will be, when using a deadline of good or best the value that can be set must be between 0 and 5.
Default it is 0, 1 or 2 will increase speed but cost in quality and rate control. A value of 4 or 5 disables rate-distortion optimization thus having a greater impact on quality.
To further utilize modern CPU’s when encoding row-based multithreading can be turned on with
-row-mt 1 this can help dramatically.
More encoding speed can be achieved with specifying the CPU threads to use when encoding with
-threads an example being:
ffmpeg -i in.mp4 -c:v libvpx-vp9 -row-mt 1 -threads 16 -cpu-used 2 -deadline good -crf 21 -b:v 0 out.webm