5

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.

6
  • wouldn't you rather convert the DTS-MA to AC3 rather than AAC?
    – James
    May 12, 2013 at 21:08
  • @James AppleTV and iOS devices don't support AC-3. (See developer.apple.com/library/ios/#documentation/AudioVideo/…)
    – slhck
    May 12, 2013 at 21:25
  • ah. misread question. thought we were converting movies for playback rather than just extracting the audio
    – James
    May 12, 2013 at 21:30
  • 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
    May 13, 2013 at 3:04
  • 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
    May 13, 2013 at 7:18

3 Answers 3

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"
1
  • 4
    Thanks very much! Well, actually I still have to supply -ac 2 otherwise the generated AAC audio will be 5.1 channel.
    – Riobard
    May 13, 2013 at 3:48
1

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

1
  • 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
    Aug 23, 2019 at 23:00
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .