Jump to content

Adding 1 chapter.xml to multiple MKV Files


bartpet

Recommended Posts

Hello, 

I am adding chapters to my collection of movies and tv episodes. I made many chapter.xml files with mkvtoolnix with different movie-lengths. I want to use one chapter.xml file to add chapters to multiple mkv files with the same movie-length. I didn't find a way yet. I'm a newbie when it comes to using scripts. I have XYplorer as a file manager and using scripts with this app went smoothly. Does anyone now how i can batch-add the chapters of 1 xml file into multiple MKV Files. Thank you

Greetings Bart Peters

Link to comment
Share on other sites

I tried with mkvtoolnix in chapter editor. I can load all mkv files into mkvtoolnix chapter editor. They show up as tabs. Than i can load one of my custom chapters.xml files. But to apply this chapters.xml i have to copy this "edition" to all the open tabs. The only way i can do this is one by one. I don't see the option to load chapter. xml files into makemkv. 

Link to comment
Share on other sites

rbjtech

Use mkvmerge - this is a command line version of mkvtoolnix

mkvmerge -o <newfile.mkv> <originalfile.mkv> --chapters <chapter file.xml>

chapter file must be MKV compatible - which if you created in the GUI mkvtoolnix, it should be (.xml)

Run from a command line - in windows use cmd etc

If you have 100's of files, then you'll neeed a script to insert the filenames, but if you only have a few, then just manually run the above multiple times.

https://mkvtoolnix.download/doc/mkvmerge.html

Link to comment
Share on other sites

Thanks for your reply

I have several chapter.xml files made in MKVToolnix with different video-playtime-lenghts. I have several 100's of MKV files all of the same lenght. To add chapter with a chapter.xml file in MKVToolnix is no problem for me. But adding about 150 MKV files and manually append the chapter.xml to all the open MKV-file-tabs takes a long time. I think that a script would do the trick, unless i overlooked some options to do this in MKVToolnix Chapter Editor.

Link to comment
Share on other sites

rbjtech
18 hours ago, bartpet said:

Thanks for your reply

I have several chapter.xml files made in MKVToolnix with different video-playtime-lenghts. I have several 100's of MKV files all of the same lenght. To add chapter with a chapter.xml file in MKVToolnix is no problem for me. But adding about 150 MKV files and manually append the chapter.xml to all the open MKV-file-tabs takes a long time. I think that a script would do the trick, unless i overlooked some options to do this in MKVToolnix Chapter Editor.

 

@echo off
setlocal ENABLEDELAYEDEXPANSION

FOR /F "delims=" %%x in ('dir /a-s /b /s *.mkv') DO (

	echo Working on : %%x

	c:\mkvtoolnix\mkvpropedit "%%x" --chapters "chapter_file.xml"

	pause

	)

pause

An EXAMPLE simple recursive script for windows is above.

Save the contents of the text above to a .bat file (use notepad etc)

Put the .bat file in the root folder of all the mkv files you want the chapter_file.xml added to

Copy the chapter file along with the .bat file (call it chapter_file.xml)

Change the c:\mkvtoolnix\mkvpropedit to where yours is stored

I've added a 'pause' on every iteration (after the mkvpropedit) - once you are happy with the results - the remove the pause - and it will add them all in seconds.

mkvpropedit does not need to rewrite the file (unlike mkvmerge) and thus is is very fast.

I'd suggest testing on a new test folder with a few mkv's - just to make sure you are happy before running.

if you do manage to get it wrong - then --chapters "" will remove any chapters from the mkv

see - mkvpropedit -- Modify properties of existing Matroska files without a complete remux (mkvtoolnix.download) - mkvpropedit is very powerful ... 

 

Link to comment
Share on other sites

Unfortunately every mkv file is in it's own folder. I first search for all mkv files without embedded chapter markers using a script in XYplorer. These MKV's are spread out over many directories. I didn't write the script myself but got it from a scripting expert on the XYplorer forum, because i am a not even a newbie. Than i select the MKV's that have approximately the same playing-time.

Next i open MKVToolnix Chapter editor, i load a chapters.xml with the playing-time that suits the mkv files from the search. I drag and drop the MKV's from the search to mkvtoolnix. And than for my problem: I have to copy the chapters.xml (template so to speak) to all the mkv files manually. It's for this action, that a script or setting would be very usefull to do this action automatically. It would save a lot of time.

When this step is completed, i only have to check the mkv files and improve if necessary, which is a rather quick process, than i save all mkv files and the job is done.

Link to comment
Share on other sites

rbjtech
On 02/12/2023 at 20:26, bartpet said:

Unfortunately every mkv file is in it's own folder. I first search for all mkv files without embedded chapter markers using a script in XYplorer. These MKV's are spread out over many directories. I didn't write the script myself but got it from a scripting expert on the XYplorer forum, because i am a not even a newbie. Than i select the MKV's that have approximately the same playing-time.

Next i open MKVToolnix Chapter editor, i load a chapters.xml with the playing-time that suits the mkv files from the search. I drag and drop the MKV's from the search to mkvtoolnix. And than for my problem: I have to copy the chapters.xml (template so to speak) to all the mkv files manually. It's for this action, that a script or setting would be very usefull to do this action automatically. It would save a lot of time.

When this step is completed, i only have to check the mkv files and improve if necessary, which is a rather quick process, than i save all mkv files and the job is done.

The above script is recursive and will find all MKV's - regardless of how many sub-folders there are.   You could have replaced the *.mkv with an input file if that has suited you better.

Anyway - glad you got it sorted out.

Link to comment
Share on other sites

Hey Rbjtech,

Thank you for your input. As soon as i get home, i'm going to try it out.  I will let you know the results. 

Greetings

Bartpet

Link to comment
Share on other sites

Hey Rbjtech,

I can't thank you enough. This is exactly what i needed. It's really saving me so much time. Great work. Much appreciated. 

Greetings

bartpet

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...