How to Use the sab Filter in FFmpeg

The FFmpeg sab (Shape Adaptive Blur) filter is a video filter used to apply edge-preserving blur to video streams. This article provides a quick guide on how the sab filter works, explains its key parameters, and demonstrates practical command-line examples to help you effectively denoise or smooth your videos while maintaining sharp edges.

Understanding the sab Filter Parameters

The sab filter works by adapting the blur shape to the features of the image, which helps prevent the blurring of sharp edges. It accepts several options, divided between luma (brightness) and chroma (color) channels.

  • luma_radius / lr: Sets the luma blur radius. A larger radius increases the blur area. (Range: 0.1 to 1024, default: 4.0)
  • luma_pre_filter_radius / lpfr: Sets the luma pre-filter radius, which helps reduce noise before the main blur is applied. (Range: 0.1 to 2.0, default: 1.0)
  • luma_strength / ls: Sets the strength of the luma blur. Higher values result in stronger smoothing. (Range: 0.1 to 100.0, default: 1.0)
  • chroma_radius / cr: Sets the chroma blur radius. If not specified, it defaults to the luma radius value.
  • chroma_pre_filter_radius / cpfr: Sets the chroma pre-filter radius. If not specified, it defaults to the luma pre-filter radius value.
  • chroma_strength / cs: Sets the chroma strength. If not specified, it defaults to the luma strength value.

Practical FFmpeg Examples

To use the sab filter, pass it to the -vf (video filter) flag in your FFmpeg command.

1. Basic Edge-Preserving Smoothing

To apply a mild, balanced blur that smooths out flat surfaces while keeping edges sharp, use the default settings:

ffmpeg -i input.mp4 -vf "sab" output.mp4

2. Strong Denoising

If you have a noisy video and want to aggressively smooth the flat areas while preserving the main outlines, increase the luma radius and strength:

ffmpeg -i input.mp4 -vf "sab=luma_radius=8.0:luma_pre_filter_radius=1.5:luma_strength=5.0" output.mp4

Using short-hand notation, this command can be written as:

ffmpeg -i input.mp4 -vf "sab=lr=8.0:lpfr=1.5:ls=5.0" output.mp4

3. Independent Luma and Chroma Filtering

To apply a strong blur to the brightness (luma) channel but keep the color (chroma) channel processing minimal, define both sets of parameters:

ffmpeg -i input.mp4 -vf "sab=lr=6.0:lpfr=1.0:ls=4.0:cr=2.0:cpfr=0.5:cs=1.0" output.mp4