FFmpeg: Combine Video and Audio Visualizer Side-by-Side

This article provides a straightforward guide on how to use FFmpeg to combine a video stream and a dynamically generated audio visualizer side-by-side into a single output file. You will learn the exact command-line structure, how the filter graph manages the assets, and how to customize the visualizer to match your video’s dimensions.

The FFmpeg Command

To merge a video and an audio visualizer side-by-side, you need to scale both video inputs to the same height and use the hstack (horizontal stack) filter.

Run the following command in your terminal:

ffmpeg -i input.mp4 -filter_complex \
"[0:v]scale=-1:480[vid]; \
 [0:a]showwaves=size=640x480:mode=line:colors=cyan[vis]; \
 [vid][vis]hstack=inputs=2[v]" \
-map "[v]" -map 0:a -c:v libx264 -crf 23 -c:a aac -b:a 192k output.mp4

Command Breakdown

Here is how the command works step-by-step:

Customizing the Visualizer

You can replace the showwaves filter with other FFmpeg audio visualization filters depending on your preference:

Ensure that whichever filter you choose, the height parameter matches the height of your scaled video stream (e.g., 480) to prevent errors with the hstack filter.