1

I am trying to write an ffmpeg command to generate a waveform from audio. I've managed to generate the waveform but I fail when trying to add a line such that the silent areas are not blank.

Currently the command is:

 -filter_complex "[0:a]aformat=channel_layouts=mono,compand=attacks=0:points=-80/-900|-45/-15|-27/-9|0/-7|20/-7:gain=15,showwavespic=s=180x26:colors=#7c84cc[fg];color=s=180x26:color=#303030[bg];[bg][fg]overlay=format=auto,drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=1:color=#7c84cc" -frames:v 1

I have added some tweaks of my own to boost the visual appeal but what I would like is to use the drawbox without the color filter. If I try to do that the line disappears during the silent part.

I have also attempted to use a transparent image as the background but that failed as well.

I have relied heavily on this question when approaching this problem:
Generating a waveform using ffmpeg

1 Answer 1

0

One option would be to use the gradients filter, to add a changing colour gradient.

e.g.

ffmpeg -i input.mp3 -filter_complex "gradients=s=vga:c0=303030:c1=7c84cc:x0=0:x1=0:y0=0:y1=640 [bg];[0:a]showwaves=mode=p2p:s=vga:split_channels=1:scale=lin:draw=scale:colors=Yellow|White[v];[bg][v]overlay=shortest=1:format=rgb:alpha=premultiplied [vid]" -map "[vid]" -map 0:a  -vsync vfr -preset ultrafast -f matroska - | ffplay -autoexit -

There is a speed parameter as well to adjust the gradient rotation.

enter image description here

Edit: Having checked because @soundflix complained this didn't show a flat line during silence, I added a 10 second silence to the middle of a piece of audio.

This was the result:

enter image description here

which rather suggests it does show a flat line using ffmpeg version 4.4.2-0ubuntu0.22.04.1

2
  • This does not answer the question (having a straight line during silent parts)
    – soundflix
    Commented Feb 25 at 21:34
  • @soundflix Correct! What this does do, is offer an option, mentioned in the question, to boost the visual appeal Commented Feb 26 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.