Convert VP9 codec videos using Ffmpeg

Posted By : Oodles Admin | 29-Apr-2015

Encoding VP9 Video using ffmpeg

 

Let’s have a close look on how we can encode VP9 videos using FFMPEG, and in order to ensure VP9 encoding, ffmpeg must built with libvpx support.

 

Recommended setting for Video On Demand -

 

ffmpeg -i <sourcefile> -c:v libvpx-vp9 -pass 1 -b:v 1000K -threads 8 -speed 4 \

 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 \

 -an -f webm /dev/null

 

Explanation -

c:v libvpx-vp9 -pass 1 -b:v 1000K - Ensures ffmpeg to encode the video in                                    VP9 with the target of 1000 Kilobits.

 

tile-columns 6 -frame-parallel -> Ensures decoders the usage of multiple                                          cores as most of the VP9 decoders use tile                                    based, Multi-threaded decoding.

 

auto-alt-ref 1 -lag-in-frames ->  Its a VP9 feature which enhances quality.

Setting auto-alt-ref and lag-in-frames >= 12 -> Will turn on VP9's alt-ref                                            frames

 

Speed - Useful to speed up the first pass.

speed 4 - Ensures VP9 to encode really really fast, sacrificing the quality.

 

 

ffmpeg -i <sourcefile> -c:v libvpx-vp9 -pass 2 -b:v 1000K -threads 8 -speed 1 \

 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 \

 -c:a libopus -b:a 64k -f webm outfile.webm

 

c:a libopus -b:a 64k - Ensures ffmpeg to encode the audio in opus with a             target of 64 Kilobits

speed 1 is a good speed vs. quality compromise. Produces output quality                 typically very close to speed 0, but usually encodes much faster.

Multithreaded encoding may be used if -threads > 1 and -tile-columns > 0.

 

 

Best Quality Recommended Setting -

 

tile-columns 0, frame-parallel 0: Turning off tile-columns and frame-parallel should give                                    a small bump in quality, but will most likely hamper                             decode performance severely.

 

ffmpeg -i <sourcefile> -c:v libvpx-vp9 -pass 1 -b:v 1000K -threads 1 -speed 4 \

 -tile-columns 0 -frame-parallel 0 -auto-alt-ref 1 -lag-in-frames 25 \

 -g 9999 -aq-mode 0 -an -f webm /dev/null

 

ffmpeg -i <sourcefile> -c:v libvpx-vp9 -pass 2 -b:v 1000K -threads 1 -speed 0 \

 -tile-columns 0 -frame-parallel 0 -auto-alt-ref 1 -lag-in-frames 25 \

 -g 9999 -aq-mode 0 -c:a libopus -b:a 64k -f webm outfile.webm

 

 

 

Difference between Constant and Constrained Quality Setting -

 

The main difference lies behind “bitrate” (b:v <bitrate> parameter). Let’s have a close look on the setting difference. Both crf <q-value> and b:v <bitrate> MUST be provided.

 

 

Constant Quality Setting -

 

Constant - b:v 0. bv MUST be 0.

 

ffmpeg -i <sourcefile> -c:v libvpx-vp9 -pass 1 -b:v 0 -crf 33 -threads 8 -speed 4 \

 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 \

 -an -f webm /dev/null

ffmpeg -i <source> -c:v libvpx-vp9 -pass 2 -b:v 0 -crf 33 -threads 8 -speed 2 \

 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 \

 -c:a libopus -b:a 64k -f webm outfile.webm

 

crf is the quality value (0-63 for VP9)

 

 

Constrained Quality Setting -

 

Constraint - b:v <bitrate> parameter, where bitrate MUST be non-zero.

 

ffmpeg -i <sourcefile> -c:v libvpx-vp9 -pass 1 -b:v 1400K -crf 33 -threads 8 -speed 4 \

 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 \

 -an -f webm /dev/null

ffmpeg -i <source> -c:v libvpx-vp9 -pass 2 -b:v 1400K -crf 33 -threads 8 -speed 2 \

 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 \

 -c:a libopus -b:a 64k -f webm outfile.webm

 

 

If b:v parameter is not defined then FFMpeg will assume a default target bitrate of 256K -- so the constrained quality mode will be triggered with a potentially very low target bitrate.

 

About Author

Author Image
Oodles Admin

Divya has more than 6 years of industrial experience in different domains – SAP EP, Search Quality Operations and Content Writing. She loves travelling across the world and also enjoys watching movies.

Request for Proposal

Name is required

Comment is required

Sending message..