Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg: add amf support #300764

Merged
merged 3 commits into from
Aug 10, 2024
Merged

ffmpeg: add amf support #300764

merged 3 commits into from
Aug 10, 2024

Conversation

jopejoe1
Copy link
Member

@jopejoe1 jopejoe1 commented Apr 1, 2024

Description of changes

I tested that this builds, but I do not have a machine with an AMD GPU to test this on.

Edit: now that i include the amf driver in this pr ot would fix #204502

Closes #204502

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@justinas
Copy link
Contributor

justinas commented Apr 1, 2024

I am able to compile, but:

[h264_amf @ 0x1a7b440] DLL libamfrt64.so.1 failed to open

I think AMF requires AMDGPU-PRO driver, which is not super usable on NixOS (requires an older kernel and whatnot). 😕

boot.kernelPackages = pkgs.linuxKernel.packagesFor
(pkgs.linuxKernel.kernels.linux_5_10.override {
structuredExtraConfig = {
DEVICE_PRIVATE = kernel.yes;
KALLSYMS_ALL = kernel.yes;
};
});

@jopejoe1
Copy link
Member Author

jopejoe1 commented Apr 2, 2024

I think AMF requires AMDGPU-PRO driver, which is not super usable on NixOS (requires an older kernel and whatnot). 😕

According to the release notes of amf there is experimental support for RADV and full support for pro drivers.

https://github.com/GPUOpen-LibrariesAndSDKs/AMF/releases/tag/v1.4.33

@justinas
Copy link
Contributor

justinas commented Apr 2, 2024

According to the release notes of amf there is experimental support for RADV and full support for pro drivers.

https://github.com/GPUOpen-LibrariesAndSDKs/AMF/releases/tag/v1.4.33

That's cool! However, we still need libamfrt64.so from the AMDGPU-PRO release. On traditional distros, it would get installed via

sudo amdgpu-install -y --usecase=amf
https://github.com/GPUOpen-LibrariesAndSDKs/AMF/wiki/Driver%20Linux

I attempted to hack this together (use the lib from AMDGPU-PRO, but not the driver itself) on my 23.11 machine via:

{
  hardware.opengl = {
    driSupport32Bit = true; # Steam, etc.
    enable = true;

    extraPackages = with pkgs; [
      rocmPackages.clr
      rocmPackages.clr.icd

      # added this
      (pkgs.runCommandNoCC "libamfrt" { } ''
        mkdir -p $out/lib
        cp ${config.boot.kernelPackages.amdgpu-pro}/opt/amdgpu-pro/lib/libamfrt* $out/lib
        ln -s $out/lib/libamfrt64.so{,.1}
      '')
    ];
  };
}

but no luck:

$ ./ffmpeg-amf/bin/ffmpeg -hide_banner -loglevel warning -i ~/Downloads/bigbuck_bunny_8bit_15000kbps_1080p_60.0fps_h264.mp4 -c:v h264_amf out.mp4
zsh: segmentation fault (core dumped)

Per GPUOpen-LibrariesAndSDKs/AMF#457 , this might need more shared libraries, a newer Mesa, etc... 😮‍💨

@Atemu Atemu marked this pull request as draft April 2, 2024 16:56
@Atemu
Copy link
Member

Atemu commented Apr 2, 2024

This clearly needs some work.

@jopejoe1
Copy link
Member Author

jopejoe1 commented Apr 2, 2024

Found out that the min version of amdgpu-pro required is 24.1.1 (23.40.02) but the version we packaged is only at 21.30.

@Svenum
Copy link

Svenum commented Apr 4, 2024

If a new amdgpu-pro version with newer kernel is on unstable I could try things in this PR.

@Atemu
Copy link
Member

Atemu commented Apr 4, 2024

@Svenum could you also publish that as a draft PR? That way others can pick it up in case you hit a wall you're not able to penetrate.

@Svenum
Copy link

Svenum commented Apr 4, 2024

I am sorry if I have expressed myself incomprehensibly, but i was not able to achive an amdgpu-pro installation on a newer kernel, but I will try.

@Atemu
Copy link
Member

Atemu commented Apr 4, 2024

Ah, sorry for the confusion.

@jopejoe1
Copy link
Member Author

got this to work now can be tested by adding amf-amdgpu-pro to hardware.graphics.extraPackages on nixos and then running ffmpeg -i test.mp4 -c:v hevc_amf out.mp4

@jopejoe1 jopejoe1 requested a review from emilazy August 2, 2024 08:40
@jopejoe1 jopejoe1 force-pushed the ffmpeg/amf branch 2 times, most recently from 5d61a6f to 2c0bb7f Compare August 8, 2024 20:23
@jopejoe1
Copy link
Member Author

jopejoe1 commented Aug 8, 2024

Removed the -amdgpu-pro part of the package name, as the package also works with the open-source driver.

Copy link
Member

@Atemu Atemu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM but untested.

A few questions.

pkgs/by-name/am/amdenc/package.nix Outdated Show resolved Hide resolved
pkgs/by-name/am/amf/package.nix Outdated Show resolved Hide resolved
pkgs/by-name/am/amf/package.nix Outdated Show resolved Hide resolved
@Atemu
Copy link
Member

Atemu commented Aug 9, 2024

Removed the -amdgpu-pro part of the package name, as the package also works with the open-source driver.

What exactly do you mean by that? amdenc is evidently a closed-source driver.

@jopejoe1
Copy link
Member Author

jopejoe1 commented Aug 9, 2024

Removed the -amdgpu-pro part of the package name, as the package also works with the open-source driver.

What exactly do you mean by that? amdenc is evidently a closed-source driver.

That it also works together with the open-source AMD driver and not just the closed source one.

And i don't want to give the impression that it can only be used together with the closed source driver.

@jopejoe1 jopejoe1 force-pushed the ffmpeg/amf branch 3 times, most recently from f380d39 to 5e62e33 Compare August 9, 2024 06:12
@Atemu
Copy link
Member

Atemu commented Aug 9, 2024

That it also works together with the open-source AMD driver and not just the closed source one.

What kind of driver are we talking about here? DRM/DRI or OGL/VK?

@jopejoe1
Copy link
Member Author

jopejoe1 commented Aug 9, 2024

That it also works together with the open-source AMD driver and not just the closed source one.

What kind of driver are we talking about here? DRM/DRI or OGL/VK?

I was talking about the VK driver and that it can be mesa's radv instead of just using the one included in amdgpu-pro.

Copy link
Member

@Atemu Atemu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully produced a decodable HEVC video using:

LD_LIBRARY_PATH=$(nix-build -A amf)/lib/ $(nix-build -A ffmpeg-full)/bin/ffmpeg -f lavfi -i testsrc -t 10 -c:v hevc_amf -y /tmp/foo.mkv

(I presume you'd place amf in the system-wide driver path in an actual deployment.)

@jopejoe1
Copy link
Member Author

jopejoe1 commented Aug 9, 2024

(I presume you'd place amf in the system-wide driver path in an actual deployment.)

At least thats what i did while testing.

@ofborg ofborg bot requested a review from Atemu August 9, 2024 20:39
@Atemu Atemu merged commit 5f00b44 into NixOS:staging Aug 10, 2024
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants