How to Use FFmpeg Shape Adaptive Blur Filter

The FFmpeg sab (Shape Adaptive Blur) filter is an edge-preserving smoothing filter designed to reduce noise and soften flat surfaces without blurring distinct contours and edges. This guide provides a direct, comprehensive explanation of the sab filter, detailing its core syntax, key parameters, and practical command-line examples for video processing.

What is the sab Filter?

Shape Adaptive Blur works similarly to bilateral filtering. Instead of uniformly blurring every pixel in an image, it analyzes the neighborhood of each pixel and restricts the blurring effect to areas of low contrast. This makes it ideal for digital noise reduction, digital makeup/skin smoothing, and stylizing video while keeping outlines crisp.

Syntax and Parameters

The standard syntax for the sab filter is:

-vf "sab=luma_radius:luma_pre_filter_radius:luma_strength[:chroma_radius:chroma_pre_filter_radius:chroma_strength]"

You can set parameters positionally or by their explicit names:

  • luma_radius (lr): Defines the blur radius for the luma (brightness) plane. Allowed values range from 0.1 to 4.0. The default is 1.0.
  • luma_pre_filter_radius (lpfr): Defines the radius of the pre-filter applied to the luma plane before edge detection. Allowed values range from 0.1 to 2.0. The default is 1.0.
  • luma_strength (ls): Sets the maximum difference threshold between pixels to allow blurring. Higher values blur across stronger edges; lower values protect more edges. Allowed values range from 0.1 to 100.0. The default is 1.0.
  • chroma_radius (cr): Radius for color planes. If omitted, it defaults to the luma_radius value.
  • chroma_pre_filter_radius (cpfr): Pre-filter radius for color planes. If omitted, it defaults to the luma_pre_filter_radius value.
  • chroma_strength (cs): Edge threshold for color planes. If omitted, it defaults to the luma_strength value.

Practical Examples

1. Subtle Denoising (Preserving Sharpness)

To clean up low-light digital grain while keeping objects sharp, apply small radius and moderate strength values:

ffmpeg -i input.mp4 -vf "sab=lr=1.5:lpfr=1.0:ls=3.0" -c:a copy output.mp4

2. Pronounced Skin Smoothing / Flat Area Softening

To create a stronger smoothing effect on faces and backgrounds without losing facial features and outlines:

ffmpeg -i input.mp4 -vf "sab=lr=3.0:lpfr=1.5:ls=10.0" -c:a copy output.mp4

3. Separate Luma and Chroma Controls

To smooth compression artifacts in color channels more aggressively than the brightness channel:

ffmpeg -i input.mp4 -vf "sab=lr=1.0:lpfr=1.0:ls=2.0:cr=2.5:cpfr=1.5:cs=8.0" -c:a copy output.mp4

Performance Considerations

The sab filter is computationally intensive because it dynamically checks pixel differences in every neighborhood. To optimize processing times:

  • Keep lr and lpfr values as low as needed to achieve the desired effect.
  • If combined with resizing filters, place sab after scaling down (or before scaling up) to reduce the total pixel count being processed.