How to use ffmpeg to downmix 5.1 DTS HD MA or Dolby TrueHD to stereo AAC with Dolby Pro Logic II?

5

4

I'm creating audio tracks from movies that can be played on Apple TV and iOS devices. Handbrake could downmix 5.1 audio to stereo with Pro Logic II matrix encoding. How can I do that with ffmpeg?

I found this link on ffmpeg Trac mentioning that I could do matrix encoding with libswresample, but further searching doesn't show how to actually use this in command line.

I tried

ffmpeg -i test.mkv -map 0:1 -c libfdk_aac -ac 2 -af aresample  -matrix_encoding dplii  out.aac

where the only audio track in the source file test.mkv is a 5.1ch DTS HD MA, but the generated AAC audio does not seem to be matrix encoded.

Riobard

Posted 2013-05-12T20:59:13.210

Reputation: 464

wouldn't you rather convert the DTS-MA to AC3 rather than AAC? – James – 2013-05-12T21:08:17.743

@James AppleTV and iOS devices don't support AC-3. (See http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html)

– slhck – 2013-05-12T21:25:34.297

ah. misread question. thought we were converting movies for playback rather than just extracting the audio – James – 2013-05-12T21:30:09.350

Well, actually Apple TV can do AC-3 passthrough to TV via HDMI if the TV supports AC-3 decoding (most LCD TVs do), or via the optical link. However if I want to view the movie on iOS devices, AAC is the only choice. I've already make ffmpeg to create an AC-3 track correctly, but the AAC DPLII is puzzling me as nothing can be found so far. – Riobard – 2013-05-13T03:04:28.010

Out of interest, what do you mean 'AAC is the only choice'? What devices are you trying to watch the movies on which don't support AC3? AFAIK the iPad supports AC3 audio in MP4 movies / tv shows. – James – 2013-05-13T07:18:33.340

I tested on iPad 3 with a MP4 movie with AC-3 audio track. There is no sound at all. Apple's official spec for iPad doesn't include AC-3 either. Where did you find that iPad supports AC-3 playback? – Riobard – 2013-05-13T18:47:59.680

Answers

8

According to the manual entry on aresample, you have to supply the resampler options in a different format:

The filter accepts the syntax [sample_rate:]resampler_options, where sample_rate expresses a sample rate and resampler_options is a list of key=value pairs, separated by ":".

That means you'd need to call it like this:

-af "aresample=matrix_encoding=dplii"

slhck

Posted 2013-05-12T20:59:13.210

Reputation: 182 472

4Thanks very much! Well, actually I still have to supply -ac 2 otherwise the generated AAC audio will be 5.1 channel. – Riobard – 2013-05-13T03:48:19.163

0

Munging together a couple of the answers here, it looks like this is the best answer:

ffmpeg -i SourceVideoWithFivePointOne.mkv -map 0:1  \
-c libfdk_aac -ac 2 -af "aresample=matrix_encoding=dplii"  \
DestinationAudioWithDolbyPLII.aac

And for bonus points, demoting the existing 5.1 channel to be channel 2, and promoting the stereo as channel 1, it would be:

ffmpeg -i SourceWithFivePointOne.mkv -c:v copy -map 0:0 -map 0:1 -map 0:1  \
-c:a:0 libfdk_aac -ac 2 -af "aresample=matrix_encoding=dplii"  \
-c:a:1 copy  \
DestinationVideoWithSurroundAndStereo.mkv

LincM

Posted 2013-05-12T20:59:13.210

Reputation: 25

0

My preferred method is to use ffmpeg to downmix the DTS to stereo and then pipe that output to Quicktime AAC command-line encoder (Quicktime is best AAC encoder in listening tests).

ffmpeg.exe -report -loglevel verbose -i "videofile.mkv" -map 0:a:0 -f wav -acodec pcm_f32le -ac 2 - | qaac.exe --tvbr 127 --quality 2 --rate keep --ignorelength --no-delay - -o "audioonly.m4a"

Requires ffmpeg.exe and qaac.exe

Robert Collier

Posted 2013-05-12T20:59:13.210

Reputation: 679

This appears to downmix to pure stereo (not some surround-enabled variant like Dolby Pro Logic II) unless I'm misunderstanding what the pcm_f32le codec does (ffmpeg -codecs describes it as "PCM 32-bit floating point little-endian"). I do appreciate the use of qaac since it'll make higher quality AAC outputs, though opus is my preference for audio encoding.

– Adam Katz – 2019-08-23T23:00:45.180