command line to convert video and copy all audio tracks untouched

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
lvving
Posts: 7
Joined: Thu Mar 14, 2019 5:19 am

command line to convert video and copy all audio tracks untouched

Post by lvving »

Description of problem or question:
I am trying to use the CLI to convert a file, MKV in this case, by converting the video track to H.265 but copy all audio tracks, untouched. The command line I used is:

handbrakecli -i "%~d1%~p1%~n1%~x1" -e x265 -q 20 --audio-lang-list und --all-audio -E copy --all-subtitles -o "output.mkv"

According to mediainfo, the starting file looks like this:
General
Unique ID : 205282442398501438185673136566789878214 (0x9A6FF5D562260A11B818A9863EDA31C6)
Complete name : Filename.mkv
Format : Matroska
Format version : Version 4
File size : 4.21 GiB
Duration : 1 h 45 min
Overall bit rate : 5 711 kb/s
Movie name : XXXXXXXXXXXXXX
Encoded date : UTC 2017-02-28 10:55:01
Writing application : mkvmerge v9.9.0 ('Pick Up') 64bit
Writing library : libebml v1.3.4 + libmatroska v1.4.5
Cover : Yes
Attachments : cover_land.jpg / small_cover.jpg / small_cover_land.jpg / cover.jpg
FileExtension_Invalid : mkv mk3d mka mks

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 4 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 1 h 45 min
Bit rate : 5 214 kb/s
Width : 1 908 pixels
Height : 1 068 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 24.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.107
Stream size : 3.85 GiB (91%)
Title : XXXXXXXXXXXXXXXXXXX
Language : English
Default : Yes
Forced : No
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709

Audio
ID : 2
Format : AC-3
Format/Info : Audio Coding 3
Commercial name : Dolby Digital
Codec ID : A_AC3
Duration : 1 h 45 min
Bit rate mode : Constant
Bit rate : 384 kb/s
Channel(s) : 6 channels
Channel layout : L R C LFE Ls Rs
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Compression mode : Lossy
Stream size : 290 MiB (7%)
Title : XXXXXXXXXXXXXXXXXX
Language : English
Service kind : Complete Main
Default : Yes
Forced : No

After using the command line listed above, the video converted, but no audio tracks were copied at all.

Can someone please post the proper command line to convert video but copy all audio tracks untouched? It needs to be generic so it works for all audio tracks, if there are more than one and also leave them untouched.
I have been trying to get this to work for several weeks now and nothing I try is consistent. The same command line listed above will work for a different MKV with no issues.
Deleted User 13735

Re: command line to convert video and copy all audio tracks untouched

Post by Deleted User 13735 »

Some audio formats will not pass through Handbrake, and must be encoded to survive.

Since you like command lines, ffmpeg and avisynth are better candidates.
lvving
Posts: 7
Joined: Thu Mar 14, 2019 5:19 am

Re: command line to convert video and copy all audio tracks untouched

Post by lvving »

I actually use ffmpeg for most conversions but occasionally it balks so I use HB as an alternative. I changed the above command line to
handbrakecli -i "%~d1%~p1%~n1%~x1" -e x265 -q 20 --all-audio -E copy --all-subtitles -o "output.mkv" (removing --audio-lang-list und)
and it seems to work without error but will not help with unknown audio tracks. The two MKVs that were failing in ffmpeg and HCLI until I removed that option and they work now. Only a temporary solution since the audio tracks were recognized.
lvving
Posts: 7
Joined: Thu Mar 14, 2019 5:19 am

Re: command line to convert video and copy all audio tracks untouched

Post by lvving »

The reason I am using command line options is because this is all scripted as part of a package.
User avatar
BradleyS
Moderator
Posts: 1860
Joined: Thu Aug 09, 2007 12:16 pm

Re: command line to convert video and copy all audio tracks untouched

Post by BradleyS »

HandBrake 1.3.0 uses "any" to mean any track and "und" to mean unknown language tracks. Prior to 1.3.0, "und" meant any.
lvving
Posts: 7
Joined: Thu Mar 14, 2019 5:19 am

Re: command line to convert video and copy all audio tracks untouched

Post by lvving »

Good to know. Removing UND and upgrading to 1.3.1 seems to be working on the same files that were failing previously.
Thanks.
BradleyS wrote: Sat Jan 11, 2020 12:57 pm HandBrake 1.3.0 uses "any" to mean any track and "und" to mean unknown language tracks. Prior to 1.3.0, "und" meant any.
Post Reply