Skip to content

Convert-Frames2mp4

Converts frames to a .MP4 video

param([string]$SourcePattern = "", [string]$TargetFile = "")

try {
	if ($SourcePattern -eq "") { $SourcePattern = Read-Host "Enter file pattern of the image frames" }
	if ($TargetFile -eq "") { $TargetFile = Read-Host "Enter file path to the new video file" }
	$StopWatch = [system.diagnostics.stopwatch]::startNew()

	"? (1/3) Searching for ffmpeg..."
	& ffmpeg -L
	if ($lastExitCode -ne 0) { throw "Can't execute 'ffmpeg' - make sure ffmpeg is installed and available" }

	"? (2/3) Checking file pattern of the image frames..."
	$Files = (Get-ChildItem -path "$SourcePattern" -attributes !Directory)

	"? (2/3) Converting source image file..."
	& ffmpeg -framerate 24 -pattern_type glob -i "$SourcePattern" -c:v libx264 -pix_fmt yuv420p "$TargetFile"

	[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
	"? converted $($Files.Count) image frames to video $TargetFile in $Elapsed sec."
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the file pattern of the image frames

An interactive directory of PowerShell scripts.