batch-filebatch-processingtruetypemkv

Batch attachment of multiple .ttf files to a .mkv


Ok, I'm total new at this... Basically I'm using a tool call mkvmerge to attach multiple font files(.ttf) to .mkv files. I have separated the .mkv files into folders together with the respective fonts I would like to attach.

My aim is to create a batch that creates a copy of all the .mkv files with all the added attachments and deposits them in a newly created a folder (i.e Revised) in the parent directory.

Beginning with just a single folder:

mkdir Revised

for %%A in (*.mkv) do "%mkvmerge%" -q -o "Revised\%%A" "%%A" --attachment-mime-type application/x-truetype-font --attach-file "%%~.ttf"

This works if I change the "%%~.ttf" to an actual .tff file name (i.e

mkdir Revised

    for %%A in (*.mkv) do "%mkvmerge%" -q -o "Revised\%%A" "%%A" --attachment-mime-type application/x-truetype-font --attach-file "sans serif.ttf"

and I would end up with newly created Revised folder which contains a .mkv file with the sans serif.tff file attach within the .mkv file itself. However I would like to add multiple .ttf files without naming them individually. (searching online it seems I need something like "$file" though I dont know how to use it)

Next if I have a parent folder with multiple sub-folders:

mkdir Revised

for /R %%A in (*.mkv) do "%mkvmerge%" -q -o "Revised\%%A" "%%A" --attachment-mime-type application/x-truetype-font --attach-file "%%~.ttf"

This just flat out doesn't work. Not just because of the "%%~.ttf" issue I'm sure.

I know that it might be a bit too ambitious, so if some one could just help solve the first half of my problem, that would be lovely. Thanks a lot in advance.

Ps: If anyone need to understand the mkvmerge specific commands to help out: https://mkvtoolnix.download/doc/mkvmerge.html

Updates: For the first part

mkdir Revised

for %%x in (*.ttf) do (
for %%A in (*.mkv) do "%mkvmerge%" -q -o "Revised\%%A" "%%A" --attachment-mime-type application/x-truetype-font --attach-file "%%x"
)

It seems to work better but I think the script would now add and remove the the .ttf files until the last .ttf file in the folder remained.


Solution

  • I have decided to take a stab at this, it is intended to be run from the parent directory holding your directories, (I have assumed that those directories are all on the same level, this is not recursing through nested directories).

    Please be aware that I am unable to test this.

    @Echo Off
    Set "mkvm=%UserProfile%\Downloads\Video Players, Editors, & Downloaders\MKVTool Batch Modifier\mkvmerge.exe"
    For /F Delims^=^ EOL^= %%A In ('Dir/B/AD 2^>Nul^|FindStr/IVXC:"Revised"'
    ) Do If Exist "%%A\*.mkv" (If Exist "%%A\*.ttf" (
            If Not Exist "Revised\" MD "Revised" 2>Nul||Exit /B
            Call :S1 "%%A"))
    GoTo :EOF
    
    :S1
    PushD %1 2>Nul||Exit /B
    Set "as=--attachment-mime-type application/x-truetype-font --attach-file"
    Set "ttfs="
    For /F Delims^=^ EOL^= %%A In ('Where .:*.ttf'
    ) Do Call Set "ttfs=%%ttfs%% %as% "%%~nxA""
    For /F Delims^=^ EOL^= %%A In ('Where .:*.mkv'
    ) Do "%mkvm%" -q -o "%~dp0Revised\%%~nxA" "%%~nxA" %ttfs%
    PopD
    

    I think I have also made this in such a way as to allow for more than one .mkv file in a directory, where each will be attached to all of the same .ttf files.