Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > New and alternative a/v containers

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd August 2010, 14:18   #1  |  Link
7ekno
Registered User
 
Join Date: Jul 2007
Posts: 389
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, 6726 views)

Last edited by 7ekno; 17th September 2011 at 22:00. Reason: Attachment & Script Update
7ekno is offline   Reply With Quote
Old 7th August 2010, 12:27   #2  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 5,665
I don't found info in mkvmerge help about:

--engage keep_bitstream_ar_info

For what is necessary?

For me work for all tracks:

--compression -1:none "%~dpnx1"

instead:

-A -S --compression -1:none "%~dpnx1" -D -S --compression -1:none "%~dpnx1" -A -D --compression -1:none "%~dpnx1"

What is the difference selecting video, audio and subs separately?
__________________
BeHappy, AviSynth audio transcoder, in Doom9 forums. NicAudio, BassAudio, audio decoders.
tebasuna51 is offline   Reply With Quote
Old 7th August 2010, 12:49   #3  |  Link
canTsTop
Registered User
 
canTsTop's Avatar
 
Join Date: Apr 2007
Location: Lithuania
Posts: 120
there is special tool for this purpose, mkWDclean http://www.matroska.org/downloads/mkclean.html
canTsTop is offline   Reply With Quote
Old 7th August 2010, 16:26   #4  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,494
Quote:
Originally Posted by tebasuna51 View Post
I don't found info in mkvmerge help about:

--engage keep_bitstream_ar_info

For what is necessary?
In older versions mkvmerge would delete the SAR info from H.264 streams. As it does not do that anymore in newer versions this option has become obsolete.
sneaker_ger is offline   Reply With Quote
Old 7th August 2010, 16:45   #5  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 7,241
Quote:
For me work for all tracks:

--compression -1:none "%~dpnx1"
Frankly i wouldn't disable compression on subtitles (vobsub)
Atak_Snajpera is online now   Reply With Quote
Old 7th August 2010, 20:01   #6  |  Link
b66pak
Registered User
 
b66pak's Avatar
 
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
Quote:
Originally Posted by canTsTop View Post
there is special tool for this purpose, mkWDclean http://www.matroska.org/downloads/mkclean.html
a .bat like this will remove header compression for audio and video (tested with a file generated with mkvmerge v4.2.0 default settings for compression):

Code:
for %%a in ("*.mkv") do mkWDclean --optimize %%a
_
__________________
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note...
Visit The Land Of Dracula (Romania - EU)!
b66pak is offline   Reply With Quote
Old 7th August 2010, 22:43   #7  |  Link
roozhou
Registered User
 
Join Date: Apr 2008
Posts: 1,181
Quote:
Originally Posted by tebasuna51 View Post
I don't found info in mkvmerge help about:

--engage keep_bitstream_ar_info

For what is necessary?
There are 18 secret hack options in mkvmerge, all started with --engage. The author provides no documentation about these options, you can only learn it from source code.

keep_bitstream_ar_info keeps the original SAR information in SPS for AVC when you specify a DAR for the video stream. It is on by default now so it's not needed any more.
roozhou is offline   Reply With Quote
Old 7th August 2010, 22:54   #8  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,494
There's a short explanation for most these options in mmg under "mux">"add command line options".
sneaker_ger is offline   Reply With Quote
Old 8th August 2010, 19:59   #9  |  Link
Mosu
MKVToolNix author
 
Mosu's Avatar
 
Join Date: Sep 2002
Location: Braunschweig, Germany
Posts: 3,816
Those options are not supported (meaning I will not give support for questions regarding the use of or the result of the use of those options). They're development hacks, hacks used for testing, stuff that simply doesn't work correctly yet etc etc.
__________________
Latest MKVToolNix is v41.0.0

If I ever ask you to upload something, please use my file server.
Mosu is offline   Reply With Quote
Old 16th August 2010, 13:08   #10  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 5,665
Quote:
Originally Posted by Atak_Snajpera View Post
Frankly i wouldn't disable compression on subtitles (vobsub)
There are now support for compressed Vobsub subtitles (zlib I suppose) in standalone players like WD TV?

@all
Thanks for your tips.
__________________
BeHappy, AviSynth audio transcoder, in Doom9 forums. NicAudio, BassAudio, audio decoders.
tebasuna51 is offline   Reply With Quote
Old 16th August 2010, 13:15   #11  |  Link
Mosu
MKVToolNix author
 
