1

I am trying to remove subtitles and chapters from all my mkv files. I've been trying to find a way to add the below batch file to also look for chapters and remove them but haven't been able to figure out how to edit the find line. Any help is very much appreciated.

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

If I rewrite the batch like this. It does what I want but it is sloppy going through the files twice.

@echo off
cls
set rootfolder="D:\uTorrent\Completed Downloads"
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 --no-chapters "%%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"
            )
            echo.
        )
    )
)
set rootfolder="D:\uTorrent\Completed Downloads"
echo Enumerating all MKVs under %rootfolder%
echo.
for /r %rootfolder% %%a in (*.mkv) do (
    for /f %%b in ('mkvmerge -i "%%a" ^| find /c /i "chapters" ') do (
        if [%%b]==[0] (
            echo "%%a" has no chapters
        ) else (
            echo.
            echo "%%a" has chapters
            mkvmerge -q -o "%%~dpna (No Chapters)%%~xa" -S --no-chapters "%%a"
            if errorlevel 1 (
                echo Warnings/errors generated during remuxing, original file not deleted
            ) else (
                del /f "%%a"
                echo Successfully remuxed to "%%~dpna (No Chapters)%%~xa"
            )
            echo.
        )
    )
)
pause
  • Shouldn't the find command also need the path to search? Tested it and it doens't work with the active path – Joey Jul 23 '14 at 09:32
  • It's pretty impractical, but you could re-encode them without chapters or subs using [Handbrake](http://handbrake.fr/) – Jonah Jul 23 '14 at 09:40
  • MKV merge will remove the subs and chapters but I want to avoid doing them 1 by 1 manually. This batch file works perfectly for find if their are subs and removing them but not chapters. I can easily edit the command to remove chapters too but if an mkv file has chapters but no subs with this current setup, it won't find the chapters. I've edited my OP with the batch file I currently use. Maybe that'll shed more light on the subject. – Kevin Mieszala Jul 23 '14 at 19:30

1 Answers1

0

Not exactly sure on what you're trying to do exactly, but I think this can help you. You can use findstr to look for multiple strings (or regular expressions!) and much more interesting things. I wrote and tested an example for you:

c:\tmp\findtest>dir /b
x.txt
y.txt
z.txt

c:\tmp\findtest>type x.txt y.txt z.txt

x.txt:
"this is x"

y.txt:
"this is y"

z.txt:
"this is z"

c:\tmp\findtest>findstr /i /r "x y" *
x.txt:"this is x"
y.txt:"this is y"

/edit: and if needed, add | find -c -v "" to that if you only care about the line count of the findstr output.

SadBunny
  • 1,416
  • 2
  • 12
  • 15