FFmpeg - Extract Blu-Ray Audio

Some music audio only titles are just becoming available on Blu-Ray, and music lovers may need to extract the audio to another portable medium. Since the Blu-Ray audio is usually one big file, the file chapters need to be found and split. Most portable media requires VFAT filesystem preventing larger files sizes, and further splitting is essential.

This article will only discuss unencrypted Blu-Ray Audio media, and merrily point users to MakeMKV for handling encrypted Blu-Ray media.

Install Required Packages
Although MPlayer can also be used, FFmpeg seems more refined when dumping or clipping specific audio chapters from DVD or Blu-Ray media.

(If somebody successfully uses MPlayer/MPlayer2 to dump PCM specified chapters, feel free to add it to this Wiki page and retitle appropriately. I've only experienced MPlayer seeking to the beginnning chapter and, not recognizing or stopping at the specified end chapter. ie. "mplayer -ao pcm:fast:file=audio.wav -chapter 2-2 -vo null -vc null input_file")

Mount Blu-Ray Disc
Blu-Rays use UDF, and require to be mounted as such. Probably best to edit the following file to provide mount points as such. (I use AutoFS, so incorporate as needed.)

Or the following will automatically decide with little to no additional access time difference,

Create the mount folders if you don't have them already,

Mount the disc,

Find Available Stream Types
You've likely found your main large media stream file on your Blu-Ray, something similar to.

Using ffplay, you'll likely see something like this within stdout,

Keep an eye on the Hz, s16/s24/s32 and kb/s, as they're indicators of audio quality.

Extract Full Audio Streams
To extract the three individual stream types into one large file, you can use FFmpeg. (Although this is likely undesirable due to file size limitations on VFAT filesystems.)

Verify you have successfully extracted the streams using ffplay or mplayer. Monitor the stdout messages to ensure proper drivers and codecs are used for the stream types specified.

(For DTS playback using MPlayer, you'll likely need to specify ac=hwdts for MPlayer for passing through DTS to your HDMI/SPDIF audio receiver. MPlayer uses the following for specifying streams, "mplayer -aid 1 -demuxer lavf ./BDMV/STREAM/00000.m2ts".)

Devices with only 16 Bit Microsoft PCM Audio Support
Some audio receivers and devices will only play 16 bit Microsoft PCM WAV files! If you have 24 bit audio files as indicated above and such hindered devices, you will need to unfortunately down mix in order for the files to be playable on those devices. The above formentioned conversion provides 24 bit PCM Riff/Aiff files, while the below ffmpeg incanatation will provide 16 bit Microsoft PCM WAV files.

Another work around, is to play the 24bit PCM WAV files using a software media player such as FFplay and MPlayer, and route the sound to your audio receiver using HDMI or S/PDIF. One other option, ensure you buy a receiver capable of playing the 24 bit PCM files via USB media!

Find Chapters
FFprobe will display the chapters to stdout, if they are preserved within the media file.

A more elaborate or useful example using ffprobe,

For extracting streams including chapter info for use with ffprobe:

(MPlayer can also identify chapters using "mindentify", however the chapter times do not appear comptabile with FFmpeg.)

Extract a Chapter
At this point, we'll assume we want Stream #1 for standard two stereo PCM WAV files (ie. map 0:1) and the second (#0.2) chapter.

FFprobe's snipped output:

The incanatation of FFmpeg we'll use for exacting this individual chapter, using seconds for start and duration indicators.

With this example, the start time will be 534.934400 and duration will be 888.087200 minus 534.934400.

For example,

Extract Multiple Chapters
I have only piped the message stdout of the CLI tools to a series of text files, utilizing grep and bc (CLI Calculator), along side VI/VIM for line duplication and clipping for creating one time scripts for extracting multiple files at once.

Someday, this will likely be automated and integrated into abcde.sh.

Cover Art
Cover art is usually found within the folder. For example:

MPlayer Upmix When 24bit Decoding Not Available
My receiver is apparently not capable of decoding 24 bit PCM WAV, but will decode 16 and 32 bit PCM WAV through HDMI.

The PCM 5.1 WAV files are encoded at 24 bit PCM 5.1 WAV 48000 Hz.

The work around here is to upmix to 32 bit using sb32le or floatle, since MPlayer by default down mixes to 16 bit or s16le. MPlayer also by default cuts channels to two channels.

No DTS-H Master?
My receiver shows it's decoding DTS-HD Master stream when bit perfect or high definition audio decoding is selected within my Window's player, but my receiver only says it's decoding the usual "DTS" decoding while playing streams within Linux. From reports on the web, bit perfect or high definition streaming to the receiver isn't possible within Linux. Other reports state it is possible using Intel's HDMI. (NVidia's video card HDMI using Linux binary drivers isn't performing DTS-HD Master here.)

Gapless Playback
Split tracks of long streams, it's nice to have gapless playback for preventing interruptions between tracks.

FIXME: The following is from Snipplr, but doesn't work for me. :-/

Or use MPlayer2:

Additional Tools
Additional tools which might be useful, but not utilized within this Wiki:
 * - A multi-purpose WAVE data processing and reporting utility, ie. splitting WAV files.
 * MPlayer - Media Player for Linux, as an option to FFmpeg
 * - Utility to create and demux TS and M2TS files