How do I generate a movie using ffmpeg using a single image (image1.png) for a duration of 15 seconds with a specific resolution so when I play the video, the image will appear on screen for 15 seconds.
4 Answers
ffmpeg -loop 1 -i image.png -c:v libx264 -t 15 -pix_fmt yuv420p -vf scale=320:240 out.mp4
- The -t 15 makes it 15 seconds long.
- The -vf scale=320:240 sets the width/height.
Make sure to use the latest ffmpeg version e.g. http://johnvansickle.com/ffmpeg/
14 Comments
ffmpeg -loop 1 -i image.png -t 5 out.mp4-r 30 before output to specify 30 FPSFound this to be faster:
ffmpeg -framerate 1/10 -i DJI_0024.JPG -c:v libx264 -t 10 -pix_fmt yuv420p -vf scale=320:240 out.mp4
-t 10 making the video 10 seconds long, and setting -framerate 1/10. Divisor of framerate should be same number as the argument to -t. This made a jpeg with large resolution to be converted to a video in less then a second for me, while the other answer took about 40 sec. Also resulting filesize became slightly smaller. from 3.38MB to 3.17MB
Comments
For high quality and encoding speed (shown here with HEVC, select the codec and its codec specific settings for compatibility in your use case):
ffmpeg -framerate 30 -i input.jpg -t 15 \
-c:v libx265 -x265-params lossless=1 \
-pix_fmt yuv420p -vf "scale=3840:2160,loop=-1:1" \
-movflags faststart \
out.mp4
-framerate 30rather than default 25 fps-t 15video duration 15 seconds-c:v libx265encode using h.265 (HEVC)-x265-params lossless=1lossless encoding, prevent artifacts for a still image. Unlike video, the image will be displayed for long enough to notice artifacts-pix_fmt yuv420pset pixel format for compatibility since input is an image (JPEGs are often YUV444, which many decoders will not accept)-vf "<options>"sets video filterscale=3840:2160specifically scale to 3840x2160 (4K)- You will want to use
3840:-1or-1:2160if your input is not exactly 16:9 (or whatever your target ratio is). This will prevent significant blurring due to an unintentional aspect ratio change. Look intopadorcropinstead, if you must have an exact resolution that does not match the ratio of the input.
- You will want to use
loop=-1:1infinitely loop (-1) for groups of 1 frame (1)movflags faststartwill put metadata at front of file for faster playback in web browsers.
I am running this in a cloud/serverless environment, so minimizing runtime is key. I tried the low framerate approach, but it did not play in my target environment or locally on VLC.
The -vf loop option is what loops the one frame here. It keeps that frame in memory and is the main reason why this is faster than other answers, while being more compatible than a fractional framerate approach.
3 Comments
Be aware to blow your Video Size with just 1 single Image!
Do this:
use ffmpeg with the Parameter -r 0.01 for almost no frame rate. This makes the file about 65% smaller
But you maybe also need to cut the length with this Paramter -ss 00:00:00 -t 00:00:27
heres my code:
ffmpeg -r 0.01 -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -tune stillimage -preset ultrafast -ss 00:00:00 -t 00:00:27 -c:a aac -b:a 96k -pix_fmt yuv420p -shortest out.mp4 -y