This PHP script will take a sequence of archive images stored in time-specific sub folders hh/mm and renumber them sequentially. Then use ffmpeg to convert the sequence into a video file. The operation is looped over an array of cameras and a staging folder is cleared prior to each video creation.
<?php
include_once("config.php");
$ftppath = "/root/path/to/images/";
$stagepath = $ftppath . 'staging/';
$date = date('ymd');
foreach ($cams as $cam) {
exec('rm ' . $stagepath . '*');
$camfile = $cam['fileroot'];
$idx = 1;
for ($j=0; $j<24; $j++)
{
for ($i=0; $i<60; $i++)
{
$n = sprintf("%02d/%02d", $j, $i);
$pathfile = $ftppath . $n . '/' . $camfile . '_320x240.jpg';
if (file_exists($pathfile)) {
$sidx = sprintf("%04d", $idx);
copy($pathfile, $stagepath . $camfile . $sidx . '.jpg');
$idx++;
}
}
}
exec('ffmpeg -r 4 -i ' . $stagepath . $camfile . '%04d.jpg ' . $ftppath . $camfile . '_' . $date . '.mp4');
}
?>