Best libvpx Settings for Screen Capture

Encoding screen captures requires specific encoder settings to maintain sharp text, preserve interface colors, and keep file sizes small despite long periods of static content. This article outlines the optimal libvpx (VP8 and VP9) settings for screen recordings, focusing on pixel formats, rate control, speed presets, and keyframe intervals to achieve pixel-perfect quality.

Use VP9 Instead of VP8

For screen captures, always choose the VP9 encoder (libvpx-vp9) over VP8 (libvpx). VP9 offers significantly better compression efficiency, native support for lossless encoding, and superior handling of sharp edges and text.

1. Pixel Format: Use YUV 4:4:4

Standard video encoding uses yuv420p chroma subsampling, which discards color data and causes red or blue text on screen captures to look blurry or pixelated. To preserve crisp text and UI elements, use the 4:4:4 pixel format:

-pix_fmt yuv444p

Note: Ensure your target media player supports VP9 4:4:4 playback (most modern browsers do).

2. Rate Control and Quality

Screen recordings consist of large areas of flat colors and static content, which compress highly efficiently. You can choose between lossless or near-lossless quality.

Lossless VP9 Encoding

For archiving or post-production where zero quality loss is required, use VP9’s native lossless mode. In this mode, the CRF parameter acts as a toggle:

-crf 0 -lossless 1

For publishing or streaming, a near-lossless constrained quality (CQ) mode offers virtually indistinguishable quality at a fraction of the file size:

-crf 15 -b:v 0

Using -crf between 15 and 25 with a bitrate limit of 0 (-b:v 0) forces the encoder to rely entirely on the quality factor, which is ideal for the highly variable motion of screen recordings.

3. CPU and Encoding Speed

The -cpu-used parameter controls the trade-off between encoding speed and compression efficiency. It ranges from 0 (slowest, highest compression) to 8 (fastest).

4. Optimize Keyframe Intervals

Because desktop screens often remain static for seconds at a time, you should increase the maximum keyframe interval (gop size). This prevents the encoder from wasting bits on unnecessary keyframes:

-g 999

For High-Quality, Highly Compressed Screen Captures (Post-Processing):

ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt yuv444p -lossless 0 -crf 15 -b:v 0 -deadline good -cpu-used 2 -g 999 output.webm

For Real-Time Lossless Screen Captures:

ffmpeg -f gdigrab -i desktop -c:v libvpx-vp9 -pix_fmt yuv444p -lossless 1 -deadline realtime -cpu-used 6 -g 999 output.webm