Skip to content

Instantly share code, notes, and snippets.

@Sybrand
Forked from alexellis/timelapse.md
Last active January 3, 2019 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Sybrand/8db4de292d9e2415068459011f44e315 to your computer and use it in GitHub Desktop.
Save Sybrand/8db4de292d9e2415068459011f44e315 to your computer and use it in GitHub Desktop.
ffmpeg time-lapse

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

MKV is an open standard, so I prefer that to MP4, it does also seem to play back 4k 60 fps less choppy.

ffmpeg -r 60 -pattern_type glob -i '*.JPG' -vf scale=3840:2160 -sws_flags lanczos -pix_fmt yuv420p -vcodec libx264 -crf 18 -preset slow timelapse_lanczos_crf18_slow.mkv

  • -r 60 - output frame rate.
  • -pattern_type glob -i '*.JPG' - all JPG files in the current directory.
  • -vf scale=3840:2160 - 4k UHD. GoPro captures in 4000x3000, but I want to squeeze it into 4k.
  • -sws_flags lanczos - I want to scale Gaussian or lanczos, I think it’s better than bicubic.
  • -pix_fmt yuv420p - Seems everyone uses this because quicktime supports only that.
  • -vcodec libx264 - everyone is using this codec - but why?
  • -crf 18 -preset slow - Add this for better quality output.

This does give you a "deprecated pixel format" warning. It would be nice to figure out how to get rid of that, but it seems to work fine.

MP4

ffmpeg -r 60 -pattern_type glob -i '*.JPG' -vf scale=1920:1080 -sws_flags lanczos -pix_fmt yuv420p -vcodec libx264 -crf 18 -preset slow timelapse_lanczos_crf18_slow_1080.mp4

Bulk convert JPGs to 1920x1080, centered

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

@billmei
Copy link

billmei commented Jan 3, 2019

Thanks for this!

The -pix_fmt yuv420p setting is technically "deprecated" which is why this gives a "deprecated pixel format" warning. The warning can't be removed because this flag must be set for compatibility with Quicktime.

I made a fork of this where instead of stretching the video, you can crop it into 16:9 instead to preserve the original resolution: https://gist.github.com/billmei/9b2ebeceb879c53de00e297f471b0719

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