<p>OpenCL is not what you need.</p>

<p>In <a href="https://trac.ffmpeg.org/wiki/HWAccelIntro" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/HWAccelIntro</a>, see the section on “FFmpeg API Implementation Status” — Notice that OpenCL is not applicable for encoding and decoding, only for use in filters.</p>

<p>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.</p>

<p>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: <a href="https://trac.ffmpeg.org/wiki/Hardware/VAAPI" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Hardware/VAAPI</a>. Usually this means selecting a different encoder, for example <code>h264_vaapi</code> instead of <code>x264</code> (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. </p>

CC BY-SA 4.0
2019-10-16T10:49:07.610Z
Manyh thanks for in-depth explanation with links! It clarifies many things for me. And sorry for late reply, I missed it before...
stalker
CC BY-SA 4.0
2019-08-21T00:01:20.507Z
2019-08-22T11:14:59.203Z
2019-08-22T11:14:59.203Z
hedgepigdaniel
<p>Recently I asked about GPU acceleration in FFmpeg using AMD Radeon (<a href="https://video.stackexchange.com/questions/26464/amd-support-for-ffmpeg-cant-get-my-dedicated-gpu-to-work">AMD support for ffmpeg? Can&#39;t get my dedicated GPU to work</a>). After many tests I see that fighting with this topic is hard, especially if I read something like that: <em>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)</em> (<a href="https://trac.ffmpeg.org/wiki/HWAccelIntro" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/HWAccelIntro</a>).</p>

<p>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: <a href="https://wiki.tiker.net/OpenCLHowTo" rel="nofollow noreferrer">https://wiki.tiker.net/OpenCLHowTo</a></p>

<p>I also installed FFmpeg with OpenCL support from Snapcraft (<a href="https://snapcraft.io/ffmpeg" rel="nofollow noreferrer">https://snapcraft.io/ffmpeg</a>):</p>

<pre><code>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
</code></pre>

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

<pre><code>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
</code></pre>

<p>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.</p>

<p>Could someone help me?</p>

<ffmpeg><linux>
FFmpeg with OpenCL support - Ubuntu 18.04
stalker
# FFmpeg with OpenCL support - Ubuntu 18.04

(Asked by: username_0 on 2019-04-19)

Recently I asked about GPU acceleration in FFmpeg using AMD Radeon (AMD support for ffmpeg? Can'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?

**Tags:** ffmpeg, linux


---

## 1 answers

### Answer by username_1 on 2019-08-21. Score: 2

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.

> **Comments:**
> **username_0**: Manyh thanks for in-depth explanation with links! It clarifies many things for me. And sorry for late reply, I missed it before...  

---

