How to Use Contrast Adaptive Sharpening in FFmpeg
This article provides a straightforward guide on how to use the
Contrast Adaptive Sharpening (cas) filter in FFmpeg. You
will learn the basic syntax of the filter, understand its primary
parameters, and see practical command-line examples to help you sharpen
your videos while preserving natural details and minimizing visual
artifacts.
Understanding the CAS Filter
The cas filter in FFmpeg is based on AMD’s FidelityFX
Contrast Adaptive Sharpening technology. Unlike traditional sharpening
filters that can introduce ugly halos or amplify compression noise, CAS
adapts to the local contrast of the image. It applies stronger
sharpening to softer areas and less sharpening to already detailed
edges, resulting in a cleaner, more natural-looking enhancement.
Basic Syntax
To use the CAS filter in FFmpeg, you apply the video filter flag
(-vf or -filter:v) followed by
cas.
The basic syntax is:
ffmpeg -i input.mp4 -vf "cas=sharpness" output.mp4Parameters
sharpness: This parameter controls the strength of the sharpening effect.- Value Range:
0.0to1.0. - Default:
0.0(which provides no sharpening). - A value of
1.0applies the maximum level of sharpening. For most videos, a value between0.3and0.7yields the best balance between clarity and noise control.
- Value Range:
Practical Examples
1. Applying Moderate Sharpening
To apply a moderate, clean sharpen to your video, use a sharpness
value of 0.5:
ffmpeg -i input.mp4 -vf "cas=0.5" -c:v libx264 -crf 18 -c:a copy output.mp42. Combining Scaling and Sharpening
Contrast Adaptive Sharpening is highly effective when applied after upscaling a video. In this example, the video is upscaled to 1080p and then sharpened with CAS to restore lost edge clarity:
ffmpeg -i input.mp4 -vf "scale=1920:1080,cas=0.6" -c:v libx264 -crf 18 output.mp43. Maximum Sharpening for Soft Footage
If your source footage is very soft or slightly out of focus, you can push the filter to its maximum limit:
ffmpeg -i input.mp4 -vf "cas=1.0" -c:v libx265 -crf 20 output.mp4Using these commands, you can easily integrate Contrast Adaptive Sharpening into your FFmpeg transcoding workflows to improve the visual quality of your video library.