<?xml version="1.0" encoding="windows-1252"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>VideoHelp Forum - Programming</title>
		<link>https://forum.videohelp.com/</link>
		<description>Everything about programming for Digital Video and multimedia applications (e.g. using Delphi/Java/VB/C/C++ etc.. to write apps for digital video). </description>
		<language>en</language>
		<lastBuildDate>Mon, 15 Jun 2026 17:40:14 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>https://forum.videohelp.com/images/misc/rss.png</url>
			<title>VideoHelp Forum - Programming</title>
			<link>https://forum.videohelp.com/</link>
		</image>
		<item>
			<title>SamA MKV Batch Script | Remove Tracks by NAMES | Add External Tracks</title>
			<link>https://forum.videohelp.com/threads/420701-SamA-MKV-Batch-Script-%7C-Remove-Tracks-by-NAMES-%7C-Add-External-Tracks?goto=newpost</link>
			<pubDate>Sun, 14 Jun 2026 13:39:48 GMT</pubDate>
			<description><![CDATA[Hi Friends, 
 
Have you ever wanted to tidy up your MKV collection but never had the time or energy? 
Remove unwanted tracks to save storage space? Or add external tracks to create a clean, neat collection? 
If the answer is yes, you're in the right place! 
 
I'm excited to share a batch script I...]]></description>
			<content:encoded><![CDATA[<div>Hi Friends,<br />
<br />
Have you ever wanted to tidy up your MKV collection but never had the time or energy?<br />
Remove unwanted tracks to save storage space? Or add external tracks to create a clean, neat collection?<br />
If the answer is yes, you're in the right place!<br />
<br />
I'm excited to share a batch script I created to remux MKV files: <b><font color="red">&quot;SamA MKV Batch Script&quot;.</font></b><br />
This script allows you to do all the following at the same time:<br />
<br />
1) Remove/keep only audio and subtitle tracks using their IDs and Languages<br />
2) Remove/keep only audio and subtitle tracks using their <b><font color="red">Names!</font></b><br />
3) Add external audio and subtitle tracks<br />
<br />
Filtering tracks using their Names is useful when the IDs are not consistent and<br />
the Languages are missing or not unique, like with some commentary tracks.<br />
<br />
<br />
<br />
<br />
<b><font size="3"><font color="blue">------------------------------------EDITING INSTRUCTIONS------------------------------------<br />
</font></font></b><br />
1) Replace &quot;D:\<a class="contentlink" href="https://www.videohelp.com/software/MKVToolNix" target="_blank" rel="nofollow">MKVToolNix</a> 99.0 x64\<a class="contentlink" href="https://www.videohelp.com/software/MKVToolNix" target="_blank" rel="nofollow">mkvmerge</a>.exe&quot; with your mkvmerge path<br />
<br />
2) • Delete or replace &quot;1,2,eng&quot; with the Track IDs and Languages<br />
        you want to remove/keep only (separated by a Comma ,)<br />
     • Comma , here means &quot;And&quot;. &quot;1,2,eng&quot; means &quot;Track IDs/Languages: 1 And 2 And eng&quot;<br />
     • Do the same for the Subs<br />
<br />
3) • Delete or replace &quot;Good_Audio¤Great_Audio¤Epic_Audio&quot; with the Track Names<br />
        you want to remove/keep only (separated by a Currency Sign ¤)<br />
     • Currency Sign ¤ here means &quot;And&quot;. &quot;Good_Audio¤Great_Audio¤Epic_Audio&quot; means<br />
        &quot;Track Names: Good_Audio And Great_Audio And Epic_Audio&quot;<br />
     • Do the same for the Subs<br />
<br />
4) • Replace &quot;MUXED_%~n1.mkv&quot; with the new mkv filename pattern<br />
     • MUXED_ here is a prefix. You can also add a suffix like %~n1_NEW.mkv<br />
<br />
5) • Replace &quot;%~n1*.ac3&quot; with the filename pattern and extension of the external tracks you want to add<br />
     • Delete or replace &quot;jpn&quot; with the Track Language you want<br />
     • Delete or replace &quot;Jpn_Audio&quot; with the Track Name you want<br />
     • Delete or replace &quot;yes&quot; with &quot;no&quot; for the Default Track flag<br />
     • Do the same for the Subs<br />
