FFmpeg with OpenCL support - Ubuntu 18.04 Recently I asked about GPU acceleration in FFmpeg using AMD Radeon (AMD support for ffmpeg? Can&#39;t get my dedicated GPU to work). After many tests I see that fighting with this topic is hard, especially if I read something like that: Feature support varies – for more complex codecs with many different profiles, hardware decoders rarely implement all of them (for example, hardware decoders tend not to implement anything beyond YUV 4:2:0 at 8-bit depth for H.264) (https://trac.ffmpeg.org/wiki/HWAccelIntro).

But maybe I just started with wrong solution? Maybe OpenCL is what I need? So I'd like to ask if someone could help me with OpenCL. I installed it on my OS (Kubuntu 18.04.2 LTS) and confirmed it works. I used tips and examples found here: https://wiki.tiker.net/OpenCLHowTo

I also installed FFmpeg with OpenCL support from Snapcraft (https://snapcraft.io/ffmpeg):

ffmpeg version n4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-avisynth --enable-cuda --enable-cuvid --enable-libdrm --enable-ffplay --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib


I use FFmpeg mainly to convert images sequences to movies - thousands of images in 2K-4K resolution. I call it usually like this:

ffmpeg -framerate 30 -i frame-%05d.png -preset ultrafast -tune film -c:v h264 -c:v libx264 -b:v 20M -pix_fmt yuv420p output.mp4


My question is (quite) simple: how can I "translate" above to FFmpeg+OpenCL language? I'm using integrated Intel HD Graphics 4600 and external AMD Radeon HD 8790M. Nevermind which device will be used, I'd like to check if OpenCL will help me to reduce time of encoding.

Could someone help me?
OpenCL is not what you need.

In https://trac.ffmpeg.org/wiki/HWAccelIntro, see the section on “FFmpeg API Implementation Status” — Notice that OpenCL is not applicable for encoding and decoding, only for use in filters.

That's because OpenCL is a low level API used for writing code in such a way that it can be accelerated by GPUs or CPU SIMD instructions depending on the platform/driver. It is used in FFmpeg to implement various filters, but you aren't using any filters. If you really want to use OpenCL for encoding/decoding, you will have to start writing your own encoder/decoder first.

For your use case (encoding a video from source frames), you are better off using an API specifically designed for video encoding. These use the separate special purpose video encoding/decoding functionality found on most modern GPUs (including integrated GPUs). The best choice depends on your platform and use case, but for example this page has some examples for using VAAPI: https://trac.ffmpeg.org/wiki/Hardware/VAAPI. Usually this means selecting a different encoder, for example h264_vaapi instead of x264 (which is a purely CPU-based encoder). To ensure good performance, avoid copying frames between host/CPU memory and device/GPU memory as much as possible.