From 0ed21682954777860677a05f802c342904719004 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Fri, 3 Mar 2023 13:28:23 +0100 Subject: [PATCH] Added convert-frames2mp4.ps1 --- Scripts/convert-csv2txt.ps1 | 4 ++-- Scripts/convert-frames2mp4.ps1 | 41 ++++++++++++++++++++++++++++++++ Scripts/copy-image-blurred.ps1 | 2 +- Scripts/copy-image-pixelated.ps1 | 2 +- 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100755 Scripts/convert-frames2mp4.ps1 diff --git a/Scripts/convert-csv2txt.ps1 b/Scripts/convert-csv2txt.ps1 index 03efa40d..14567665 100755 --- a/Scripts/convert-csv2txt.ps1 +++ b/Scripts/convert-csv2txt.ps1 @@ -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 -} \ No newline at end of file +} diff --git a/Scripts/convert-frames2mp4.ps1 b/Scripts/convert-frames2mp4.ps1 new file mode 100755 index 00000000..8a9daafa --- /dev/null +++ b/Scripts/convert-frames2mp4.ps1 @@ -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 +} diff --git a/Scripts/copy-image-blurred.ps1 b/Scripts/copy-image-blurred.ps1 index c12c19ba..7464c66d 100755 --- a/Scripts/copy-image-blurred.ps1 +++ b/Scripts/copy-image-blurred.ps1 @@ -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])" diff --git a/Scripts/copy-image-pixelated.ps1 b/Scripts/copy-image-pixelated.ps1 index 4a3564d2..c38bc33e 100755 --- a/Scripts/copy-image-pixelated.ps1 +++ b/Scripts/copy-image-pixelated.ps1 @@ -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])"