Find all MKV, extract English subtitles, remove all subtitles, delete original MKV from subtitles removed

0

0

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).

David Custer

Posted 2013-05-25T00:24:16.633

Reputation: 373

Question was closed 2013-05-29T18:17:18.920

Does mkvmerge -i show the language of the subs? – Endoro – 2013-05-25T05:05:34.630

No, looks like I'm asking the wrong question. – David Custer – 2013-05-25T06:07:58.703

It shoes the language with the mkvmerge --identify-verbose switch. – Endoro – 2013-05-25T06:17:34.210

IT DOES!! Yay were getting somewhere!!! – David Custer – 2013-05-25T09:40:42.647

Edited the batch file to include --identify-verbose above. – David Custer – 2013-05-25T09:49:33.840

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 – 2013-05-25T11:02:31.077

1

And, moreover, there is a nice GUI for batch demuxing, mkvcleaver.

– Endoro – 2013-05-25T11:42:37.343

I have SAB***d run a batch script that has 4 other batch scripts. I'm not looking to use a GUI manually. – David Custer – 2013-05-25T22:00:48.793

Answers

1

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(
        )
    )
)

Endoro

Posted 2013-05-25T00:24:16.633

Reputation: 2 036

I installed sed-src. Can't find app to add to me environment variables. – David Custer – 2013-05-25T23:09:24.360

Press [Windows]+[Pause], select --> Advanced --> Environment Variables – Endoro – 2013-05-25T23:14:06.410

@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 – 2013-05-25T23:15:02.740

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 – 2013-05-25T23:15:30.463

I installed sed fine. But all I see is a Makefile – David Custer – 2013-05-25T23:16:45.640

No I did the complete package with src. – David Custer – 2013-05-25T23:17:58.173

@Karan - my code does find all english subs, even "multiple". Look at the code ..... – Endoro – 2013-05-25T23:18:07.430

Just downloaded the binary, and it has the exe, I guess I'll just uninstall the complete package. – David Custer – 2013-05-25T23:18:56.693

@David do you want to compile your own sed, or do you want to use sed?? – Endoro – 2013-05-25T23:19:24.137

I'd like to just use SED. Thats why I used the complete package. I must be really dumb. sorry. The Binary is missing .dll. Only exe in folder for binary. What is the easiest way to use sed? – David Custer – 2013-05-25T23:21:45.800

@Endoro: You're right, that %%i in the for loop will be set to multiple track IDs if required. I was thinking of how I do it manually, which is to specify all tracks to be extracted in one go, i.e. 1:subtrack1.sub 2:subtrack2.sub etc. Here mkvextract will be executed multiple times, once per subtitle track. – Karan – 2013-05-25T23:22:01.233

@Karan - if you are in a hurry and have no time for demuxing you can build just one command line for mkvextract. This more demuxing takes me only a few extra seconds ... – Endoro – 2013-05-25T23:24:53.630

@Endoro: It's fine, I was just commenting on how the code works vs. how I do it manually. I don't think running mkvextract multiple times will cause a significant delay, even with large files. If required I guess a single pass can be achieved with more code, but why bother? It's not like a few seconds saved per file is going to make such a huge difference here. – Karan – 2013-05-25T23:27:51.517

So what do I do about this sed? When I install using the complete package, i get a makefile. When I download binary, I get a exe but no dll. – David Custer – 2013-05-25T23:35:28.383

I installed the exe they give you. From there I got a makefile. – David Custer – 2013-05-25T23:39:59.447

1

Download sed-4.2.1-setup.exe here

– Endoro – 2013-05-25T23:40:23.417

I should have done that in the first place. I just didn't know If I'd need to source at any point. Obviously that was a STupid notion. – David Custer – 2013-05-25T23:46:26.707

OMFG it works. You sir are my HERO! – David Custer – 2013-05-25T23:51:21.460

@David - I changed my code to have ONLY one call of MKVExtract. You can try this too. – Endoro – 2013-05-25T23:52:58.923