<br />
6) • Delete the Caret Exclamation ^! if you want to keep only the specified tracks (from Points 2 and 3 above)<br />
     • Caret Exclamation ^! here means &quot;Remove&quot;. ^!!FINAL_AUDIO! means &quot;Remove the specified audio tracks&quot;.<br />
        !FINAL_AUDIO! means &quot;keep only the specified audio tracks&quot;<br />
     • Do the same for the Subs<br />
<br />
<br />
<br />
<br />
<a class="contentlink" href="https://postimg.cc/CdKXQN41" target="_blank" rel="nofollow"><img style="max-width:100%;max-heigth:100%" src="https://i.postimg.cc/sfPz1HQp/Editing.png" border="0" alt="" /></a><br />
<br />
<br />
<br />
<br />
<b><font size="3"><font color="blue">------------------------------------SamA MKV BATCH SCRIPT------------------------------------<br />
</font></font></b><br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">@echo off<br />
chcp 1252 &gt;nul<br />
color 0E<br />
setlocal enabledelayedexpansion<br />
<br />
set &quot;MKVMERGE=D:\MKVToolNix 99.0 x64\mkvmerge.exe&quot;<br />
<br />
set &quot;AUDIO_IDS=1,2,eng&quot;<br />
set &quot;SUBS_IDS=7,8,jpn&quot;<br />
<br />
set &quot;AUDIO_NAMES=Good_Audio¤Great_Audio¤Epic_Audio&quot;<br />
set &quot;SUBS_NAMES=Good_Subs¤Great_Subs¤Epic_Subs&quot;<br />
<br />
goto :MAIN<br />
<br />
:SET_NEW_FILE<br />
set &quot;NEW_FILE=MUXED_%~n1.mkv&quot;<br />
exit /b<br />
<br />
:ADD_TRACKS<br />
for %%n in (&quot;%~n1*.ac3&quot;) do (<br />
set &quot;ADD_AUDIO=!ADD_AUDIO! --language 0:jpn --track-name 0:&quot;Jpn_Audio&quot; --default-track 0:yes &quot;%%n&quot;&quot;<br />
)<br />
<br />
for %%o in (&quot;%~n1*.ass&quot;) do (<br />
set &quot;ADD_SUBS=!ADD_SUBS! --language 0:eng --track-name 0:&quot;Eng_Subs&quot; --default-track 0:yes &quot;%%o&quot;&quot;<br />
)<br />
exit /b<br />
<br />
:FINAL_FLAGS<br />
set &quot;FINAL_AUDIO=-a ^!!FINAL_AUDIO!&quot;<br />
set &quot;FINAL_SUBS=-s ^!!FINAL_SUBS!&quot;<br />
exit /b<br />
<br />
<br />
:MAIN<br />
set &quot;AUDIO_COUNT=0&quot;<br />
if not defined AUDIO_NAMES goto :AUDIO_PARSED<br />
:PARSE_AUDIO<br />
for /f &quot;tokens=1,* delims=¤&quot; %%a in (&quot;!AUDIO_NAMES!&quot;) do (<br />
set /a AUDIO_COUNT+=1<br />
set &quot;AUDIO_MATCHES[!AUDIO_COUNT!]=%%a&quot;<br />
set &quot;AUDIO_NAMES=%%b&quot;<br />
)<br />
if defined AUDIO_NAMES goto :PARSE_AUDIO<br />
:AUDIO_PARSED<br />
<br />
set &quot;SUBS_COUNT=0&quot;<br />
if not defined SUBS_NAMES goto :SUBS_PARSED<br />
:PARSE_SUBS<br />
for /f &quot;tokens=1,* delims=¤&quot; %%c in (&quot;!SUBS_NAMES!&quot;) do (<br />
set /a SUBS_COUNT+=1<br />
set &quot;SUBS_MATCHES[!SUBS_COUNT!]=%%c&quot;<br />
set &quot;SUBS_NAMES=%%d&quot;<br />
)<br />
if defined SUBS_NAMES goto :PARSE_SUBS<br />
:SUBS_PARSED<br />
<br />
for /f &quot;delims=&quot; %%e in ('dir /b *.mkv') do (<br />
set &quot;ID=&quot;<br />
set &quot;TRACK_NAME=&quot;<br />
set &quot;TYPE=&quot;<br />
set &quot;SUPER_AUDIO_IDS=&quot;<br />
set &quot;SUPER_SUBS_IDS=&quot;<br />
set &quot;ADD_AUDIO=&quot;<br />
set &quot;ADD_SUBS=&quot;<br />
<br />
call :SET_NEW_FILE &quot;%%e&quot;<br />
<br />
echo.<br />
echo ==============================================================================================================<br />
echo&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  *** PROCESSING FILE: &quot;%%e&quot; ***<br />
echo ==============================================================================================================<br />
echo.<br />
<br />
for /f &quot;tokens=1,* delims=:&quot; %%f in ('cmd /c &quot;&quot;!MKVMERGE!&quot; -J &quot;%%~fe&quot;&quot;') do (<br />
set &quot;KEY=%%f&quot;<br />
set &quot;VAL=%%g&quot;<br />
<br />
for /f &quot;tokens=* delims= &quot; %%h in (&quot;!KEY!&quot;) do set &quot;KEY=%%h&quot;<br />
for /f &quot;tokens=* delims= &quot; %%i in (&quot;!VAL!&quot;) do set &quot;VAL=%%i&quot;<br />
set &quot;KEY=!KEY:&quot;=!&quot;<br />
set &quot;VAL=!VAL:&quot;=!&quot;<br />
if &quot;!VAL:~-1!&quot;==&quot;,&quot; set &quot;VAL=!VAL:~0,-1!&quot;<br />
<br />
if &quot;!KEY!&quot;==&quot;id&quot;&nbsp; &nbsp; &nbsp; &nbsp;  set &quot;ID=!VAL!&quot;<br />
if &quot;!KEY!&quot;==&quot;track_name&quot; set &quot;TRACK_NAME=!VAL!&quot;<br />
if &quot;!KEY!&quot;==&quot;type&quot; (<br />
set &quot;TYPE=!VAL!&quot;<br />
<br />
if &quot;!TYPE!&quot;==&quot;audio&quot; (<br />
for /L %%j in (1,1,!AUDIO_COUNT!) do (<br />
echo(&quot;!TRACK_NAME!&quot;| findstr /I /C:&quot;!AUDIO_MATCHES[%%j]!&quot; &gt;nul &amp;&amp; (<br />
REM FOR FULL MATCHES, REPLACE LINE ABOVE WITH...&nbsp;  if /I &quot;!TRACK_NAME!&quot;==&quot;!AUDIO_MATCHES[%%j]!&quot; (<br />
if defined SUPER_AUDIO_IDS (set &quot;SUPER_AUDIO_IDS=!SUPER_AUDIO_IDS!,!ID!&quot;) else set &quot;SUPER_AUDIO_IDS=!ID!&quot;<br />
)<br />
)<br />
)<br />
<br />
if &quot;!TYPE!&quot;==&quot;subtitles&quot; (<br />
for /L %%l in (1,1,!SUBS_COUNT!) do (<br />
echo(&quot;!TRACK_NAME!&quot;| findstr /I /C:&quot;!SUBS_MATCHES[%%l]!&quot; &gt;nul &amp;&amp; (<br />
REM FOR FULL MATCHES, REPLACE LINE ABOVE WITH...&nbsp;  if /I &quot;!TRACK_NAME!&quot;==&quot;!SUBS_MATCHES[%%l]!&quot; (<br />
if defined SUPER_SUBS_IDS (set &quot;SUPER_SUBS_IDS=!SUPER_SUBS_IDS!,!ID!&quot;) else set &quot;SUPER_SUBS_IDS=!ID!&quot;<br />
)<br />
)<br />
)<br />
<br />
set &quot;ID=&quot;<br />
set &quot;TRACK_NAME=&quot;<br />
set &quot;TYPE=&quot;<br />
)<br />
)<br />
<br />
call :ADD_TRACKS &quot;%%e&quot;<br />
<br />
set &quot;FINAL_AUDIO=&quot;<br />
if defined AUDIO_IDS set &quot;FINAL_AUDIO=!AUDIO_IDS!&quot;<br />
if defined SUPER_AUDIO_IDS (<br />
if defined FINAL_AUDIO (<br />
set &quot;FINAL_AUDIO=!FINAL_AUDIO!,!SUPER_AUDIO_IDS!&quot;<br />
) else (<br />
set &quot;FINAL_AUDIO=!SUPER_AUDIO_IDS!&quot;<br />
)<br />
)<br />
<br />
set &quot;FINAL_SUBS=&quot;<br />
if defined SUBS_IDS set &quot;FINAL_SUBS=!SUBS_IDS!&quot;<br />
if defined SUPER_SUBS_IDS (<br />
if defined FINAL_SUBS (<br />
set &quot;FINAL_SUBS=!FINAL_SUBS!,!SUPER_SUBS_IDS!&quot;<br />
) else (<br />
set &quot;FINAL_SUBS=!SUPER_SUBS_IDS!&quot;<br />
)<br />
)<br />
<br />
call :FINAL_FLAGS<br />
<br />
&quot;!MKVMERGE!&quot; -o &quot;!NEW_FILE!&quot; !FINAL_AUDIO! !FINAL_SUBS! &quot;%%e&quot; !ADD_AUDIO! !ADD_SUBS!<br />
)<br />
<br />
echo.<br />
echo ==============================================================================================================<br />
echo&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  *** MISSION ACCOMPLISHED ***<br />
echo ==============================================================================================================<br />
echo.<br />
<br />
pause</code><hr />
</div> <br />
<br />
<br />
<b><font size="3"><font color="blue">------------------------------------USE INSTRUCTIONS------------------------------------<br />
</font></font></b><br />
1) You need to have MKVToolNix as the script uses mkvmerge<br />
2) Copy everything starting with <b>@echo off</b> and ending with <b>pause</b><br />
3) Paste it into Notepad<br />
4) Choose ANSI encoding before saving<br />
5) Save it as a .bat file<br />
6) Place the batch file inside the folder containing your MKV files<br />
7) Open the file to run the script<br />
8) • <b><font color="red">IMPORTANT:</font></b> Check the <b>&quot;REM FOR FULL MATCHES, REPLACE LINE ABOVE WITH...&quot;</b><br />
        parts for full Track Name matching<br />
     • If left unchanged, &quot;Comm&quot; (or any other part of &quot;Commentary&quot;) will match Track Name &quot;Commentary&quot;<br />
     • If replaced, only &quot;Commentary&quot; will match Track Name &quot;Commentary&quot;<br />
9) External Tracks to be added must be in the same folder as your MKV files and must start with<br />
     the same filename. For example: Episode01.mkv, then Episode01.ac3 and Episode01_Subs01.ass<br />
10) Avoid editing anything else unless you know what you're doing<br />
11) <b><font color="red">Always test the new MKV files</font></b> before deleting the originals<br />
<br />
<br />
<br />
<br />
<b><font size="3"><font color="blue">------------------------------------FINAL NOTES------------------------------------</font></font></b><br />
<br />
1) I've attached an archived copy of <b>SamA MKV Batch Script.bat</b> here for your convenience<br />
2) The script should work reliably with most MKV files. The only requirements are:<br />
     • The mkvmerge JSON structure remains consistent across MKVToolNix versions.<br />
         If the JSON structure changes in a future version, the parsing logic may need to be updated<br />
     • The Currency Sign ¤ (which is extremely rare) is not used in Track Names.<br />
         If it is used, simply change the delimiter to another rare character<br />
3) The !MKVMERGE! command at the bottom of the script can be customized to add<br />
     extra functions, like track ordering, chapter handling, and attachment support. For example:<br />
     <div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&nbsp; &nbsp;  &quot;!MKVMERGE!&quot; -o &quot;!NEW_FILE!&quot; !FINAL_AUDIO! !FINAL_SUBS! &quot;%%e&quot; !ADD_AUDIO! !ADD_SUBS! --track-order 0:2,0:1</code><hr />
</div> 4) Feel free to share or modify the script</div>


	<div style="padding:10px">

	

	

	

	
		<fieldset class="fieldset">
			<legend>Attached Files</legend>
			<ul>
			<li>
	<img class="inlineimg" src="/rar.gif" alt="File Type: rar" />
	<a class="contentlink" href="attachments/92708-1781514055/SamA MKV Batch Script.rar">SamA MKV Batch Script.rar</a> 
(132.7 KB)
</li> 
			</ul>
		</fieldset>
	

	</div>
 ]]></content:encoded>
			<category domain="https://forum.videohelp.com/forums/38-Programming">Programming</category>
			<dc:creator>SamA89</dc:creator>
			<guid isPermaLink="true">https://forum.videohelp.com/threads/420701-SamA-MKV-Batch-Script-%7C-Remove-Tracks-by-NAMES-%7C-Add-External-Tracks</guid>
		</item>
	</channel>
</rss>
