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

feat: implement support for AMD AMF codecs #163

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from

Conversation

kode54
Copy link
Contributor

@kode54 kode54 commented Jan 16, 2025

This is a draft until things settle.

Some notes:
The gstreamer Dockerfile applies a patch from my Gist repo. I probably should have stuffed that patch into this repo instead. I wasn't thinking clearly enough last night to realize that Docker has access to the local files of this repo.

Edit 4: You need to mount your local distribution's compatible AMF libraries into the image as read-only volumes:

Either for Docker run:

-v /opt/amdgpu-pro/lib/x86_64-linux-gnu/libamdenc64.so.1.0:/usr/lib/libamdenc64.so:ro
-v /opt/amdgpu-pro/lib/x86_64-linux-gnu/libamfrt64.so.1.4.36:/usr/lib/libamfrt64.so.1:ro

Edit 5: Here, have a Docker Compose preset, assuming you built all these images locally:

services:
  wolf:
    container_name: wolf
    image: wolf:dev-amf
    environment:
      - XDG_RUNTIME_DIR=/tmp/sockets
      - HOST_APPS_STATE_FOLDER=/etc/wolf
    volumes:
      - /etc/wolf/:/etc/wolf/:rw
      - /tmp/sockets:/tmp/sockets:rw
      - /var/run/docker.sock:/var/run/docker.sock:rw
      - /dev/:/dev/:rw
      - /run/udev:/run/udev:rw
      - /usr/lib/libamdenc64.so.1.0:/usr/lib/libamdenc64.so:ro
      - /usr/lib/libamfrt64.so.1.4.36:/usr/lib/libamfrt64.so.1:ro
    device_cgroup_rules:
      - 'c 13:* rmw'
    devices:
      - /dev/dri
      - /dev/uinput
      - /dev/uhid
    network_mode: host
    restart: unless-stopped

Edit 2: The version of AMF that this image set creates requires bleeding edge AMDGPU VCN firmware. I hope it's possible to update your test machines to the latest available linux-firmware package.

Edit 3: Basically, whatever Docker host you run this on requires the amdgpu kernel module to interface with the GPU, and the latest available linux-firmware package or equivalent for your distribution. This should at least be Ubuntu 24.04 or whatever other LTS is available from 2024, or a more bleeding edge distribution if you prefer. After all, the AMF package this bundles is targeting Ubuntu 24.04, and is running on an Ubuntu 24.10 image.

Edit: Some editing instructions for your config.toml, based on the current v4 format, in case you don't want to reset your config and paste in your UUID and device pairings:

First, look at your gstreamer.video default_source setting. If there is a max-bytes=0, it should be removed. If there is a max-buffers, it should be changed to 5 or so.

Second, for every gstreamer.video.defaults.* plugin entry already in existence, this may be worth tweaking, but not applicable to AMF. If the first part of the video_params is queue !, it should be changed to queue leaky=downstream max-size-buffers=5 !. If it already has the leaky=downstream part, change the max-size-buffers to 5 or so. This seems to help some codecs. Just so long as the leaky parameter is there, of course.

Third, add the default plugin settings for amfcodec, directly underneath the gstreamer.video.defaults.qsv section:

    [gstreamer.video.defaults.amfcodec]
    video_params = '''queue leaky=downstream max-size-buffers=5 !
videoconvertscale !
video/x-raw, chroma-site={color_range}, width={width}, height={height}, format=NV12, colorimetry={color_space}'''

Finally, add the three codec sections, in the [[gstreamer.video.*_encoders]] sections, below the respective plugin_name = 'qsv' sections, and directly above the respective plugin_name = 'vaapi' sections. If they are not ordered before the vaapi sections, the vaapi sections will take priority, as they are tried in order of the config file:

AV1:

    [[gstreamer.video.av1_encoders]]
    check_elements = [ 'amfav1enc', 'videoconvertscale' ]
    encoder_pipeline = '''amfav1enc gop-size=-1 ref-frames=1 bitrate={bitrate} rate-control=cbr usage=ultra-low-latency pa-taq-mode=mode2 !
av1parse !
video/x-av1, stream-format=obu-stream, alignment=frame, profile=main'''
    plugin_name = 'amfcodec'

H.264:

    [[gstreamer.video.h264_encoders]]
    check_elements = [ 'amfh264enc', 'videoconvertscale' ]
    encoder_pipeline = '''amfh264enc aud=false b-frames=0 gop-size=-1 ref-frames=1 bitrate={bitrate} rate-control=cbr usage=ultra-low-latency pa-taq-mode=mode2 !
h264parse !
video/x-h264, profile=main, stream-format=byte-stream'''
    plugin_name = 'amfcodec'

HEVC:

    [[gstreamer.video.hevc_encoders]]
    check_elements = [ 'amfh265enc', 'videoconvertscale' ]
    encoder_pipeline = '''amfh265enc gop-size=0 ref-frames=1 bitrate={bitrate} rate-control=cbr usage=ultra-low-latency pa-taq-mode=mode2 !
h265parse !
video/x-h265, profile=main, stream-format=byte-stream'''
    plugin_name = 'amfcodec'

@kode54 kode54 force-pushed the dev-amf branch 4 times, most recently from a024caf to 1e35a2a Compare January 17, 2025 01:40
@kode54
Copy link
Contributor Author

kode54 commented Jan 17, 2025

New changes thus far:

  • Moving the Gstreamer patches into the repo
  • Adding two extra patches, one to update the AMF headers, the other to take advantage of that to support ultra-low-latency and webcam usage for AV1
  • Fixing the H.264 encoder graph string, which somehow was missing the h264parse and the properties/format arguments
  • Adding some extra arguments to the encoder graphs for PQ decision making, based on documentation (mode2 is supposed to be "gaming" oriented)

@salty2011
Copy link
Contributor

Given this is using the AMF codec pretty some changes to the config.toml to tell it to use the codec will be required. For testing could you supply the required changes you made to your config.toml

@kode54
Copy link
Contributor Author

kode54 commented Jan 17, 2025

The needed changes are in the diff logs for the default config files.

@kode54
Copy link
Contributor Author

kode54 commented Jan 17, 2025

I'll document the changes, but really, it's for the best that everyone who wishes to apply them manually look at the Files changed tab of the PR. I'll edit it into the OP of this PR.

@kode54
Copy link
Contributor Author

kode54 commented Jan 18, 2025

I amended the OP again with a third edit.

@kode54
Copy link
Contributor Author

kode54 commented Jan 19, 2025

Added instructions for mounting your own AMF runtime into the Wolf container. You need libamfrt64.so.1 and libamdenc64.so. I'm not sure if Docker will let you volume include the shorter named symlinks directly, but the container needs the short names exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants