cancel
Showing results for 
Search instead for 
Did you mean: 

Drivers & Software

davidbfg
Adept I

AMF in linux using FFmpeg

I have been trying to utilize the amf-amdgpu-pro package from driver 19.30 in Ubuntu 18.04 using the latest branch of FFmpeg to do an h264_amf encode with varying success.

I have a dual GPU system with a rx vega 56 and a rx 480. I have noticed when the vega 56 card is active I have the capability to do an encode with ffmpeg using the h264_amf encoder. The problem arises when I use VFIO to do pci pass-through for the vega 56 card to a vm. This effectively disables my vega gpu during boot and the rx 480 is the only accessible card.

In that scenario a simple command that worked earlier (i.e. "./ffmpeg -i videoplayback.flv -c:v h264_amf accel.mkv") will report "AMF failed to initialise on the given Vulkan device: 1." From looking through the source the call that is failing is to InitVulkan it appears to be passed Null by ffmpeg based on the documentation this should retrieve the default vulkan device. The error InitVulkan returns is 1 meaning AMF_FAIL while the documentation states the only expected errors are AMF_NOT_SUPPORTED and AMF_ALREADY_INITIALIZED that might just be a clerical error to not include.

Since this is a new package and has a soft release where it is not installed automatically I can certainly understand that not everything would work perfect out of the box. I was hoping someone could get back to me with if the rx 480 is known to be supported by the amf-amdgpu-pro package in the 19.30 driver or not. Thanks.

I am aware vaapi is an alternative way of accessing the hardware encoding on the gpu but I've run into a lot of performance problems with it. That is why I was really hoping the amf package would be able to do the trick with the rx 480.

4 Replies
jniltinho
Journeyman III

Hi,

I have the same problem.

Nilton OS / FFMPEG NVENC · GitLab 

I compiled ffmpeg with amf support

[h264_amf @ 0x55f7cb4ec640] AMF initialisation failed via D3D9: error 10.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

ffmpeg version 4.2.1-0ub~18.04 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
  configuration: --prefix=/opt/ffmpeg-obs --extra-version='0ub~18.04' --toolchain=hardened --bindir=/opt/ffmpeg-obs/bin --disable-static --enable-shared --extra-cflags='-fPIC -m64 -I/opt/ffmpeg-obs/include' --extra-ldflags=-L/opt/ffmpeg-obs/lib --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-hardcoded-tables --enable-v4l2_m2m --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libfdk-aac --enable-libass --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-chromaprint --enable-frei0r --enable-libxml2 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-nonfree --enable-libfdk-aac --enable-ffnvcodec --enable-cuvid --enable-nvenc --enable-amf --enable-libx265 --enable-libx264 --enable-libxvid --enable-libopus --enable-librtmp --enable-vaapi --enable-vdpau --enable-gray --enable-iconv --enable-pic --enable-libaom --enable-nonfree
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
 DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_crystalhd h264_v4l2m2m h264_cuvid ) (encoders: libx264 libx264rgb h264_amf h264_nvenc h264_omx h264_v4l2m2m h264_vaapi nvenc nvenc_h264 )
 DEV.L. hevc                 H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_cuvid ) (encoders: libx265 nvenc_hevc hevc_amf hevc_nvenc hevc_vaapi )

Linux Mint 19.3 (Base Ubuntu 18.04) 64Bits

RX 590

0 Likes

I appreciate your enthusiasm. Unfortunately I can tell you are at a different stage than I am. Even though you have "--enable-amf" added to the compile arguments it wont do anything if it is not supported in the code.

Here is the commit for adding amf support in linux. https://github.com/FFmpeg/FFmpeg/commit/f8ad2ddd7a51df5d6e768ba2a6f65ee64b94e29b#diff-3adfff78d6c720...

If you go through it you will see the error code you are getting is deleted (in amfenc.c file) when they added support for AMF through the vulkan api. You should be trying to compile on the latest ffmpeg code base; whatever version you have is not going to work.

Do note that only the h264 encoder is supported. Once you update your code please let me know what happens. It would help me a lot to know if your get stuck at the same error as me "AMF failed to initialise on the given Vulkan device: 1." or something else happens.

Thanks.

0 Likes

I ran into this error to ("AMF failed to initialize on the given Vulkan device: 1."). 

My device is RX570 on ubuntu 20.04, and the solution is select the right icd file provide by 'amdgpu-pro' driver, not the one in 'amdgpu'

pastedImage_1.png

After choose the correct file I can use ffmpeg built with AMF support to encode H264 (HEVC still fail)

But seems it's slower than encoding with x264 by Ryzen 9 3900X

0 Likes

Thanks, this solved the issue. I copied the values from the amd_icd64.json in the amdgpu-pro folder to the default icd file to get things running.

I don't know if this is a newb question but how do you "select the right icd." I attempted to google it but came up empty. Seems like you have the right idea on proper managements vs how I just forced the default values. If you can link instructions to something that would be great.

Thanks.

0 Likes