0

Struggling for some time in that problem. I have a list of videos going this way, by pairs :

magic.mkv magic-1.mkv

food.mkv food-2.mkv

wedding.mkv wedding-3.mkv

etc.

Each video has its pair, and the pair has a number that is incrementing every time. I want to mux each pair together. And for each pair : First video (without the numbers) keep everything except for chapters, Second video (with the incrementing number) to keep all subtitles only.

Now I know how to select tracks and so on, what I don't know, is how to make this .bat file mux those pairs, whiches are all in the same folder. (I know I could put each pair in a different folder, but I have more than 700 files so first I would like to see if there is a way to do this with code)

Opened to any suggestion (I'm not very tech saavy please be specific).

Thank you in advance.

Tried that, and it crashed ("error the file cannont be opened for reading" - open file error) :

for %%a & for %%a-1 in (*.mkv) do "\\\\\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"

Tried that, and it crashed ("error the file cannont be opened for reading" - open file error) :

for %%a in (*.mkv) do "C:\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" '(' %%~na-1%%~xa ')' --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"

Tried that, and it does not crash, but it looks for the second video like that : videoone.mkv-1, as opposed to videoone-1.mkv. It means that %%a will look for the full name including the specified extension, so probably %%a is not the right thing to use since I need to specify a file name, then the extension :

for %%a in (*.mkv) do "C:\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" '(' %%a %%a-1 ')' --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"
Compo
  • 36,585
  • 5
  • 27
  • 39
estevenin
  • 3
  • 3

1 Answers1

0

Does the following example script help you out?

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

For %%G In (
    *-1*.mkv
    *-2*.mkv
    *-3*.mkv
    *-4*.mkv
    *-5*.mkv
    *-6*.mkv
    *-7*.mkv
    *-8*.mkv
    *-9*.mkv
) Do (
    Set "filebasename=%%~nG"
    SetLocal EnableDelayedExpansion
    Set "filebasename=!filebasename:.=?!"
    For %%H In ("!filebasename:-=.!") Do (
        EndLocal
        Set "pairedfilebasename=%%~nH"
        SetLocal EnableDelayedExpansion
        Set "pairedfilebasename=!pairedfilebasename:.=-!"
        For %%I In ("!pairedfilebasename:?=.!") Do (
            EndLocal
            If Exist "%%~I%%~xG" (
                Echo matching suffixed filename to "%%~I%%~xG" is "%%~G"
            )
        )
    )
)

Pause

All you should need to do, if it works for you, is change the Echo command line to your particular mkvmerge.exe command line, remembering that "%%~I%%~xG" is the non suffixed filename and "%%G" is the suffixed one.

Depending upon the makeup of your specific filenames you may wish to change:

    *-1*.mkv
    *-2*.mkv
    *-3*.mkv
    *-4*.mkv
    *-5*.mkv
    *-6*.mkv
    *-7*.mkv
    *-8*.mkv
    *-9*.mkv

to:

    *-*0.mkv
    *-*1.mkv
    *-*2.mkv
    *-*3.mkv
    *-*4.mkv
    *-*5.mkv
    *-*6.mkv
    *-*7.mkv
    *-*8.mkv
    *-*9.mkv

If your filenames are even more complex, you may be better advised to change to outer For loop to a For /F loop using the Dir command piped to findstr.exe filtering using something like /IR "\-[123456789][0123456789]*\.mkv$".

Compo
  • 36,585
  • 5
  • 27
  • 39
  • Hi Compo, thank you very much for the feedback. I'm struggling to understand where to insert the mkvmerge path, the output path, and the specific track selections. I have modified it that way : https://codefile.io/f/WuFVh7UZV2 But it returns that the -o (output) command is not recognized. Also not sure if the mkvmerge path is in the right place, as well as the track selection. It seems that the files are properly selected though, so the loop is definitely working as it should. – estevenin Jul 11 '23 at 09:01
  • You replace the line ```Echo matching suffixed filename to "%%~I%%~xG" is "%%~G"``` with your `mkvmerge` command line. – Compo Jul 11 '23 at 09:57
  • Thank you very much for the tip ! I managed to make it work ! Here is the full code that I'v entered : https://codefile.io/f/7rjeZJ8tkv I was trying to replace it by my own command line, however I only had to use the MKVToolNix command line, as the 'do' was actually already there. So I took that line, replaced the file names by "%%~I%%~xG" and "%%~G" accordingly, and it has worked perfectly ! Thank you so much for the help, there are hundreds of files to work with, that's a big spine out of my foot. I hope this helps others too. – estevenin Jul 12 '23 at 11:03