Skip to content

Instantly share code, notes, and snippets.

@leso-kn
Last active February 17, 2025 19:28
Show Gist options
  • Save leso-kn/1f12d794df5bb1471aa7c2210f1e8669 to your computer and use it in GitHub Desktop.
Save leso-kn/1f12d794df5bb1471aa7c2210f1e8669 to your computer and use it in GitHub Desktop.
Use WidevineCDM on musl (native musl-browsers, uses gcompat only on libwidevinecdm.so)
#!/bin/sh
pulse=$(echo /tmp/pulse-*)
docker run --rm -ti \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /dev/dri:/dev/dri \
-v /run/user/$(id -u)/pulse:/run/pulse \
-v $pulse:$pulse \
alpine \
ash -c "
set -e
apk add firefox gcompat patchelf font-noto
# step 1: generate firefox profile
DISPLAY=:0 firefox -headless | while read lin; do pkill firefox; done
export ffprofile=\$(echo /root/.mozilla/firefox/*.default-release)
echo 'user_pref(\"media.eme.enabled\", true);user_pref(\"media.gmp-manager.updateEnabled\", true);' >> \$ffprofile/prefs.js
printf 'Installing widevine cdm'
# step 2: let firefox install Widevine
DISPLAY=:0 firefox -headless 'https://bitmovin.com/demos/drm' 2>/dev/null >/dev/null &
while ! stat \$ffprofile/gmp-widevinecdm/*/LICENSE.txt 2>/dev/null >/dev/null
do
printf '.'
sleep 1
done
sleep 1
pkill firefox
# step 3: patch firefox Widevine to import gcompat.so.0 (requires GMP-sandboxing to be disabled)
patchelf --add-needed /lib/libgcompat.so.0 \$ffprofile/gmp-widevinecdm/*/libwidevinecdm.so
MOZ_DISABLE_GMP_SANDBOX=1 DISPLAY=:0 firefox
ash
"
@leso-kn
Copy link
Author

leso-kn commented Mar 24, 2023

Demonstrational script runs on linux in any X11 environment with pulseaudio or pipewire.

Requirements (only for demonstration, the technique does not require any of the below):

  • Docker
  • X11
  • Pulseaudio (optional, for audio)

@leso-kn
Copy link
Author

leso-kn commented Mar 24, 2023

DRM functionality can be tested at: https://bitmovin.com/demos/drm

@quadraplat
Copy link

do you think an approach like this would/could work on chromium?

@leso-kn
Copy link
Author

leso-kn commented Feb 16, 2025

@quadraplat Likely, yes! I belive chromium does not download libwidevinecdm.so automatically and in the case of Google Chrome, the library is distributed together with the browser. For chromium the steps should be: https://github.com/proprietary/chromium-widevine

From there on this patch should work in the same way, like in the case of Firefox it may be required to disable some signature checks though, like Firefoxes GMP sandboxing

@quadraplat
Copy link

yea, probably the sandbox that is messing me up...
I can patch it just fine and place it the correct place, but cant get widevine content to play. would be super nice to not need to have a the same borwser installed twice just to watch netflix....

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