[PR #163] [CLOSED] feat: implement support for AMD AMF codecs #379

Closed
opened 2026-10-15 13:00:08 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/games-on-whales/wolf/pull/163
Author: @kode54
Created: 1/16/2025
Status: ❌ Closed

Base: stable ← Head: dev-amf


📝 Commits (1)

  • bf5a815 feat: implement support for AMD AMF codecs

📊 Changes

13 files changed (+3391 additions, -14 deletions)

View changed files

📝 .dockerignore (+2 -1)
📝 docker/gpu-drivers.Dockerfile (+5 -0)
📝 docker/gstreamer.Dockerfile (+8 -1)
➕ docker/gstreamer/gst-amf-av1-usage.patch (+31 -0)
➕ docker/gstreamer/gst-amf-headers.patch (+2299 -0)
➕ docker/gstreamer/gst-amf-linux.patch (+765 -0)
➕ docker/gstreamer/gst-mr-8269.patch (+162 -0)
📝 docs/modules/dev/pages/how-it-works.adoc (+1 -1)
📝 docs/modules/dev/pages/manual_build.adoc (+12 -1)
📝 src/moonlight-server/state/configTOML.cpp (+29 -2)
📝 src/moonlight-server/state/data-structures.hpp (+1 -0)
📝 src/moonlight-server/state/default/config.include.toml (+38 -4)
📝 src/moonlight-server/state/default/config.v4.toml (+38 -4)

📄 Description

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'

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/games-on-whales/wolf/pull/163 **Author:** [@kode54](https://github.com/kode54) **Created:** 1/16/2025 **Status:** ❌ Closed **Base:** `stable` ← **Head:** `dev-amf` --- ### 📝 Commits (1) - [`bf5a815`](https://github.com/games-on-whales/wolf/commit/bf5a815ac946fed58c8849b2919cce72754ffa07) feat: implement support for AMD AMF codecs ### 📊 Changes **13 files changed** (+3391 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `.dockerignore` (+2 -1) 📝 `docker/gpu-drivers.Dockerfile` (+5 -0) 📝 `docker/gstreamer.Dockerfile` (+8 -1) ➕ `docker/gstreamer/gst-amf-av1-usage.patch` (+31 -0) ➕ `docker/gstreamer/gst-amf-headers.patch` (+2299 -0) ➕ `docker/gstreamer/gst-amf-linux.patch` (+765 -0) ➕ `docker/gstreamer/gst-mr-8269.patch` (+162 -0) 📝 `docs/modules/dev/pages/how-it-works.adoc` (+1 -1) 📝 `docs/modules/dev/pages/manual_build.adoc` (+12 -1) 📝 `src/moonlight-server/state/configTOML.cpp` (+29 -2) 📝 `src/moonlight-server/state/data-structures.hpp` (+1 -0) 📝 `src/moonlight-server/state/default/config.include.toml` (+38 -4) 📝 `src/moonlight-server/state/default/config.v4.toml` (+38 -4) </details> ### 📄 Description 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' ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-15 13:00:08 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
games-on-whales/wolf#379
No description provided.