WDTV LIVE Groups > WDTV LIVE - General Discussion

mkv header compression easy fixes using batch files

(1/13) > >>

adrian:
did this for myself since i am a really lazy person and decided to share it with others. i wanted an easy way to quickly fix multiple mkv files so they would work on my wdtv. these two solutions work on every mkv in a folder and subfolders. most of the work is not mine, i had problems getting the original batch files i found to work so i just fixed, modified, cut and pasted into new ones which worked for me.

firstly from the matroska website http://www.matroska.org/downloads/mkclean.html is a tool called mkclean. in this download zip is another tool mkWDclean.exe
make a folder and put mkWDclean.exe in it then create a batch file and paste and copy the code below into it.

--- Code: ---FOR /F "delims=*" %%A IN ('dir /b /s *.mkv') DO CALL:WDTVFIX "%%A"
START "" logging.txt
GOTO :eof
:WDTVFIX
mkWDclean --optimize %~dpnx1 %~dpn1_fixed.mkv
if not errorlevel 0 (
ECHO Failed on %~nx1 remux! >> logging.txt
goto :eof)
ECHO OFF
REM remove the REM's below to delete original files
REM if exist "%~dpn1_fixed.mkv" (
REM del "%~dpnx1")
ECHO Processing of %~nx1 successful! >> logging.txt
goto :eof
--- End code ---

save the batch file and double click to run it. (if you should want to stop it part way through the keyboard shortcut is Ctl-C)

what it does is for every file *.mkv it finds it runs it through mkWDclean and saves the output as *_fixed.mkv
it does not delete the original files unless you remove the REM from the bottom so it reads

