How to Make a Video from a Still Image and Audio with FFmpeg
With one image and an audio file, a single FFmpeg command can produce a video that shows the image while the audio plays. This method is useful when you want to post a podcast episode, your own song, or a lecture recording to a video site with an album cover or a cover image.
In my test environment, I made MP4 files from a 1280×720 PNG and a 30-second audio file. I removed or changed the options one at a time and checked the resulting videos with ffprobe. The basic command is as follows.
ffmpeg -loop 1 -i cover.png -i audio.m4a -c:v libx264 -pix_fmt yuv420p -c:a copy -shortest out.mp4
The test environment was a virtual machine running Ubuntu 24.04.5 with FFmpeg 6.1.1 (Ubuntu package 6.1.1-3ubuntu5), 4 CPU cores, and 16 GB of memory. The images were PNG and JPEG files exported from FFmpeg's test image (testsrc2). The audio was a 30-second stereo file (AAC, MP3, and WAV) made by mixing a sine wave and pink noise in FFmpeg. I did not play the resulting videos on a smartphone, a video site, or other players. I also did not test with real photos or recorded audio, or with encoders other than H.264.
- 1. The role of each part of the command
- 2. Without -loop 1, the video is only one frame
- 3. Without -shortest, the video does not stop when the audio ends
- 4. Choosing -c:a for each audio format
- 5. Without -pix_fmt yuv420p, the profile changes
- 6. With -framerate 1, it is faster but the video ends before the audio
- 7. The effect of -tune stillimage was small
- 8. Images with an odd width or height cause an error
The role of each part of the command
With the basic command, FFmpeg reads the image repeatedly as a 25-frames-per-second video and puts it into an MP4 together with the audio. All three runs finished in 4.48 to 4.71 seconds and produced the following video. The ffprobe output is shown in the order of video stream, audio stream, and whole file.
stream|codec_name=h264|profile=High|codec_type=video|pix_fmt=yuv420p|r_frame_rate=25/1|duration=30.000000|nb_read_frames=750
stream|codec_name=aac|profile=LC|codec_type=audio|r_frame_rate=0/0|duration=30.000000|nb_read_frames=1292
format|duration=30.000000|size=656374
The video has 750 frames and lasts 30.0 seconds, which matches the 30.0-second audio. The file size was about 656 KB.
| Option | Role |
|---|---|
-loop 1 |
After the image is read, starts over from the beginning and keeps reading it |
-c:v libx264 |
Encodes the video as H.264 |
-pix_fmt yuv420p |
Sets the color format to 4:2:0 |
-c:a copy |
Puts the audio in without re-encoding it |
-shortest |
Stops when the shortest stream ends |
-loop and -framerate (default 25), which sets the number of frames per second, are input options for the image2 demuxer that reads image files. They are described in FFmpeg's documentation for the image2 input. -shortest is listed in the detailed ffmpeg command option reference, which says that encoding finishes when the shortest output stream ends.
Without -loop 1, the video is only one frame
When I removed -loop 1 and also left out -shortest, an MP4 was produced without any error.
ffmpeg -i cover.png -i audio.m4a -c:v libx264 -pix_fmt yuv420p -c:a copy noloop.mp4
stream|codec_name=h264|profile=High|codec_type=video|pix_fmt=yuv420p|r_frame_rate=25/1|duration=0.040000|nb_read_frames=1
stream|codec_name=aac|profile=LC|codec_type=audio|r_frame_rate=0/0|duration=30.000000|nb_read_frames=1292
format|duration=30.000000|size=507213
The whole file is 30 seconds long, but the video is only one frame (0.04 seconds). The image was read only once, so there are no video frames for the rest of the time.
Without -shortest, the video does not stop when the audio ends
When I kept -loop 1 but removed -shortest, the image was read without end. In the test, I stopped it with timeout after 15 seconds. The progress output at that point was as follows.
frame= 2739 fps=182 q=-1.0 Lsize= 1064kB time=00:01:49.44 bitrate= 79.7kbits/s speed=7.28x
In those 15 seconds, 109.56 seconds of video (2,739 frames) had been written. The audio ends at 30 seconds, so the remaining roughly 80 seconds are silent video with only the image. To stop the video at the end of the audio, you need -shortest (or -t, described later).
Choosing -c:a for each audio format
-c:a copy puts the input audio into the MP4 without re-encoding it. Both AAC in .m4a and MP3 in .mp3 went into an MP4 with -c:a copy. For MP3, the audio in the MP4 still reported codec_name=mp3.
When I used -c:a copy with a WAV file, an MP4 was produced without any error, and the audio stayed as pcm_s16le (uncompressed audio). The file was 5,462,442 bytes, which is larger than the original WAV (5,292,110 bytes). For WAV input, you should therefore re-encode the audio to AAC.
ffmpeg -loop 1 -i cover.png -i audio.wav -c:v libx264 -pix_fmt yuv420p -c:a aac -b:a 192k -shortest out.mp4
The video made with this command was 896,334 bytes, and its audio was AAC.
Without -pix_fmt yuv420p, the profile changes
When I removed -pix_fmt yuv420p from the basic command and made the video from a PNG, the video became yuv444p, and the H.264 profile was "High 4:4:4 Predictive." The same profile was used when I made the video from a JPEG image (yuvj444p).
stream|codec_name=h264|profile=High 4:4:4 Predictive|codec_type=video|pix_fmt=yuv444p|r_frame_rate=25/1|duration=30.000000|nb_read_frames=750
Without -pix_fmt, the encoder chose 4:4:4, which does not thin out color information, from a PNG in rgb24. With -pix_fmt yuv420p, the profile was "High" for both PNG and JPEG sources.
With -framerate 1, it is faster but the video ends before the audio
Since the image does not move, it may seem unnecessary to create 25 frames per second. When I added -framerate 1 on the input side to make it 1 frame per second, processing became much faster.
ffmpeg -loop 1 -framerate 1 -i cover.png -i audio.m4a -c:v libx264 -pix_fmt yuv420p -c:a copy -shortest out.mp4
| Frames per second | Processing time (3 runs) | Frame count | Video length | File size |
|---|---|---|---|---|
| 25 (default) | 4.48 to 4.71 seconds | 750 | 30.00 seconds | 656,374 bytes |
| 1 | 0.58 to 0.68 seconds | 29 | 29.00 seconds | 548,279 bytes |
However, with -framerate 1 the video ended at 29 frames and 29.0 seconds, which is one second shorter than the 30-second audio.
I also checked a case where the audio length is not a whole number of seconds. With 30.5-second audio, the video made with -shortest was 30.36 seconds at 25 fps and 29.00 seconds at 1 fps. In both cases, the video ended before the audio.
The ffmpeg command documentation describes -shortest_buf_duration, which sets the maximum length of frames buffered when using -shortest, and says that a larger value may make -shortest more accurate in some cases. I tried values of 0.1, 1, 10, and 60, but the 25 fps video stayed at 30.36 seconds in every case.
If you write the audio length (30.5, found with ffprobe) in -t instead of using -shortest, the video becomes slightly longer than the audio.
ffmpeg -loop 1 -i cover.png -i audio.m4a -c:v libx264 -pix_fmt yuv420p -c:a copy -t 30.5 out.mp4

With 1 fps and -t 30.5, the video had 31 frames and lasted 31.0 seconds, and the whole file was also 31.0 seconds. The 0.5 seconds after the audio ends contain only the image and no sound. At 25 fps, the difference was only 0.14 seconds shorter with -shortest and 0.02 seconds longer with -t. If you want to keep the length difference small rather than reduce processing time, keeping the default of 25 is the safer choice.
The effect of -tune stillimage was small
libx264 accepts stillimage as a value for -tune. The libx264 option description says that -tune adjusts the encoder settings. With the test image, the file was 662,992 bytes with the option and 656,374 bytes without it. The processing times were 4.52 to 4.84 seconds and 4.48 to 4.71 seconds, almost no difference. For this image, the option did not make the file smaller.
Images with an odd width or height cause an error
With an image whose width or height is odd, such as 1279×719, H.264 encoding with -pix_fmt yuv420p did not start, and no video was created.
[libx264 @ 0x…] width not divisible by 2 (1279x719)
[vost#0:0/libx264 @ 0x…] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
Error while filtering: Generic error in an external library
[out#0/mp4 @ 0x…] Nothing was written into output file, because at least one of its streams received no packets.
The 0x… is a memory address that changes for each process, so it is omitted. When I added a scale filter that rounds the width and height down to multiples of 2, a 1278×718 video was created.
ffmpeg -loop 1 -i odd.png -i audio.m4a -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -pix_fmt yuv420p -c:a copy -shortest out.mp4




