View Single Post
Old 2nd August 2010, 13:18   #1  |  Link
7ekno
Guest
 
Posts: n/a
fixMKV v2 *updated* - MKV Header Compression fix

Hi all,

New version in post 19 BELOW!, stuff kept here for prosperity and continuity of replies :P

I have a couple of standalone media players that don't like the recent MKVToolnix v4.1.1 or greater MKVmerge default of using header compression

So as an interim fix (until firmware upgrades available, etc) I have coded this quick and dirty BAT file to convert all problem MKVs in a directory into good behaving citizens on media players!

Code:
@ECHO OFF
SET HOMEDIR=%~dp0
REM SET %MKVTOOLPATH=C:\Program Files\MKVToolnix
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
IF "%MKVTOOLPATH%" == "" (
DIR "%HOMEDRIVE%\mkvmerge.exe" /s /b >"%HOMEDIR%findmkvmerge"
SET /P MKVTOOLPATH=<"%HOMEDIR%findmkvmerge"
DEL "%HOMEDIR%findmkvmerge"
)
IF "%MKVTOOLPATH%" == "" (
ECHO MKVToolnix NOT found!!!>"%HOMEDIR%logging.txt"
GOTO STATUS
) ELSE (
ECHO MKVToolnix found at "%MKVTOOLPATH%">"%HOMEDIR%logging.txt"
ECHO.>>"%HOMEDIR%logging.txt"
)

:STARTFILES
IF "%~dpnx1" == "" GOTO DRAGDONE
ECHO PROCESSING ALL FILES DRAGGED AND DROPPED!!
ECHO PROCESSING ALL FILES DRAGGED AND DROPPED>>"%HOMEDIR%logging.txt"
ECHO.>>"%HOMEDIR%logging.txt"
SET dropped=yes
CALL :MKVFIXMUX %1 "%MKVTOOLPATH%"
SHIFT
GOTO STARTFILES

:DRAGDONE
IF "%dropped%" == "yes" GOTO STATUS
ECHO PROCESSING ALL FILES IN THIS DIRECTORY AND ALL SUBDIRECTORIES!!
ECHO PROCESSING ALL FILES IN THIS DIRECTORY AND ALL SUBDIRECTORIES>>"%HOMEDIR%logging.txt"
ECHO.>>"%HOMEDIR%logging.txt"
FOR /F "delims=*" %%A IN ('dir /b /s *.MKV') do CALL :MKVFIXMUX "%%A" "%MKVTOOLPATH%"

:STATUS
START "" "%HOMEDIR%logging.txt"
ping 1.1.1.1 -w 1000 -n 2$1>nul
del "%HOMEDIR%logging.txt"
GOTO END

:MKVFIXMUX
"%~dp2mkvmerge.exe" -o "%~dpn1_fix.MKV" -A -S --compression -1:none "%~dpnx1" -D -S --compression -1:none "%~dpnx1" -A -D "%~dpnx1">>"%HOMEDIR%logging.txt"
if not errorlevel 0 (
ECHO FAILED! on "%~dpnx1" remux!>>"%HOMEDIR%logging.txt"
)
if exist "%~dpn1_fix.MKV" (
del "%~dpnx1"
rename "%~dpn1_fix.MKV" "%~nx1"
ECHO SUCCESSFUL! processing of "%~dpnx1">>"%HOMEDIR%logging.txt"
)

:END
Copy and paste the above code as FIXMKV.CMD into your Top Level Directory that requires fixing (it will parse everything in that directory and everything in ALL subdirectories) OR create the file on your Desktop (for drag & drop functionality)!

It requires MKVToolnix v4.1.1 or later INSTALLED or UNZIPPED onto the Windows Install drive (if you didn't install MKVToolnix and it's NOT on the same drive as Windows, you will have to remove the 'REM' command and manually specify where the MKVToolnix directory is located) ...

7ekno
EDIT: Code fixed for inadvently removing subtitle header compression :P
EDIT2: Code rewritten for Drag & Drop and Double Click function with better logging and self cleanup :P
Attached Files
File Type: 7z FixMKV.7z (810 Bytes, 6990 views)

Last edited by 7ekno; 17th September 2011 at 21:00. Reason: Attachment & Script Update
  Reply With Quote