title: using ffmpeg to create a wavefile image from opus
body: <p>I have been trying to use ffmpeg to create a wavefile image from an opus file.  so far i have found three different methods but cannot seem to determine which one is the best.</p>
  
  <p>The end result is hopefully to have a sound-wave that is only approx. 55px in height.  The image will become part of a css background-image.</p>
  
  <p>Adapted from <a href="https://stackoverflow.com/a/32276471/1109017">Generating a waveform using <code>ffmpeg</code></a>:</p>
  
  <blockquote>
    <p>ffmpeg -i file.opus -filter_complex
    "showwavespic,colorbalance=bs=0.5:gm=0.3:bh=-0.5,drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=1:color=black@0.5"
    file.png</p>
  </blockquote>
  
  <p>which produces this image:
  <a href="https://i.stack.imgur.com/52diy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/52diy.png" alt="enter image description here"></a></p>
  
  <p>Next, I found this one (and my favorite because of the simplicity):</p>
  
  <blockquote>
    <p>ffmpeg -i test.opus -lavfi showwavespic=split_channels=1:s=1024x800 test.png</p>
  </blockquote>
  
  <p>And here is what that one looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/u4eLx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u4eLx.png" alt="enter image description here"></a></p>
  
  <p>Finally, this one from <a href="https://trac.ffmpeg.org/wiki/Waveform" rel="nofollow noreferrer">FFmpeg Wiki: Waveform</a>, but it seems less efficient using a second utility (gnuplot) rather than just ffmpeg:</p>
  
  <blockquote>
    <p>ffmpeg -i  file.opus    -ac 1 -filter:a
    aresample=4000 -map 0:a -c:a pcm_s16le -f data - |  \
    gnuplot  -e "set
    terminal png size 525,050;set output
    'file.png';unset key;unset tics;unset border; set
    lmargin 0;set rmargin 0;set tmargin 0;set bmargin 0; plot '
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/FHmgF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FHmgF.png" alt="enter image description here"></a></p>
  
  <p>Option two is my favorite, but i dont like the margins on the top and bottom of the waveforms.</p>
  
  <p>Option three (using gnuplot) makes the best 'shaped' image for our needs, since the initial spike in sound seems to make the rest almost too small to use (lines tend to almost disappear) when the image is sized at only 50 pixels high.</p>
  
  <p>Any suggestions how might best approach this?  I really understand very little about any of the options I see, except of course for the size.  Note too i have 10's of thousands to process, so naturally i want to make a wise choice at the very beginning.</p>