Let's say you have a folder with 40 .jpegs (frames captured from a webcam).
How to convert it to a video exactly 3 seconds long?
Using FFmpeg on Windows.
31 Answer
- Rename images files sequentially:
- a. Explorer (no 3rd party tools) method: Sort pictures by date (or filename) so oldest is at top. Select them all, right-click oldest one on top, rename, type img. They all are renamed in this format: img (1).jpg, img (2).jpg, img (11).jpg
- b. I’m told this powershell command can do:
dir *.jpg | %{$x=0} {Rename-Item $_ -NewName "Base$($x.tostring('000000')).jpg"; $x++ } - c. AntRename Portable can easily do this
- Run this command:
ffmpeg -i "img (%d).jpg" timelapse.mp4- a. -i says this is the input
- b. %d is a sequence pattern (look for decimals/numbers) that’ll match filenames like this: img (1).jpg, img (2).jpg, img (11).jpg. Documentation mostly gives example %03d which will match zero-padded filenames: img001.jpg, img002.jpg
- c. Additional options:
- C1. -f image2 forces the image2 muxer/demuxer which it usually figures out on its own
- C2. Framerate default is 25fps, customize it (-r 15). I set to 1fps with 21 pics to MP4 & it was a black video so mileage may vary, but I think MP4 format is to blame
Useful links: • • • • •
Things that didn't work in Windows ffmpeg build (nothing is stopping you from doing it in Linux):
- Wildcards *: Failed (err msg: globbing is not supported by this libavformat build):
ffmpeg -pattern_type glob -i *.jpg timelapse.mp4 - concat demuxer with text file that mostly has file paths to all pictures.
Failed (err msg: unsafe file name, operation not permitted):
ffmpeg -f concat -i input.txt timelapse.mp4 - Piping (their example using cat linux command, I tried dir). Failed below commands give this error: pipe:: Invalid data found when processing input.
dir *.jpg /s /b | ffmpeg -i - timelapse.mp4© *.jpg | ffmpeg -i - timelapse.mp4- Failed below commands give this error: Could not find codec parameters for stream 0 (Video: none, none): unknown codec.
copy *.jpg | ffmpeg -f image2pipe -i - timelapse.mp4&dir *.jpg /s /b | ffmpeg -f image2pipe -i - timelapse.mp4
- Failed below commands give this error: Could not find codec parameters for stream 0 (Video: none, none): unknown codec.