Can't change track order

I have a bunch of files with:

0:0 Video
0:1 Audio
0:2 Sub1
0:3 Sub2

I want to change the track order of sub 2 and 3 so that it becomes

0:0 Video
0:1 Audio
0:2 Sub2
0:3 Sub1

I have a functioning batch script

–audio-tracks 1 ^
–subtitle-tracks 2,3 ^
–default-track 1 ^
–default-track 3 ^

That will create a new file with all the tracks.

Likewise, using the GUI program to create a command ending in

–track-order 0:0,0:1,0:3,0:2

Will successfully change the order.

However, applying that command to the previous batch

–audio-tracks 1 ^
–subtitle-tracks 2,3 ^
–default-track 1 ^
–default-track 3 ^
–track-order 0:0,0:1,0:3,0:2

Gives me

Error: No source files were given.

How do I make the batch file change the track order?

Welcome!

You’ll have to copy-paste the whole command line used in order to see where you went wrong.

The goal of the batch is to take a folder of episodes, remove the English dub, then switch the order of the subs so that the one I want to play is the first sub track in the file.

The first batch file, which removes the English dub is:

mkdir output
for %%a in ("*.mkv") do mkvmerge.exe -o "output\%%~na.mkv" ^
--audio-tracks 2 ^
--subtitle-tracks 3,4 ^
--default-track 2 ^
--default-track 4 ^
"%%a"

That works.

Using the GUI to change the track order, and copying that output generates this:

"C:\Program Files\MKVToolNix\mkvmerge.exe" --ui-language en --priority lower --output ^"[Output.mkv]^" --language 0:und --display-dimensions 0:1920x1080 --language 1:ja --track-name 1:Stereo --sub-charset 2:UTF-8 --language 2:en --track-name ^"[Name]^" --sub-charset 3:UTF-8 --language 3:en --track-name ^"[Name]^" ^"[Input.mkv]^" --track-order 0:0,0:1,0:3,0:2

Which works.

However, ideally, this would all be done in one batch command, so, copying the last command (–track order…), which the documentation also suggests is the correct command to change track order, results in this command:

mkdir output
for %%a in ("*.mkv") do mkvmerge.exe -o "output\%%~na.mkv" ^
--audio-tracks 2 ^
--subtitle-tracks 3,4 ^
--default-track 2 ^
--default-track 4 ^
–track-order 0:0,0:1,0:3,0:2
"%%a"

Which does not work, returning:

Error: No source files were given.

My workaround is to just copy past the generated command and manually change the titles to each file in the folder.

You’re copy-pasting in a way that converts two single dashes in front of track-order to a single em-dash character:

Good: --track-order …
Bad: –track-order …

The documentation clearly has two separate dash characters in front of each option.

BTW, when you copy-paste these types of example code here, you should not use regular quoting for the text (> quoted text), but block code quotes. These start with ``` on a line alone, then the text, lastly another line with three ```. That way consecutive dashes won’t be “prettified” by converting them into an em-dash character by your browser.

That’s just a formatting issue here. (Issue noted, original reply edited)

The batch as displayed in Notepad++ shows the 2 spaced dashes.

Also, all of the batch files are using the same dashes, including the ones that work. I’m literally copying the command from the working prompt generated from the GUI.

I’m generating the command in GUI, copy pasting it into Notepad++, checking that the batch file works (it does), then copy pasting the command, from Notepad++, into the other batch, still in Notepad++, where the batch file fails saying “Error: no source files were given”.

The issue is not with Notepad++'s copy paste, since my work around involves copy pasting the full GUI command and manually changing the file name in each line.

Have you realized that there’s no ^ at the end of the --track-order line in your copy-pasted example above? That means that from the point of view of the for command the command ends after --track-order, and the "%%a" isn’t seen by for, therefore for won’t emit any file name in the command.

I was not aware that was a thing, that worked. Thanks.