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