How do I use ffmpeg / mkvtoolnix to strip non-English audio streams and subtitle streams?
Posted: 12 Oct 2023, 13:12
After trying a few different found online solutions that most were python scripts or making a bat file use ffmpeg and mkvtoolnix (the gui front end for command line backend tools) I read a few comments and found this on another forum. I don’t remember the specific one so I’m not able to give specific credit. I can say it’s not mine. Also it seems to work in a limited way. It’ll do what is asked but instead of all files in a folder it will process some. Not sure why not all. Anyway the goal is basically the same but done in filebot using the groovy scripting. I basically don’t want any subtitles, I don’t want other language selections. Less to get set right only to have it start again the next episode etc.
At present the goal is to:
—————
Filebot correctly renames the file via AMC.
- demux the file, so audio streams and video streams can be selected specifically.
- Remux with only selected audio stream (English), set English Audio track as the first and only audio stream. Copy the video stream without modifying it. Remux to .MKv file and output to different folder.
-Retitle remux to match the file name and save.
————————-
##The code found to do this##
At present the goal is to:
—————
Filebot correctly renames the file via AMC.
- demux the file, so audio streams and video streams can be selected specifically.
- Remux with only selected audio stream (English), set English Audio track as the first and only audio stream. Copy the video stream without modifying it. Remux to .MKv file and output to different folder.
-Retitle remux to match the file name and save.
————————-
##The code found to do this##
batch: Select all
@echo off
if not exist NEW\*.* md NEW
if exist temp\*.* (del /q temp\*.*) else md temp
for %%a in ("*.mkv") do call :Process "%%a"
goto :end
:Process
:: Set the first stream, normally the video, to English. (In case it's not English.)
ffmpeg -i "%~1" -vcodec copy -acodec copy -metadata:s:0 language=eng -y "temp\%~1"
:: Copy the English streams (video+audio) to a new video.
ffmpeg -i "temp\%~1" -vcodec copy -acodec copy -map 0:m:language:eng -y "NEW\%~1"
goto :eof
:end
rd /s /q temp