Time-lapse Scripts

When making my train time-lapse videos I used FFmpeg and some PowerShell scripts to streamline the process. The dashcam I used didn’t compress the videos very much and recorded the video in 10 minute chunks. The videos needed transcoded to a more efficient codec while also changing the speed of the video. Afterwards, all the clips needed merged into one file. This was a bit of an introduction to PowerShell scripting for me. The scripts ended up a bit rough around the edges, but they got the job done.

Batch Transcode Script

# Batch Transcode Script
# Batch_Transcode.ps1

$files = Get-ChildItem ".\" -Filter *.mp4
$i = 0
$j = $files.count

foreach ($f in $files){
	$i = $i + 1
	$program = "./ffmpeg"
	$args = '-i', "$f", '-an', '-c:v', 'libx265', '-preset', 'slower', '-crf', '30', '-filter:v', '"scale=-1:1080, fps=60, setpts=0.0166*PTS"', "O$f"
	write-host
	write-host
	write-host
      write-host "$i/$j"
      write-host $program $args 
      write-host
	& $program $args
}

Stitch Script

# Stitch Together Videos
# Stitch.ps1

$files = Get-ChildItem ".\" -Filter *.mp4
foreach ($f in $files) {
	$line = "file '$f'"
	Out-File -FilePath 'infiles.txt' -InputObject $line -Append -Encoding ASCII
}

.\ffmpeg -f concat -i infiles.txt -c copy output.mp4