FFmpeg audio encoder new encode function
<p>I would like to update an AV Audio encoder using function <code>avcodec_encode_audio (deprecated)</code> to <code>avcodec_encode_audio2</code>, without modifying the structure of existing encoder:</p>

<pre><code> outBytes = avcodec_encode_audio(m_handle, dst, sizeBytes, (const short int*)m_samBuf);
</code></pre>

<p>where:</p>

<p>1)  m_handle AVCodecContext</p>

<p>2)  dst, uint8_t * destination buffer</p>

<p>3)  sizeBytes, uint32_t size of the destination buffer</p>

<p>4) m_samBuf void * to the input chunk of data to encode (this is casted to: const short int*)</p>

<p>is there a simply way to do it?</p>

<p>Im tryng with:</p>

<pre><code>int gotPack = 1;
memset (&amp;m_Packet, 0, sizeof (m_Packet));
m_Frame = av_frame_alloc();

av_init_packet(&amp;m_Packet);
m_Packet.data = dst;
m_Packet.size = sizeBytes;

uint8_t* buffer = (uint8_t*)m_samBuf;
m_Frame-&gt;nb_samples = m_handle-&gt;frame_size;

avcodec_fill_audio_frame(m_Frame,m_handle-&gt;channels,m_handle-&gt;sample_fmt,buffer,m_FrameSize,1);

outBytes = avcodec_encode_audio2(m_handle, &amp;m_Packet, m_Frame, &amp;gotPack);
char error[256];
av_strerror(outBytes,error,256);

if (outBytes&lt;0){
    m_server-&gt;log(1,1,"Input data: %d, encode function call error: %s \n",gotPack, error);
    return AUDIOWRAPPER_ERROR;
}
av_frame_free(&amp;m_Frame);
</code></pre>

<p>it compiles but it does not encode anything, i dont here audio at the output if I pipe the output stream on mplayer, wich was warking prior to the upgrade.</p>

<p>What am I doing wrong?</p>

<p>The encoder accept only two sample formats:</p>

<pre><code>AV_SAMPLE_FMT_S16,         ///&lt; signed 16 bits
AV_SAMPLE_FMT_FLT,         ///&lt; float
</code></pre>

<p>here is how the buffer is allocated:</p>

<pre><code>free(m_samBuf);
int bps = 2;
if(m_handle-&gt;codec-&gt;sample_fmts[0] == AV_SAMPLE_FMT_FLT) {
    bps = 4;
}
m_FrameSize = bps * m_handle-&gt;frame_size * m_handle-&gt;channels;
m_samBuf = malloc(m_FrameSize);
m_numSam = 0;
</code></pre>