Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So far:

@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 --identify-verbose "%%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.
        )
    )
)

Which finds all MKV files recursively from a specified path, and removes all subtitles from the MKV files found (if the MKV found contains subtitles), finally deleting all the original MKV files that had the subtitles removed.

I'm looking to add when it runs mkvmerge -i if has English subtitles, tell it to extract them to the directory of the MKV file before remuxing (using mkvextract).

share|improve this question

closed as too localized by Karan, Tanner, techie007, Brad Patton, Mokubai May 29 '13 at 18:17

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Does mkvmerge -i show the language of the subs? –  Endoro May 25 '13 at 5:05
    
No, looks like I'm asking the wrong question. –  David Custer May 25 '13 at 6:07
    
It shoes the language with the mkvmerge --identify-verbose switch. –  Endoro May 25 '13 at 6:17
1  
The issue is, mkvmerge --identify-verbose makes strings with lenghts over 13,000 chars, look here, this is more for and findstr can treat. Therefore I would suggest to use sed in the batch script. –  Endoro May 25 '13 at 11:02
1  
And, moreover, there is a nice GUI for batch demuxing, mkvcleaver. –  Endoro May 25 '13 at 11:42
show 3 more comments

1 Answer

up vote 1 down vote accepted

Identify english subtitles in MKV video files with GNU sed:

@echo off&setlocal
set "rootfolder=C:\video\test"
echo Enumerating all MKVs under %rootfolder%
echo.
for /r "%rootfolder%" %%a in (*.mkv) do (
    for /f %%b in ('mkvmerge  --ui-language en -i "%%a" ^| find /c /i "subtitles"') do (
        if "%%b"=="0" (
            echo(%%a has no subtitles
        ) else (
            echo(%%a has subtitles
            set "line="
            for /f "delims=" %%i in ('mkvmerge --ui-language en --identify-verbose "%%a" ^| sed "/subtitles/!d;/language:eng/!d;s/.* \([0-9]*\):.*/\1/"') do (
                echo(english Track ID: %%i
                call set line=%%line%% %%i:"%%~dpna (Sub Track %%i).sub"
            )
            setlocal enabledelayedexpansion
            mkvextract tracks "%%a" --ui-language en !line! ||(echo Demuxing error!&goto:eof)
            endlocal
            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(
        )
    )
)
share|improve this answer
    
I installed sed-src. Can't find app to add to me environment variables. –  David Custer May 25 '13 at 23:09
    
Press [Windows]+[Pause], select --> Advanced --> Environment Variables –  Endoro May 25 '13 at 23:14
    
@Endoro: Unfortunately this is heavily dependent on the proper language code being specified in the MKV for each track. For example, I have a bunch of files like this where this will obviously fail, although both embedded subtitle tracks are in English. I don't know if there's a better solution though; will have to look into this a bit more when I have some free time on my hands. –  Karan May 25 '13 at 23:15
    
OOps. I'm sorry I wasn't clear. I cannot find sed.exe I looking in all the program files for sed and cannot find any application. –  David Custer May 25 '13 at 23:15
1  
Download sed-4.2.1-setup.exe here –  Endoro May 25 '13 at 23:40
show 15 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.