How to Use the FFmpeg unsharp_opencl Filter

This article provides a quick guide on how to use the hardware-accelerated unsharp_opencl filter in FFmpeg to sharpen or blur your videos. You will learn the system prerequisites, the core parameters of the filter, and how to construct a working FFmpeg command that utilizes OpenCL GPU acceleration to process video frames efficiently.

Prerequisites for OpenCL in FFmpeg

To use the unsharp_opencl filter, your system must meet the following requirements:

  1. GPU Drivers: You must have compatible graphics drivers installed (NVIDIA, AMD, or Intel) that support OpenCL.
  2. FFmpeg Build: Your FFmpeg binary must be compiled with OpenCL support enabled (configured with --enable-opencl). You can verify this by running ffmpeg -protocols or checking the configuration banner of your FFmpeg output.

Syntax and Key Parameters

The unsharp_opencl filter accepts several parameters to control the sharpening or blurring effect. The most commonly used options include:

Example Command

Because unsharp_opencl runs on the GPU, you must initialize the OpenCL device and upload the video frames to the GPU memory (hwupload) before applying the filter. If you are encoding back to a standard CPU-based codec, you must download the frames back to system memory (hwdownload) and format them correctly.

Below is a standard command to sharpen a video using unsharp_opencl:

ffmpeg -init_hw_device opencl=gpu -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:v libx264 -c:a copy output.mp4

Command Breakdown: