[FFmpeg-devel] aac_ac3_parser.c bug with splitted headers + patch

Nir Drang nir
Sun May 11 20:00:02 CEST 2008

Hi ,

This is my first post so If I have violated any rules regarding posting
messages please let me know.

I have created a ts file with aac audio and h.264 using a trranscoding phase
from mpeg2+ac3 using ffmpeg .


Now when I try to convert the output to mp4 I noticed that the audio frame
rate is wrong and other strange stuff happening.

I debugged it and discovered that when the aac header (7 bytes) was residing
cross ts packets there is a bug.

In my scenario 6 header bytes were in one ts packet and 1 header byte was in
the second packet.


It looked like the code doesn't handle this situation quite well.

I have patched it and requesting your comments to my patch , I might have
broke something else :


int ff_aac_ac3_parse(AVCodecParserContext *s1,

                     AVCodecContext *avctx,

                     const uint8_t **poutbuf, int *poutbuf_size,

                     const uint8_t *buf, int buf_size)


    AACAC3ParseContext *s = s1->priv_data;

    ParseContext *pc = &s->pc;

    int len, i;

    int new_frame_start;




    if(s->remaining_size <= buf_size){

        if(s->remaining_size && !s->need_next_header){

            i= s->remaining_size;

            s->remaining_size = 0;

        }else{ //we need a header first


            for(i=s->remaining_size; i<buf_size; i++){

                s->state = (s->state<<8) + buf[i];

                if((len=s->sync(s->state, s, &s->need_next_header,






av_log(avctx, AV_LOG_ERROR, "frame size= %d\n",len);

              i-= s->header_size -1;

              s->remaining_size = len;

                if(!new_frame_start || i < 0 ){

                    s->remaining_size += i;

                    goto get_next;





... "


The red bolded is my patched code , this is line 55 in aac_ac3_parser.c .


In my case I got I < 0 (-6) due to the split header case .


In general I cant see when the original if(!new_frame_start) would hit
anyway since when len > 0 the flag new_frame_start will be on .









More information about the ffmpeg-devel mailing list