01304 827609 info@use-ip.co.uk Find us

how to make a timelapse with continuous recording, after the fact

spirch

Well-Known Member
Messages
76
Points
8
so I wanted to do timelapse for my own benefit and while searching i found out that it wasn't that easy.

I made this powershell script that prepare everything for you, you need ffmpeg (search for it)

if you have any question, let me know. step by step in the header of the file
if you see any mistake, let me know.
if you have any idea on how to improve this, let me know.

(this script should work for anything, not only hikvision)

example: 4 days of video in 11 minutes, 78 video file (mp4) from the cameras




Code:
###
### not tested with space in folder / file name
###
### 0. configure below
### 1. run this script
### 2. run _batch.bat, go sleep
### 3. when done run _concat.bat
### 4. enjoy your _final.mp4 video
###

###config begin

$path = $PSScriptRoot #path where the video are
$factor = "0.005" #this is how you can figure out; total video in second * factor = time of final video in second. 0.005 = 7m30s for 24h
$parallelRun = 2 #how many ffmpeg do you want to run in parallel, it peak at 3-4 gig of per run for me
$ffmpegPath = "D:\Download\ffmpeg-20200209-5ad1c1a-win64-static\bin\ffmpeg.exe" #where is ffpmeg
$fileExt = "*.mp4" #extension of the videos

###config end

$files = Get-ChildItem $path  -File -filter $fileExt
$count = $files.Count
$filePerBatch = ([Math]::Ceiling($count / $parallelRun))

$i=1

$PSDefaultParameterValues=@{'out-file:encoding'='ascii'}

$videoList = Join-Path $path "_videolist.txt"
foreach ($file in $files) 
{
    $videoIn = Join-Path $path $file 
    $videoOut = Join-Path $path "__out-$(($i++).ToString('00000')).mp4"
    $batchFile = Join-Path $path "_Batch$([Math]::Ceiling($i / $filePerBatch)).bat"
    
    Write-Output "file '$($videoOut)' " >> $videoList
    Write-Output "start /low /wait /b $($ffmpegPath) -i $($videoIn) -filter:v ""setpts=$($factor)*PTS"" -an $($videoOut)" >> $batchFile
}

$concatFile = Join-Path $path "_concat.bat"
Write-Output "start /low /wait /b $($ffmpegPath) -safe 0 -f concat -i $($videoList) -c copy _final.mp4" >> $concatFile

$batchFiles =  Join-Path $path "_batch.bat"
For ($i=1; $i -le $parallelRun; $i++) 
{
    $batchFile = Join-Path $path "_Batch$($i).bat"
    Write-Output "start $($batchFile)" >> $batchFiles
}
 
Back
Top