Added convert-frames2mp4.ps1

This commit is contained in:
Markus Fleschutz 2023-03-03 13:28:23 +01:00
parent 4e215f4cd3
commit 0ed2168295
4 changed files with 45 additions and 4 deletions

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Converts a .CSV file into a text file
.DESCRIPTION
This PowerShell script converts a .CSV file into a text file.
This PowerShell script converts a .CSV file into a text file and prints it.
.PARAMETER Path
Specifies the path to the .CSV file
.EXAMPLE
@ -27,4 +27,4 @@ try {
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
}

41
Scripts/convert-frames2mp4.ps1 Executable file
View File

@ -0,0 +1,41 @@
<#
.SYNOPSIS
Converts frames to a .MP4 video
.DESCRIPTION
This PowerShell script converts multiple image frames into a video in MP4 format. It requires ffmpeg.
.PARAMETER SourcePattern
Specifies the file pattern of the image frames
.PARAMTER TargetFile
Specifies the path to the new video file.
.EXAMPLE
PS> ./convert-frames2mp4 C:\Frames\*.jpg C:\video.mp4
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
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 .MP4 video $TargetFile in $Elapsed sec."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -43,7 +43,7 @@ try {
$x += $increment
}
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✅ copied $ImageFile to $Frames frames in 📂$TargetDir in $Elapsed sec."
"✅ copied image $ImageFile to $Frames frames in 📂$TargetDir in $Elapsed sec."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -43,7 +43,7 @@ try {
}
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✅ copied $SourceFile to a series of 300 pixelated frames in 📂$TargetDir in $Elapsed sec."
"✅ copied image $SourceFile to 300 pixelated frames in 📂$TargetDir in $Elapsed sec."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"