Command line MKV header editing

MKV playback, recompression, remuxing, codec packs, players, howtos, etc.
Post Reply
Woodstock
Posts: 10331
Joined: Sun Jul 24, 2011 11:21 pm

Command line MKV header editing

Post by Woodstock »

I have about 12,600 MKV files that I need to do header edits on. Specifically, I want to set the "default" and "forced" flags on the first subtitle track of each, and maybe set the title to match the file name.

I can do this one file at a time with the header editor in mkvtoolnix, but that's far more tedious than I want to do. I'm not unwilling to use mkvmerge to do it if I have to re-write the files.

But, I figured I'd ask if there was a better way. I can script it for Windows or Linux as necessary, since both have access to the files, I just need the magic incantation.

(and the reason is that I finally discovered that the FORCED track flag works with some player to do what the DEFAULT flag is supposed to do.)
Chetwood
Posts: 982
Joined: Mon Aug 30, 2010 9:16 am

Re: Command line MKV header editing

Post by Chetwood »

JMkvpropedit v1.4.3 - Batch GUI for mkvpropedit

allows you to set flags and generate a command-line. I'd start with this but if it does not work, I have a batch on my system somewhere that could help as well. Gonna check it out if you don't make progress.
MultiMakeMKV: MakeMKV batch processing (Win)
MultiShrink: DVD Shrink batch processing
Offizieller Uebersetzer von DVD Shrink deutsch
Woodstock
Posts: 10331
Joined: Sun Jul 24, 2011 11:21 pm

Re: Command line MKV header editing

Post by Woodstock »

Hmm... I'd have to re-do my Java configuration to run it, but I can take a look at that (currently only MakeMKV can use/find Java on my system).

Although I just noticed that my copy of mkvpropedit is VERY old. Will have to go fetch the latest.

Thanks!
Woodstock
Posts: 10331
Joined: Sun Jul 24, 2011 11:21 pm

Re: Command line MKV header editing

Post by Woodstock »

After over two months, I finally got motivated enough to dig through the MKVPropEdit documents to get the syntax right for my batch file. So I figured I should finish off this topic.

Code: Select all

(path to executable)\mkvpropedit.exe %1 -e track:s1 --set flag-default=1 --set flag-forced=1
Saved this as SetSubtitleFlags.bat and I can call it with:

Code: Select all

call SetSubtitleFlags "File To Set Flags On.mkv"
It makes a bunch of assumptions, of course - the main one being that the FIRST subtitle track is always the one I want to be forced to play.

I still have to run it against all those files in all those directories, but it definitely will be faster than clicking.
Woodstock
Posts: 10331
Joined: Sun Jul 24, 2011 11:21 pm

Re: Command line MKV header editing

Post by Woodstock »

I updated my SetSubtitleFlags.bat to also set the file title. Some disks I have do not have single-episode playlists, so I break them up with handbrake... except that handbrake's modern iterations will copy the title in the source MKV to the destination MKV, so all the episodes output will appear to be the same name as the input file, when viewed on a media server.

The new batch file copies the file name portion to the title field in the MKV file:

Code: Select all

(path to executable)\mkvpropedit.exe %1 -e track:s1 --set flag-default=1 --set flag-forced=1 --edit info --set "title=%~n1"
With this, when given the file path "V:\anime\dubbed\Irregular at Magic High School\The Irregular at Magic High School Visitor Arc HD01.mkv", the title is set to The Irregular at Magic High School Visitor Arc HD01 (along with the subtitle track flags being set).
Post Reply