How to Sharpen Video with FFmpeg Unsharp Filter
This article provides a straightforward guide on how to use the
FFmpeg unsharp filter to enhance and sharpen blurry or soft
videos. You will learn the basic syntax of the filter, understand its
key parameters (luma, chroma, matrix size, and amount), and see
practical command-line examples to get immediate results.
Understanding the Unsharp Filter Syntax
The unsharp filter in FFmpeg works by applying a blur
matrix to the video and subtracting it from the original image, which
increases the contrast of the edges.
The basic syntax for the filter is:
-vf "unsharp=luma_msize_x:luma_msize_y:luma_amount:chroma_msize_x:chroma_msize_y:chroma_amount"You can define parameters for both luma (brightness/details) and chroma (color). Usually, sharpening luma is enough to make a video look sharper without introducing color artifacts.
Key Parameters Explained
msize_xandmsize_y(Matrix Size): These define the width and height of the search matrix. They must be odd integers between 3 and 23. The default value is 5. A larger matrix size targets larger details, while a smaller size targets fine details.amount(Sharpening Intensity): This is a float value representing the strength of the effect.- Positive values (0.0 to 1.5): Sharpen the image.
- Negative values (-1.5 to 0.0): Blur the image.
- Default value: 1.0 for luma, 0.0 for chroma.
Practical FFmpeg Examples
1. Default Sharpening
If you use the filter without any parameters, FFmpeg applies a
default luma sharpening effect of 5:5:1.0:5:5:0.0.
ffmpeg -i input.mp4 -vf "unsharp" -c:a copy output.mp42. Light Sharpening
To apply a subtle sharpening effect to your video, reduce the amount to around 0.5. This helps to avoid harsh edges and digital noise.
ffmpeg -i input.mp4 -vf "unsharp=5:5:0.5:0:0:0.0" -c:a copy output.mp4(Note: Setting the chroma values to 0:0:0.0 disables sharpening on the color channels, which prevents color noise).
3. Strong Sharpening
For videos that are noticeably blurry, you can increase the matrix size to 7x7 and set the sharpening amount to 1.5.
ffmpeg -i input.mp4 -vf "unsharp=7:7:1.5:0:0:0.0" -c:a copy output.mp44. Sharpening Both Luma and Chroma
If you also want to sharpen the color edges of your video, you can apply the filter to the chroma channel.
ffmpeg -i input.mp4 -vf "unsharp=5:5:1.0:5:5:0.8" -c:a copy output.mp4Tips for Best Results
- Avoid Over-Sharpening: Setting the
amountvalue too high (above 1.5) will introduce “halo” artifacts around edges and increase video compression noise. - Check Performance: The
unsharpfilter is CPU-intensive. If you are transcoding long videos, start with a short test clip using the-tparameter (e.g.,-t 10for a 10-second test) to find the perfect balance between quality and render speed.