Auto convert to mkv

HandBrake for Windows support
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
Rottleve
Posts: 4
Joined: Sat Jun 10, 2017 1:08 pm

Auto convert to mkv

Post by Rottleve »

Is it possible with HandBrake to create a similar script to automatically convert all video files (e.g. avi, mp4, etc.) to mkv? :?:
I'm not referring to the subtitles but to the "if"s (if already mkv -> do nothing, if any other video format -> convert to mkv):

Code: Select all

@echo off
cls
set rootfolder=C:\
echo Enumerating all MKVs under %rootfolder%
echo.
for /r %rootfolder% %%a in (*.mkv) do (
    for /f %%b in ('mkvmerge -i "%%a" ^| find /c /i "subtitles"') do (
        if [%%b]==[0] (
            echo "%%a" has no subtitles
        ) else (
            echo.
            echo "%%a" has subtitles
            mkvmerge -q -o "%%~dpna (No Subs)%%~xa" -S "%%a"
            if errorlevel 1 (
                echo Warnings/errors generated during remuxing, original file not deleted
            ) else (
                del /f "%%a"
                echo Successfully remuxed to "%%~dpna (No Subs)%%~xa", original file deleted
            )
            echo.
        )
    )
)
Tjabo
Novice
Posts: 63
Joined: Sun May 20, 2012 11:50 am

Re: Auto convert to mkv

Post by Tjabo »

There are two possible answers to this; yes and no, but mostly no...

Yes, you could write a script that uses the CLI version of HB to re-encode any video file that's supported by HB and store it in a MKV container.

No, you can't use HandBrake to remux a video file into a different container without re-encoding at least the video which will result in a loss of image quality. The amount of detail lost depends on both the source and the settings used, and can range from virtually undetectable to very visible. Re-encoding is also very time consuming compared to just re packaging the content into a new container.

In my opinion you are probably better off looking at something like mkvmerge from the MKVToolNix package. Here is an ancient thread on Doom9 about this. Note that it's old enough to have been archived, so information might be outdated.

ffmpeg is also able to remux video files, but I can't remember ever using it for this myself. But it may be worth checking it out if you don't feel mkvmerge works for you.
Post Reply