Add Filename (minus the .mkv) as a Title to a folder of Matroska videos
Posted: 12 Dec 2020 08:12
Code: Select all
INFO.BAT version 1.5
--------------------------------------------------------------------------------
Windows version : Microsoft Windows [Version 10.0.19042.685]
Product name : Windows 10 Pro, 64 bit
Performance indicators : Processor Cores: 4 Visible RAM: 8268000 kilobytes
Date/Time format : (dd/mm/yy) 12/12/2020 0:46:11.23
__APPDIR__ : C:\WINDOWS\system32\
ComSpec : C:\WINDOWS\system32\cmd.exe
PathExt : .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Extensions : system: Enabled user: Disabled
Delayed expansion : system: Disabled user: Disabled
Locale name : en-GB Code Pages: OEM 437 ANSI 1252
DIR format : 10/12/2020 06:52 PM 1,543,503,872 pagefile.sys
Permissions : Elevated Admin=No, Admin group=Yes
Missing from the tool collection: debug
I have several folders full of MKV video files (mainly TV programmes) and I would like to add a "Title" into each of them. I can use the program mkvmerge.exe to do this. The correct syntax would be:-
Code: Select all
mkvmerge --title < text string> -o "<path/filename>"
This is fine for an individual video file but, naturally, I would like to process all the files in each folder in one go; hence the need for a batch file to do this.
I started by using this snippet:-
Code: Select all
for %%f in (*.mkv) do %mkvmerge% --title %%~nI -o "Output_Folder_Path/%%f" "%%f"
I used "%~nI" because I read somewhere that that would "fetch" the filename and strip the extension off it which was just what I wanted to do, ie: add the filename of each video (without the .mkv extension) as its title (embedded in its Matroska container). This didn't work at all, at first, but when I added the second "%" (%~nI replaced by %%~nI) the loop worked ran perfectly. However, although it processed all the videos successfully, it just set (the text) "%~nI" as the title of each and every video instead of their filenames! lol.
So next I tried replacing %%~nI with %%~nf, thus:-
Code: Select all
for %%f in (*.mkv) do %mkvmerge% --title %%~nf -o "Output_Folder_Path/%%f" "%%f"
Since (I thought) using the loop counter variable (?) as the argument for the --title option seemed to be corrupting it, I tried to introduce a new variable that might overcome this and produced this:-
Code: Select all
for %%f in (*.mkv) do SET str=%~nf & %mkvmerge% --title %%str "Output_Folder_Path/%%f" "%%f"
Code: Select all
for %%f in (*.mkv) do SET str=%f & SET str=%~nstr %mkvmerge% --title %%str "Output_Folder_Path/%%f" "%%f"
Can any kind soul out there offer me a simple adjustment to the original piece of code that will successfully do what I want?
Ideally, if you could just tell me what to replace <your_suggestion> with in the code below, that would be great but if that's not possible I'd be happy to get any other suggestions you'd care to offer.
Code: Select all
for %%f in (*.mkv) do %mkvmerge% --title <your_suggestion> -o "Output_Folder_Path/%%f" "%%f"
I hope I've explained all this properly but, if not, or there's any other info you need, please don't hesitate to get in touch.
Thanks,
The Highlander.
[/size]