FFmpeg - Extract Blu-Ray Audio

Info
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. Since most most portable media requires VFAT filesystem preventing larger files sizes, this becomes 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 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")

Find Available Stream Types
You've likely found your main large meda stream file on your Blu-Ray, something similar to "./BDMV/STREAM/0000.m2ts".

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

Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc Stream #0:1[0x1100]: Audio: pcm_bluray (HDMV / 0x564D4448), 48000 Hz, stereo, s32, 2304 kb/s Stream #0:2[0x1101]: Audio: pcm_bluray (HDMV / 0x564D4448), 48000 Hz, 5.1(side), s32, 6912 kb/s Stream #0:3[0x1102]: Audio: dts (DTS-HD MA) ([134][0][0][0] / 0x0086), 48000 Hz, 5.1(side), s16, 1536 kb/s

Stream #0 on this audio only Blu-Ray is only a black screen with song titles. We'll skip this stream since we want audio only PCM WAV Stream #1 is the PCM two channel stereo mix. Stream #2 is the PCM 5.1 high resolution mix. Stream #2 is the DTS mix.

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 typeps 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.)

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

(MPlayer can also identify chapters using "mplayer -indentify", 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 chapter.

Chapter #0.2: start 534.934400, end 888.087200

You're 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.