Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG waveform transparent, background solid color

Tags:

ffmpeg

mp3

I am trying to generate a waveform with ffmpeg, I want the background to be a solid color, and the actual waveform to be transparent. The following achieves partially what i want, except that in has a black background. I would like to be able to change this to any color, but have the waveform be transparent. How can i achieve this with ffmepg?

ffmpeg -i input.mp3 -filter_complex \
"[0:a]aformat=channel_layouts=mono,\
compand=gain=-6, \
showwavespic=s=600x120, \
colorchannelmixer=rr=1:gg=0:bb=0:aa=1,\
drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=1:color=red,\
format=rgba,\
colorkey=#ff0000" \
-vframes 1 output.png

This generates this waveform: the background is black, the waveform itself is transparent. How do I change the background color to a different color, while still keeping the waveform transparent?

enter image description here

like image 556
user1152226 Avatar asked May 10 '26 12:05

user1152226


1 Answers

Use this

ffmpeg -i input.mp3 -filter_complex \
   "[0:a]aformat=channel_layouts=mono,compand=gain=-6, \
    showwavespic=s=600x120:colors=white,negate[a]; \
    color=red:600x120[c]; \
    [c][a]alphamerge"  -vframes 1 output.png

The color specified in the showwavespic ensures that you get a strict duochrome output. Better than pulling a key.

like image 139
Gyan Avatar answered May 12 '26 12:05

Gyan