Skip to content

Conversation

@OvchinnikovDmitrii
Copy link
Contributor

Description of Change:
Added linux support for amf encoder through vulkan.

To use h.264(AMD VCE) encoder on linux amdgru-pro version 19.20+ and amf-amdgpu-pro package(amdgru-pro contains, but does not install automatically) are required.(https://www.amd.com/ru/support/)

initialization of amf encoder occurs in this order:

  1. trying to initialize through dx11
  2. trying to initialize through dx9
  3. trying to initialize through vulkan

Only vulkan initialization available on linux.

Test on:

  • [+ ] Windows 10+ (via MinGW)
  • [ +] Ubuntu Linux

@jstebbins
Copy link
Contributor

The changes to libhb look innocent enough. I can't test since I don't have the necessary hardware.

Have you submitted the ffmpeg patch to ffmpeg yet? I don't see it on their mailing list. It would be nice to have that reviewed and accepted by them before committing to HandBrake.

@OvchinnikovDmitrii
Copy link
Contributor Author

The changes to libhb look innocent enough. I can't test since I don't have the necessary hardware.

Have you submitted the ffmpeg patch to ffmpeg yet? I don't see it on their mailing list. It would be nice to have that reviewed and accepted by them before committing to HandBrake.

Not yet, but I will.
It takes time to review and accept.

@jstebbins
Copy link
Contributor

It takes time to review and accept.

Been there, done that 😜

@sr55 sr55 added this to the 1.3.0 milestone Jul 12, 2019
@sr55
Copy link
Contributor

sr55 commented Jul 12, 2019

Ditto on hardware :/

@bradleysepos
Copy link
Contributor

@OvchinnikovDmitrii Will you please re-post the ffmpeg-devel thread here so we can more easily follow it? Thanks.

@bradleysepos bradleysepos modified the milestones: 1.3.0, Unscheduled Aug 5, 2019
@OvchinnikovDmitrii
Copy link
Contributor Author

Hi! i reuploaded a new version of a patch (with docs and some refactoring) (https://patchwork.ffmpeg.org/patch/14319/).

@bradleysepos bradleysepos modified the milestones: Unscheduled , 1.3.0 Aug 26, 2019
@OvchinnikovDmitrii
Copy link
Contributor Author

Hi! FFmpeg accepted the patch (FFmpeg/FFmpeg@f8ad2dd)

@bradleysepos
Copy link
Contributor

Awesome. I requested a review on #ffmpeg-devel IRC yesterday and Philip came through.

@jstebbins Are you good with this going in HandBrake?

@jstebbins
Copy link
Contributor

Yep, fine by me 👍

@bradleysepos bradleysepos merged commit 67bf399 into HandBrake:master Aug 28, 2019
@bradleysepos
Copy link
Contributor

Merged. Thanks @OvchinnikovDmitrii!

@sr55
Copy link
Contributor

sr55 commented Sep 3, 2019

@OvchinnikovDmitrii We have a user reporting that it's not currently working on a Radeon VII with amdgpu pro driver.

0119-08-03 19:45:37 23BD27C0 [AMFDeviceVulkanImpl] Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(716):Assertion failed:vkCreateDevice() failed, Error=-7
0119-08-03 19:45:37 23BD27C0 [AMFDeviceVulkanImpl] Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(406):AMF_ERROR 1 : AMF_FAIL: CreateDeviceAndFindQueues() failed
0119-08-03 19:45:37 23BD27C0 [AMFContextImpl] Error: ../../../../../runtime/src/core/ContextImpl.cpp(797):AMF_ERROR 1 : AMF_FAIL: pDeviceVulkan->Init(pVulkanDevice)
[19:45:37] VCE: AMF failed to initialise on the given Vulkan device.
Cannot load libnvidia-encode.so.1
0119-08-03 19:45:37 23BD27C0 [AMFDeviceVulkanImpl] Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(716):Assertion failed:vkCreateDevice() failed, Error=-7
0119-08-03 19:45:37 23BD27C0 [AMFDeviceVulkanImpl] Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(406):AMF_ERROR 1 : AMF_FAIL: CreateDeviceAndFindQueues() failed
0119-08-03 19:45:37 23BD27C0 [AMFContextImpl] Error: ../../../../../runtime/src/core/ContextImpl.cpp(797):AMF_ERROR 1 : AMF_FAIL: pDeviceVulkan->Init(pVulkanDevice)
0119-08-03 19:45:37 23BD27C0 [AMFDeviceVulkanImpl] Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(716):Assertion failed:vkCreateDevice() failed, Error=-7
0119-08-03 19:45:37 23BD27C0 [AMFDeviceVulkanImpl] Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(406):AMF_ERROR 1 : AMF_FAIL: CreateDeviceAndFindQueues() failed
0119-08-03 19:45:37 23BD27C0 [AMFContextImpl] Error: ../../../../../runtime/src/core/ContextImpl.cpp(797):AMF_ERROR 1 : AMF_FAIL: pDeviceVulkan->Init(pVulkanDevice)
0119-08-03 19:45:37 23BD27C0 [AMFDeviceVulkanImpl] Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(716):Assertion failed:vkCreateDevice() failed, Error=-7
0119-08-03 19:45:37 23BD27C0 [AMFDeviceVulkanImpl] Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(406):AMF_ERROR 1 : AMF_FAIL: CreateDeviceAndFindQueues() failed
0119-08-03 19:45:37 23BD27C0 [AMFContextImpl] Error: ../../../../../runtime/src/core/ContextImpl.cpp(797):AMF_ERROR 1 : AMF_FAIL: pDeviceVulkan->Init(pVulkanDevice)
[19:45:37] hb_init: starting libhb thread
[19:45:37] thread 7fef1a9b7700 started ("libhb")

-7 appears to be VK_ERROR_DEVICE_LOST which doesn't really tell us much.

@OvchinnikovDmitrii
Copy link
Contributor Author

@sr55
Could you provide some more info?

  1. Driver version
  2. Was amf-amdgpu-pro package installed?
  3. Does vulkan works normally?(simplest way to check "vulkaninfo | less", vulkaninfo can be installed by "sudo apt-get install vulkan-utils")

@sr55
Copy link
Contributor

sr55 commented Sep 4, 2019

Let me confirm.

He did say that the ffmpeg build works fine so it would suggest the vce_common.c init is the failure point

"VCE: AMF failed to initialise on the given Vulkan device."
That seems to be hitting AMF library directly.

@sr55
Copy link
Contributor

sr55 commented Sep 6, 2019

s55: amf version is 19.30_855429-1, output of vulkaninfo: https://pastebin.com/J0udhGX8

That's the report back

@OvchinnikovDmitrii
Copy link
Contributor Author

s55: amf version is 19.30_855429-1, output of vulkaninfo: https://pastebin.com/J0udhGX8

That's the report back

Looks like the driver version is up to date and vulkan works fine. We tried to reproduce this on Radeon VII and the same driver version, but the encoding was successful. I sent the information to the amf development team. I'll wait for their answer and come back.

@OvchinnikovDmitrii
Copy link
Contributor Author

@sr55 Could you also provide this?

  1. Output of commands:
    apt list --installed >software.txt
    sudo lshw >harware.txt
  2. executable file and small sample video with error

@sr55
Copy link
Contributor

sr55 commented Sep 17, 2019

I've asked the user to join us here for feedback.

@bradleysepos
Copy link
Contributor

User reports the following with invocation of HandBrake latest on Arch Linux:

0119-08-17 15:51:07 50B727C0 [AMFDeviceVulkanImpl]   Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(716):Assertion failed:vkCreateDevice() failed, Error=-7
0119-08-17 15:51:07 50B727C0 [AMFDeviceVulkanImpl]   Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(406):AMF_ERROR 1 : AMF_FAIL: CreateDeviceAndFindQueues() failed
0119-08-17 15:51:07 50B727C0 [AMFContextImpl]   Error: ../../../../../runtime/src/core/ContextImpl.cpp(797):AMF_ERROR 1 : AMF_FAIL: pDeviceVulkan->Init(pVulkanDevice)
[15:51:07] VCE: AMF failed to initialise on the given Vulkan device.
 
Cannot load libnvidia-encode.so.1
0119-08-17 15:51:07 50B727C0 [AMFDeviceVulkanImpl]   Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(716):Assertion failed:vkCreateDevice() failed, Error=-7
0119-08-17 15:51:07 50B727C0 [AMFDeviceVulkanImpl]   Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(406):AMF_ERROR 1 : AMF_FAIL: CreateDeviceAndFindQueues() failed
0119-08-17 15:51:07 50B727C0 [AMFContextImpl]   Error: ../../../../../runtime/src/core/ContextImpl.cpp(797):AMF_ERROR 1 : AMF_FAIL: pDeviceVulkan->Init(pVulkanDevice)
0119-08-17 15:51:07 50B727C0 [AMFDeviceVulkanImpl]   Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(716):Assertion failed:vkCreateDevice() failed, Error=-7
0119-08-17 15:51:07 50B727C0 [AMFDeviceVulkanImpl]   Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(406):AMF_ERROR 1 : AMF_FAIL: CreateDeviceAndFindQueues() failed
0119-08-17 15:51:07 50B727C0 [AMFContextImpl]   Error: ../../../../../runtime/src/core/ContextImpl.cpp(797):AMF_ERROR 1 : AMF_FAIL: pDeviceVulkan->Init(pVulkanDevice)
0119-08-17 15:51:07 50B727C0 [AMFDeviceVulkanImpl]   Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(716):Assertion failed:vkCreateDevice() failed, Error=-7
0119-08-17 15:51:07 50B727C0 [AMFDeviceVulkanImpl]   Error: ../../../../../runtime/src/core/DeviceVulkanImpl.cpp(406):AMF_ERROR 1 : AMF_FAIL: CreateDeviceAndFindQueues() failed
0119-08-17 15:51:07 50B727C0 [AMFContextImpl]   Error: ../../../../../runtime/src/core/ContextImpl.cpp(797):AMF_ERROR 1 : AMF_FAIL: pDeviceVulkan->Init(pVulkanDevice)
[15:51:07] hb_init: starting libhb thread
[15:51:07] thread 7f8247954700 started ("libhb")
Missing input device. Run HandBrakeCLI --help for syntax.

@bradleysepos
Copy link
Contributor

User reported hardware: https://pastebin.com/WZVBhcz9

And software: https://pastebin.com/Z7g7gwyV

@OvchinnikovDmitrii
Copy link
Contributor Author

User reported hardware: https://pastebin.com/WZVBhcz9

And software: https://pastebin.com/Z7g7gwyV

There are 2 versions of vulkan driver in the software list:

  1. lib32-vulkan-amdgpu-pro 19.30_855429-1 = the correct driver
  2. lib32-Vulcan-Radeon 19.1.7-1-open source Mesa driver

It is possible that the wrong driver is loading and causing an error.

@ghost
Copy link

ghost commented Sep 25, 2019

I was the one with the VII. Seems like the drivers was the problem all along. I did uninstall the open source Vulkan drivers and encoding in h.264 doesn't spit out any errors and the output seems fine.

@yurtesen
Copy link

I was thinking of testing VCE. Do the CLI option visible in help output when VCE support is enabled? It is not mentioned anywhere in Handbrake documentation.

@bradleysepos
Copy link
Contributor

VCE on Linux is experimental. You can enable it when building from source by passing --enable-vce to configure.

@yurtesen
Copy link

@bradleysepos I was trying to figure out if there is an option to enable it when running HandBrakeCLI like an encoder option etc. Because documentation and most posts on internet only mention using the Handbrake GUI to enable it. Hmm?

@bradleysepos
Copy link
Contributor

It depends what you mean by enable. VCE support must be enabled at configure time, then when using HandBrakeCLI you must select the encoder you want to use with --encoder. Run HandBrakeCLI --help for a list of encoders.

@yurtesen
Copy link

yurtesen commented Nov 16, 2019

@bradleysepos yes, but I enabled it yet I see nothing in the --help output

I built it with

# ./configure --disable-numa --disable-gtk --disable-qsv --disable-nvenc --enable-vce --enable-fdk-aac

and I see:

-------------------------------------------------------------------------------
Build system:       x86_64-pc-linux-gnu
Host system:        x86_64-pc-linux-gnu
Target platform:    linux
Harden:             False
Sandbox:            False (not supported on target platform)
Enable FDK-AAC:     True
Enable FFmpeg AAC:  True  (required on target platform)
Enable NVENC:       False
Enable QSV:         False
Enable VCE:         True
-------------------------------------------------------------------------------
Build is configured!

But nothing in the encoder section of the binary which is built!

   -e, --encoder <string>  Select video encoder:
                               x264
                               x264_10bit
                               x265
                               x265_10bit
                               x265_12bit
                               mpeg4
                               mpeg2
                               VP8
                               VP9
                               theora

I mean nothing related to VCE is in encoder section?

@bradleysepos
Copy link
Contributor

Hmm, I believe it should be listed there if everything's functional.

Can you do a quick encode with any settings you want, and provide the output here? Would help to see what the CLI is seeing.

@sr55
Copy link
Contributor

sr55 commented Nov 16, 2019

If it's not listed, it means the drivers are not setup correctly.
There won't be any logging when it's not available.

@yurtesen
Copy link

@sr55 you are right, I seem to be missing some libraries that handbrake is looking at startup. It could come handy if there was a way to report what was missing to user. Anyway, I ran out of time now, but I will try this later perhaps next year again. Thanks for the help!

@sr55
Copy link
Contributor

sr55 commented Nov 16, 2019

It's enough of a pain on Linux that it's not practical I'm afraid. It's not even as simple as having the correct driver. You also need to make sure the open source one isn't loading

It also gets quite messy between distros.

@yurtesen
Copy link

@sr55 It was just a suggestion as it was not very straightforward to figure out why I did not see the hardware encoding option. If it is not possible then it is not possible....

I thought handbrake already had some checks as you guys put it adequately it only shows the encoder if the driver is installed properly. I also ran it with strace and it was looking for libamfrt64 at startup.

Anyway, thanks for the help. I will return back to trying this if and when I install the amdgpu-pro driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants