Loop Static Image with Audio using FFmpeg
This article provides a straightforward guide on how to convert a single static image and an audio file into a continuous video using the powerful command-line tool FFmpeg. You will learn the exact command needed to loop the image, sync it to the duration of the audio track, and export the final video file quickly and efficiently.
To combine a single static image and an audio file into a video, you can use a single FFmpeg command. Because an image has no inherent duration, you must tell FFmpeg to loop the image infinitely and then stop rendering once the audio track ends.
Here is the standard command to achieve this:
ffmpeg -loop 1 -framerate 2 -i image.jpg -i audio.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest output.mp4Understanding the Command Parameters
-loop 1: This loops the input image indefinitely. It must be placed before the image input flag.-framerate 2: Sets the video frame rate. Using a low frame rate like 1 or 2 frames per second keeps the output file size small without affecting the quality of a static image.-i image.jpg: Specifies the path to your static input image.-i audio.mp3: Specifies the path to your input audio file.-c:v libx264: Uses the H.264 video codec, which is highly compatible with almost all media players and web platforms.-tune stillimage: An encoder preset that optimizes the compression algorithm for video frames that do not change, drastically reducing the final file size.-c:a aac: Encodes the audio using the AAC codec, ensuring high compatibility with video formats.-b:a 192k: Sets the audio bitrate to 192kbps for high-quality sound.-pix_fmt yuv420p: Sets the pixel format to YUV 4:2:0. This step is critical for ensuring the output video plays correctly on web browsers and mobile devices.-shortest: This parameter tells FFmpeg to stop writing the output file as soon as the shortest input finishes. Since the image loop is infinite, this ensures the video ends exactly when the audio file ends.output.mp4: The name of your final output video file.
By running this command in your terminal or command prompt, FFmpeg will quickly package your image and audio into a perfectly synchronized MP4 video suitable for uploading to platforms like YouTube or Vimeo.