Skip to content

Instantly share code, notes, and snippets.

@Pierstoval Pierstoval/timelapse.cmd
Last active Jul 14, 2018

What would you like to do?
Timelapse from imges with FFMPEG and ImageMagick
REM Batch file for Windows only
REM This script takes images from a
REM This is NOT an usual glob pattern.
REM This example matches 4 digits, like "DSC_0243".
ffmpeg.exe -r 24 -i %PATTERN%.%EXTENSION% -s hd720 -vcodec libx264 out.mp4
REM Some additional information retrieven from this gist:
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
* 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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.