Converting hundreds of pictures of naming style "frame_0000.jpg", "frame_0001.jpg" into an avi?
Solution 1
The correct command should be
ffmpeg -f image2 -i frame_%04d.jpg view.avi
The %04d
means the number is 4 characters in length, zero padded (0000-9999).
If you want to do a range, I would just move the files you want into their own directory.
This is easy with a gui, but with command line you could do
mv frame_0[5-9]* newfolder
mv frame_1000* newfolder
Solution 2
glob pattern
For those of you using a non-ancient build of ffmpeg
the glob pattern is the most flexible method:
ffmpeg -framerate 10 -pattern_type glob -i "*.png" -pix_fmt yuv420p output.mkv
sequence
This will convert a series of numbered inputs, image-0001.png
, image-0002.png
, etc:
ffmpeg -framerate 30000/1001 -i image-%04d.png -pix_fmt yuv420p output.mkv
- Add
-start_number
, such as-start_number 100
, as an input option if you want to start with particular image.
cat
You can also use cat
to pipe your images to ffmpeg
:
cat *.jpg | ffmpeg -framerate ntsc -f image2pipe -c:v mjpeg -i - -pix_fmt yuv420p output.mp4
Notes
The output will use the same frame rate as the input. If you do not declare
-framerate
then the default of 25 will be used. You can also add-r
as an output option, such as in-r 25
, if you wantffmpeg
to read the input at a certain rate, and then drop or duplicate frames to achieve a different output frame rate.Depending on your input,
ffmpeg
version, and selected encoder,ffmpeg
will attempt to avoid or minimize chroma subsampling. Although this may be good in a technical sense it can produce an output that is not playable by non-FFmpeg based players. Adding-pix_fmt yuv420p
will ensure that your output is playable when encoding to H.264 video.It is recommended to use a recent build of
ffmpeg
since development is so active and to avoid bugs that have already been fixed. See the FFmpeg Download page for links to builds for Windows, OS X, and Linux.
Also see
- image2 demuxer documentation for additional information, options, and examples.
- FFmpeg and x264 Encoding Guide for help on getting a good quality output.
- FFmpeg slideshow from images - only one frame shown for potential common issues and how to resolve them.
Related videos on Youtube
Mohamad Najib
Updated on September 18, 2022Comments
-
Mohamad Najib almost 2 years
I have all of these images as jpegs and I want to stream them into an AVI. I am trying to use ffmpeg with the command noted here but I get an error "No such file or directory".
My exact command is (from the folder containing all of these files):
ffmpeg -f image2 -i frame_%d.jpg view.avi
How do I do this? Also, how can I do this for a specific range of images? Say I only want frames 500 to 1000, so I want frame_0500.jpg to frame_1000.jpg?
-
soandos over 12 yearsIf you were doing it one by one, does it work (thinking of a workaround)?
-
Mohamad Najib over 12 yearsI think that is the reason, you're correct :) But there's no way I'm renaming thousands of files to remove those zeros. There must be a way ffmpeg can handle this?
-
soandos over 12 yearsYou can rename the files with Bulk Renamer but I don't think there is a way to do it without that
-
Mike Fitzpatrick over 12 yearsYou can use
frame_%04d.jpg
to correctly handle the leading zeros butffmpeg
will still insist the sequence start at 0001. To start are 0500 I think you'll need to bulk rename.
-