title: Convert decoded frames to WAV format using ffmpeg libraries
body: <p>I have a stl queue of pointers to decoded frames on the heap
  (e.g. <code>decode_queue&lt;AVFrame *&gt;</code>)
   and I want to take those frames from the stl queue and encode them in WAV format. I tried using the examples that come with ffmpeg they break when I try to change the encoder to pcm_s32le/pcm_s16le. For example for decoding_encoding.c example, I just tried to change some parameters and all of a sudden I am getting a floating point exception.
  Is there a something I can do? I am really lost.  </p>
  
  <p><strong>UPDATE</strong>
  In decoding_encoding.c i changed the line:</p>
  
  <p><code>codec = avcodec_find_encoder(AV_CODEC_ID_MP2);</code></p>
  
  <p>to</p>
  
  <p><code>codec = avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE);</code></p>
  
  <p>this changed ended up making the <code>c-&gt;frame_size == 0</code> So the buffer is never created:</p>
  
  <p><code>buffer_size = av_samples_get_buffer_size(NULL, c-&gt;channels, c-&gt;frame_size,
                                               c-&gt;sample_fmt, 0);</code> </p>
  
  <p>In that case instead of the line:</p>
  
  <p><code>frame-&gt;nb_samples     = c-&gt;frame_size;</code></p>
  
  <p>I changed it to </p>
  
  <p><code>frame-&gt;nb_samples     = 10000</code> </p>
  
  <p>and </p>
  
  <p><code>buffer_size = av_samples_get_buffer_size(NULL, c-&gt;channels, 10000,
                                               c-&gt;sample_fmt, 0);</code></p>
  
  <p>just to see what happens(basically substituted <code>c-&gt;frame_size</code> for 10000). It compiles but it creates an output file but the player cannot find a stream for it or it is filled with garbage. At this point I am still stuck not sure what to do to get the output.WAV file.   </p>
  
  <p>Also, is a RIFF header automatically added or do I have to manually add it in as well?</p>