[Ffmpeg-devel] Audio Decoding and Encoding Using FFmpeg: program crashing at avcodec_encode_audio

Renjith Nair renjith4
Tue Mar 7 14:29:41 CET 2006

Hi All,

I have a problem while trying to encode audio using ffmpeg. Whenever the
 function avcodec_encode_audio is called teh system crashes. When that line
is commented out then the program works without any problem. Can anybody
have a clue, what is wrong with this code. Thanks in Advance.

P.S: I am developing an audio encoding/decoding api using ffmpeg and
planning to publish the code and the documentation on the web for free. Very
few ffmpeg documentations (for programmers) are currently available on the
web. So i plan to create a programmer's documentation with sample programs
to assist the further development of ffmpeg. All are welcome to co-operate.

The code with the problem is the following:
outBuf = (int16_t*)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
output = (uint8_t*)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);

while(av_read_frame(pFormatCtx, &packet)>=0)
     // Is this a packet from the audio stream?
    // Decoding the frame
    len = avcodec_decode_audio(pCodecCtx,outBuf, &outBufSize,packet.data,

    // Encoding the frame
    outPacket.size = avcodec_encode_audio(pCodecCtx,output, outputSize,
(short*)outBuf);//<-- This line causes the crash
} // End of while loop

Where the variables are  of the following types

AVFormatContext *pFormatCtx;
AVCodecContext  *pCodecCtx;
AVPacket    packet,outPacket;
int16_t         *outBuf;
uint8_t            *output;
int        len,outBufSize,outSize;
int        outputSize=AVCODEC_MAX_AUDIO_FRAME_SIZE; // must be initialised
else produces an error

Thanks & Regards,

More information about the ffmpeg-devel mailing list