Skip to content

Instantly share code, notes, and snippets.

@billmei
Forked from Sybrand/timelapse.md
Last active January 14, 2022 10:54
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save billmei/9b2ebeceb879c53de00e297f471b0719 to your computer and use it in GitHub Desktop.
Save billmei/9b2ebeceb879c53de00e297f471b0719 to your computer and use it in GitHub Desktop.
ffmpeg time-lapse

Convert sequence of GoPro Hero 6 Black JPEG images to MKV / MP4 video

ffmpeg \
  -r 30000/1001 \
  -pattern_type glob -i '*.JPG' \
  -vf "crop=in_w:in_w*9/16,scale=3840:-2" \
  -sws_flags lanczos \
  -pix_fmt yuv420p \
  -vcodec libx264 \
  -crf 18 -preset slow \
  output.mkv
  • -r 30000/1001 - 30 fps frame rate. Why divide by 1001? See drop-frame timecode.
  • -pattern_type glob -i '*.JPG' - all JPG files in the current directory. Note this is case sensitive.
  • -vf "crop=in_w:in_w*9/16,scale=3840:-2" - 4k UHD. GoPro captures in 4000x3000, so need to crop it to 16:9 resolution. Change 3840 to 1920 if you want HD 1080p resolution.
  • -sws_flags lanczos - I want to scale Gaussian or lanczos, I think it’s better than bicubic.
  • -pix_fmt yuv420p - Required to support Quicktime.
  • -vcodec libx264 - everyone is using this codec - but why?
  • -crf 18 -preset slow - Add this for better quality output.
  • output.mkv - Output filename. Change to .mp4 if you want MP4.

Bulk convert JPGs to 1920x1080, centered

This is not required as long as you use the crop option in ffmpeg, but is included for reference in case you want to crop the images with ImageMagick first before feeding them into ffmpeg (this is slower than using ffmpeg directly).

find . -name '*.JPG' -exec convert {} -resize '1920x1080^' -gravity center -crop '1920x1080+0+0' "{}_cropped.jpg" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment