Skip to content

Instantly share code, notes, and snippets.

@debuti
Forked from alexellis/timelapse.md
Last active August 22, 2019 07:45
Show Gist options
  • Save debuti/8dbf50b64cfb00f6d561c73cc6059cad to your computer and use it in GitHub Desktop.
Save debuti/8dbf50b64cfb00f6d561c73cc6059cad to your computer and use it in GitHub Desktop.
ffmpeg time-lapse

Convert sequence of JPEG images to MP4 video

ffmpeg -r 24 -pattern_type glob -i '*.JPG' -s hd1080 -vcodec libx264 timelapse.mp4

  • -r 24 - output frame rate
  • -pattern_type glob -i '*.JPG' - all JPG files in the current directory
  • -s hd1080 - 1920x1080 resolution

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

Bulk rename to date

find . -type f | grep JPG$ | xargs -I{} sh -c 'mv -n "$1" $(date -r "$1" +"%Y%m%d_%H%M%S").jpg' - "{}"

Bulk rename sequentially

a=1
for i in *.JPG; do
  new=$(printf "%04d.jpg" "$a")
  mv -i -- "$i" "$new"
  let a=a+1
done

Create gif

ffmpeg -i timelapse.mp4 -filter_complex "[0:v] fps=12,scale=480:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" timelapse.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment