pcm data reduce after encoding and decoding using FFMPEG
<p>I capture audio raw PCM data with directx from microphone.  Everytime I receive a PCM packet, the len is 4000(16000HZ, 16Bit, mono).Then I write these PCM data into 1.pcm, at the same time encode these datas using FFMPEG to mp2 format and write into 2.mp2 files. Every PCM packet(the length is 4000) can be encoded to mp2 packet, and the length of the encoded data is 144. Then I use FFMPEG to decode 2.mp2 file into raw PCM and again write into 3.pcm. The decoding sourcecode is following:</p>

<pre><code>   while(true) {

    //size = fread(inbuf, 1, 256, fAudioFile); // for amr-nb
    size = fread(inbuf, 1, 144, fAudioFile);   // for mp2
    if (size == 0) {
        TRACE("reach the end of file \n");
    break;
    }

    inbuf_ptr = inbuf;

    memset((void*)pcmBuf, 0, 102400);
    pcmLen = 0;
    char *ptr = pcmBuf;
    while(size &gt; 0) {

    out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
    len = avcodec_decode_audio2(c, (short*)ptr, &amp;out_size, 
                        inbuf_ptr, size);
    if (len &lt; 0) {
        TRACE("fail to decode this time %d\n", size);
        break;
    }
    if (out_size &gt; 0) {
        TRACE("here we successfully decode audio the len is %d \n", out_size);
        ptr += out_size;
        pcmLen += out_size;
    }

    size -= len;
    inbuf_ptr += len;
    }
}
</code></pre>

<p>And I find everytime I read 144 data from 2.mp2 and decode these data to raw PCM, the length of decoding data is 2304， not the original length 4000(the length of raw PCM I capture using directx), and if I use directsound to play these deconding PCM data, it play faster than normal. If 1.pcm(the raw data before encoding) plays for 60 seconds, maybe 3.pcm(the data after encoding and decoding) just plays for about 34 seconds. Why this problem occurs? How can I solve this problem? Thanks in advance!</p>
