Multiple audio tracks with handbrake

Ewan Walker picture Ewan Walker · Jun 26, 2019 · Viewed 8.2k times · Source

Trying to encode video in a fairly generalized manner a typical call will look like:

HandBrakeCLI --encoder-preset medium --encoder-level 4.1 --format av_mkv --encoder x264 --quality 21 --aencoder aac,ac3 --audio-copy-mask aac,ac3,dtshd,dts,mp3 -a 1,2 -s 0,1,2,3,4 -x threads=38 -i Input.mkv -o Output.mkv

The issue is that I want to do the following with audio tracks:

  • If there a high bitrate track (e.g. dts) convert it to ac3
  • If there is an aac track re-encode it (or copy it)
  • If there is no aac track and a high bitrate track create an aac track

Essentially, how would I be able to conditionally choose what to do based on the audio track or would I need to do some sort of pre-processing to identify what kind of audio tracks I am dealing with and change the command programmatically based on that?

Answer

Granger picture Granger · Sep 27, 2019

There's no way to do what you want in Handbrake, at present.

But you might be able to get what you want without it. Essentially, there's a tedious way to both keep the original track and transcode it at the same time.

What I'm presently doing is transcoding the first track to AAC, and also keeping all original track(s). (the originally-encoded first track becomes track 2, and so on.)

E.g. here's my audio-options:

--all-subtitles --audio 1,1,2,3,4,5,6,7,8,9,10,11 --aencoder ca_aac,copy,copy,copy,copy,copy,copy,copy,copy,copy,copy,copy --mixdown dpl2,7point1,7point1,7point1,7point1,7point1,7point1,7point1,7point1,7point1,7point1,7point1 --audio-copy-mask aac,ac3,eac3,truehd,dts,dtshd --audio-fallback aac

I list the first track twice, then follow that pattern in the encoder and mixdown. (I don't care about mp3 or flaac.)

The result, for me, is that the first track is always compatible with my old TVs, but if I ever want the original audio track, I can just switch tracks when I go to play the video.