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 (media-video/makemkv) for handling encrypted Blu-Ray media.
- 1 Install Required Packages
- 2 Mount Blu-Ray Disc
- 3 Find Available Stream Types
- 4 Extract Audio Streams
- 5 Tips
- 6 References
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 ./BDMV/STREAM/0000.m2ts.
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 Audio Streams
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!
Extract Individual Chapters
FFprobe will display the chapters to stdout, if they are preserved within the media file.
(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.
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 is usually found within the /mnt/dvd/BDMV/META/DL 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.)
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 which might be useful, but not utilized within this Wiki:
- media-sound/shntool - A multi-purpose WAVE data processing and reporting utility, ie. splitting WAV files.
- MPlayer - Media Player for Linux, as an option to FFmpeg
- media-video/tsmuxer - Utility to create and demux TS and M2TS files
Properly configure ALSA for pass-through digital audio, including specifying default decoding codecs for hardware digital decoders when using MPlayer.