Skip to content

Instantly share code, notes, and snippets.

@jccr
Forked from ruario/h264-vivaldi-linux.md
Created August 26, 2018 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jccr/b55d56d5fd3012d0039594fcf399dbf2 to your computer and use it in GitHub Desktop.
Save jccr/b55d56d5fd3012d0039594fcf399dbf2 to your computer and use it in GitHub Desktop.
How to enable HTML5 MP4 (H.264/AAC) video in Vivaldi for Linux, via an alternative FFMpeg library

How to enable HTML5 MP4 (H.264/AAC) video in Vivaldi for Linux, via an alternative FFMpeg library

Intro

The following is a quick guide to get this working on various Linux distros. As a side note, if you have Chrome installed alongside Vivaldi, Netflix should also work after making these changes. Alternatively, use my latest-widevine.sh to fetch and extract Chrome's copy of Widevine, so that it can be used by Vivaldi.

If you don't have working Flash video and need that in addition, please refer to these instructions.

Note: This guide is primarily aimed at users of Vivaldi stable releases. If it does not solve your issues, read this in addition.

Ubuntu

Install chromium-codecs-ffmpeg-extra

sudo apt update && sudo apt install chromium-codecs-ffmpeg-extra

You will now need to restart Vivaldi. You can then test support on this page.

Arch

Install from the AUR

If you want to use the latest stable, install vivaldi and vivaldi-ffmpeg-codecs.

If you want to use the latest snapshot, install vivaldi-snapshot and vivaldi-snapshot-ffmpeg-codecs.

Install from the unofficial herecura repo

Alternatively, you can also get both of these packages from from the unofficial [herecura] repo.

Note: Do not use the herecura repo, if you use related distros like Chakra and Manjaro. These are not real “Arch Linux” and have differences that are great enough, that you are likely to encounter problems (if not right away, then some time in the future).

After installing from the AUR or the linked unofficial repository, will now need to restart Vivaldi. You can then test support on this page.

Other distros

If your distro does not provide a package with a suitable library or one is not detected, you can run the script ./latest-proprietary-media.sh (included with this gist) as your normal user (not root) to fetch and install the Ubuntu file. Once installed, simply restart Vivaldi. You can then test support on this page.

If you would prefer not use a script, here is a short summary of how to do this manually.

First, have a look in http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/ for a “chromium-codecs-ffmpeg-extra” package from Ubuntu 16.04.

Fetch it like so (adjusting the package name as needed):

wget http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/chromium-codecs-ffmpeg-extra_66.0.3359.181-0ubuntu0.16.04.1_amd64.deb

To Extract out the lib and install it for Vivaldi's usage, enter the following (adjusting the package name as needed):

ar p chromium-codecs-ffmpeg-extra_66.0.3359.181*.deb data.tar.xz | tar Jx ./usr/lib/chromium-browser/libffmpeg.so --strip 4
install -Dm644 libffmpeg.so "$HOME/.local/lib/vivaldi/libffmpeg.so"

Next time you restart Vivaldi it should find this library and use it to decode proprietary media.

Building your own replacement libffmpeg.so

If you want to build your own replacement libffmpeg use the Arch vivaldi-snapshot-ffmpeg-codecs PKGBUILD as a guide.

If you are a maintainer and intend to repackage Vivaldi browser for your distro, you might want to consider making vivaldi-ffmpeg-codecs or vivaldi-snapshot-ffmpeg-codecs packages containing a replacement libffmpeg.so library. It is suggested that you place this library in the directory /opt/vivaldi/ or /opt/vivaldi-snapshot/ directories respectively. You will need to update these packages from time to time as Vivaldi ups its Chromium version.

