kh_concat.bat

Browser view only. Use the download link if you want to save the file.

Back to Toolbox
@echo off
if x%1x == xx goto error1
:: You can force a join type here, or use auto
:: set methodtype=thorough
:: set methodtype=quick
:: set methodtype=binary
set methodtype=auto


setlocal enabledelayedexpansion

set argCount=0
for %%x in (%*) do (
   set /A argCount+=1
   set "argVec[!argCount!]=%%~x"
)

echo Number of processed arguments: %argCount%

echo. >mylist.txt
for /L %%i in (1,1,%argCount%) do echo file '!argVec[%%i]!'>>mylist.txt

echo Joining these files:
type mylist.txt
echo.
timeout /t 4 >nul

if /i not [%methodtype%] == [auto] goto method%methodtype%
:: if we're here, it's on auto
if /i [%~x1] == [.mts] goto methodbinary
if /i [%~x1] == [.mkv] goto methodquick
if /i [%~x1] == [.vob] goto methodbinary
if /i [%~x1] == [.mp4] goto methodquick
if /i [%~x1] == [.mov] goto methodquick
goto methodquick



:methodquick
	if /i not [%~x1] == [.mts] goto nowarn1
	echo. WARNING: Using Quick FFmpeg join, but file is MTS!
	timeout /t 4 >nul
	:nowarn1
	echo Launching FFMPEG for Quick FFmpeg concat...
	ffmpeg -f concat -safe 0 -i "mylist.txt" -c:v copy -c:a copy joined%~x1
goto postconvert

:methodthorough
	if /i not [%~x1] == [.mts] goto nowarn2
	echo. WARNING: Using Quick FFmpeg join, but file is MTS!
	timeout /t 4 >nul
	:nowarn2
	echo Launching FFMPEG for concat (Thorough mode)...
	ffmpeg -f concat -safe 0 -i "mylist.txt" -q:v 0 joined%~x1
goto postconvert

:methodbinary
	if /i [%~x1] == [.mts] goto nowarn3
	echo. WARNING: BINARY MERGE being used on %~x1 file!
	timeout /t 4 >nul
	:nowarn3

	set sourcepart="%~nx1" + "%~nx2"
		if exist %3 set sourcepart=%sourcepart% + "%~nx3"
		if exist %4 set sourcepart=%sourcepart% + "%~nx4"
		if exist %5 set sourcepart=%sourcepart% + "%~nx5"
		if exist %6 set sourcepart=%sourcepart% + "%~nx6"
		if exist %7 set sourcepart=%sourcepart% + "%~nx7"
		if exist %8 set sourcepart=%sourcepart% + "%~nx8"
		if exist %9 set sourcepart=%sourcepart% + "%~nx9"
		echo. Joining files in Binary mode. This could take a while...
		::echo Debug: Zero param="%0" and First param="%1" and sourcepart = "%sourcepart%"  Ext=%~x1
		copy /b %sourcepart% joined%~x1
goto postconvert


:postconvert
del mylist.txt
goto end

:error1
	echo Usage: %~n0 [file1 file2 file3 ... ] for concat together
	echo.
	echo Spaces in filenames are now supported!
	goto end

:end
timeout /t 6