--- Code: ---FOR /F "delims=*" %%A IN ('dir /b /s *.mkv') DO CALL:WDTVFIX "%%A"
START "" logging.txt
GOTO :eof
:WDTVFIX
mkWDclean --optimize %~dpnx1 %~dpn1_fixed.mkv
if not errorlevel 0 (
ECHO Failed on %~nx1 remux! >> logging.txt
goto :eof)
ECHO OFF
REM remove the REM's below to delete original files
if exist "%~dpn1_fixed.mkv" (
del "%~dpnx1"
ECHO Processing of %~nx1 successful! >> logging.txt
goto :eof
--- End code ---

an alternate method already used by others on this site uses mkvmerge. i just created a batch file to automate it.
you need the latest mkvtoolnix from their website http://www.bunkus.org/videotools/mkvtoolnix/downloads.html
there are two batch files depending upon whether you use the installer or the standalone 7zip archive

installed version
create a folder and make a batch file containing the code below. put your mkv files in the folder and run the batch file to fix them.


--- Code: ---REM Whipped up by TEKNO to fix MKV header compression issues on Standalone media players!
REM fixMKV version 1.2
REM Requires MKVToolnix v4.1.1 INSTALLED (it auto detects where)
@ECHO OFF
cd "%~dp0"
SET KEY="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\mmg.exe"
FOR /F "tokens=2*" %%A IN ('REG QUERY %KEY%') DO SET MKVTOOLPATH=%%B
ECHO MKVToolnix found at %MKVTOOLPATH% > logging.txt
FOR /F "delims=*" %%A IN ('dir /b /s *.MKV') do CALL :MKVFIXMUX "%%A" "%MKVTOOLPATH%"
START "" logging.txt
GOTO :eof
:MKVFIXMUX
"mkvmerge.exe" -o "%~dpn1_fix.mkv" --engage keep_bitstream_ar_info -A -S --compression -1:none "%~dpnx1" -D -S --compression -1:none "%~dpnx1" -A -D --compression -1:none "%~dpnx1"
if not errorlevel 0 (
ECHO Failed on %~nx1 remux! >> logging.txt
goto :eof)
REM if exist "%~dpn1_fix.mkv" (
REM del "%~dpnx1")
ECHO Processing of %~nx1 successful! >> logging.txt
goto :eof
--- End code ---

in the original version the link to the mkvmerge program was referenced by "%~dp2mkvmerge.exe" which did not work on my system(s) but did when i changed it to "mkvmerge.exe" (when you install mkvtoolnix it creates a PATH reference to its install folder.

standalone version
create a folder and extract mkvtoolnix-unicode-4.2.0.7z into it so it is in a sub-folder called mkvtoolnix. the archive uses 7zip http://www.7-zip.org/download.html.
create a batch file in the folder and paste the code below into it. launch the batch file to fix all mkv files in the directory.


--- Code: ---REM Whipped up by TEKNO to fix MKV header compression issues on Standalone media players!
REM MKVfix version 1.2
REM For use with the ZIPPED version of MKVToolnix v4.1.1 or greater
REM Change the "SET MKVTOOLPATH =" to the DIRECTORY that you have unzipped MKVToolnix too!
@ECHO OFF
cd "%~dp0"
SET MKVTOOLPATH=%~dp0mkvtoolnix
ECHO MKVToolnix found at %MKVTOOLPATH% > logging.txt
FOR /F "delims=*" %%A IN ('dir /b /s *.MKV') do CALL :MKVFIXMUX "%%A" "%MKVTOOLPATH%"
START "" logging.txt
GOTO :eof
:MKVFIXMUX
%MKVTOOLPATH%\mkvmerge.exe -o "%~dpn1_fix.mkv" --engage keep_bitstream_ar_info -A -S --compression -1:none "%~dpnx1" -D -S --compression -1:none "%~dpnx1" -A -D --compression -1:none "%~dpnx1"
if not errorlevel 0 (
ECHO Failed on %~nx1 remux! >> logging.txt
goto :eof)
REM if exist "%~dpn1_fix.mkv" (
REM del "%~dpnx1")
ECHO Processing of %~nx1 successful! >> logging.txt
goto :eof
--- End code ---

again to get it to delete the originals delete the "REM " from the two lines so they are

--- Code: ---if exist "%~dpn1_fix.mkv" (
del "%~dpnx1")
--- End code ---
i had two problems with the original version of this firstly the SET MKVTOOLPATH= was SET MKVTOOLPATH = , it didn't like the spaces. and secondly it again failed to reference mkvmerge successfully.
hopefully this will be of use to someone until wd gets round to adding support for header compression to their firware; but i will not be holding my breath.

in terms of speed the mkvmerge method is faster.

Whoheart:

That's great Adrian, thanks for going through all the trouble! :)

RavRob:
Nice Tut

Tx Bro

s1l3nc0r:
Thanks a lot for this quick fix.

Do you think it would be possible to automate this process ?

So every time a new mkv file appears in a directory, it gets passed through this batch script.

adrian:
i am sure it is possible to use a wildcard match to omit those which have already been processed, but one of the issues i had early on was it went through the folder alphabetically and fixed those files which had already been fixed. e.g. it fixed "video1.mkv" to "video1-fixed.mkv" and then fixed "video1-fixed.mkv" to "video1-fixed-fixed.mkv"

at this point since it only has to deal with a small subset of mkv with header compression enabled i prefer a level of human intelligence rather than the blind obedience of computers.
i'd rather know that every mkv i put in a folder will be fixed when i run the batch and get a coffee, and can then be moved into the various subfolders i want, rather than hope a rogue named mkv does not end up in the folder and gets fixed repeatedly filling up hdd space.

there is no reason the batch file cannot be scheduled to run at set intervals but again you run into the literal mindedness of computers which will faithfully gigo (garbage in garbage out) you into a mess.

alternatively there are undoubtedly people out there with much better batch skills than me who could figure out a way to omit those mkv which have already been processed; i am not one of them. i figured out just enough to get it to work until wd update their firmware. already i am seeing some of those groups which had header compressione enabled now disabling it so i am satisfied with what i have.  :-\

Navigation

[0] Message Index

[#] Next page

Go to full version