Is there a single command that will set all subtitle tracks in an MKV file to standard = no?
I know how to do this manually in the GUI, but I would very much like to automate this process.
Thanks in advance for your help!
Is there a single command that will set all subtitle tracks in an MKV file to standard = no?
I know how to do this manually in the GUI, but I would very much like to automate this process.
Thanks in advance for your help!
Welcome!
Unfortunately there isn’t. Each track-specific option requires a track ID. There’s the special track ID -1 that applies to all tracks in a file, but there’s no special track ID that applies to all subtitle tracks in a file.
What you’d have to do is to identify the file with e.g. mkvmerge -J yourfile.mkv, parse the output (with -J the output is JSON which can be used easily in any type of scripting language; with the jq tool it’s even easy enough to use from shell scripts) & generate the command line options for mkvmerge yourself.
See the documentation for the documentation for track IDs & this FAQ entry for examples how to automate things. Example 2 in the latter does pretty much what you want.
Thanks for those hints - Example 2 really looks exactly like what I want to achieve!
Since Ruby is not my preferred language, I tried to do the same in Python, using pymkv.
I succeeded in opening an MKV, finding the default subtitles track, setting it’s default flag to False and getting a quite long command that generates a copy of the input file with this change - great, it works! ![]()
Since I can see that MKVToolNix GUI can do the same in place without the need to copy the whole video, I hope there is some option I can add to the command to make this change directly in the input file.
Simply replacing all occurences of the output file path with the input file didn’t work. I only got an error that said this would overwrite one of the input files.
Can anyone point me into the right direction, please?
mkvmerge always creates new files. mkvpropedit edits file in-place. It’s important that you read the documentation for mkvpropedit as it doesn’t use the same track IDs that mkvmerge uses when targeting tracks.
Please note that some programs cannot cope with how mkvpropedit has to do the modifications sometimes (they’re perfectly valid, but some programs don’t implement parts of the Matroska specs required for locating important elements properly). See this FAQ entry for how this type of issue might manifest.
Great - that’s what I was looking for!
Since in all cases I encountered until now the default subtitles track was always the first one, it works with this command:
mkvpropedit --edit track:s1 --set flag-default=0 filename.mkv
This sets the default flag for the first subtitles track to “No”.
Thank you very much for your help!
You’re quite welcome.
Just in case someone needs something similar: Here ist the simple bash script I am using now.
You can just run it with one or several arguments, each argument is handled individually. If it’s a file, the default flag is removed from the first subtitle track. If it’s a directory, the same is done for each file directly inside it.
#!/usr/bin/env bash
set -euo pipefail
for input in "$@"
do
if [ -d "${input}" ] ; then
echo "Directory: $input";
cd "$input"
for file in * ; do
if [ -f "$file" ]; then
echo "$file"
set +e
mkvpropedit --edit track:s1 --set flag-default=0 "${file}";
set -e
fi
done
else
if [ -f "${input}" ]; then
echo "File: ${input}";
set +e
mkvpropedit --edit track:s1 --set flag-default=0 "${input}";
set -e
else
echo "${input} is not valid";
fi
fi
echo
done
read -n 1 -s -r -p "-- Press any key to continue --"
With a desktop file similar to this, you can just drop files or folders onto a desktop icon to do this quickly:
[Desktop Entry]
Name=RemoveSubtitlesDefault
Exec=~/scripts/mkv_remove_subtitle_default.sh %f
Comment=Remove subtitles default flag from all MKV files
Terminal=true
Type=Application
For Windows I only wrote a very simple script that only works with folders, which you can just drop onto the script file:
cd %1
for /r %%i in (*) do "C:\Program Files\MKVToolNix\mkvpropedit.exe" --edit track:s1 --set flag-default=0 "%%i"
pause
Since this reads very similar and is basically just the other way around, I’m not gonna start a new thread but instead post it here. I hope that’s fine.
Without remuxing the file, I would like to batch edit some VobSub subtitle tracks and set the Forced flag to “English FN.”
However, it seems that mkvpropedit does not work with “Name” (or VobSub) at all i.e.:
–edit track:name=“English FN”
Is that still true, or am I missing something?
I then tried to use mkvmerge -J to get the track name’s ID and pass that directly to mkvpropedit and set the flag that way.
And it seems to be doing something too:
Found “English FN” at track:s5
The file is being analyzed.
The changes are written to the file.
Done.
However, upon checking the file in MKVToolNix, contrary to the success message, the flag hasn’t been set to track 5. As a matter of fact, it seems that it’s always the very last track in the file that gets flagged.
Next, I checked the properties and found that none of the subtitle tracks actually have their name or language visible in the file’s metadata. mkvmerge -J shows that the subtitle headers don’t seem to have writable metadata. So mkvpropedit has silently been doing nothing because it can’t insert metadata into those VobSub tracks.
“id”: 5,
“type”: “subtitles”,
“properties”: {
“language”: null,
“track_name”: null,
“flag_forced”: null
}
On the other hand, the UI clearly shows the flag–on the last track, that is.
I read somewhere that this is a known limitation of how VobSub tracks are muxed into MKVs–that they lack header metadata space and simply cannot be patched after the fact, da da da. Is that true, and what can I do to batch edit those subtitle tracks withough remuxing the MKVs anyway?
You help is much appreciated!
I just figured it out–I was missing something. It is working as expected now.
For future readers, the FAQ entry seems here: Automation examples - mbunkus/mkvtoolnix - Codeberg.org