Skip to content

Instantly share code, notes, and snippets.

@JBou
Last active May 4, 2024 18:01
Show Gist options
  • Save JBou/41a19db4c513d7acc7f6b97d151da7ff to your computer and use it in GitHub Desktop.
Save JBou/41a19db4c513d7acc7f6b97d151da7ff to your computer and use it in GitHub Desktop.
Install newest mesa driver inside emby docker container

This gist installs the newest mesa driver inside a emby docker container

Usage:

Go inside the docker container:

docker exec -it emby /bin/bash

curl -s -L https://gist.githubusercontent.com/JBou/41a19db4c513d7acc7f6b97d151da7ff/raw/emby_install_mesa.sh | bash

Afterwards you have to go to Diagnostic Options -> FFmpeg Options on the Emby Admin Dashboard and change the following parameters:

Use custom LD_LIBRARY_PATH/usr/lib/x86_64-linux-gnu:/app/emby/lib:/app/emby/extra/lib

Use custom LIBVA_DRIVERS_PATH/usr/lib/x86_64-linux-gnu/dri:/app/emby/extra/lib/dri

Next go to Dashboard and restart the emby server.

Docker Mod:

As alternative, use this docker mod:

https://github.com/linuxserver/docker-mods/tree/jellyfin-amd

#!/usr/bin/with-contenv bash
AMDGPU_RELEASE=${AMDGPU_RELEASE:-5.4.1}
# Determine if setup is needed
if [ ! -f "/usr/bin/apt" ]; then
echo "**** Image is not Ubuntu, skipping opencl-intel install ****"
exit 0
fi
if [ ! -f "/etc/apt/sources.list.d/kisak-mesa.list" ]; then
echo "**** Adding kisak-mesa repo ****"
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF63F0F2B90935439" | gpg --dearmor | tee /usr/share/keyrings/kisak-mesa.gpg >/dev/null
source /etc/lsb-release
echo "deb [signed-by=/usr/share/keyrings/kisak-mesa.gpg] http://ppa.launchpad.net/kisak/kisak-mesa/ubuntu ${DISTRIB_CODENAME} main" > /etc/apt/sources.list.d/kisak-mesa.list
fi
if [ ! -f "/etc/apt/sources.list.d/amdgpu-focal.list" ]; then
echo "**** Adding amdgpu repo ****"
curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor | tee /usr/share/keyrings/rocm.gpg >/dev/null
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/${AMDGPU_RELEASE} ubuntu main" > /etc/apt/sources.list.d/amdgpu-focal.list
fi
pkgs='mesa-vdpau-drivers mesa-va-drivers mesa-vdpau-drivers libdrm-radeon1 rocm-opencl-runtime'
install=false
for pkg in $pkgs; do
status="$(dpkg-query -W --showformat='${db:Status-Status}' "$pkg" 2>&1)"
if [ ! $? = 0 ] || [ ! "$status" = installed ]; then
install=true
break
fi
done
if "$install"; then
echo "**** Adding mesa and rocm-opencl-runtime to package install list ****"
apt update && apt install -y $pkgs
fi
FILES=$(find /dev/kfd -type c -print 2>/dev/null)
for i in $FILES
do
VIDEO_GID=$(stat -c '%g' "${i}")
VIDEO_UID=$(stat -c '%u' "${i}")
# check if user matches device
if id -u abc | grep -qw "${VIDEO_UID}"; then
echo "**** permissions for ${i} are good ****"
else
# check if group matches and that device has group rw
if id -G abc | grep -qw "${VIDEO_GID}" && [ $(stat -c '%A' "${i}" | cut -b 5,6) = "rw" ]; then
echo "**** permissions for ${i} are good ****"
# check if device needs to be added to video group
elif ! id -G abc | grep -qw "${VIDEO_GID}"; then
# check if video group needs to be created
VIDEO_NAME=$(getent group "${VIDEO_GID}" | awk -F: '{print $1}')
if [ -z "${VIDEO_NAME}" ]; then
VIDEO_NAME="video$(head /dev/urandom | tr -dc 'a-z0-9' | head -c4)"
groupadd "${VIDEO_NAME}"
groupmod -g "${VIDEO_GID}" "${VIDEO_NAME}"
echo "**** creating video group ${VIDEO_NAME} with id ${VIDEO_GID} ****"
fi
echo "**** adding ${i} to video group ${VIDEO_NAME} with id ${VIDEO_GID} ****"
usermod -a -G "${VIDEO_NAME}" abc
fi
# check if device has group rw
if [ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]; then
echo -e "**** The device ${i} does not have group read/write permissions, attempting to fix inside the container. ****"
chmod g+rw "${i}"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment