2024-11-08 12:38:20 +01:00
|
|
|
The *convert-frames2mp4.ps1* Script
|
|
|
|
===========================
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
|
|
convert-frames2mp4.ps1 [[-SourcePattern] <string>] [[-TargetFile] <string>]
|
|
|
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2023-05-26 12:20:18 +02:00
|
|
|
```powershell
|
|
|
|
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2023-05-26 12:20:18 +02:00
|
|
|
```powershell
|
|
|
|
<#
|
|
|
|
.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 video $TargetFile in $Elapsed sec."
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-11-20 11:52:20 +01:00
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:53)*
|