The Hidden Blog

As it turns out, I do have a hostname.

Listening to a movie as an audiobook

Published on July 27, 2022

Today I was reading a comment on HN that piqued my interest.

I used to rip the audio of my favourite movies and listen to them like audiobooks. Because I was usually familiar with the visual parts, I could enjoy the dialogue and the music in a different way.

This sounded like a simple enough task with FFmpeg, so I wanted to give it a try with my favorite movie.

Find audio track in the file

First step is to check what kind of tracks are in the movie file. The best tool for that depends on your source file, in my case that’s an MKV file so I used mkvinfo.

mkvinfo My\ favorite\ movie.mkv

It will give information about the video and audio tracks available in the file. Being interested in the audio track only we look for a section showing Track type: audio. It will look similar to that:

| + Track
|  + Track number: 2 (track ID for mkvmerge & mkvextract: 1)
|  + Track UID: 2018713736
|  + Track type: audio
|  + Codec ID: A_DTS
|  + Name: 5.1 DTS 1510 Kbps - DTSHD MA Core

The important part is the information about mkvextract which tells us that it is “track 1” if we use mkvextract to extract the audio track.

Extract audio track

We use mkvextract to extract the audio track from the file and define that we want to extract the first track (tracks 1:output.dtshd) and store it as output.dtshd. The file ending doesn’t matter.

mkvextract My\ favorite\ movie.mkv tracks 1:output.dtshd

Transcode to Apple Lossless / FLAC

Next step is to transcode that file from DTS-HD to something that’s more portable like ALAC or FLAC.

ALAC:

ffmpeg -i output.dtshd -acodec alac my-favorite-movie-as-an-audiobook.m4a

FLAC:

ffmpeg -i output.dtshd -acodec flac my-favorite-movie-as-an-audiobook.flac

If you want to double check the bitrate / sampling rate of the FLAC file you can use metaflac like metaflac --list my-favorite-movie-as-an-audiobook.flac to inspect the file.

Update: Extraction & transcode with ffmpeg

As Manu correctly pointed out on Twitter you can also combine some of these steps into one.

Also don’t have to do a separate extraction step, ffmpeg can do it all in one go: “ffmpeg -i input.mkv -map 0:1 -acodec alac output.m4a”.