How to Use the unsharp_opencl Filter in FFmpeg

This article provides a quick, step-by-step guide on how to accelerate video sharpening in FFmpeg using the GPU-powered unsharp_opencl filter. You will learn how to initialize OpenCL, upload video frames to your graphics hardware, apply the sharpening filter, and download the processed frames back for final encoding.

To run the unsharp_opencl filter, your version of FFmpeg must be compiled with OpenCL enabled (typically configured with the --enable-opencl flag). Because OpenCL runs on the GPU, you must explicitly initialize your hardware device and transfer the video frames to GPU memory before applying the filter.

1. The Basic Command Structure

Below is the standard command template used to run the unsharp_opencl filter:

ffmpeg -init_hw_device opencl=gpu:0 -filter_hw_device gpu -i input.mp4 -filter_complex "[0:v]format=yuv420p,hwupload,unsharp_opencl=luma_msize_x=5:luma_msize_y=5:luma_amount=1.0,hwdownload,format=yuv420p" -c:a copy output.mp4

2. Command Breakdown

3. Adjusting Filter Parameters

You can fine-tune the sharpening effect by modifying the parameters of the unsharp_opencl filter. The most common parameters include:

Example with custom parameters:

ffmpeg -init_hw_device opencl=ocl -filter_hw_device ocl -i input.mp4 -filter_complex "[0:v]format=yuv420p,hwupload,unsharp_opencl=luma_msize_x=7:luma_msize_y=7:luma_amount=1.5:chroma_msize_x=3:chroma_msize_y=3:chroma_amount=0.5,hwdownload,format=yuv420p" output.mp4