View difference between Paste ID: 3qH3r7Gp and yNmMfMdm
SHOW: | | - or go back to the newest paste.
1
@echo off
2
SetLocal EnableDelayedExpansion
3
title %~n0
4
5
:: only process these input files
6
set supported_formats=avi,bik,flv,m2ts,m4p,m4v,mkv,mov,mp2,mp4,mpg,mpeg,mpe,mpv,mts,qt,swf,wmv,xmf,webm
7
8
:: temporary created txt file for concat list
9
set filelist=temp_concat.txt
10
11
set playsound=true
12
13
:: check for input files
14
if "%~1"=="" ( echo ERROR: NO INPUT & echo  & pause & goto :eof ) else (
15
if "%~2"=="" ( echo ERROR: only ONE input file & pause & goto :eof )
16
if NOT "%cd%\"=="%~dp1" cd /d "%~dp1"
17
)
18
19
:: delete filelist is exists
20
if exist %filelist% del %filelist%
21
22
:: iterate_files
23
FOR %%A IN (%*) DO CALL :LogFile "%%~A"
24
if exist %filelist% goto :ffmpeg
25
goto :eof
26
27
:LogFile
28
for %%G in (%supported_formats%) do (
29
	if /i %~x1==.%%G (
30
		if "!first!"=="" (
31
			set "first=%~n1"
32
			set "extension=%~x1"
33
			if /i !extension!==.mp4 CALL :check_audio_mp4 "%~1"
34
		) else (
35
			set "last=%~n1"
36
		)
37
		echo ^file '%~nx1'>>%filelist%
38
		goto :eof
39
	)
40
)
41
echo ERROR: %~1 - extension not supported & goto :eof
42
43
:: if audio stream is not supported in mp4 container, switch to mov (Quicktime). So far I included conditionals for uncompressed pcm, flac and alac audio.
44
:check_audio_mp4
45
for /f "tokens=*" %%L in ('ffprobe.exe -hide_banner -show_streams -select_streams a -show_entries stream^=codec_name -loglevel quiet "%~1"') do (
46
	echo "%%L"| find /i "codec_name" > nul 2>&1
47
	if !ErrorLevel!==0 (
48
		for /f "tokens=2 delims==" %%C in ("%%L") do (
49
			echo "%%C"| find /i "pcm" && ( set "extension=.mov" & goto :eof)
50
			if /i "%%C"=="flac" set "extension=.mov" & goto :eof
51
			if /i "%%C"=="alac" set "extension=.mov" & goto :eof
52
		)
53
	)
54
)
55
goto :eof
56
57
:ffmpeg
58
title Concat %first% - %last%  ^>   %first%-%last%_merged%extension%"
59
set "output=%first%-%last%_merged%extension%"
60
ffmpeg.exe -f concat -safe 0 -i %filelist% -map 0:v -map 0:a? -c copy "%output%"
61
if not !errorlevel!==0 CALL :ErrorSubroutine %output%
62
del %filelist%
63
if defined goterror ( pause & goto :eof)
64
if %playsound%==true powershell -c (New-Object Media.SoundPlayer "C:\Windows\Media\tada.wav").PlaySync();
65
goto :eof
66
67
:: if output file is empty, deletes it. prints some messages. stores goterror var.
68
:ErrorSubroutine
69
title ERROR ^^! ^^! ^^!
70
if "%~z1"=="0" del %1
71
CALL :Message "ERROR: FILE OUTPUT FAILED"
72
set goterror=true
73
echo 
74
goto :eof
75
76
:: prints simple message
77
:Message
78
echo.
79
echo ----------------------------------
80
echo %~1
81
if not "%~2"=="" echo %~2
82
if not "%~3"=="" echo %~3
83
echo ----------------------------------
84
goto :eof
85