Skip to content

Notes on encoding settings

Kagami Hiiragi edited this page Aug 20, 2018 · 30 revisions

GOP

ffmpeg -c:v libvpx-vp9 uses kf_max_dist=9999 (infinite) and kf_mode=auto by default which means if your source is mostly static, you will have only one keyframe for the entire video (vpxenc CLI tool uses max keyframe interval of 5 seconds by default).

UPDATE: libvpx 1.6.0 now uses kf_max_dist=128 by default. See: [1], [2]

frame-parallel, tile-columns, row-mt

Read this thread. Summary: -frame-parallel should be disabled since libvpx 1.4.0. Its multithreading capabilities were removed, resulting in it becoming effectively decrepit. -tile-columns slightly affects output quality but it's the only mechanism in VP9 to provide multithread encoding and decoding.

UPDATE: ffmpeg 3.3/libvpx 1.7.0 support -row-mt option which provides better encoding parallelization.

threads

Threads autodetection doesn't work with libvpx so you need to manually raise -threads value.

Profiles, transparency

  • Current state of VP9 profiles in libvpx: [1], [2]; summary: support for different chroma subsamplings, support for higher bit depths, but some players/devices/decoders may lack support e.g. Chrome-based browsers; see also bug 1215089
  • Current state of VP8/VP9 alpha: [1], [2], [3]; summary: you can encode video with alpha channel with libvpx (-pix_fmt yuva420p), Chrome and Firefox 53+ can display it

Colormatrix

Firefox always uses BT.601 colormatrix to display WebM, see bug 1210357. Chrome respects video's colormatrix tags and has height-based heuristics. In order to make WebM look exactly the same in these two browsers you need to convert video to BT.601 (-vf colormatrix=bt709:bt601; also don't forget about dithering) and tag it so (-colorspace bt470bg; only for VP9, VP8 always uses BT.601 per spec).

UPDATE: Firefox 52+ supports tagged BT.709 videos, BT.601 is default. Chrome also support colormatrix tags. So always mark your videos and they should be displayed correctly in both browsers.

UPDATE2: Firefox 53+ has BT.709 by default for VP9. It was compared with mpv's output on this video and showed almost the same picture, with minor differences for blue and pink stripes. Chromium's output for the same video is very different, slightly similar to --vf format=colormatrix=bt.709:colorlevels=full. I.e. BT.709 is correctly chosen but overall picture seems to be very wrong.

TODO: Research Edge behavior?
TODO: Get some reference BT.709 implementation, file bugs to Firefox and Chrome.

Defaults

These are the defaults when using ffmpeg with libvpx-vp9 1.6.0:

  • profile=0
  • quality=good (deadline=1000000)
  • speed=1 (-cpu-used = -speed)
  • frame-parallel=1
  • tile-columns=6
  • row-mt=0
  • auto-alt-ref=1
  • lag-in-frames=25
  • aq-mode=0
  • kf_max_dist=128 (-g)

References: FFmpeg: libvpxenc.c, libvpx: [1], [2].

Other