[HN Gopher] Make timelapses easily using FFmpeg
       ___________________________________________________________________
        
       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
        
       Author : indiantinker
       Score  : 156 points
       Date   : 2024-05-19 15:24 UTC (7 hours ago)
        
       | _Microft wrote:
       | ffmpeg 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 wrote:
         | Hmm, 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 wrote:
           | If I were yo guess, it might be using the GNU libc (or
           | compatible) glob functionality under the hood.
        
         | ncr100 wrote:
         | Obligatory humor: 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 wrote:
         | Also be aware of this infamous "bug"
         | 
         | > The sortedness of glob.glob's output is platform-dependent.
         | 
         | https://bugs.python.org/issue33275#msg315254
         | 
         | https://pubs.acs.org/doi/10.1021/acs.orglett.9b03216
        
           | dewey wrote:
           | At least in this case you'd find out pretty quickly!
        
         | atif089 wrote:
         | wsl --cd=%cd% ffmpeg -framerate 30 -pattern_type glob -i
         | '*.JPG' -c:v libx264 -r 30 -pix_fmt yuv420p timelapse.mp4
        
         | gsich wrote:
         | Correct, most annoying bug there is.
        
         | canucker2016 wrote:
         | Or 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 or
         | https://shotstack.io/learn/use-ffmpeg-to-concatenate-video/
        
       | mpeyton wrote:
       | I 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=f
       | rame,pad=1920:1080:-1:-1:eval=frame"'
       | 
       | https://mpeyton.com/posts/rimworld_timelapse_ffmpeg/
        
       | ufmace wrote:
       | Nice, 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 wrote:
         | Davinci 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 wrote:
           | Davinci 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 wrote:
           | I 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/
        
         | wmil wrote:
         | To be fair, pulling out a professional video editor for small
         | changes is like learning emacs to edit some config files. You
         | don't need 99% of the features.
         | 
         | Also as an FYI to everyone, FFmpeg does support nVidia GPU
         | acceleration but it might not be enabled in your build. So
         | check if you use it a lot.
        
           | ufmace wrote:
           | Probably true, but ffmpeg seems to have a ton of features
           | too. It seems to me that CLI apps are inherently better at
           | not distracting you with things you don't need. A CLI flag
           | that you don't use is invisible outside of the man pages, not
           | so for a menu or toolbar of a zillion options with names and
           | icons you don't understand.
        
         | madeofpalk wrote:
         | Indeed. I find it baffling how hard it is to just make
         | lightweight edits to videos on Windows. At a bare minimum I
         | would like to clip a video, or crop or change audio tracks. My
         | cheat sheet of ffmpeg commands still remains to be the easiest
         | way for me to do this.
        
         | ozay wrote:
         | I recently found LosslessCut (https://github.com/mifi/lossless-
         | cut) that is basically a GUI for ffmpeg, you can make simple
         | edits without re-encoding the stream.
        
         | StableAlkyne wrote:
         | Blender has a very well done video editor, it's probably my
         | favorite foss video editor so far. It also uses ffmpeg under
         | the hood
         | 
         | Worth a try!
        
       | spuz wrote:
       | I'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 wrote:
         | why is high export quality fiddly with ffmpeg?
        
           | fragmede wrote:
           | there 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 wrote:
         | Resolve is insanely heavyweight for such a simple task. Those
         | video editor UIs are incredibly hard to understand for people
         | not using them every day.
        
       | sam_goody wrote:
       | I 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 wrote:
         | try                   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 wrote:
       | Does this add any interframe blur or are you controlling that
       | based on exposure time ? Very important for quality Timelapse's
        
       | nov21b wrote:
       | Been 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
        
         | Tempest1981 wrote:
         | Nice! What equipment do you use to capture? And does it push to
         | some server... running RTSP?
        
           | nov21b wrote:
           | I 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 wrote:
             | Thank you, was looking for a cheap webcam security set up
             | using the great near-wasted cameras on older android
             | phones.
        
           | gmiller123456 wrote:
           | If 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_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 wrote:
       | Where 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
        
         | timonoko wrote:
         | If 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)
        
       | rolobio wrote:
       | I 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 wrote:
         | AV1 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 wrote:
           | Thanks I will give it a try.
        
       | fragmede wrote:
       | back 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 wrote:
         | Please 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.
        
           | eichin wrote:
           | besides, chatgpt can only do that _because_ of tips like
           | this...
        
       | shinycode wrote:
       | Maybe someone should collect all those commands and create a
       | website or a gist that list them with search possible. They are
       | gems !
        
       | can16358p wrote:
       | Is 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 wrote:
         | FWIW, 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?
        
       | yboris wrote:
       | Somewhat unrelated, but a beautiful tool for extracting
       | screenshots from video: _MoviePrint_
       | 
       | https://www.movieprint.org/ &
       | https://github.com/fakob/MoviePrint_v004/
        
       ___________________________________________________________________
       (page generated 2024-05-19 23:00 UTC)