Ripping BluRay Audio Discs to FLAC

UPDATE: This script has been superseded to add more features and correct a major issue, see here.

I’ve been buying some BluRay audio discs as a relatively inexpensive route to HD audio content, there’s some great remasters and remixes coming out and many include a conventional CD and BluRay audio in various formats, from 96/24 LPCM, 192/24 LPCM or various surround sound formats.

There’s numerous pieces of software for this and some paid for options might be slightly simpler, but I’m using MakeMKV ( as it’s cross-platform and cheaper than many other options (it’s free for DVD ripping, a one off payment for BluRay ripping.

The latest version of MakeMKV can rip the audio tracks to FLAC, the result of which, in the case of a BluRay audio disc, is a video file (the video part of which is usually the track listing) and a FLAC audio track. It also results in all audio tracks being in a single video file, with chapter metadata identifying the individual tracks.

What we need to do is split the video file into chapters and demux the audio streams to produce a FLAC file we can use on our music playback system of choice (in my case various Squeezeboxes or a Raspberry Pi with a Wolfson / Cirris audio card).

Whilst this can be done with various open source tools, remembering the command line to type to achieve it can be frustrating, so I cobbled together some bash script to do the hard work, based on a post in the MakeMKV forum here.

The workflow is: –

  1. Choose tracks in MakeMKV to rip, along with the relevant audio track you require
  2. Split resulting video file into chapters
  3. Demux audio into FLAC file
  4. Add metadata (tags)
  5. Listen and enjoy!

First of all, run MakeMKV and enable ‘Expert’ mode within the settings.

expert modeThis will give you the choice of a FLAC option when ripping the chosen tracks

flacThis will result in a number of MKV video files once the ripping process has completed.

The next challenge is to split, demux and tag the resulting files, this is where the bash script comes in, the following script uses mkvmerge to split the single video file into chapters (placing the split files into a folder with the same name as a ripped track), it will then ask you for track names for each chapter (which is the name of each song), this will rename the files with the titles you type in (or press enter to keep them the same). Although this doesn’t add tags to the files, you can use many audio tagging tools to convert the file name to tags.

Once the files are split and renamed, it uses mkvextract to demux the audio to a FLAC file, deleting the individual MKV files.


SCRIPT=`basename "$0"`
MKVMERGE=`which mkvmerge`


if [ "$1" == "" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "$SCRIPT: Give MKV to chapter-split as an argument"
echo "$SCRIPT: e.g.: title00.mkv"
echo "$SCRIPT: e.g.: title01.mkv"
exit 1

if [ ! -f "$1" ]; then
echo "$SCRIPT: MKV file not found [$1]"
exit 1


printf "Output folder is "${outdir}"\n"

if [ ! -d "$outdir" ]; then
echo "$SCRIPT: The output directory ($outdir) does not exist, creating"
mkdir "$outdir"

if [ "$MKVMERGE" == "" ] || [ ! -x "$MKVMERGE" ]; then
echo "$SCRIPT: 'mkvmerge' seems to be missing"
echo "Is mkvtoolnix Installed?"
echo "sudo apt-get install mkvtoolnix"
exit 2


#Split MKV file into chapters
"$MKVMERGE" --split chapters:all "${infile}" -o "${outdir}/${infile%.mkv}_%02d.mkv"

cd "${outdir}"

#Ask user for new file names
for file in *.mkv
printf "Current file name: "${file%.*}"\n"
printf "Please enter new name (leave blank for same)\n"
read newname
if [ -z "$newname" ]; then
printf "Leaving file name unchanged\n"
mv "${file}" "$track - ${newname}.mkv"

#Extract flac audio from renamed MKV chapter files
for file in *.mkv
mkvextract tracks "$file" 1:"${file%.*}".flac;
printf "Deleting MKV file\n"
rm "${file}"

The script above accepts the file to be demuxed as it’s input argument. Assuming you’ve saved the above to a file called, you can run it thus: –

./ inputfile.mkv

The result will be a folder named ‘inputfile’ containing all of the audio tracks in the original MKV as FLAC files, with the names you entered into the script when asked.

You can then use your tagging tool of choice to convert the file names to tags, adding Artist info and dates as necessary.

It would be nice to automate this latter part, if anyone knows a way to add this functionality in automatically, please let me know in the comments and I’ll amend this post accordingly for the benefit of others.






This entry was posted in Music, Technical. Bookmark the permalink.

1 Response to Ripping BluRay Audio Discs to FLAC

  1. blipppy says:

    thank you for this! i am attempting to rip my XTC Black Sea blu-ray. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.