Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;This script combines all videos in a folder into a single video file, fixing resolution differences by
- ; making the width and height of the resulting video the largest width and height of the consituent videos.
- ;
- ;Requires all videos use the same file extension and have a two digit serialized suffix. This allows the script
- ; to group together videos i.e. "abc 01.mp4|abc 02.mp4|abc 03.mp4" from "def 01.mp4|def 02.mp4"
- ;
- ;Also requires this function (https://www.autohotkey.com/boards/viewtopic.php?style=7&t=3806) as well as
- ; ffmpeg to be added to your path variable.
- ;
- ;Final output is rendered into a subfolder, and original files are not deleted.
- #NoEnv
- #include FileGetProperties.ahk
- SetWorkingDir %A_ScriptDir%
- aWidth := []
- aHeight := []
- aName := []
- FileSelectFolder, vWorkingDirectory
- if ErrorLevel
- ExitApp
- FileCreateDir, %vWorkingDirectory%\Concatenated Videos
- vFileList := ""
- Loop, Files, %vWorkingDirectory%\*
- vFileList .= A_LoopFileLongPath "`n"
- Sort, vFileList
- Loop, parse, vFileList, `n
- {
- if (((aName.Length() > 1) and (InStr(A_LoopField, "01." . vExtension))) or (A_LoopField = ""))
- {
- vMaxWidth := Max(aWidth*)
- vMaxHeight := Max(aHeight*)
- GoSub, FFMPEG
- if (A_LoopField = "")
- {
- FileDelete, %vWorkingDirectory%\ConcatList.txt
- Break
- }
- aWidth := []
- aHeight := []
- aName := []
- }
- aWidth.Push(FGP_Value(A_LoopField,316))
- aHeight.Push(FGP_Value(A_LoopField,314))
- aName.Push(A_LoopField)
- SplitPath, A_LoopField,vFileName,,vExtension
- }
- ExitApp
- FFMPEG:
- FileDelete, %vWorkingDirectory%\ConcatList.txt
- Loop
- {
- vPadX := Format("{:d}",((vMaxWidth - aWidth[A_Index])/2))
- vPadY := Format("{:d}",((vMaxHeight - aHeight[A_Index])/2))
- vConcatName := vWorkingDirectory . "\Concatenated Videos\" . SubStr(vFileName, 1, -7) . "." . vExtension
- vTempName1 := aName[A_Index]
- vTempName2 := SubStr(aName[A_Index], 1, -4) . "b." . vExtension
- FileAppend, file '%vTempName2%'`n, %vWorkingDirectory%\ConcatList.txt
- runwait, ffmpeg -i "%vTempName1%" -filter_complex "[0]pad=w=%vMaxWidth%:h=%vMaxHeight%:x=%vPadX%:y=%vPadY%:color=black" "%vTempName2%"
- if (A_Index = aName.Length())
- Break
- }
- Sleep 500
- runwait, ffmpeg -f concat -safe 0 -i "%vWorkingDirectory%\ConcatList.txt" -c copy "%vConcatName%"
- FileDelete, %vWorkingDirectory%\*b.%vExtension%
- Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement