How to Loop an Image in FFmpeg
This article explains how to use the -loop option in
FFmpeg to convert a single static image into a continuous video loop.
You will learn the correct command syntax, how to set a specific
duration for the video, and how to apply essential encoding settings to
ensure the output plays smoothly across different media players.
To loop an image in FFmpeg, you must place the -loop 1
option before specifying the input image. This tells
FFmpeg to read the single image infinitely. Because the loop is
infinite, you must also define a stopping point using the duration
parameter (-t) or a frame limit.
Basic Command Syntax
Here is the standard command to create a 10-second MP4 video from a single image:
ffmpeg -loop 1 -i input.png -c:v libx264 -t 10 -pix_fmt yuv420p output.mp4Parameter Breakdown
-loop 1: Enables looping for the input file. Placing it before-iensures FFmpeg loops the source image. Setting it to1enables looping, while0disables it.-i input.png: Specifies your source image file (supports PNG, JPG, WebP, etc.).-c:v libx264: Selects the H.264 video codec, which ensures wide compatibility with modern browsers and devices.-t 10: Sets the duration of the output video in seconds. In this case, the final video will be exactly 10 seconds long. If you omit this, FFmpeg will run indefinitely until manually stopped.-pix_fmt yuv420p: Sets the pixel format. Static images often use pixel formats that are incompatible with standard video players. Converting toyuv420pensures the video plays correctly on macOS, iOS, QuickTime, and web browsers.output.mp4: The name and format of your output file.
Adding Audio to the Loop
If you want to loop the image to match the length of an audio track
(like an MP3 or WAV file), you can combine the image loop with the
-shortest flag:
ffmpeg -loop 1 -i input.png -i audio.mp3 -c:v libx264 -c:a aac -pix_fmt yuv420p -shortest output.mp4In this command: * -i audio.mp3:
Imports your audio file. * -c:a aac:
Encodes the audio to AAC format. *
-shortest: Tells FFmpeg to stop encoding
as soon as the shortest input finishes. Since the image loops
infinitely, the video will end exactly when the audio file ends.