How to Use FFmpeg xBR Filter for Pixel Art

This guide explains how to use the xbr (Scale by Rules) filter in FFmpeg to upscale pixel art graphics and animations using high-quality, rules-based interpolation. You will learn the fundamental syntax of the filter, the differences between its scaling factors, and how to apply it to both static images and video files to achieve sharp, smooth curves without the typical blurriness of standard bilinear upscaling.

Understanding the xBR Filter

The xbr filter is a high-quality pixel art scaling algorithm. Unlike traditional interpolation methods like bilinear or bicubic scaling—which blur pixels to create smooth gradients—xBR uses a rules-based approach to detect edges, curves, and diagonals. It then blends colors along these patterns to smooth out jagged lines (aliasing) while maintaining the distinct, sharp look of hand-drawn pixel art.

FFmpeg supports three scaling factors for the xbr filter: 2x, 3x, and 4x.

Basic Command Syntax

To apply the xbr filter, use the -vf (video filter) flag in your FFmpeg command. The basic syntax for the filter is:

xbr=n=SCALE_FACTOR

Where SCALE_FACTOR can be 2, 3, or 4. If you do not specify a scale factor, FFmpeg defaults to 3.

Upscaling a Static Image

To upscale a pixel art image (such as a PNG) by a factor of 4:

ffmpeg -i input.png -vf "xbr=n=4" output.png

Upscaling a Video

To upscale a low-resolution pixel art video file by a factor of 2 and output it as an MP4:

ffmpeg -i input.mp4 -vf "xbr=n=2,format=yuv420p" -c:v libx264 -crf 18 output.mp4

Note: The format=yuv420p filter is included in the video chain to ensure the output video uses a pixel format widely compatible with modern media players.

Combining xBR with Other Filters

Because xbr only supports exact scaling factors of 2, 3, and 4, you may need to combine it with the standard scale filter to reach a specific target resolution (like 1080p or 4K).

To achieve the cleanest results, first upscale the asset using the xbr filter to get as close as possible to your target resolution, then use the scale filter with the neighbor (nearest neighbor) flag to scale the rest of the way.

For example, to upscale a \(320 \times 240\) pixel art video to \(1920 \times 1080\) (1080p):

  1. Apply xbr=n=4 to scale the video to \(1280 \times 960\).
  2. Apply scale=1920:1080:flags=neighbor to stretch the video to 1080p while maintaining sharp edges.

The complete FFmpeg command is:

ffmpeg -i input.mp4 -vf "xbr=n=4,scale=1920:1080:flags=neighbor,format=yuv420p" -c:v libx264 -crf 18 output.mp4