FFMPEG image sequence to video with specific duration
5,571
- 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: • https://trac.ffmpeg.org/wiki/Slideshow • https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence • https://ffmpeg.org/faq.html#How-do-I-encode-single-pictures-into-movies_003f • https://ffmpeg.org/ffmpeg-formats.html#image2-1 • https://photo.stackexchange.com/questions/1254/which-software-to-assemble-a-time-lapse-from-images
Things that didn't work in Windows ffmpeg build (nothing is stopping you from doing it in Linux): https://trac.ffmpeg.org/wiki/Slideshow
- 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.
Related videos on Youtube
Author by
SharpAffair
Updated on September 18, 2022Comments
-
SharpAffair almost 2 years
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.
-
gregg almost 6 yearsWhich operating system? I assure you it matters since I did this recently. You didn't detail if you've researched other posts I am confident speak about this
-
SharpAffair almost 6 years@gregg I've researched other posts, but haven't found any exact matches.
-
gregg almost 6 yearsIf you could I'd update your question with links to those & why they didn't work so people know not to suggest those & that you did some homework :)
-
-
SharpAffair almost 6 yearsIs it possible to keep standard frame rate (25), but accomplish the desired duration of the video by adding/skipping frames?
-
gregg almost 6 yearsYou have 40 pictures. To get a 3sec video you'd have to do 13-14fps video (40/3). If you don't want certain pictures included delete/move those & then redo the math to get the new FPS with the sole purpose of controlling the length of the clip
-
SharpAffair almost 6 yearsThe number of pictures will vary. And I need to keep the framerate 25. To automatically match the length by inserting/removing frames, I can run an extra command: ffmpeg -i customframerate.avi -qscale 0 -r 25 -y standardframerate.avi, but any way to accomplish it from beginning?
-
gregg almost 6 yearsNo idea. This is literally my second project/time using ffmpeg. I just happened to have a lot of notes/trouble with it so I shared. Please upvote if you appreciate the input, you don't have to accept it as the answer if you don't want to