Created
February 6, 2025 17:41
-
-
Save mshem/aee9abf700468ebca08ab6e4a4c49d96 to your computer and use it in GitHub Desktop.
Webcam timelapse script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$timestamp = "drawtext=fontfile=/Windows/Fonts/Arial.ttf: text='%{localtime}': x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1: fontsize=30" | |
$Days = Read-Host "How many days?" | |
$Rate = Read-Host "How many times per day?" | |
$Name = Read-Host "name the folder:" | |
$DrivePath = "C:\GD\" | |
$Dir = "$DrivePath\timelapses\images\$Name" | |
mkdir $Dir | |
$total = ([int]$Days * [int]$Rate) | |
$x=1..[int]$Days | |
foreach($day in $x){ | |
$y=1..[int]$Rate | |
foreach($set in $y){ | |
$count = (($day - 1) * [int]$Rate) + $set | |
echo "Capturing set $count out of $total" | |
ffmpeg -hide_banner -loglevel error -f dshow -video_size 1600x1200 -framerate 7 -pixel_format yuyv422 -i video="USB Microscope" -frames:v 10 -vf $timestamp -y "$Dir\micro-$count-%03d.jpeg"; | |
ffmpeg -hide_banner -loglevel error -f dshow -video_size 1920x1080 -framerate 30 -i video="USB Video Device" -frames:v 10 -vf $timestamp -y "$Dir\$count-%03d.jpeg"; | |
foreach($deletable in 1..9){ | |
rm "$Dir\micro-$count-00$deletable.jpeg" | |
rm "$Dir\$count-00$deletable.jpeg" | |
} | |
$sleep = (86400 / [int]$Rate) | |
if ($count -ne $total) { | |
echo "Sleeping for $sleep seconds" | |
Start-Sleep -s $sleep | |
} | |
} | |
} | |
ffmpeg -hide_banner -loglevel error -r 30 -f image2 -s 1600x1200 -i "$Dir\micro-%d-010.jpeg" -pix_fmt yuv420p "$DrivePath\timelapses\videos\micro-$Name.mp4" | |
ffmpeg -hide_banner -loglevel error -r 30 -f image2 -s 1920x1080 -i "$Dir\%d-010.jpeg" -pix_fmt yuv420p "$DrivePath\timelapses\videos\$Name.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment