Waveform generation using ffmpeg

I am trying to create a waveform image using ffmpeg.

I have successfully created a waveform image, however this does not look very good ...

I was looking to try to create an image so that it looks better, but I could not find any information about this or about any textbooks on this subject.

I use PHP and shell_exec to create a waveform.

I know there is a php library that can do this, but because of the file format, this is a lengthy process.

The code I use 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, because at the moment there are empty places, and I would like to set the background and color of the wave.

+5
source share
2 answers

Default waveform

enter image description here

 ffmpeg -i stereo_input.foo -filter_complex showwavespic -frames:v 1 output.png 

Notes

  • Pay attention to the segment of silent audio in the middle.

  • The default colors are red (left channel) and green (right channel) for stereo input.

  • Color mixes when channels overlap.

  • The background is transparent.

  • You can change the colors of the channel using the colors parameter, for example, "showwavespic=colors=blue|yellow" . See the list of valid color names or use hexadecimal notation, such as #ffcc99 .

  • If the default colors are white and gray on a black background, your ffmpeg too old. See the FFmpeg Download link for links to the latest ffmpeg binaries.

  • If you get Option 'colors' not found , your ffmpeg will be too old. See the FFmpeg Download link for links to the latest ffmpeg binaries.

  • See the showwavespic filter documentation for more information .

  • If you want to use video instead of an image, use the showwaves filter .

Bizarre signal

enter image description here

 ffmpeg -i input -filter_complex \ "[0:a]aformat=channel_layouts=mono, \ compand=gain=-6, \ showwavespic=s=600x120:colors=#9cf42f[fg]; \ color=s=600x120:color=#44582c, \ drawgrid=width=iw/10:height=ih/5:color=# 9cf42f@0.1 [bg]; \ [bg][fg]overlay=format=rgb,drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=1:color=#9cf42f" \ -vframes 1 output.png 

Parameter Explanation

  • aformat reduces the sound to mono. Otherwise, by default, stereo input will produce a waveform with a different color for each channel (see Example above Default value ).

  • compand changes the dynamic range of the sound to make the waveform look less flat. This makes a less accurate representation of the actual sound, but can be more visually appealing.

  • showwavespic makes the actual waveform.

  • The color source filter is used to make the color background the same size as the waveform.

  • drawgrid adds a grid over the background. The grid does not represent anything, but only for looks. The color of the mesh is the same as the color of the hideous wave ( #9cf42f ), but the opacity is set to 10% ( @0.1 ).

  • overlay will place [bg] (which I called a filter for the background) behind [fg] (waveform).

  • Finally, drawbox will make a horizontal line so that any dumb areas are not so ugly.

Background Image

Of course, you can use an image or video instead of a background:

enter image description here

 ffmpeg -i audio -i image -filter_complex \ "[1:v]scale=600:-1,crop=iw:120[bg]; \ [0:a]showwavespic=s=600x120:colors=cyan|aqua[fg]; \ [bg][fg]overlay" \ -q:v 3 showwavespic_bg.jpg 
+22
source

I hope the question is not too stupid, but I tried the solution above and got this output: output from ffmpeg

Use this command to get a raw sound signal (removed compand = gain = -6 to get realistic output):

 ffmpeg -f s16le -ac 1 -i audio.raw -filter_complex \ "[0:a]aformat=channel_layouts=mono, \ showwavespic=s=600x120:colors=#9cf42f[fg]; \ color=s=600x120:color=#44582c, \ drawgrid=width=iw/10:height=ih/5:color=# 9cf42f@0.1 [bg]; \ [bg][fg]overlay=format=rgb,drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=1:color=#9cf42f" \ -vframes 1 output.png 

And this is what I got when I imported the raw data into Audacity, the sound saturation is clearly visible compared to the output of ffmpeg: Form of impudence

I tried many different options, but the output of ffmpeg looks like a good unsaturated sound, and in courage you can hear and see that it is really saturated.

PS sorry, not enough reputation to insert images into the question.

0
source

All Articles