Upscale Pixel Art in FFmpeg Using the xBR Filter

Upscaling pixel art without introducing blur, artifacts, or distortion requires edge-directed interpolation rather than standard linear filtering. The xbr (Scale by Rules) filter in FFmpeg uses edge-detection rules to upscale low-resolution 2D graphics while preserving sharp outlines, smooth curves, and clean color boundaries. This guide explains how the filter works, how to configure its scaling factors, and how to chain it for higher resolutions.

Understanding the xBR Filter

Traditional scaling methods like bilinear or bicubic interpolation produce blurry edges, while nearest-neighbor scaling preserves hard pixel boundaries but causes chunky, jagged lines. The xbr filter analyzes patterns in 2x2 to 4x4 pixel neighborhoods and applies procedural rules to smooth diagonal edges and corners while maintaining the hand-drawn aesthetic of pixel art.

In FFmpeg, the xbr video filter accepts a single main parameter:

  • n: The scaling factor. Supported values are 2, 3, and 4 (corresponding to 2xBR, 3xBR, and 4xBR algorithms). The default value is 3.

Basic Usage

To apply the filter to an image or video, use the -vf (video filter) flag followed by xbr=n=<factor>.

2x Upscaling

ffmpeg -i input.png -vf "xbr=n=2" output_2x.png

3x Upscaling (Default)

ffmpeg -i input.png -vf "xbr=n=3" output_3x.png

4x Upscaling

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

You can also use the shorthand syntax without parameter names:

ffmpeg -i input.png -vf "xbr=4" output_4x.png

Upscaling to Higher Magnifications

Because the maximum native scaling factor for xbr is 4, higher scale factors require chaining filters together.

8x Upscaling (Chained xBR)

To achieve an 8x upscale, chain a 4x filter with a 2x filter:

ffmpeg -i input.png -vf "xbr=4,xbr=2" output_8x.png

16x Upscaling

Apply the 4x filter twice:

ffmpeg -i input.png -vf "xbr=4,xbr=4" output_16x.png

Upscaling to Specific Resolutions

If your target resolution does not match an exact 2x, 3x, or 4x multiple (such as scaling retro footage to 1080p or 4K), apply xbr first, followed by a secondary scale filter set to flags=neighbor (nearest neighbor) to prevent blur.

For example, to upscale a 320x240 image to 1920x1080:

ffmpeg -i retro_game.png -vf "xbr=4,scale=1440:1080:flags=neighbor,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" output_1080p.png

This command performs a 4x upscale via xbr, scales it to a 4:3 1080p-compatible height using nearest-neighbor interpolation, and pads the sides to fit a 16:9 1080p canvas with black bars.

Handling Video Files

When processing video files, ensure you specify proper encoding flags and pixel formats to maintain color fidelity and compatibility across players:

ffmpeg -i input_gameplay.mp4 -vf "xbr=4,format=yuv420p" -c:v libx264 -crf 18 -preset slow -c:a copy output_gameplay_4x.mp4

The format=yuv420p filter guarantees that the output video uses a standard pixel format supported by most media players, while -crf 18 ensures high visual quality.