Skip to content

Instantly share code, notes, and snippets.

@mrintrepide
Last active February 6, 2024 00:27
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrintrepide/3033c35ee9557e66cff7806f48dbd339 to your computer and use it in GitHub Desktop.
Save mrintrepide/3033c35ee9557e66cff7806f48dbd339 to your computer and use it in GitHub Desktop.
VP9 Encode Guide (ffmpeg, libvpx-vp9, vpxenc)

WIP

VP9 encode is very very slow ?
Yes and no. Unlike x265 use all core to speed up encode time, the low threaded libvpx-vp9 use for me 4 core of my Ryzen 3900X. Encode 4 video in the same time -> x4 "boost".

Quality (Unconstrained)

Force dynamic bitrate with b:v 0
Set quality level with -crf <quality level> is a integer (0 to 63)
libvpx use -deadline and ffmpeg -quality need to be set to good.

Speed

libvpx use -cpu-used and ffmpeg -speed 0 to 8 but > 4 isn't recommended.
Lowering this value increase quality.
Optional for linux user: use gamemoderun to dynamic set (cpu) performance scheduler.

Multithreading

For boost encode without decreasing quality -row-mt 1
Threaded tile -tile-columns 0 but can be for little threaded boost: 1 for 720p, 2 for 1080p, 3 for 2160p, 0 for non-HD or better quality.
Don't set it > Set OFF other -tile-rows 0 and -frame-parallel 0, don't boost and can decrease quality.

Multi pass

Better quality with more frame complexity and increase bitrate with -auto-alt-ref 6 (2-pass only)
Set alt-ref look ahead -lag-in-frames 25

Other

No VP9 adaptative quantization -aq-mode 0
-tune-content film better film grain, less blur but increase bitrate/file size
-enable-tpl 1 unclear is new but somebody use it. Need more info/test (lower distortion). Better PSNR but lower SSIM

Example

ffmpeg -hide_banner -i 'input video' -pix_fmt yuv420p10le -c:v libvpx-vp9 -b:v 0 -crf 31 -speed 1 -quality good -static-thresh 0 -tile-columns 0 -tile-rows 0 -frame-parallel 0 -row-mt 1 -aq-mode 0 -auto-alt-ref 6 -lag-in-frames 25 -enable-tpl 1 -profile:v 2 -g 240 -an -sn -pass 1 -f null -

ffmpeg -hide_banner -i 'input video' -pix_fmt yuv420p10le -c:v libvpx-vp9 -b:v 0 -crf 31 -speed 1 -quality good -static-thresh 0 -tile-columns 0 -tile-rows 0 -frame-parallel 0 -row-mt 1 -aq-mode 0 -auto-alt-ref 6 -lag-in-frames 25 -enable-tpl 1 -profile:v 2 -g 240 -an -sn -pass 2 -f webm out.webm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment