I've got lots of images stored on a server, and a reference in a MySQL database so that i can easily query it for image from specific dates/time.
Images is taken with an interval of 7 images/hour.
Lets say i want to create a timelapse from the last 4 days, and make a 5 sec movie. How can i calculate how to evenly drop frames to get to that desired length of 5 seconds?
This is what i got so far.
Total images: 4 Days * 24 hours * 7 images/hour = 672 images Required images at 24 fps: 24 * 5 = 120 images
Divide the total images with the required images to find out which/every frame i need to keep
672 / 120 = 5.6
Then i loop trough all 672 images, and every 5th or 6th time i store a reference to the image in an array.
Here is my problem. If i round up i get a video thats longer than i want, and if i round down i get a video thats shorter.
If i keep every 5th image when looping: 134 images / 24 fps = 5.6 sec video If i keep every 6th image when looping: 112 images / 24 fps = 4.6 sec video
Is it possible to get it better, and still skip images evenly?
Solved this using xxfelixxx's answer in PHP Heres the code in PHP:
$start = 1;
$stop = 672; // Total Images
$dur = 5; // Video Duration
$n = 24 * $dur; // Required frames - 24 FPS * Duration
$next = $start;
$step = ( $stop - $start ) / $n;
$frames = array();
for ($i = 1; $i <= $n; $i++) {
$frames[] = round($next);
$next += $step;
};
var_dump($frames);