[FFmpeg-devel] Avcodec_decode_audio3 decoding problems

Thu May 20 15:05:12 CEST 2010

Please excuse me if you receive this email twice, I sent it to livav-user list and now I realice this list might be more appropriate.

The problem I have is that I am trying to obtain the audio stream from a set of videos. I am using the following function to decode an audio packet:

int Video::getAudioPacket(short*& audio_out)
  AVPacket        packet;

    //read into the video looking for the next stream
   while(av_read_frame(m_pFormatCtx, &packet)>=0)
        //is this packet from the audio stream?
        if(packet.stream_index == m_audioStream)
            int outsize = AVCODEC_MAX_AUDIO_FRAME_SIZE;

            int decoded = avcodec_decode_audio3(m_pACodecCtx, audio_out, &outsize, &packet);

        if(decoded < 0)
                /* error */
                printf("Error decoding the audio(return value: %d)\n", decoded);

            //obtain the number of samples from the number of decoded bytes
            outsize /= sizeof(short);


    //at the end of the file we do not read anything

I have two problems:

1) In some videos I am getting the right data, but in others I just get 0'os. The videos I am getting 0'os for have been edited using other editing tools, but ffmpeg does not crash when decoding them, nor complaints (except for an initial message "[mp2 @ 0x10302de00]Header missing" which I am not sure whether I have to ignore or not).If I try running ffmpeg in command line to extract the audio it DOES decode these videos and I do get non-zero oputputs.
What am I doing wrong?

2) It looks like I must be iteratively reading the same data over and over, as the output on the videos that have non-zero outputs is repeated many times. What should I include to avoid doing it?

Thanks for your help

Xavier Anguera

More information about the ffmpeg-devel mailing list