Create Linear Audio Waveforms with FFmpeg

This guide explains how to convert an audio file into a linear waveform visualization using FFmpeg. By leveraging FFmpeg's built-in audio visualization filters, you can generate both animated video waveforms that sync directly with your track and static waveform images. Below, you will find direct command-line examples, parameter breakdowns, and styling options to customize the appearance and resolution of your waveform.

Real-Time Animated Linear Waveform

To render an MP4 video where the waveform draws dynamically as the audio plays, use the showwaves filter.

Run the following command:

ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1920x1080:mode=line:r=30:colors=white[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p -c:a aac output.mp4

Breakdown of Parameters:

  • -i input.mp3: Specifies your source audio track.
  • -filter_complex: Invokes the filtergraph.
  • showwaves: The filter responsible for transforming audio into video frames.
  • s=1920x1080: Defines the output video resolution (Width x Height).
  • mode=line: Sets the visualization mode. The line value draws continuous vertical lines for each sample.
  • r=30: Specifies the frame rate (30 fps).
  • colors=white: Sets the waveform color. Hex codes can also be used (e.g., 0x00FFAA).
  • [v]: Labels the processed video output.
  • -map "[v]" -map 0:a: Combines the generated visual stream with the original audio stream.
  • -c:v libx264 -pix_fmt yuv420p: Encodes the video stream to H.264 format with maximum player compatibility.
  • -c:a aac: Encodes the audio stream to AAC.

Centered Waveform Variation

If you want a balanced waveform extending evenly from the horizontal center line, change the mode parameter to cline:

ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1920x1080:mode=cline:colors=0x00FFCC:scale=sqrt[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p -c:a copy output.mp4
  • mode=cline: Centers the audio samples along the middle of the frame.
  • scale=sqrt: Applies a square root scale to the amplitude, which boosts quieter parts of the audio visually so the waveform remains visible during lower volumes. Other options include lin (linear, default) and log (logarithmic).
  • -c:a copy: Copies the source audio directly into the output container without re-encoding.

Static Waveform Image

If you only need a single static image representing the entire audio file from start to finish, use the showwavespic filter instead:

ffmpeg -i input.mp3 -filter_complex "showwavespic=s=1920x1080:colors=#FF5500" -frames:v 1 waveform.png
  • showwavespic: Analyzes the entire audio file and renders the complete waveform into a single image frame.
  • -frames:v 1: Stops processing after generating the first frame, saving the result directly to an image file.