Skip to content

Instantly share code, notes, and snippets.

@Pierstoval
Last active July 14, 2018 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pierstoval/f97f3010b159f09b97bc25b8207596db to your computer and use it in GitHub Desktop.
Save Pierstoval/f97f3010b159f09b97bc25b8207596db to your computer and use it in GitHub Desktop.
Timelapse from imges with FFMPEG and ImageMagick
REM Batch file for Windows only
REM This script takes images from a
SET EXTENSION=jpg
REM This is NOT an usual glob pattern.
REM This example matches 4 digits, like "DSC_0243".
SET PATTERN=DSC_%04d"
ffmpeg.exe -r 24 -i %PATTERN%.%EXTENSION% -s hd720 -vcodec libx264 out.mp4
REM Some additional information retrieven from this gist: https://gist.github.com/porjo/3e4b182089c430a54a64
REM Thanks to the initial contributor!
REM -r 24 - output frame rate
REM -pattern_type glob -i '*.JPG' - all JPG files in the current directory
REM -i DSC_%04d.JPG - e.g. DSC_0397.JPG
REM -s hd1080 - 1920x1080 resolution
REM Add the following after -vcodec libx264 to achieve better quality output
REM -crf 18 -preset slow
<?php
/**
* This script converts all images to resize them & make them a bit lighter for the final timelapse.
* It executes ImageMagick once per image instead of using commands like "magick convert *.jpg ..."
* because it saves LOT of memory & performances, is way faster!
* Will always convert to JPEG for maximum space.
*/
$extension = 'jpg';
$pattern = 'DSC_*'; // This is a glob pattern, feel free to customize it if you like
$resizeToSize = '1280x720';
$jpegQuality = '85'; // Must be from 0 to 100, 100 being the best quality, 0 the worst.
$files = glob(trim(__DIR__, '\\/').DIRECTORY_SEPARATOR.$pattern.$extension);
if (!is_dir('out')) {
mkdir('out', 0777, true);
}
$baseCmd = 'magick convert "%s" -thumbnail '.$resizeTo.' -quality '.$jpegQuality.' "out/%s.'.$extension.'"';
foreach ($files as $file) {
$cmd = sprintf($baseCmd, $file, basename($file,".jpg"));
echo $cmd."\n";
system($cmd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment