brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -loop 1 turns an audio file and one picture into a video

Ffmpeg
~/tips/tip-ffmpeg-loop-image-audio

ffmpeg -loop 1 -i cover.jpg -i episode.mp3 -c:v libx264 -tune stillimage -pix_fmt yuv420p -c:a aac -shortest episode.mp4

Makes a video from a still image and a sound file, for sites that only accept video.

Some platforms only take video, even when all you have is a podcast episode or a song. A still picture with the audio under it is enough.

ffmpeg -loop 1 -i cover.jpg -i episode.mp3 -c:v libx264 -tune stillimage -pix_fmt yuv420p -c:a aac -shortest episode.mp4

-loop 1 in front of the image makes ffmpeg repeat that one picture forever. -shortest stops the output when the shortest input ends, which is the audio, since the picture never ends. Without -shortest the command keeps going until you stop it.

-tune stillimage tells x264 that nothing moves, which keeps the file small. -pix_fmt yuv420p is there for compatibility: a JPEG often decodes to a format that many players and phones can’t show.

One thing to check: the image size should be even in width and height, or the encoder complains. Add -vf scale=-2:1080 if your cover is an odd size. Also, -shortest can leave the video a fraction longer or shorter than the audio, because it stops on packet borders. A 5-second test sound can come out at exactly 5 seconds, but I wouldn’t count on frame precision with this option.

Further reading: ffmpeg documentation, FFmpeg wiki: H.264 video encoding guide

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link