Skip to content

Instantly share code, notes, and snippets.

Forked from porjo/
Created March 9, 2017 08:48
Star You must be signed in to star a gist
What would you like to do?
ffmpeg time-lapse

Convert sequence of JPEG images to MP4 video

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

  • -r 24 - output frame rate
  • -pattern_type glob -i '*.JPG' - all JPG files in the current directory
  • -i DSC_%04d.JPG - e.g. DSC_0397.JPG
  • -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

Copy link

ziadloo commented Apr 28, 2019

Thanks but why there are two -is? Also, when I run your command I get an error:

Could find no file with path 'IMG_%04d.jpg' and index in the range 0-4
IMG_%04d.jpg: No such file or directory

Of course, my file names are like IMG_1234.jpg and that's why I've changed the pattern. When I remove the second -i which causes issues, the process goes through but the result is a messed up video with flat colors in it. I'm not sure if this is relevant, but I'm getting this warning too:

deprecated pixel format used, make sure you did set range correctly

Any help is appreciated, thanks.

Copy link

carpii commented Jun 22, 2019

The two -i arguments are just a copy/paste mistake

deprecated pixel format used, make sure you did set range correctly

According to ffmpeg this warning is intended for users of the ffmpeg library, and when calling ffmpeg from commandline it can be ignored...

I haven't noticed any ill effects by ignoring it

Copy link

H4R0 commented Aug 26, 2019

Thank you for this, but its extremly slow. If you got a Intel CPU or dedicated GPU u can use hardware acceleration which is 100x times faster.

ffmpeg -y -vaapi_device /dev/dri/renderD128 -framerate 24 -pattern_type glob -i '*.png' -s:v 1920x1080 -vf 'format=nv12,hwupload' -c:v h264_vaapi timelapse.mkv

quality / filesize is close to "-crf 18 -preset slow"

Copy link

jtanman commented Oct 14, 2019

Is there a way to do multiple directories with glob input? I'm trying to do something like this, but it hasn't been working.

ffmpeg -pattern_type glob -i "Time\ Lapse\ 11/*.JPG" \
-pattern_type glob -i "Burst\ Sequence\ 5/*.JPG" \
-pattern_type glob -i "Burst\ Sequence\ 6/*.JPG" \
-r 30 -c:v libx264 -crf 23 -preset fast -pix_fmt yuv420p tl11_combined.mp4

Copy link

sxiii commented Jun 12, 2020

@jtanman -- I think it would be much easier to write a bash script that does the following:

  • creates temp directory
  • copies all files from DIR1 to temp
  • copies all files from DIR2 to temp
  • runs FFMPEG with your files in temp directory and creates result movie
  • moves your movie from temp to current directory
  • removes the temp directory
    :) This should work fast & easy.

Copy link

putout commented Jan 14, 2021

hi the command provided above in the original post only creates about 10 seconds duration in the video i have 1000+ images in the directory. ..

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

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