@ECHO OFF
cd "%~dp0"
REM SET MKVTOOLPATH=C:\Program Files (x86)\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
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
"%~dp2mkvmerge.exe" -o "%~dpn1_fix.MKV" --engage keep_bitstream_ar_info -A -S --compression -1:none "%~dpnx1" -D -S --compression -1:none "%~dpnx1" -A -D "%~dpnx1"
if not errorlevel 0 (
ECHO Failed on %~nx1 remux! >> logging.txt
goto :eof
)
if exist "%~dpn1_fix.MKV" (
del "%~dpnx1"
rename "%~dpn1_fix.MKV" "%~nx1"
)
ECHO Processing of %~nx1 successful! >> logging.txt
goto :eof