How to play Blu-ray in Linux

If you’ve been using Linux a while you may remember when DVDs first hit the scene and due to copy protection Linux couldn’t play them. When the CSS (Content Scramble System) was eventually reverse engineered it didn’t take long for DVD support to be added to Linux though it took jumping through a few hoops to get it to work.

Blu-ray is at that stage now. The protection mechanism has been reverse engineered and the keys to decrypt discs are out there. Media players like mplayer and VLC can even playback the file formats natively. But it’s not a point-and-click affair just yet and it won’t be for a while.

Playing The Fifth Element Blu-Ray under Ubuntu 11.04 with VDPAU acceleration.

However if you feel like getting your hands dirty with a fun project – not to mention the pleasure of seeing your legitimately owned Blu-rays play back on Linux – here’s what you have to do.
Note the following assumes a good level of knowledge and experience with Linux at the command-line so brush up on your terminal-fu and grab your favourite Blu-ray discs!

The hard way

We’ll start with the hard way because following it will provide a great insight into how Blu-ray protection works. That and you’ll really appreciate the easy way when you get to it. For our own testing we used three Blu-ray discs under Ubuntu 11.04: Batman Begins The Fifth Element and Firefly Season 1.

Start by grabbing these tools:
DumpHD (or search ‘dumphd’ in Ubuntu’s Software Center)

These are all also conveniently listed here thanks to KenD00 on the Doom9 forums who wrote DumpHD.

Also make sure you have mplayer installed (“sudo apt-get install mplayer” or install from Software Center) and finally you need to grab an up-to-date Blu-ray key database – every disc has its own unique identifier and decrypting key. The main thread on the Doom9 forums for this is here. At the time of writing one of the more up-to-date databases can be found at this link.

If the Blu-ray you want to play has its key made public and in a database like this playback is pretty simple to do. First some preparation:

* Install DumpHD from Ubuntu’s Software Center (or if you grabbed the archive decompress it)
* Create the DumpHD user directory: “mkdir ~/.dumphd”
* Decompress the whole BDVMDugger archive to ~/.dumphd
* Decompress aacskeys-0.4.0c.tar.gz to a temporary directory
* Copy the file ‘’ from the lib/linux32 or linux64 directory to /usr/lib
* Re-name the key database linked above from KEYDB.txt to KEYDB.cfg and copy to ~/.dumphd

DumpHD will first look at the KEYDB.cfg file for known keys and failing that automatically try and decrypt the key directly from the disc using aacskeys and BDVMdeugger.

To play a Blu-ray then do the following:
* Insert the Blu-ray you want to play and browse it via Naultius (or any other file manager)
* Find the BDMV/STREAM directory and find the largest .m2ts file (sort by size to find quickly) – this is the movie itself
* Play the file using DumpHD piping the output to a player like mplayer. For example: “dumphd –infile:BDMV/STREAM/00000.m2ts /media/BATMAN_BEGINS/ | mplayer -cache 8192 -aid 4353 -“

Note that trailing ‘-‘ for the output pipe your command won’t work without it! Also in the command you’ll see specifying the .m2ts file directly loading from the mount point under /media for the Blu-ray disc and telling mplayer to use the default English audio track. You can also use other flags like “-vo vdpau -vc ffh264vdpau” to enable accelerated VDPAU playback on Nvidia GPUs or “-lavdopts threads=4” to perform multi-threaded decoding on the CPU.

Alaternatively you can also run DumpHD stand-alone and use its GUI to rip the Blu-ray to your hard drive — but of course you need a lot of space for a disc (20G or more depending on the movie). You can then play the decrypted movie more simply with mplayer or VLC by just clicking on the .m2ts file.

All this is good unless your Blu-ray is relatively new and the key isn’t out there yet and DumpHD can’t decrypt the disc. This was the case in our testing where Batman Begins and The Fifth Element would play up to this stage but Firefly would not. If this is the case you can try running DumpHD from the command line and noting the output – if it can decrypt it you’ll see a field called Volume Unique Key (VUK) which can be added to KEYDB.cfg using the format specified in the file. However even with this you may need to go one step further and use a conversion table:

* Run DumpHD stand-alone to use the GUI and load your disk from the /media mount
* You’ll see the disc’s volume ID in the top left. Click DiscID and copy this.
* In a terminal change to the your user DumpHD directory (“cd ~/.dumphd”)
* Run “sh”
* Click ‘Settings > Set Volume ID’. Paste the ID you got from DumpHD.
* Click ‘Settings > Set Disc Mount Path’. Locate the mount point for the disc under /media.
* Click ‘Run’. This may take a few minutes.

When complete BDVNdebugger will save a file called conv_tab.bin in the directory where you ran “sh”. This decrypted conversion table can be supplied with DumpHD like so: “dumphd –infile:BDMV/STREAM/00002.m2ts –convtable:/home/apcmag/.dumphd/conv_tab.bin /media/FIREFLYUS_D1/ …”.

Lastly if a disc still won’t play you can try using an updated host certificate – DumpHD comes with one by default but any can be used. The above thread on disc keys includes a file linked in this post with an alternative host certificate. Using these values to replace those in the HostKeyCertificate.txt file in the ~/.dumphd directory finally allowed Firefly to play on our Ubuntu system.

So that’s the hard way. What’s the easy way?

The easy way

Let’s be clear: this is still more work than it takes to play DVDs under Linux but it’s not quite as convoluted as the above. It’s also not free. This uses MakeMKV a commercial product that does at least come with a 30-day trial so you can try before you buy.

First grab MakeMKV from here. Follow the installation instructions in the post which includes downloading and compiling both archives. After decompressing this amounts to:

sudo apt-get install build-essential libc6-dev libssl-dev libgl1-mesa-dev libqt4-dev
cd makemkv_v1.6.12_oss
make -f makefile.linux
sudo make -f makefile.linux install
cd makemkv_v1.6.12_bin
make -f makefile.linux
sudo make -f makefile.linux install

This will install MakeMKV binaries into your path for both GUI and command-line use.

Next grab a handy script by Jaeger here which calls makemkvcon to decrypt and stream the first title from the disk and output via VLC (if you don’t have VLC installed install it with “sudo apt-get install vlc”). Download the archive for Linux and decompress it then install curl (required for the script) with “sudo apt-get install curl”.

Before running it on Ubuntu we need to make a few edits. Run “nano -w” and do the following:
* Change “${COUNT} == 60” to “${COUNT} == 120” to give makemkvcon more time to decrypt a disk. In our testing even on a very fast system it sometimes took more than a minute to work.
* Change “${VLCPATH}VLC” to “${VLCPATH}vlc” at the bottom otherwise your VLC install won’t be called (case is everything!)

You can also if you like change VLC to mplayer if you prefer and add your favourite flags (such as for accelerated VDPAU decoding). On the same line you’ll see it tells VLC to play ‘title0.ts’. If this isn’t the correct title on the disk to play and you’ll know pretty quick once it starts playing change this to ‘title1.ts’ or higher as required.

Save the script and simply run with “./”.

And that’s it — certainly not simple but this will change over time. Don’t hold your breath however it took many years before DVD playback became fire and forget and Blu-ray is still new by comparison. Note that HTPC boxes running Linux-based builds (like MythTV or XBMC) can also use MakeMKV to playback Blu-rays via plugins that once set up will allow you to just insert a disc and away you go. But maybe we’ll look at that next time!