Mosu's Avatar
 
Join Date: Sep 2002
Location: Braunschweig, Germany
Posts: 3,816
VobSub subtitles have always been compressed in Matroska -- so either a player supports zlib compressed VobSubs or it doesn't support VobSubs in Matroska at all. That would be my guess.
__________________
Latest MKVToolNix is v41.0.0

If I ever ask you to upload something, please use my file server.
Mosu is offline   Reply With Quote
Old 19th August 2010, 05:48   #12  |  Link
shaxs
Registered User
 
Join Date: Sep 2003
Posts: 1
Hi Everyone,

So my 720p MKV tv shows used to work fine until recently when streamed to my Patriot Box Office or my Xbox 360. Now neither can play more recent MKV files. I tried your .bat fix and my xbox still cannot play it. I have no tried the Patriot yet. Any clue how to get MKVs to work on the Xbox again using windows media center on the xbox?
shaxs is offline   Reply With Quote
Old 19th September 2010, 16:38   #13  |  Link
tormento
Acid fr0g
 
tormento's Avatar
 
Join Date: May 2002
Location: Italy
Posts: 1,034
Tried to mux a mkv with MKVToolnix 4.3.0 and then applied MKWDClean with no parameters. The files still does not work on WDTV Live.

What am I doing wrong?
__________________
@turment on Telegram
tormento is offline   Reply With Quote
Old 19th September 2010, 23:21   #14  |  Link
Video Dude
Senior Member
 
Join Date: Apr 2004
Posts: 1,048
Quote:
Originally Posted by tormento View Post
Tried to mux a mkv with MKVToolnix 4.3.0 and then applied MKWDClean with no parameters. The files still does not work on WDTV Live.

What am I doing wrong?
Use 4.0.0 and see if it works.
Video Dude is offline   Reply With Quote
Old 20th September 2010, 07:16   #15  |  Link
tormento
Acid fr0g
 
tormento's Avatar
 
Join Date: May 2002
Location: Italy
Posts: 1,034
Quote:
Originally Posted by Video Dude View Post
Use 4.0.0 and see if it works.
With < 4.1.0 I don't even need to clean or remux.. I know that..
__________________
@turment on Telegram
tormento is offline   Reply With Quote
Old 28th August 2011, 16:21   #16  |  Link
piratburner
Registered User
 
Join Date: Jul 2008
Posts: 61
Network share on NAS

Would it be possible to update the CMD file to work on network share ?

I have all my MKV on a unraid server.

//Peter
piratburner is offline   Reply With Quote
Old 2nd September 2011, 13:01   #17  |  Link
7ekno
Registered User
 
Join Date: Jul 2007
Posts: 389
Quote:
Originally Posted by piratburner View Post
Would it be possible to update the CMD file to work on network share ?

I have all my MKV on a unraid server.

//Peter
BAT/CMD do not support UNC names

The only way to achieve that is to map a share to network drive ...

7ek
7ekno is offline   Reply With Quote
Old 15th September 2011, 07:22   #18  |  Link
jeff3611
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks 7ekno, just the tool I need to simplify things.

However, is that possible to include a checking routine before fixing every mkv in the dir tree. What I meant was fix only the mkv with compressed header in it.

Cool scripts, thanks.
jeff3611 is offline   Reply With Quote
Old 17th September 2011, 13:47   #19  |  Link
7ekno
Registered User
 
Join Date: Jul 2007
Posts: 389
fixMKV version 2 *updated*

Quote:
Originally Posted by jeff3611 View Post
However, is that possible to include a checking routine before fixing every mkv in the dir tree.
Sure! I bring you fixMKV v2 :P

Tools needed:
MKVToolnix - Either installed or unzipped to the same drive as Windows (if not, you will have to remove the "REM" statement and manually enter the file path to mkvmerge.exe)
MediaInfo CLI version - Use the same version as your OS (so 64bit for 64bit OS, 32bit for 32bit OS), extract "MediaInfo.dll" and "MediaInfo.exe" to the same folder as fixMKV v2 (if not, you will have to manually enter the file path to MediaInfo.exe by deleting the %~dp0 in the "SET MEDIAINFOPATH=%~dp0" line and replacing it with your file path)

