From audio to video with ffmpeg

From audio to video with ffmpeg

A video content is something that social media and website used widely. Also a Video content it’s some more engaging and with a better reaction than a simple audio. Working on a webradio, I’m always looking for some solution that can engage people in order to attract people so my Idea was to modify audio content to create a video content.

But how you can create a video content from a video content?

ffmpeg has a huge collection of functions, one of these is waveform that can generate a video from an audio, the video simply shows the waveform of the audio. It’s good, but for me this is just a starting point

ffmpeg -i input_audio.mp3 -filter_complex \
"[0:a]showwaves=s=1280x100:colors=Red:mode=cline:rate=25:scale=sqrt[outputwave]" \

I’m using here filter_complex because I want a chain of filters, and this is only one of the steps. Let me explain the parameters:

[0:a] this means: from the stream 0 take the audio…

showwaves=s=1280×100 this is the filter, showwave, and the output format 1280×100

colors=Red the color of the waveform….

mode=cline the type of the waveform, line…..

rate=25 … how many frame

scale=sqrt …the scale. sqrt is good

[outputwave] this is a placeholder….we will use it later in the chain.

But what I want is a video, where the waveform it’s only an overlay level on it. The base video could be a pre-created video that can be used for all the audio content. It could be a slideshow video, something created in graphic, a static foto or with simple animation. So let’s suppose that this video exists. But How can this video fit the audio length, that can be variable?

How can, a pre-created video, fit the audio length of an audio file with a variable length?

My idea is to loop the pre-created video for the length of the audio and overlay on it, the waveform created from the audio file!

And I want this in a single ffmpeg command! And so…

ffmpeg -stream_loop -1 -i video.mp4 \
-i input_audio.mp3 -filter_complex \
"[1:a]showwaves=s=1280x100:colors=Red:mode=cline:rate=25:scale=sqrt[outputwave]; \
[0:v][outputwave] overlay=0:main_h-overlay_h:shortest=1 [out]" \
-map '[out]' -map '1:a' -c:a copy -y \

-stream_loop -1 -i video.mp4 This loops the input video, video.mp4, idefinetly*
-i input_audio.mp3….outputwave] we already covered this….
[0:v][outputwave] overlay=0:main_h-overlay_h:shortest=1 [out] this get the video of the first video, with [0:v] and the video of the waveform, [outputwave] as the input for the overlay filter, and put it in the position bottom with 0:main_h-overlay_h. The magic happens with shortest=1 that means: do this overlay for the length of the shorter. *The loop is infinitely long but the waveform no! And this means: for the length of the waveform!

-map ‘[out]’ -map ‘1:a’ -c:a copy -y this map the output as a video and copy the audio of the

This is a frame of the final video:

Liked this article? Consider a donation!