v1.1 - more dynamic

This commit is contained in:
2021-12-23 10:57:46 +01:00
parent 212a058819
commit 1b76956795
2 changed files with 44 additions and 11 deletions

View File

@@ -1,28 +1,58 @@
# TimelapseGenerator.ps1
# Generates a customizable timelapse
#
# Changelog:
# v1.1 - A bit more dynamic, updated ffmpeg to newest available version, changed codec to x265, added parameter handling
# v1.0 - Initial concept
$Camera = "Skiakersgutua"
$Style = "Monthly"
if ($Style -eq "Monthly") {
$Rate = "2"
}
else { $Rate = "10"}
param ($Camera='Skiakersgutua',$Style='Daily',[string]$Month)
switch ($Style) {
"Daily" { $rate = "10"; break}
"Monthly" { $rate = "2"; break}
# "Yearly" { $rate = "2"; break}
default {"Something else happened"; break}
}
$TempProcessingDir = "C:\Temp\AutoTimelapse\" # Photos are copied here for temporary processing
$TimelapsePhotoSrc = "\\megabyte.home.zyrex.org\Vault\Vault\Upload\Webcam\Timelapse\" # Here lies all the photos
$CompletedTimelapseDir = "\\megabyte.home.zyrex.org\Mediavault\Privat\Timelapses\"
# Get Current Month
$MonthCur = Get-Date -Format MM
# Get Last month
$MonthProcess = $MonthCur - 1
# Use passed parameter if it exists
if ($Month) {
$MonthProcess = $Month
}
# Copy photos to correct folder
$photos = Get-ChildItem $TimelapsePhotoSrc
$Copyphotos = $photos | Where-Object {$_.name -Like "$($Camera)_????$($MonthProcess)??_12-00-??.jpg"}
if ($style -eq "Monthly") {
$Copyphotos = $photos | Where-Object {$_.name -Like "$($Camera)_????$($MonthProcess)??_12-00-??.jpg"}
}
elseif ($Style -eq "Daily") {
$photos = $photos|Where-Object {$_.length -gt 150000}
$Copyphotos = $photos | Where-Object {$_.name -Like "$($Camera)_????$($MonthProcess)*"}
}
#elseif ($Style -eq "Yearly") {
# # Takes all previous monthlies and combines them to a yearly timelapse
# $MonthlyTimelapses = Get-ChildItem $CompletedTimelapseDir | Where-Object {$_.Name -like "*.mkv"}
# foreach ($file in $MonthlyTimelapses) {
# ""
# }
#}
$regex = '(?<filedate>\d{4}(?:\.|-|_)?\d{2}(?:\.|-|_)?\d{2})[^0-9]'
If($Copyphotos[1] -match $regex) {
$date = $Matches['filedate'] -replace '(\.|-|_)',''
$date = [datetime]::ParseExact($date,'yyyyMMdd',[cultureinfo]::InvariantCulture)
$Year = Get-date $date -Format yyyy
}
foreach ($lapse in $Copyphotos) {
Copy-Item $lapse.fullname $TempProcessingDir\
@@ -32,9 +62,12 @@ $i = 1
Get-ChildItem $TempProcessingDir | Sort-Object | ForEach-Object { Rename-Item $_.FullName -NewName ("$($Camera)_{0:D5}.jpg" -f $i++) }
# Make timelapse
# -crf bestemmer kvalitet. 20 er default, 51 er dårligst
# første -r er fin på 10 for kjapp timelapse, -r 5 er fin for litt roligere. andre -r kan være 30 eller 25? (Quick 25, normal 10)
& "./ffmpeg.exe" -r $rate -i "$tempProcessingDir\$($Camera)_%05d.jpg" -s hd1080 -c:v libx264 -r 30 -pix_fmt yuv420p -preset slow -crf 20 \\megabyte.home.zyrex.org\Mediavault\Privat\Timelapses\Gaardsplass_2020-$MonthProcess.mkv
if ($Style -eq "Daily" -or $style -eq "Monthly") {
& "./ffmpeg.exe" -r $rate -i "$tempProcessingDir\$($Camera)_%05d.jpg" -s hd1080 -c:v libx265 -crf 28 $CompletedTimelapseDir\$Camera-$Style-$Year-$MonthProcess.mkv
}
elseif ($Style -eq "Yearly") {
& "./ffmpeg.exe" -f concat -safe 0 -i $MonthlyTimelapses -c copy YearlyTimelapse-$Camera.mkv
}
# Cleanup
Remove-Item $TempProcessingDir\* -Force

Binary file not shown.