I am trying to generate a waveform image using ffmpeg.
I have successfully made a waveform image, however it doesn't look very nice...
I have been looking around to try and style the image to make it look nicer, however I have been unable to find any information on this or any tutorials on this.
I am using PHP and shell_exec to create the waveform.
I am aware that there are php library that can do this but due to file format this is a lengthy process.
The code I am using is as follows:
$command = 'convertvid\bin\ffmpeg -i Temp\\'.$file.' -y -lavfi showwavespic=split_channels=0:s='.$width.'x50 Temp\\'.$PNGFileName;
shell_exec($command);
Basically I would like to add a line through the middle as there are blank spots at the moment and would like to be able to set the background and wave colour.
Default waveform
Notes
Notice the segment of silent audio in the middle.
Default colors are red (left channel) and green (right channel) for a stereo input.
The color is mixed where the channels overlap.
The background is transparent.
You can change the channel colors with the
colors
option, such as"showwavespic=colors=blue|yellow"
. See a list of valid color names or use hexadecimal notation, such as#ffcc99
.If the default colors are white and gray on a black background then your
ffmpeg
is too old. See the FFmpeg Download page for links to recentffmpeg
binaries.If you get
Option 'colors' not found
then yourffmpeg
is too old. See the FFmpeg Download page for links to recentffmpeg
binaries.See the showwavespic filter documentation for additional options.
If you want a video instead of an image use the showwaves filter.
Fancy waveform
Explanation of options
aformat downsamples the audio to mono. Otherwise, by default, a stereo input would result in a waveform with a different color for each channel (see Default waveform example above).
compand modifies the dynamic range of the audio to make the waveform look less flat. It makes a less accurate representation of the actual audio, but can be more visually appealing.
showwavespic makes the actual waveform.
color source filter is used to make a colored background that is the same size as the waveform.
drawgrid adds a grid over the background. The grid does not represent anything, but is just for looks. The grid color is the same as the hideous waveform color (
#9cf42f
), but opacity is set to 10% (@0.1
).overlay will place
[bg]
(what I named the filtergraph for the background) behind[fg]
(the waveform).Finally, drawbox will make the horizontal line so any silent areas are not as ugly.
Image background
Of course you can use an image or video instead for the background: