View Full Version : Replace video with new video on many mkv
_kermit
11th July 2021, 17:41
I have a few MKVs I want to replace the video track
I can't figure out how to do this scripted (in this case powershell, but I'm fine even with batch).
the principle is always like that:
* New Video Track (to be added)
* Old Video Track (to be removed)
* Audio (everything else kept)
* subs
* chapter, global etc.
So, keep everything else while replacing the video with another file (always same name).
any pointers, examples?
SeeMoreDigital
11th July 2021, 18:03
You can add and remove, video, audio and subtitle tracks/streams using MKVToolNix GUI
_kermit
11th July 2021, 18:59
You can add and remove, video, audio and subtitle tracks/streams using MKVToolNix GUI
"I can't figure out how to do this scripted (in this case powershell, but I'm fine even with batch)." :)
therube
14th July 2021, 21:02
This is very basic. Test & see if something like this works for you.
MUX - V_A - out.mkv.BAT:
@ECHO OFF
ECHO MUX 0:VIDEO:CLIP:0 with 1:AUDIO:CLIP:0 -- *IN THAT ORDER, only!*
ECHO much like how Video To Video does it, as opposed to "MUX" which is
ECHO really a "JOIN"
ECHO.
ECHO therube 02/09/2015
ECHO.
ECHO VIDEO:
ECHO %1
ECHO AUDIO:
ECHO %2
ECHO.
ECHO OUTPUT TO .mkv, as that allows stuff like mp4 vid + opus aud, which won't work in .mp4
ECHO.
PAUSE
ECHO.
SET OUT=C:\OUT
ECHO OUT=: %OUT%
SET OFILE=%OUT%\%~n1_MUX_AV%~x1.mkv
ECHO Output filename:
ECHO "%OFILE%"
SET LOG=%OUT%\MUX_AV.TXT
ECHO.
PAUSE
SET VIDEO=%1
SET AUDIO=%2
ECHO %VIDEO% > %LOG%
ECHO %AUDIO% >> %LOG%
ECHO. >> %LOG%
ECHO ffmpeg >> %LOG%
ECHO -i %VIDEO% >> %LOG%
ECHO -i %AUDIO% >> %LOG%
ECHO -c copy -map 0:v:0 -map 1:a:0 -bsf:a aac_adtstoasc >> %LOG%
ECHO "%OFILE%" >> %LOG%
ECHO. >> %LOG%
ECHO ========================================================================================= >> %LOG%
ECHO. >> %LOG%
SF %LOG%
PAUSE
:: ffmpeg -i %VIDEO% -i %AUDIO% -c copy -map 0:v:0 -map 1:a:0 -bsf:a aac_adtstoasc "%OFILE%" 2>&1 | tee -a %LOG%
ffmpeg -i %VIDEO% -i %AUDIO% -c copy -map 0:v:0 -map 1:a:0 "%OFILE%" 2>&1 | tee -a %LOG%
ECHO.
PAUSE
touch "%OFILE%" --reference=%1
PAUSE
EXIT
In my case, the intent is to MUX a new audio track in place of the existing.
You would want to adjust it such that the video track is replaced.
The file with your video & the file with your audio need to be in that order, video, then audio (at least as written above).
Touch is the UNIX touch command. Can be ignored if you don't care about setting the file's date to that of the existing (video) file.
tee is the UNIX tee command.
SF is (a renamed) ShowTx (https://www.horstmuc.de/show.htm). Simply substitute (Windows) TYPE if you want.
_kermit
15th July 2021, 12:42
This is very basic. Test & see if something like this works for you.
MUX - V_A - out.mkv.BAT:
@ECHO OFF
ECHO MUX 0:VIDEO:CLIP:0 with 1:AUDIO:CLIP:0 -- *IN THAT ORDER, only!*
ECHO much like how Video To Video does it, as opposed to "MUX" which is
ECHO really a "JOIN"
ECHO.
ECHO therube 02/09/2015
ECHO.
ECHO VIDEO:
ECHO %1
ECHO AUDIO:
ECHO %2
ECHO.
ECHO OUTPUT TO .mkv, as that allows stuff like mp4 vid + opus aud, which won't work in .mp4
ECHO.
PAUSE
ECHO.
SET OUT=C:\OUT
ECHO OUT=: %OUT%
SET OFILE=%OUT%\%~n1_MUX_AV%~x1.mkv
ECHO Output filename:
ECHO "%OFILE%"
SET LOG=%OUT%\MUX_AV.TXT
ECHO.
PAUSE
SET VIDEO=%1
SET AUDIO=%2
ECHO %VIDEO% > %LOG%
ECHO %AUDIO% >> %LOG%
ECHO. >> %LOG%
ECHO ffmpeg >> %LOG%
ECHO -i %VIDEO% >> %LOG%
ECHO -i %AUDIO% >> %LOG%
ECHO -c copy -map 0:v:0 -map 1:a:0 -bsf:a aac_adtstoasc >> %LOG%
ECHO "%OFILE%" >> %LOG%
ECHO. >> %LOG%
ECHO ========================================================================================= >> %LOG%
ECHO. >> %LOG%
SF %LOG%
PAUSE
:: ffmpeg -i %VIDEO% -i %AUDIO% -c copy -map 0:v:0 -map 1:a:0 -bsf:a aac_adtstoasc "%OFILE%" 2>&1 | tee -a %LOG%
ffmpeg -i %VIDEO% -i %AUDIO% -c copy -map 0:v:0 -map 1:a:0 "%OFILE%" 2>&1 | tee -a %LOG%
ECHO.
PAUSE
touch "%OFILE%" --reference=%1
PAUSE
EXIT
In my case, the intent is to MUX a new audio track in place of the existing.
You would want to adjust it such that the video track is replaced.
The file with your video & the file with your audio need to be in that order, video, then audio (at least as written above).
Touch is the UNIX touch command. Can be ignored if you don't care about setting the file's date to that of the existing (video) file.
tee is the UNIX tee command.
SF is (a renamed) ShowTx (https://www.horstmuc.de/show.htm). Simply substitute (Windows) TYPE if you want.
ffmpeg instead of mkvtoolnix. Didn't think of that.
Would the remaining parts of the original mkv be kept for the new one when just replacing the video?
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.