Reorder audio-tracks on headless system

Discussion of the HandBrake command line interface (CLI)
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
mohahn
Posts: 10
Joined: Fri Mar 24, 2017 10:12 am

Reorder audio-tracks on headless system

Post by mohahn »

Hello,

I'm lost a bit and I'm not a pro.
At the moment I'm using MakeMKV and HandBrakeCLI in a headless environment (on Ubuntu/Xenial) for ripping and compressing my BluRay movies. I'm using the following commands:

Code: Select all

makemkvcon mkv /dev/cdrom all "/media/rip" --minlength=120 -r
HandBrakeCLI  -i "/media/rip/track01" -o "/media/convert/track01" --preset="High Profile" --subtitle scan --subtitle-forced
This produces a compressed MKV for most source discs, containing two audio tracks (2.0 and a 5.1 track). However, when playing this MKV on my DVR (VU+ Duo2), only the 2.0 track is selected as default audio track. I can choose 5.1 manually, but is there a way to flag the 5.1 track as default audio track inside the MKV or to reorder the tracks, that an available 5.1 channel becomes first track before 2.0?
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Reorder audio-tracks on headless system

Post by JohnAStebbins »

What is your objective? Do you need both audio tracks? Do you have devices that can only play AAC? Do you require exactly aac and ac3 tracks, or would you rather have a DTS track when the source audio is DTS?

To do exactly what you've asked (reorder the tracks), you can manually specify the audio codec settings on the command line, e.g. -E copy:ac3,aac. But I'm not sure that's what you really want.
mohahn
Posts: 10
Joined: Fri Mar 24, 2017 10:12 am

Re: Reorder audio-tracks on headless system

Post by mohahn »

@JohnAStebbins Thanks a lot for you reply. As the system runs headless I don't know which audio tracks are present in real when converting. As my Denon receiver is on every time I watch TV I prefer to use any (german) 5.1 track as first audio track. The Enhanced Movie Center on VU+ Duo2 has an option to select an existing AC3 automatically, but that does not work for an unknown reason. So I do not want to change HandBrakeCLIs default behaviour that is executed with the above command (so an existing AAC-2.0 track beside AC3-5.1 is fine for me for downward compatibility on other devices), but I want any 5.1 track as first audio track.

BTW: My poor knowledge says to me, that AC3 is only the compression of an audio track, i.e. DTS, isn't it?
mohahn
Posts: 10
Joined: Fri Mar 24, 2017 10:12 am

Re: Reorder audio-tracks on headless system

Post by mohahn »

I cannot edit my post, so here an updated one (I've googled a bit for audio formats and codecs). Fact: As the system runs headless I don't know which audio tracks are present in real when converting.

But, if possible and available in stream, I'd like to have one of DTS/AC3 for 5.1 and a AAC for 2.0.

Whe "copy:ac3" passes through audio track if supported, what is done when copy is not supported? Does HandBrake re-compress the AC3 stream?
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Reorder audio-tracks on headless system

Post by JohnAStebbins »

"copy:ac3" will only pass ac3 audio. If the source audio is not ac3, it will re-encode it to ac3. I believe what you want is the following

Code: Select all

-E copy,aac --audio-copy-mask=ac3,dts --audio-fallback=ac3
This means, pass through the first track if it matches audio-copy-mask and fallback to encoding to ac3 if it does not match. Then encode the second track to aac. You can read more documentation of these with HandBrakeCLI --help
mohahn
Posts: 10
Joined: Fri Mar 24, 2017 10:12 am

Re: Reorder audio-tracks on headless system

Post by mohahn »

@JohnAStebbins

That seems to work. Thanks a lot. Another question on this: when there is only one 2-channel AC3 stream in source then a second audio stream in destination MKV is produced nevertheless. And it has exactly the same settings as first audio track. Is there any option to prevent creation of duplicate audio streams (based on same decoder settings)?

Code: Select all

[11:44:13] libhb: scan thread found 1 valid title(s)
+ title 1:
  + stream: /data/source/Zootropolis_t00.mkv
  + duration: 00:18:23
  + size: 1920x1080, pixel aspect: 1/1, display aspect: 1.78, 23.976 fps
  + autocrop: 0/0/0/0
  + support opencl: no
  + support hwd: not built-in
  + chapters:
    + 1: cells 0->0, 0 blocks, duration 00:05:47
    + 2: cells 0->0, 0 blocks, duration 00:05:44
    + 3: cells 0->0, 0 blocks, duration 00:06:52
  + audio tracks:
    + 1, English (AC3) (2.0 ch) (iso639-2: eng), 48000Hz, 320000bps
  + subtitle tracks:
    + 1, German (iso639-2: deu) (Bitmap)(PGS)
+ Using preset: High Profile
Invalid codec aac, using default for container.
[11:44:15] Auto Passthru: allowed codecs are AC3, DTS
[11:44:15] Auto Passthru: fallback is AC3
[11:44:15] Auto Passthru: using AC3 Passthru for track 1
[11:44:15] work: mixdown not specified, track 2 setting mixdown Stereo
[11:44:15] work: compression level not specified, track 2 setting compression level 2.00
[11:44:15] sync: expecting 26465 video frames
[11:44:15] mask dilate thread started for segment 3
[11:44:15] mask dilate thread started for segment 2
[11:44:15] job configuration:
[11:44:15]  * source
[11:44:15]    + /data/source/Zootropolis_t00.mkv
[11:44:15]    + title 1, chapter(s) 1 to 3
[11:44:15]    + container: matroska,webm
[11:44:15]    + data rate: 18007 kbps
[11:44:15]  * destination
[11:44:15]    + /data/target/Zootropolis_t00.mkv
[11:44:15]    + container: Matroska (libavformat)
[11:44:15]      + chapter markers
[11:44:15]  * video track
[11:44:15]    + decoder: h264
[11:44:15]    + filters
[11:44:15]      + Decomb (default settings)
[11:44:15]      + Framerate Shaper (0:27000000:1126125)
[11:44:15]        + frame rate: same as source (around 23.976 fps)
[11:44:15]      + Crop and Scale (1920:1080:0:0:0:0)
[11:44:15]        + source: 1920 * 1080, crop (0/0/0/0): 1920 * 1080, scale: 1920 * 1080
[11:44:15]    + loose anamorphic
[11:44:15]      + storage dimensions: 1920 * 1080, mod 2
[11:44:15]      + pixel aspect ratio: 1 / 1
[11:44:15]      + display dimensions: 1920 * 1080
[11:44:15]    + encoder: H.264 (libx264)
[11:44:15]      + preset:  medium
[11:44:15]      + profile: high
[11:44:15]      + level:   4.1
[11:44:15]      + quality: 20.00 (RF)
[11:44:15]  * subtitle track 1, German (track 2, id 0x2) Picture [PGS] -> Passthrough, Default
[11:44:15]  * audio track 1
[11:44:15]    + decoder: English (AC3) (2.0 ch) (track 1, id 0x1)
[11:44:15]      + bitrate: 320 kbps, samplerate: 48000 Hz
[11:44:15]    + AC3 Passthru
[11:44:15]  * audio track 2
[11:44:15]    + decoder: English (AC3) (2.0 ch) (track 1, id 0x1)
[11:44:15]      + bitrate: 320 kbps, samplerate: 48000 Hz
[11:44:15]    + mixdown: Stereo
[11:44:15]    + encoder: MP3 (libmp3lame)
[11:44:15]      + bitrate: 160 kbps, samplerate: 48000 Hz
[11:44:15]      + compression level: 2.00
[11:44:15] reader: first SCR 0 id 0x0 DTS 0
Post Reply