Code:
@ECHO OFF
SET HOMEDIR=%~dp0
SET MEDIAINFOPATH=%~dp0
SET LOGFILE=%~dpn0_log.txt
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%" == "" (
FOR /F "tokens=*" %%I IN ('DIR "%HOMEDRIVE%\mkvmerge.exe" /s /b') DO SET MKVTOOLPATH=%%I
)
IF "%MKVTOOLPATH%" == "" (
ECHO %DATE%%TIME%: MKVToolnix NOT found!!!>"%LOGFILE%"
GOTO STATUS
) ELSE (
ECHO %DATE%%TIME%: MKVToolnix found at "%MKVTOOLPATH%">"%LOGFILE%"
)
IF EXIST "%MEDIAINFOPATH%MediaInfo.exe" (
ECHO %DATE%%TIME%: MediaInfo.exe CLI found at "%MEDIAINFOPATH%">>"%LOGFILE%"
) ELSE (
ECHO %DATE%%TIME%: MediaInfo.exe CLI NOT FOUND at "%MEDIAINFOPATH%">>"%LOGFILE%"
GOTO STATUS
)
IF (%1) == () GOTO CLICKED
ECHO FixMKV v2 removing Header Compression from all files DROPPED!!
ECHO %DATE%%TIME%: PROCESSING ALL FILES DRAGGED AND DROPPED>>"%LOGFILE%"

:DROPFILES
IF (%1) == () GOTO STATUS
CALL :MKVFIXMUX %1 "%MKVTOOLPATH%"
SHIFT
GOTO DROPFILES

:CLICKED
ECHO FixMKV v2 removing Header Compression from all files in %HOMEDIR% AND all Sub-Directories!!
ECHO %DATE%%TIME%: PROCESSING ALL FILES IN %HOMEDIR% + SUBDIRECTORIES>>"%LOGFILE%"
FOR /F "delims=*" %%A IN ('dir /b /s *.MKV') DO CALL :MKVFIXMUX "%%A" "%MKVTOOLPATH%"

:STATUS
START "" "%LOGFILE%"
PING 1.1.1.1 -w 1000 -n 2$1>nul
DEL "%LOGFILE%"
GOTO END

:MKVFIXMUX
"%MEDIAINFOPATH%mediainfo.exe" "%~dpnx1">"%HOMEDIR%%~n1.nfo"
FIND /C /I "Header stripping" "%HOMEDIR%%~n1.nfo">nul
IF NOT ERRORLEVEL 1 (
ECHO %DATE%%TIME%: "%~nx1" - Header Compression Found, processing ... >>"%LOGFILE%"
"%~dp2mkvmerge.exe" -o "%~dpn1_fix.MKV" -A -S --compression -1:none "%~dpnx1" -D -S --compression -1:none "%~dpnx1" -A -D "%~dpnx1">nul
IF ERRORLEVEL 1 (
  ECHO %DATE%%TIME%: "%~nx1" - REMUX FAILED somehow!!>>"%LOGFILE%"
  GOTO CLEAN
  )
IF EXIST "%~dpn1_fix.MKV" (
  DEL "%~dpnx1"
  RENAME "%~dpn1_fix.MKV" "%~nx1"
  ECHO %DATE%%TIME%: "%~nx1" - SUCCESSFUL remux.>>"%LOGFILE%"
  GOTO CLEAN
  )
) ELSE (
ECHO %DATE%%TIME%: "%~nx1" - SKIPPED - No Header Compression.>>"%LOGFILE%"
GOTO CLEAN
)
:CLEAN
DEL "%HOMEDIR%%~n1.nfo"

:END
The advantages of fixMKV v2 are:
- Bit more neat and concise logging with autocleanup
- The use of MediaInfo to determine if an MKV has header compression or not and skip the file if nothing needs doing
- Can be run from a top level directory and will automatically crawl all sub-directories
- Files can be dragged and dropped on the BAT file for processing (and will still be skipped if not needed)

Cheers,
7ekno
Attached Files
File Type: 7z FixMKV2.7z (1,021 Bytes, 7287 views)

Last edited by 7ekno; 17th September 2011 at 21:58. Reason: new update
7ekno is offline   Reply With Quote
Old 18th September 2011, 02:15   #20  |  Link
jeff3611
Registered User
 
Join Date: Feb 2006
Posts: 3
Quote:
Originally Posted by 7ekno View Post
Sure! I bring you fixMKV v2 :P

Super cool!, thanks again.
jeff3611 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:36.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.