Skip to content

Instantly share code, notes, and snippets.

@sincladk
Forked from alexellis/timelapse.md
Last active October 20, 2020 01:18
Show Gist options
  • Select an option

  • Save sincladk/19b7de48c8bdf84839c97b9e73bba5b6 to your computer and use it in GitHub Desktop.

Select an option

Save sincladk/19b7de48c8bdf84839c97b9e73bba5b6 to your computer and use it in GitHub Desktop.
ffmpeg time-lapse

Convert sequence of PNG images to MP4 video (4K)

ffmpeg -r 24 -start_number 1000 -i Time-Lapse-%04d.png -c:v libx264 -pix_fmt yuv420p time-lapse-4k.mp4

Convert sequence of PNG images to MP4 video (1080p)

ffmpeg -r 30 -start_number 1000 -i Time-Lapse-%04d.png -s hd1080 -vcodec libx264 -crf 18 -preset slow -pix_fmt yuv420p time-lapse.mp4

Convert sequence of JPEG images to MP4 video

ffmpeg -r 30 -start_number 3413 -i IMG_%04d.jpg -s hd1080 -vcodec libx264 -crf 18 -preset slow -pix_fmt yuv420p time-lapse.mp4

  • -r 30 - output frame rate
  • -start_number 3413 - the first index number of the images
  • -i IMG_%04d.jpg - all JPG files in the current directory matching this pattern (e.g. IMG_3413.jpg)
    • Note: can be replaced with -i IMG_%d.jpg if there are no leading zeros (e.g. IMG_1.jpg, IMG_2.jpg...IMG_10.jpg...IMG_100.jpg)
  • -s hd1080 - 1920x1080 resolution
  • -pix_fmt yuv420p - setting the pixel format for QuickTime/iPhone support

Slower, better quality

Add the following after -vcodec libx264 to achieve better quality output

-crf 18 -preset slow

Bulk convert JPGs to 1920x1080, centered

convert input.jpg -resize '1920x1080^' -gravity center -crop '1920x1080+0+0' output.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment