FFmpeg Doesn't Use GPU for Transcoding?

I have an AMD 5600XT graphics card which is supposed to support H.265 encoding and decoding, but for some reason when I’m transcoding one file format to the other, the CPU is utilized instead.

Is this the anticipated behaviour or should ffmpeg be using the GPU for this process?

The current command I’m using is:

for i in *.mp4; do 
    ffmpeg -i "$i" -c:v libx265 -vtag hvc1 -threads 16 "temp/$i"
done

See FFmeg: Hardware video acceleration

What’s the output of vainfo?

You certainly need to specify hevc_vaapi codec and maybe some other parameter to specify the vaapi device with ffmpeg…

Here it is:

sarah@MidnightStarSign:~$ vainfo
vainfo: VA-API version: 1.9 (libva 2.9.1)
vainfo: Driver version: Mesa Gallium driver 20.1.8 for AMD Radeon RX 5600 XT (NAVI10, DRM 3.39.0, 5.9.1-1-MANJARO, LLVM 10.0.1)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc

Also, the driver package is installed:

Hmm, I have no idea how to do that though :frowning:

❯ pacman -F vainfo
community/libva-utils 2.8.0-1 [installed: 2.9.1-1]
    usr/bin/vainfo

:wink:

Already fixed in my edit :smiley:

Aha! I was distracted, didn’t notice. I had forgotten to actually post the reply a few minutes ago.

Your GPU definitely supports H.265. What command are your running to transcode videos?

That’s in the edit of the main post :slight_smile:

Ah, okay. I’m about at the end of my knowledge, anyway. Maybe you can add something from the example: FFmpeg: x265

Don’t forget to check the FFmpeg & libav documentation linked here.

1 Like

Libx265 is the software encoding (cpu)
For hardware acceleration it’s hevc_vaapi for h265 and h264_vaapi for h264 like as the exemple below from the link given by @Yochanan

$ ffmpeg -threads 1 -i file.ext -vaapi_device /dev/dri/renderD128 -vcodec h264_vaapi -vf format=‘nv12|vaapi,hwupload’ output.mp4

The exemple above is for h264_vaapi it should work by replacing it by hevc_vaapi. And check the vaapi_device and change to the available one in the system.

There is certainly plenties of exemple on internet…
A simple search with ffmpeg hevc_vaapi should give you plenty of result

For nvidia nvenc it’s h264_nvenc and hevc_nvenc

There is also option to use acceleration for reading the input file… you can find with a search

After i never used amd card and i don’t know much about them… i only used nvenc

4 Likes