Skip to content

Instantly share code, notes, and snippets.

@ScribbleGhost
Last active January 26, 2023 03:24
Show Gist options
  • Save ScribbleGhost/9eed21773f37f67ed901617d499e512f to your computer and use it in GitHub Desktop.
Save ScribbleGhost/9eed21773f37f67ed901617d499e512f to your computer and use it in GitHub Desktop.
Extract all subtitles from MKV video file, and make a copy of the video file without subtitles. Requires mkvmerge and subtitleedit CLI in PATH
@echo off
FOR %%A IN (*.mkv) DO (
echo %%~nxA
FOR /F %%I IN ('mkvmerge -i "%%A" ^| FIND /C "SubRip"') DO (IF %%I GTR 0 (echo SRT found in file) & (subtitleedit /convert "%%A" SubRip) else (echo SRT not found in file))
echo.&echo.
FOR /F %%I IN ('mkvmerge -i "%%A" ^| FIND /C "SubStationAlpha"') DO (IF %%I GTR 0 (echo ASS found in file) & (subtitleedit /convert "%%A" SubStationAlpha) else (echo ASS not found in file))
echo.&echo.
FOR /F %%I IN ('mkvmerge -i "%%A" ^| FIND /C "VobSub"') DO (IF %%I GTR 0 (echo. &echo. &echo. &echo. & echo VobSub - SUB/IDX found in file. You should use SubtitleEdit to convert the subtitles to a text-based format such as SRT) else (echo VobSub not found in file))
echo.&echo.
FOR /F %%I IN ('mkvmerge -i "%%A" ^| FIND /C "subtitles"') DO (IF %%I GTR 0 (rename "%%~nxA" old-"%%~nxA") & (mkvmerge -o "%%A" --no-subtitles "old-%%A"))
)
pause
@ScribbleGhost
Copy link
Author

Alternatively, instead of using mkvmerge.exe in the last line you could also use:

FOR /F %%I IN ('mkvmerge  -i "%%A" | FIND /C "subtitles"') DO (IF %%I GTR 0 (echo     SRT found in file) & (rename "%%A" "%%~dpnA"-ORIGINALBACKUP.%%~xA) & (ffmpeg -hide_banner -loglevel quiet -i "%%A" -sn -vcodec copy -acodec copy "%%A") else (echo     No subtitles found in the file...))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment