Best AVIF Settings for Code Screenshots

Capturing computer screenshots of code demands distinct encoder configurations because standard AV1 presets prioritize natural photographic content, often causing blurry monospace typography and color bleeding across syntax highlighting. This guide details the essential AVIF encoder tuning options—primarily full chroma subsampling, screen-content tuning, quantizer controls, and edge-preservation settings—necessary to produce lightweight, pixel-perfect images of terminal and IDE windows.

1. Enforce YUV 4:4:4 Chroma Subsampling

By default, image and video encoders use YUV 4:2:0 subsampling, which halves color resolution horizontally and vertically to save bandwidth. For code screenshots with multi-colored text on dark or light backgrounds, 4:2:0 results in severe color bleeding, fringing around characters, and unreadable punctuation.

  • Target setting: Set the pixel format to yuv444p or 4:4:4.
  • Impact: Preserves full-resolution color data for every individual pixel, ensuring syntax tokens (such as red keywords or cyan variables) remain crisp against the background.

2. Set the Encoder Tuning Flag to Screen or SSIM

Most AV1 encoders (such as libaom, SVT-AV1, and rav1e) default to perceptual metrics like VMAF or visual psychovisual models that blur high-frequency noise. Because code consists entirely of high-frequency sharp edges, standard perceptual tuning degrades text legibility.

  • libaom (avifenc): Use --tune ssim. While libaom does not have a dedicated screen mode in the image encoder frontend, SSIM penalizes edge deformation more strictly than the default subjective metric.
  • SVT-AV1: Set --tune 0 (Visual quality/MQ) or enable screen content tools if utilizing an SVT-AV1 pipeline.
  • Screen Content Tools: Ensure intra-block copy (IBC) and palette mode are enabled if exposed by the encoder. These tools are built into AV1 specifically to identify repeating screen patterns, such as monospace character fonts and uniform background colors.

3. Use 10-Bit Color Depth

Even when your source screenshot is 8-bit sRGB, encoding the output as 10-bit (yuv444p10le) significantly improves the compression efficiency of the AV1 format.

  • Why it matters: The internal math of the AV1 transforms operates with less rounding error at 10-bit depth. This reduces gradient banding in IDE themes and prevents block compression artifacts near the boundaries of high-contrast text without increasing file size.

4. Optimize Quantization (CRF / CQ Levels)

Screenshots of code contain large areas of flat color mixed with isolated high-contrast pixels. Avoid aggressive compression that triggers discrete cosine transform (DCT) ringing artifacts around character glyphs.

  • Constant Quality (CRF/Q): Target a quantizer scale between 15 and 25 (on a 0–63 scale, where 0 is lossless). A quality setting of roughly Q=75 to Q=85 in tools like avifenc maintains clean font edges.
  • Min/Max Quantizers: Keep the minimum and maximum quantizers close together (or lock them using a single CQ value) to prevent the encoder from smoothing out lines of code in complex sections.

5. Disable Filtering and Adaptive Smoothing

Video-oriented AV1 features attempt to soften grain and sharp lines to make motion appear smoother. For static code captures, these mechanisms must be suppressed:

  • Loop Restoration and Deblocking: In photographic images, in-loop deblocking filters hide tile seams. On pixelated text, overzealous filtering blurs thin stems on characters like i, l, and punctuation marks like ;. Keep deblocking filter strengths low or at default zero-offsets.
  • Sharpness: If using encoders with an explicit sharpness control (such as libaom's --sharpness parameter), increase it to a value between 1 and 4 to prevent edge transitions from flattening.

Practical Implementation

Using the reference tool avifenc (libaom-based), the optimal command for a code screenshot is:

avifenc --min 15 --max 25 -d 10 -y 444 --tune ssim -s 4 screenshot.png code_optimized.avif

Using ffmpeg with libaom-av1:

ffmpeg -i screenshot.png -c:v libaom-av1 -crf 20 -b:v 0 -pix_fmt yuv444p10le -cpu-used 4 -aom-params tune=ssim:enable-rect-partitions=1 code_optimized.avif

These parameters balance encoding time, keep file sizes far below comparable PNGs, and guarantee legible, artifact-free code rendering.