#!/bin/sh
# Discourage Ubuntu users from using this script, since they can (and should) install chromium-codecs-ffmpeg-extra directly
if [ -r /etc/os-release ] && grep -qx 'ID=ubuntu' /etc/os-release; then
echo "You should not use this script on Ubuntu, install chromium-codecs-ffmpeg-extra via apt instead." >&2
read -p "Do you wish to continue anyway? [y/N]: " YN
case "$YN" in
[Yy]*) : ;;
[Nn]*) echo "Exiting." ; exit ;;
*) echo 'Answer not recognised, assuming "No". Exiting.'; exit ;;
esac
fi
# Make sure the user is not runing as superuser
if [ "$UID" = "0" ]; then
echo 'Do not run this script as root or via sudo. Run it as your normal user.' >&2
exit 1
fi
available () {
command -v $1 >/dev/null 2>&1
}
# Make sure we have wget or curl
if available wget; then
SILENT_DL="wget -qO-"
LOUD_DL="wget"
elif available curl; then
SILENT_DL="curl -sL"
LOUD_DL="curl -O"
else
echo "Install Wget or cURL" >&2
exit 1
fi
# Set temp dir
TMP=${TMP:-/tmp}
# Set staging dir
STAGINGDIR=$TMP/chromium-codecs-ffmpeg-extra-staging
# Setup Arch
case $(uname -m) in
x86_64) ARCH=x86_64; DEB_ARCH=amd64; REPO=http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/ ;;
i?86) ARCH=i386; DEB_ARCH=i386; REPO=http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/ ;;
armhf) ARCH=armhf; DEB_ARCH=armhf; REPO=http://ports.ubuntu.com/ubuntu-ports/pool/universe/c/chromium-browser/ ;;
arm64) ARCH=arm64; DEB_ARCH=arm64; REPO=http://ports.ubuntu.com/ubuntu-ports/pool/universe/c/chromium-browser/ ;;
esac
# Work out the VERSION
# Limit the UBUNTU version to 16.04 to avoid the glibc bump in 18.04, so that this works for older distros
UBUNTU_PACKAGE=$(${SILENT_DL} $REPO | sed -rn "s/.*(chromium-codecs-ffmpeg-extra_([0-9]+\.){3}[0-9]+-[0-9]ubuntu[0-9]\.16\.04\.[1-9]_$DEB_ARCH.deb).*/\1/p" | sort | tail -n 1)
## The original match was
## UBUNTU_PACKAGE=$(${SILENT_DL} $REPO | sed -rn "s/.*(chromium-codecs-ffmpeg-extra_([0-9]+\.){3}[0-9]+-[0-9]ubuntu[0-9]\.([0-9]{2}\.){2}[0-9\.]*_$DEB_ARCH.deb).*/\1/p" | sort | tail -n 1)
VERSION=$(echo "${UBUNTU_PACKAGE}" | sed -rn "s/.*_(([0-9]+\.){3}[0-9]+)-.*/\1/p")
# Error out if $VERISON is unset, e.g. because previous command failed
if [ -z "$VERSION" ]; then
echo "Could not work out the latest version; exiting" >&2
exit 1
fi
# Don't start repackaging if the same version is already installed
if [ -r "$HOME/.local/lib/vivaldi/chromium-codecs-ffmpeg-extra-version.txt" ]; then
. "$HOME/.local/lib/vivaldi/chromium-codecs-ffmpeg-extra-version.txt"
if [ "$INSTALLED_VERSION" = "$VERSION" ]; then
echo "The latest chromium-codecs-ffmpeg-extra ($VERSION) is already installed"
exit 0
fi
fi
# Now we could screw things up so exit on first error
set -e
# If the staging directory is already present from the past, clear it down
# and re-create it.
if [ -d "$STAGINGDIR" ]; then
rm -fr "$STAGINGDIR"
fi
mkdir "$STAGINGDIR"
cd "$STAGINGDIR"
# Now get the deb package
$LOUD_DL "$REPO$UBUNTU_PACKAGE"
# Extract the contents of the chromium-codecs-ffmpeg-extra package
if available bsdtar; then
DEB_EXTRACT_COMMAND='bsdtar xOf'
elif available ar; then
DEB_EXTRACT_COMMAND='ar p'
else
echo 'You must install BSD tar or GNU binutils to use this script.' >&2
exit 1
fi
$DEB_EXTRACT_COMMAND ${UBUNTU_PACKAGE} data.tar.xz | tar xJf - ./usr/lib/chromium-browser/libffmpeg.so --strip 4
# Check the libffmpeg.so dependencies are resolved
if LANGUAGE=en ldd libffmpeg.so 2>&1 | grep -qm1 'not \(a dynamic executable\|found\)'; then
cat <<EOF >&2
It is not possible to use this alternative libffmpeg on your system.
Let us know via a post in our forums, mentioning your distro and distro
version:
https://forum.vivaldi.net/category/35/vivaldi-browser-for-linux
EOF
exit 1
fi
# Note the version number for future reference, during upgrades
echo "INSTALLED_VERSION=$VERSION" > chromium-codecs-ffmpeg-extra-version.txt
# Install the files
install -Dm644 libffmpeg.so "$HOME/.local/lib/vivaldi/libffmpeg.so"
install -Dm644 chromium-codecs-ffmpeg-extra-version.txt "$HOME/.local/lib/vivaldi/chromium-codecs-ffmpeg-extra-version.txt"
# Tell the user we are done
cat <<EOF
The following files were installed onto your system:
$HOME/.local/lib/vivaldi/libffmpeg.so
$HOME/.local/lib/vivaldi/chromium-codecs-ffmpeg-extra-version.txt
Restart Vivaldi and test H.264/MP4 support via this page:
http://www.quirksmode.org/html5/tests/video.html
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment