PDA

View Full Version : Batch file editing using MKVToolNix


LanguidLegend
5th February 2013, 13:53
So basically what I'm trying to do is to recursively search out MKV and AVI files in a particular folder and change their apsect ratios to 16:9.

Here is the folder/files setup:
MainFolder\
MainFolder\file1.mkv
MainFolder\file2.avi
...
MainFolder\Subfolder1\
MainFolder\Subfolder1\file1.mkv
MainFolder\Subfolder1\file2.avi
...
MainFolder\Subfolder2\
MainFolder\Subfolder2\file.mkv
...

Here is what I have so far in my batch file (fixAspect.bat):
@echo off
SET mkvmerge="C:\Program Files (x86)\MKVToolNix\mkvmerge.exe"
CD [C:\...\MainFolder]
FOR /R %%I IN (*.mkv) DO (mkvmerge -v -o "%%~nI (remux).mkv" "--aspect-ratio 16/9" "%%~I")
PAUSE

However it seems to skip right down to the PAUSE line every time.. any ideas why?

sneaker_ger
5th February 2013, 14:02
Any error messages?

For --aspect-ratio you have to supply a trackID: --aspect-ratio 0:16/9

Mkvpropedit can edit display width and height without remuxing, btw.

LanguidLegend
5th February 2013, 14:09
Any error messages?

For --aspect-ratio you have to supply a trackID: --aspect-ratio 0:16/9

Mkvpropedit can edit display width and height without remuxing, btw.
Thanks for the quick reply!
So how would I replace mkvmerge with mkvpropedit in that example?

sneaker_ger
5th February 2013, 14:19
You can either set the values in pixels (most common), like e.g.:
mkvpropedit "%%I" --edit track:v1 --set display-width=1920 --set display-height=1080

Or less common:
mkvpropedit "%%I" --edit track:v1 --set display-width=16 --set display-height=9 --set display-unit=3

Be careful when working on files without a backup. What exactly has to be done depends highly on the source files - working with anamorphic files is not trivial.

LanguidLegend
5th February 2013, 14:34
Do you know where I can find a complete list of options for the command, because the source website (http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvpropedit.html) doesn't list those.

sneaker_ger
5th February 2013, 15:00
Just run the very first command listed on that website:
mkvpropedit -l

Explanations for valid values are listed in the mkv specs.

LanguidLegend
5th February 2013, 15:37
That's awesome, think I got it working!
Thanks :D


One last thing: I've also been trying to write a batch file which would search folders recursively, merging subtitles (.srt files) with the video files of the same name. Would you know how to do that?

sneaker_ger
5th February 2013, 16:07
FOR /R %%I IN (*.srt) DO (
if exist "%%~nI.mkv" mkvmerge -o "%%~nI (remux).mkv" "%%~nI.mkv" "%%I"
)

LanguidLegend
5th February 2013, 16:09
Actually I'm stuck on one snag.
Here is my batch file now:
@echo on
SET /P folder=Source folder:
CD /D %folder%
PAUSE
FOR /R %%I IN (*.mkv) DO (mkvpropedit "%%~I" --edit track=v1 --set display-width=16 --set display-height=9 --set display-unit=3)

but I get this output:
A:\#Videos\Movies\#Comedy>(mkvpropedit "A:\#Videos\...\file.mkv" --edit track=v1 --set display-width=16 --set display-height=9 --set display-unit=3)
Error: Invalid selector in '--edit track=v1'.

sneaker_ger
5th February 2013, 16:13
--edit track:v1 with ":".

LanguidLegend
5th February 2013, 16:13
--edit track:v1 with ":".

oh.... haha thanks

LanguidLegend
5th February 2013, 16:29
Thanks for all your help sneaker!

Do you know if there is any utility like this which raises or lowers a video's overall volume?

sneaker_ger
5th February 2013, 16:31
None that I know of. There are programs like mp3 gain, aac gain and maybe a few others which could be incorporated into a batch but I don't think anything exists that works directly on mkvfiles without re-encoding.

LanguidLegend
5th February 2013, 16:36
Aw too bad, because its weird - I have some files (even within the same season/folder) which are very noticeably louder or quieter than the others. I've tried the replay gain option with VLC but it didn't really make a difference..

sneaker_ger
5th February 2013, 17:29
I'm not saying it's impossible, but it requires some work (time) and depending on the format you'll have to live with quality degradation (though it may be impossible not hear).

LanguidLegend
18th February 2013, 10:46
Hey sneaker, got another quick followup question for ya.
So here's my code:
@echo off
setlocal enabledelayedexpansion
SET /P folder=Source folder:

CD /D %folder%

FOR /R %%I IN (*.avi) DO (
ECHO %%~fI
IF EXIST "%%~fI" ( :if an avi file exists, convert it
echo "%%~I" exists
mkvmerge -o "%%~dI%%~pI%%~nI.mkv" "%%I"
IF EXIST "%%~nI.mkv" ( :if mkv conversion successful, then delete source file
RECYCLE "%%~fI"
ECHO "%%~I DELETED" )
)
)

FOR /R %%I IN (*.mp4) DO (
ECHO %%~fI
IF EXIST "%%~fI" ( :if an mp4 file exists, convert it
echo "%%~I" exists
mkvmerge -o "%%~dI%%~pI%%~nI.mkv" "%%I"
IF EXIST "%%~nI.mkv" ( :if mkv conversion successful, then delete source file
RECYCLE "%%~fI"
ECHO "%%~I DELETED" )
)
)
pause

FOR /R %%I IN (*.mkv) DO (mkvpropedit "%%~I" --edit track:v1 --set display-width=16 --set display-height=9 --set display-unit=3)

It is going through folders I know have avi & mp4 files in them but the IF EXIST conditional keeps failing for some reason..

LanguidLegend
18th February 2013, 10:53
Actually, figured it out -- had to comment out the setlocal line..