9 ms·
Make timelapses easily using FFmpeg
I make a lot of Timelapse and have tried a lot of ways to make Timelapses using python etc, today I found the easiest one using FFMpeg :)
ffmpeg -framerate 30 -pattern_type glob -i '*.JPG' -c:v libx264 -r 30 -pix_fmt yuv420p timelapse.mp4
- _Microft 2y agoffmpeg is such a great tool! Be aware that -pattern_type glob is not supported on Windows, though, iirc. A workaround is to name your jpegs with consecutive numbers (not necessarily starting at 0) and use a pattern with a counter placeholder in it instead.
- ancientstraits 2y agoHmm, I wonder why `-pattern_type glob` doesn't work on Windows. Perhaps it is something that could easily be programmed into the source code?
- mhitza 2y agoIf I were yo guess, it might be using the GNU libc (or compatible) glob functionality under the hood.
- ncr100 2y agoObligatory humor: https://youtu.be/9kaIXkImCAM https://youtu.be/9kaIXkImCAM Note of support: ffmpeg supported many of the transcoding needs of my former employer back in 2007, being a "friendly" tool to the team. Yes it had/s issue. Being open source gave us a lifeline, to be able to fix our own stuff, and build up our video and audio live streaming and video watching white label service.
- philshem 2y agoAlso be aware of this infamous “bug” > The sortedness of glob.glob's output is platform-dependent. https://bugs.python.org/issue33275#msg315254 https://bugs.python.org/issue33275#msg315254 https://pubs.acs.org/doi/10.1021/acs.orglett.9b03216 https://pubs.acs.org/doi/10.1021/acs.orglett.9b03216
- dewey 2y agoAt least in this case you'd find out pretty quickly!
- atif089 2y agowsl --cd=%cd% ffmpeg -framerate 30 -pattern_type glob -i '*.JPG' -c:v libx264 -r 30 -pix_fmt yuv420p timelapse.mp4
- gsich 2y agoCorrect, most annoying bug there is.
- canucker2016 2y agoOr you can use '-f concat' and specify a text file with the explicit order of image files to be used as input - no need to hope and pray that the wildcard will pick the files in the correct order. see https://trac.ffmpeg.org/wiki/Concatenate https://trac.ffmpeg.org/wiki/Concatenate or https://shotstack.io/learn/use-ffmpeg-to-concatenate-video/ https://shotstack.io/learn/use-ffmpeg-to-concatenate-video/
- gmiller123456 2y agoI use -pattern_type glob on Windows without issue. Not sure how long I've been using it, at least a year, possibly two. This is what I use: ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p out.mp4
- mpeyton 2y agoI recently wrote a blog post about doing this to create timelapses of Rimworld colonies. I didn’t realize -pattern_type glob didn’t work on windows though… I’ll have to update it. Also, an assumption in your command is that all the images are the same aspect ratio. If they’re not, you can use this to dynamically pad it out with black bars on either size: ‘-vf "scale=1920:1080:force_original_aspect_ratio=decrease:eval=frame,pad=1920:1080:-1:-1:eval=frame"’ https://mpeyton.com/posts/rimworld_timelapse_ffmpeg/ https://mpeyton.com/posts/rimworld_timelapse_ffmpeg/
- ufmace 2y agoNice, thanks! I tried using ffmpeg for a minor video editing task I had a few months ago - just a cut, crop, rescale, and volume adjust. I've tried a few of the mainstream GUI video editing tools, and IMO, they all have incomprehensible UIs, are way too bloated, and usually far too expensive for what I'm trying to do. FFmpeg may not be dead simple, but I find it much easier to skim the command line flag list to figure out how to do what I want. And once I do, I can save down a handful of useful sets of flags and refer to them next time. Cheers to ffmpeg, one of the kings of FOSS! If you ever feel the need to do any kind of video conversion or editing, definitely try to do it in ffmpeg first.
- 1f60c 2y agoDavinci Resolve has a free (as in beer) version that is quite capable and easy to use, even as someone who'd only used iMovie before. The only problem is that "how to do X in Davinci Resolve" has been taken over by slop.
- ufmace 2y agoDavinci Resolve is actually the first thing that came to mind on the subject of, okay it's free, that's nice, but I can't for the life of me figure out how to do anything in it. I suppose it's not necessarily their fault that the search results for how to do basic things are garbage, but I guess an advantage of CLI apps is how-to results for them don't seem to attract nearly as much SEOified clickbait.
- dylan604 2y agoI shoot RAW from an older Canon 5D which Resolve does not read natively. So there's a bit of a conversion step going from CR2. My typical workflow is to use Adobe RAW to process the images, then import the RAW directly to AE to render out with whatever repositioning or cropping. Let's not forget LR Timelapse[0] as part of the workflow too. [0] https://lrtimelapse.com/ https://lrtimelapse.com/
- kristianp 2y agoI was reading about how to create timelapses on a canon dslr and someone pointed out that each frame you take adds to your shutter count and consumes the lifetime of your shutter. Do you find that a problem? For example a frame every 2 seconds for 8 hours is 14,400 actuations of the shutter.
- spuz 2y agoI'd recommend Da Vinci Resolve for making timelapses. It performs really well and let's you scrub through before rendering anything which lets you clip just the part that you need. Plus you get the benefit of high export quality which can be fiddly with ffmpeg.
- swyx 2y agowhy is high export quality fiddly with ffmpeg?
- fragmede 2y agothere are a bunch of flags to get exactly right in order to get it to give you a high quality image out. there are wrappers to do this more easily for you, ffmpeg is a low level tool.
- WheatMillington 2y agoResolve is insanely heavyweight for such a simple task. Those video editor UIs are incredibly hard to understand for people not using them every day.
- bfors 2y agoI would argue that ffmpeg has the hardest to understand interface in the video editing space (unless you can find a command someone else came up with that does exactly what you want)
- sam_goody 2y agoI wanted to print out one of those flipbooks I had as a kid, where the frames are printed and as the pages are flipped it looks like a movie. Is that something ffmpeg could do? Is there any good resource for recipes like these?
- fragmede 2y agotry ffmpeg -ss 00:01:00 -i input.avi -t 30 -vf "fps=1,scale=320:-1:flags=lanczos" output_%04d.jpg 00:01:00 is where to start the flip book, 30 is thirty seconds worth, and 1 fps is how many frames per second. this'll make output_XX.jpg from the Avi which you can then print
- Melatonic 2y agoDoes this add any interframe blur or are you controlling that based on exposure time ? Very important for quality Timelapse's
- nov21b 2y agoBeen making timelapses with ffmpeg since forever, such a great tool. I try to always have a cam pointed at the sky and upload a snapshot every minute. A telegram command triggers the creation of a timelapse with a similar cli command like the OP. https://www.youtube.com/watch?v=5GvaFBzOu2c https://www.youtube.com/watch?v=5GvaFBzOu2c
- Tempest1981 2y agoNice! What equipment do you use to capture? And does it push to some server... running RTSP?
- nov21b 2y agoI use an old Android phone with a long deprecated app called MobileWebCam (still available on certain sites) I removed the battery and connected the charger directly. It uploads a picture every minute, a Node.js backend creates the timelapse with ffmpeg. Currently experimenting with a TP-Link C520 cam and a Raspberry Pi. You can point the camera to different positions using ONVIF, use ffmpeg to grab the stream and take a snapshot, then process this again on the server. Downside is the wide angle / fish eye lens and occasionally a corrupted stream snapshot.
- Jerrrrry 2y agoThank you, was looking for a cheap webcam security set up using the great near-wasted cameras on older android phones.
- gmiller123456 2y agoIf you want an all sky solution, zwoastro.com ships an all sky lens with many of their small sensor planetary cameras. There's also a selection of software to handle the photos, making time-lapse, uploading etc. It came in really useful for seeing the Aurora outburst. Here's a short write up I did for my local club recently: https://m.facebook.com/story.php?id=101640086556073&story_fbid=7469450569774951 https://m.facebook.com/story.php?id=101640086556073&story_fb... I'm also working on a new one that uses an ASI533 Pro and a 4mm lens from a mirrorless camera to get better quality images.
- timonoko 2y agoWhere FFMPEG really shines is stabilising video. Unfortunately not all versions have "vidstab". ffmpeg -i "$1" -vf vidstabdetect=shakiness=5:show=1 dummy.avi ffmpeg -i "$1" -vf yadif, format=yuv420p, vidstabtransform=zoom=2:optzoom=0:crop=black -c:v libx264 -b:a 32k stabilized264.mp4 Yesterweek's shaky video shot from a kayak: https://youtu.be/4pM0VeH4NE0?si=H2qTJfcvis3QmFlj https://youtu.be/4pM0VeH4NE0?si=H2qTJfcvis3QmFlj
- timonoko 2y agoIf you really wish to install all the available options, you can run: brew install homebrew-ffmpeg/ffmpeg/ffmpeg $(brew options homebrew-ffmpeg/ffmpeg/ffmpeg --compact)
- dheera 2y agoHow about $ ffmpeg-english "capture video from the camera every 1 second and write it to jpg files" $ ffmpeg-english "take all of the images ending with .jpg in this directory and make a 30fps timelapse of it" Sound awesome? Here's the code for ffmpeg-english: #!/usr/bin/env python3 import openai import sys import os import time # Ensure you have set your OpenAI API key as an environment variable openai.api_key = os.getenv("OPENAI_API_KEY") client = openai.OpenAI() def get_ffmpeg_command(task_description): # Call the OpenAI API with the task description response = client.chat.completions.create( model="gpt-4", messages=[ {"role":"system", "content":"You are an expert in FFmpeg commands. Given the following English description of a task, you respond with the correct FFmpeg command. Do not include any other information in your response except for the command only."}, {"role":"user", "content":task_description}, ], max_tokens=150, temperature=0.5 ) command = response.choices[0].message.content.strip() return command def main(): if len(sys.argv) < 2: print("Usage: ffmpeg-english <task_description>", file=sys.stderr) sys.exit(1) task_description = " ".join(sys.argv[1:]) ffmpeg_command = get_ffmpeg_command(task_description) # some basic guardrails assert(ffmpeg_command.startswith("ffmpeg")) assert(";" not in ffmpeg_command) assert("|" not in ffmpeg_command) print(f"Executing command: {ffmpeg_command} in 2 seconds (^C to cancel)") time.sleep(2) os.system(ffmpeg_command) if __name__ == "__main__": main()
- rolobio 2y agoI looked into using ffmpeg to “compress” video podcasts by lowering the framerate a lot, but it didn’t seem to do as much as I thought (about 50% size reduction). The theory was that a video podcast is mostly talking heads with an occasional chart on the screen, so you really only need a frame every second, or five seconds.
- sergiotapia 2y agoAV1 exceeds at these type of videos. It's why so many anime people use it. Try encoding the video to AV1 with OPUS audio. You'll get ridiculous gainz! My command is: $ffmpegPath -i $_.FullName -r 23.976 -vf scale=1280:720 -c:v libsvtav1 -pix_fmt yuv420p10le -crf 30 -preset 10 -g 300 -c:a libopus -b:a 96k -ac 2 -c:s copy -map 0 $destPath
- rolobio 2y agoThanks I will give it a try.
- invalidator 2y agoReducing framerate doesn't help much when there isn't a lot changing between frames. Here are some better optimizations: Noise reduction, so you compress less useless noise: -vf hqdn3d Turn up the Constant Rate Factor. This will make better visual tradeoffs than decreasing frame rate. 23 is a good starting point for h264, but keep increasing it until you don't like how the content looks: -crf 23 Throw more CPU at the problem: -preset veryslow
- fragmede 2y agoback when computers were hard, tips like this were gold. but these days, for for a well trod/documented thing like ffmpeg, asking ChatGPT to make the ffmpeg command you want works really well, eg "give me ffmpeg to make a video from a series of jpegs" and iterate from there.
- crtasm 2y agoPlease don't let this line of thinking put you (the reader) off sharing tips. Here we now have a thread containing other information we may not have thought to ask anyone/thing about, discussion, history, etc.
- shinycode 2y agoMaybe someone should collect all those commands and create a website or a gist that list them with search possible. They are gems !
- can16358p 2y agoIs there a variant that encodes ProRes lossless? I usually open them up in a new project just to create a lossless input video to work with in After Effects, and use that (if I use image sequence directly, DaVinci Resolve acts in weird ways). ffmpeg might ease that AE part.
- 4759597283 2y agoFWIW, ProRes isn’t a lossless codec (tho it should be perceptually lossless in most cases). Ffmpeg can encode into ProRes, but it’s technically an unofficial implementation. What issues do you run into with image sequences?
- can16358p 2y agoRight, calling it technically lossless is wrong but 422 HQ gives impressive results so I we can probably safely say that it is "practically" lossless. In DaVinci Resolve, many tools go awry with image sequences: for example temporal noise reduction simply doesn't work with a compound clip with image sequences, I also remember having problems with caching performance. I have a few very strange/buggy problems with Resolve though I love color grading with it regardless, so I want to avoid the buggy sides of Resolve (as it's one of the buggiest software I've ever used) but use the upsides of it (grading and some OpenFX filters). It would help me on this process.
- Am4TIfIsER0ppos 2y agoffmpeg has 2 prores encoders
- varelse 2y ago[dead]
- yboris 2y agoSomewhat unrelated, but a beautiful tool for extracting screenshots from video: MoviePrint https://www.movieprint.org/ https://www.movieprint.org/ & https://github.com/fakob/MoviePrint_v004/ https://github.com/fakob/MoviePrint_v004/
- brokenmachine 2y agoI use VLC for that. I press shift-s to take a snapshot, not sure if that's a default hotkey or I set it to that a long time ago. In the preferences you choose where it will save to and what format.
- sen 2y agoI use a Raspberry Pi Zero with a Pi Camera and ffmpeg to make timelapses of plants growing from seedlings each season when we plant tomatoes/potatoes/etc. It's a great way to show the kids how different plants grow from seed, and such a cheap/easy project. Bash script running on a cron job every hour with: DATE=$(date +"%Y%m%d%H%M") raspistill -o /home/pi/timelapse/$DATE.jpg -awb off -awbg 1.8,1.6 Then another bash script running once a week: DATE=$(date +"%Y%m%d%H%M") ffmpeg -framerate 12 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p -vf 'scale=1920:-2,crop=1920:1080:0:(in_h-1000)' 'timelapse-$DATE.mp4' scp timelapse-$DATE.mp4 username@my.server:/home/user/ (Edited/simplified, I do a few other things in the scripts like compile the timelapse with pre-made timelapses and share via nginx on the Pi itself)
- yaky 2y agoFFMpeg really helped me out not too long ago. I tried KDenLive and ShotCut to edit some videos, which I rarely do, only to be overwhelmed and then discover that ffmpeg command can do everything from timelapses to trimming and brightness/contrast adjustments. And you can "preview" the result too, using ffplay.
- remram 2y agoWhat does -framerate do here? The manual is not turning up anything, other than it's similar to -r for certain input formats.
- Am4TIfIsER0ppos 2y agoIt sets the framerate for the input video. The default for the image2 demuxer is 25.
- remram 2y agoOh I see, I had assumed that they'd want a much slower speed, but they actually show 30 different input images per second in the 30 fps video.
- nwallin 2y agoYou can also glob with c printf style format. ffmpeg -framerate 30 -i image-%05d.jpg -c:v libx265 -crf 35 -pix_fmt yuv420p timelapse.mp4 Will get images of the form image-00000.jpg, image-00001.jpg, ... image-99999.jpg.
- CantPickAName 2y agoSeems like there are a lot of experts here with FFmpeg, so perhaps one of you can help me. I have a bunch of old videos that use MTS as the file extension. I would like to convert these to an MP4 (or MKV) file but I would like to do it while keeping the metadata (date taken, date created, etc.). Is there a way to do this? The scripts I've seen change the file extension by just changing the container but they never keep the metadata which is a huge issue for me.
- rsk 2y agoit can also read frames from stdin, for example: cat *.jpg | ffmpeg -r 90 -f image2pipe -i - -codec:v libx264 -preset fast -crf 23 -vf format=yuv420p video.mp4
- mackid 2y agoI took photos every few minutes for about a year. I wrote some custom code to pick out a set of frames from several consecutive days, but with the sun at the same angle in the sky. I then blended these frames together. This makes a ghostly look, without the bright flashes of cloud passing or weather changing. As I moved forward in time, I selected frames from the next angle in the sky, so it looks like only a day passes. You’ll see the shadows move as if a day passes, when really a year goes by. https://youtu.be/RAsJE5ddt_U https://youtu.be/RAsJE5ddt_U
- SixDouble5321 2y agoThis is awesome. What kind of hardware are you using? If you don't mind.
- robertlagrant 2y agoVery cool.
- dekhn 2y agoVery cool! We tried to do the same thing with a series of photos taken along the solar eclipse, but didn't have enough density or consistency to make it compelling.
- xspiral 2y agoThat's awesome! FFmpeg is super powerful. I've been using it for video edits too. It’s amazing how such a simple command can handle complex tasks. Thanks for sharing this tip!
- salzig 2y agoJust dropping this "random" ffmpeg command here, as a reminder that you can turn video files into actual transparent webm using ffmpeg -t 5 -i example.mp4 -c:v libvpx-vp9 -b:v 2M -filter_complex "[0:v]chromakey=0x00ff00:0.3:0.2[out]" -map "[out]" -map 0:a stop.webm` where `example.mp4` is a video with the typical green background. Maybe someone needs it :)
- 153957 2y agoffmpeg works really well for this. I have also been making time-lapse movies for over a decade, starting with using just Quicktime Pro 7 to combine the images into movies. Later using various other tools. Now I also use ffmpeg, and want to keep track of exactly how each movie is put together so looked for a way to script each movie. Now I use ffmpeg-python (not a lot of recent updates, but just works) to steer ffmpeg, with my own time-lapse specific Python package https://pypi.org/project/time-lapse/ https://pypi.org/project/time-lapse/ to assemble the movies, and for each movie I have a single script which describes which frames are part of it and how they are combined into a movie; https://github.com/153957/time-lapse-scripts https://github.com/153957/time-lapse-scripts I am quite happy with the setup, making it easy to recreate movies in the future from source, but at higher resolutions or different codecs.