ffmpeg -r 1/5 -start_number 2 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
This line worked fine but I want to create a video file from images in another folder. Image names in my folder are:
img001.jpg
img002.jpg
img003.jpg
...
How could I input images files from a different folder? Example: C:\mypics
I tried this command but ffmpeg
generated a video with the first image (img001.jpg) only.
ffmpeg -r 1/5 -start_number 0 -i C:\myimages\img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
-pattern_type glob
This great option makes it easier to select the images in many cases.
Slideshow video with one image per second
Add some music to it, cutoff when the presumably longer audio when the images end:
Here are two demos on YouTube:
Be a hippie and use the Theora patent-unencumbered video format:
Your images should of course be sorted alphabetically, typically as:
and so on.
I would also first ensure that all images to be used have the same aspect ratio, possibly by cropping them with
imagemagick
or nomacs beforehand, so that ffmpeg will not have to make hard decisions. In particular, the width has to be divisible by 2, otherwise conversion fails with: "width not divisible by 2".Normal speed video with one image per frame at 30 FPS
Here's what it looks like:
GIF generated with: https://askubuntu.com/questions/648603/how-to-create-an-animated-gif-from-mp4-video-via-command-line/837574#837574
Add some audio to it:
Result: https://www.youtube.com/watch?v=HG7c7lldhM4
These are the test media I've used:a
Images generated with: How to use GLUT/OpenGL to render to a file?
It is cool to observe how much the video compresses the image sequence way better than ZIP as it is able to compress across frames with specialized algorithms:
opengl-rotating-triangle.mp4
: 340Kopengl-rotating-triangle.zip
: 7.3MConvert one music file to a video with a fixed image for YouTube upload
Answered at: https://superuser.com/questions/700419/how-to-convert-mp3-to-youtube-allowed-video-format/1472572#1472572
Full realistic slideshow case study setup step by step
There's a bit more to creating slideshows than running a single ffmpeg command, so here goes a more interesting detailed example inspired by this timeline.
Get the input media:
Now we have a quick look at all image sizes to decide on the final aspect ratio:
which outputs:
so the classic 480p (640x480 == 4/3) aspect ratio seems appropriate.
Do one conversion with minimal resizing to make widths even (TODO automate for any width, here I just manually looked at
identify
output and reduced width and height by one):This produces terrible output, because as seen from:
ffmpeg just takes the size of the first image, 556x494, and then converts all others to that exact size, breaking their aspect ratio.
Now let's convert the images to the target 480p aspect ratio automatically by cropping as per ImageMagick: how to minimally crop an image to a certain aspect ratio?
So now, the aspect ratio is good, but inevitably some cropping had to be done, which kind of cut up interesting parts of the images.
The other option is to pad with black background to have the same aspect ratio as shown at: Resize to fit in a box and set background to black on "empty" part
Generally speaking though, you will ideally be able to select images with the same or similar aspect ratios to avoid those problems in the first place.
About the CLI options
Note however that despite the name,
-glob
this is not as general as shell Glob patters, e.g.:-i '*'
fails: https://trac.ffmpeg.org/ticket/3620 (apparently because filetype is deduced from extension).-r 30
makes the-framerate 1
video 30 FPS to overcome bugs in players like VLC for low framerates: VLC freezes for low 1 FPS video created from images with ffmpeg Therefore it repeats each frame 30 times to keep the desired 1 image per second effect.Next steps
You will also want to:
cut up the part of the audio that you want before joining it: Cutting the videos based on start and end time using ffmpeg
TODO: learn to cut and concatenate multiple audio files into the video without intermediate files, I'm pretty sure it's possible:
Tested on
ffmpeg 3.4.4, vlc 3.0.3, Ubuntu 18.04.
Bibliography
See the Create a video slideshow from images – FFmpeg
I tested below parameters, it worked for me
below parameters also worked but it always skips the first image
making a video from images placed in different folders
First, add image paths to imagepaths.txt like below.
Sample usage as follows;
-safe 0 parameter prevents Unsafe file name error
Related links
FFmpeg making a video from images placed in different folders
FFMPEG An Intermediate Guide/image sequence
Concatenate – FFmpeg
cat *.png | ffmpeg -f image2pipe -i - output.mp4
from wiki
Simple Version from the Docs
Works particularly great for Google Earth Studio images: