static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    AVIContext *avi = s->priv_data;
    ByteIOContext *pb = s->pb;
    uint32_t tag, tag1, handler;
    int codec_type, stream_index, frame_period, bit_rate;
    unsigned int size, nb_frames;
    int i;
    AVStream *st;
    AVIStream *ast = NULL;
    char str_track[4];
    int avih_width=0, avih_height=0;
    int amv_file_format=0;
    avi->stream_index= -1;
    if (get_riff(avi, pb) < 0)
        return -1;
    avi->fsize = url_fsize(pb);
    if(avi->fsize<=0)
        avi->fsize= avi->riff_end;
    stream_index = -1;
    codec_type = -1;
    frame_period = 0;
    for(;;) {
        if (url_feof(pb))
            goto fail;
        tag = get_le32(pb);
        size = get_le32(pb);
#ifdef DEBUG
        print_tag("tag", tag, size);
#endif
        switch(tag) {
        case MKTAG('L', 'I', 'S', 'T'):
            tag1 = get_le32(pb);
#ifdef DEBUG
            print_tag("list", tag1, 0);
#endif
            if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
                avi->movi_list = url_ftell(pb) - 4;
                if(size) avi->movi_end = avi->movi_list + size + (size & 1);
                else     avi->movi_end = url_fsize(pb);
#ifdef DEBUG
                printf("movi end=%"PRIx64"\n", avi->movi_end);
#endif
                goto end_of_header;
            }
            break;
        case MKTAG('d', 'm', 'l', 'h'):
            avi->is_odml = 1;
            url_fskip(pb, size + (size & 1));
            break;
        case MKTAG('a', 'm', 'v', 'h'):
            amv_file_format=1;
        case MKTAG('a', 'v', 'i', 'h'):
            frame_period = get_le32(pb);
            bit_rate = get_le32(pb) * 8;
            get_le32(pb);
            avi->non_interleaved |= get_le32(pb) & AVIF_MUSTUSEINDEX;
            url_fskip(pb, 2 * 4);
            get_le32(pb);
            get_le32(pb);
            avih_width=get_le32(pb);
            avih_height=get_le32(pb);
            url_fskip(pb, size - 10 * 4);
            break;
        case MKTAG('s', 't', 'r', 'h'):
            tag1 = get_le32(pb);
            handler = get_le32(pb);
            if(tag1 == MKTAG('p', 'a', 'd', 's')){
                url_fskip(pb, size - 8);
                break;
            }else{
                stream_index++;
                st = av_new_stream(s, stream_index);
                if (!st)
                    goto fail;
                ast = av_mallocz(sizeof(AVIStream));
                if (!ast)
                    goto fail;
                st->priv_data = ast;
            }
            if(amv_file_format)
                tag1 = stream_index ? MKTAG('a','u','d','s') : MKTAG('v','i','d','s');
#ifdef DEBUG
            print_tag("strh", tag1, -1);
#endif
            if(tag1 == MKTAG('i', 'a', 'v', 's') || tag1 == MKTAG('i', 'v', 'a', 's')){
                int64_t dv_dur;
                if (s->nb_streams != 1)
                    goto fail;
                if (handler != MKTAG('d', 'v', 's', 'd') &&
                    handler != MKTAG('d', 'v', 'h', 'd') &&
                    handler != MKTAG('d', 'v', 's', 'l'))
                   goto fail;
                ast = s->streams[0]->priv_data;
                av_freep(&s->streams[0]->codec->extradata);
                av_freep(&s->streams[0]);
                s->nb_streams = 0;
                if (ENABLE_DV_DEMUXER) {
                    avi->dv_demux = dv_init_demux(s);
                    if (!avi->dv_demux)
                        goto fail;
                }
                s->streams[0]->priv_data = ast;
                url_fskip(pb, 3 * 4);
                ast->scale = get_le32(pb);
                ast->rate = get_le32(pb);
                url_fskip(pb, 4);
                dv_dur = get_le32(pb);
                if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {
                    dv_dur *= AV_TIME_BASE;
                    s->duration = av_rescale(dv_dur, ast->scale, ast->rate);
                }
                stream_index = s->nb_streams - 1;
                url_fskip(pb, size - 9*4);
                break;
            }
            assert(stream_index < s->nb_streams);
            st->codec->stream_codec_tag= handler;
            get_le32(pb);
            get_le16(pb);
            get_le16(pb);
            get_le32(pb);
            ast->scale = get_le32(pb);
            ast->rate = get_le32(pb);
            if(ast->scale && ast->rate){
            }else if(frame_period){
                ast->rate = 1000000;
                ast->scale = frame_period;
            }else{
                ast->rate = 25;
                ast->scale = 1;
            }
            av_set_pts_info(st, 64, ast->scale, ast->rate);
            ast->cum_len=get_le32(pb);
            nb_frames = get_le32(pb);
            st->start_time = 0;
            st->duration = nb_frames;
            get_le32(pb);
            get_le32(pb);
            ast->sample_size = get_le32(pb);
            ast->cum_len *= FFMAX(1, ast->sample_size);
            switch(tag1) {
            case MKTAG('v', 'i', 'd', 's'):
                codec_type = CODEC_TYPE_VIDEO;
                ast->sample_size = 0;
                break;
            case MKTAG('a', 'u', 'd', 's'):
                codec_type = CODEC_TYPE_AUDIO;
                break;
            case MKTAG('t', 'x', 't', 's'):
                codec_type = CODEC_TYPE_DATA;
                break;
            default:
                av_log(s, AV_LOG_ERROR, "unknown stream type %X\n", tag1);
                goto fail;
            }
            ast->frame_offset= ast->cum_len;
            url_fskip(pb, size - 12 * 4);
            break;
        case MKTAG('s', 't', 'r', 'f'):
            if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {
                url_fskip(pb, size);
            } else {
                st = s->streams[stream_index];
                switch(codec_type) {
                case CODEC_TYPE_VIDEO:
                    if(amv_file_format){
                        st->codec->width=avih_width;
                        st->codec->height=avih_height;
                        st->codec->codec_type = CODEC_TYPE_VIDEO;
                        st->codec->codec_id = CODEC_ID_AMV;
                        url_fskip(pb, size);
                        break;
                    }
                    get_le32(pb);
                    st->codec->width = get_le32(pb);
                    st->codec->height = get_le32(pb);
                    get_le16(pb);
                    st->codec->bits_per_sample= get_le16(pb);
                    tag1 = get_le32(pb);
                    get_le32(pb);
                    get_le32(pb);
                    get_le32(pb);
                    get_le32(pb);
                    get_le32(pb);
                    if (tag1 == MKTAG('D', 'X', 'S', 'B')) {
                        st->codec->codec_type = CODEC_TYPE_SUBTITLE;
                        st->codec->codec_tag = tag1;
                        st->codec->codec_id = CODEC_ID_XSUB;
                        break;
                    }
                    if(size > 10*4 && size<(1<<30)){
                        st->codec->extradata_size= size - 10*4;
                        st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
                        get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
                    }
                    if(st->codec->extradata_size & 1)
                        get_byte(pb);
                    if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {
                        st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));
#ifdef WORDS_BIGENDIAN
                        for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
                            st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);
#else
                        memcpy(st->codec->palctrl->palette, st->codec->extradata,
                               FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
#endif
                        st->codec->palctrl->palette_changed = 1;
                    }
#ifdef DEBUG
                    print_tag("video", tag1, 0);
#endif
                    st->codec->codec_type = CODEC_TYPE_VIDEO;
                    st->codec->codec_tag = tag1;
                    st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
                    st->need_parsing = AVSTREAM_PARSE_HEADERS;
                    break;
                case CODEC_TYPE_AUDIO:
                    get_wav_header(pb, st->codec, size);
                    if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){
                        av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align);
                        ast->sample_size= st->codec->block_align;
                    }
                    if (size%2)
                        url_fskip(pb, 1);
                    st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;
                    if (st->codec->codec_id == CODEC_ID_AAC && st->codec->extradata_size)
                        st->need_parsing = AVSTREAM_PARSE_NONE;
                    if (st->codec->stream_codec_tag == ff_get_fourcc("Axan")){
                        st->codec->codec_id  = CODEC_ID_XAN_DPCM;
                        st->codec->codec_tag = 0;
                    }
                    if (amv_file_format)
                        st->codec->codec_id  = CODEC_ID_ADPCM_IMA_AMV;
                    break;
                default:
                    st->codec->codec_type = CODEC_TYPE_DATA;
                    st->codec->codec_id= CODEC_ID_NONE;
                    st->codec->codec_tag= 0;
                    url_fskip(pb, size);
                    break;
                }
            }
            break;
        case MKTAG('i', 'n', 'd', 'x'):
            i= url_ftell(pb);
            if(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX)){
                read_braindead_odml_indx(s, 0);
            }
            url_fseek(pb, i+size, SEEK_SET);
            break;
        case MKTAG('v', 'p', 'r', 'p'):
            if(stream_index < (unsigned)s->nb_streams && size > 9*4){
                AVRational active, active_aspect;
                st = s->streams[stream_index];
                get_le32(pb);
                get_le32(pb);
                get_le32(pb);
                get_le32(pb);
                get_le32(pb);
                active_aspect.den= get_le16(pb);
                active_aspect.num= get_le16(pb);
                active.num       = get_le32(pb);
                active.den       = get_le32(pb);
                get_le32(pb);
                if(active_aspect.num && active_aspect.den && active.num && active.den){
                    st->codec->sample_aspect_ratio= av_div_q(active_aspect, active);
                }
                size -= 9*4;
            }
            url_fseek(pb, size, SEEK_CUR);
            break;
        case MKTAG('I', 'N', 'A', 'M'):
            avi_read_tag(pb, s->title, sizeof(s->title), size);
            break;
        case MKTAG('I', 'A', 'R', 'T'):
            avi_read_tag(pb, s->author, sizeof(s->author), size);
            break;
        case MKTAG('I', 'C', 'O', 'P'):
            avi_read_tag(pb, s->copyright, sizeof(s->copyright), size);
            break;
        case MKTAG('I', 'C', 'M', 'T'):
            avi_read_tag(pb, s->comment, sizeof(s->comment), size);
            break;
        case MKTAG('I', 'G', 'N', 'R'):
            avi_read_tag(pb, s->genre, sizeof(s->genre), size);
            break;
        case MKTAG('I', 'P', 'R', 'D'):
            avi_read_tag(pb, s->album, sizeof(s->album), size);
            break;
        case MKTAG('I', 'P', 'R', 'T'):
            avi_read_tag(pb, str_track, sizeof(str_track), size);
            sscanf(str_track, "%d", &s->track);
            break;
        default:
            if(size > 1000000){
                av_log(s, AV_LOG_ERROR, "well something went wrong during header parsing, "
                                        "ill ignore it and try to continue anyway\n");
                avi->movi_list = url_ftell(pb) - 4;
                avi->movi_end  = url_fsize(pb);
                goto end_of_header;
            }
            size += (size & 1);
            url_fskip(pb, size);
            break;
        }
    }
 end_of_header:
    if (stream_index != s->nb_streams - 1) {
    fail:
        for(i=0;i<s->nb_streams;i++) {
            av_freep(&s->streams[i]->codec->extradata);
            av_freep(&s->streams[i]);
        }
        return -1;
    }
    if(!avi->index_loaded && !url_is_streamed(pb))
        avi_load_index(s);
    avi->index_loaded = 1;
    avi->non_interleaved |= guess_ni_flag(s);
    if(avi->non_interleaved)
        clean_index(s);
    return 0;
}
['static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n    AVIContext *avi = s->priv_data;\n    ByteIOContext *pb = s->pb;\n    uint32_t tag, tag1, handler;\n    int codec_type, stream_index, frame_period, bit_rate;\n    unsigned int size, nb_frames;\n    int i;\n    AVStream *st;\n    AVIStream *ast = NULL;\n    char str_track[4];\n    int avih_width=0, avih_height=0;\n    int amv_file_format=0;\n    avi->stream_index= -1;\n    if (get_riff(avi, pb) < 0)\n        return -1;\n    avi->fsize = url_fsize(pb);\n    if(avi->fsize<=0)\n        avi->fsize= avi->riff_end;\n    stream_index = -1;\n    codec_type = -1;\n    frame_period = 0;\n    for(;;) {\n        if (url_feof(pb))\n            goto fail;\n        tag = get_le32(pb);\n        size = get_le32(pb);\n#ifdef DEBUG\n        print_tag("tag", tag, size);\n#endif\n        switch(tag) {\n        case MKTAG(\'L\', \'I\', \'S\', \'T\'):\n            tag1 = get_le32(pb);\n#ifdef DEBUG\n            print_tag("list", tag1, 0);\n#endif\n            if (tag1 == MKTAG(\'m\', \'o\', \'v\', \'i\')) {\n                avi->movi_list = url_ftell(pb) - 4;\n                if(size) avi->movi_end = avi->movi_list + size + (size & 1);\n                else     avi->movi_end = url_fsize(pb);\n#ifdef DEBUG\n                printf("movi end=%"PRIx64"\\n", avi->movi_end);\n#endif\n                goto end_of_header;\n            }\n            break;\n        case MKTAG(\'d\', \'m\', \'l\', \'h\'):\n            avi->is_odml = 1;\n            url_fskip(pb, size + (size & 1));\n            break;\n        case MKTAG(\'a\', \'m\', \'v\', \'h\'):\n            amv_file_format=1;\n        case MKTAG(\'a\', \'v\', \'i\', \'h\'):\n            frame_period = get_le32(pb);\n            bit_rate = get_le32(pb) * 8;\n            get_le32(pb);\n            avi->non_interleaved |= get_le32(pb) & AVIF_MUSTUSEINDEX;\n            url_fskip(pb, 2 * 4);\n            get_le32(pb);\n            get_le32(pb);\n            avih_width=get_le32(pb);\n            avih_height=get_le32(pb);\n            url_fskip(pb, size - 10 * 4);\n            break;\n        case MKTAG(\'s\', \'t\', \'r\', \'h\'):\n            tag1 = get_le32(pb);\n            handler = get_le32(pb);\n            if(tag1 == MKTAG(\'p\', \'a\', \'d\', \'s\')){\n                url_fskip(pb, size - 8);\n                break;\n            }else{\n                stream_index++;\n                st = av_new_stream(s, stream_index);\n                if (!st)\n                    goto fail;\n                ast = av_mallocz(sizeof(AVIStream));\n                if (!ast)\n                    goto fail;\n                st->priv_data = ast;\n            }\n            if(amv_file_format)\n                tag1 = stream_index ? MKTAG(\'a\',\'u\',\'d\',\'s\') : MKTAG(\'v\',\'i\',\'d\',\'s\');\n#ifdef DEBUG\n            print_tag("strh", tag1, -1);\n#endif\n            if(tag1 == MKTAG(\'i\', \'a\', \'v\', \'s\') || tag1 == MKTAG(\'i\', \'v\', \'a\', \'s\')){\n                int64_t dv_dur;\n                if (s->nb_streams != 1)\n                    goto fail;\n                if (handler != MKTAG(\'d\', \'v\', \'s\', \'d\') &&\n                    handler != MKTAG(\'d\', \'v\', \'h\', \'d\') &&\n                    handler != MKTAG(\'d\', \'v\', \'s\', \'l\'))\n                   goto fail;\n                ast = s->streams[0]->priv_data;\n                av_freep(&s->streams[0]->codec->extradata);\n                av_freep(&s->streams[0]);\n                s->nb_streams = 0;\n                if (ENABLE_DV_DEMUXER) {\n                    avi->dv_demux = dv_init_demux(s);\n                    if (!avi->dv_demux)\n                        goto fail;\n                }\n                s->streams[0]->priv_data = ast;\n                url_fskip(pb, 3 * 4);\n                ast->scale = get_le32(pb);\n                ast->rate = get_le32(pb);\n                url_fskip(pb, 4);\n                dv_dur = get_le32(pb);\n                if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {\n                    dv_dur *= AV_TIME_BASE;\n                    s->duration = av_rescale(dv_dur, ast->scale, ast->rate);\n                }\n                stream_index = s->nb_streams - 1;\n                url_fskip(pb, size - 9*4);\n                break;\n            }\n            assert(stream_index < s->nb_streams);\n            st->codec->stream_codec_tag= handler;\n            get_le32(pb);\n            get_le16(pb);\n            get_le16(pb);\n            get_le32(pb);\n            ast->scale = get_le32(pb);\n            ast->rate = get_le32(pb);\n            if(ast->scale && ast->rate){\n            }else if(frame_period){\n                ast->rate = 1000000;\n                ast->scale = frame_period;\n            }else{\n                ast->rate = 25;\n                ast->scale = 1;\n            }\n            av_set_pts_info(st, 64, ast->scale, ast->rate);\n            ast->cum_len=get_le32(pb);\n            nb_frames = get_le32(pb);\n            st->start_time = 0;\n            st->duration = nb_frames;\n            get_le32(pb);\n            get_le32(pb);\n            ast->sample_size = get_le32(pb);\n            ast->cum_len *= FFMAX(1, ast->sample_size);\n            switch(tag1) {\n            case MKTAG(\'v\', \'i\', \'d\', \'s\'):\n                codec_type = CODEC_TYPE_VIDEO;\n                ast->sample_size = 0;\n                break;\n            case MKTAG(\'a\', \'u\', \'d\', \'s\'):\n                codec_type = CODEC_TYPE_AUDIO;\n                break;\n            case MKTAG(\'t\', \'x\', \'t\', \'s\'):\n                codec_type = CODEC_TYPE_DATA;\n                break;\n            default:\n                av_log(s, AV_LOG_ERROR, "unknown stream type %X\\n", tag1);\n                goto fail;\n            }\n            ast->frame_offset= ast->cum_len;\n            url_fskip(pb, size - 12 * 4);\n            break;\n        case MKTAG(\'s\', \'t\', \'r\', \'f\'):\n            if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {\n                url_fskip(pb, size);\n            } else {\n                st = s->streams[stream_index];\n                switch(codec_type) {\n                case CODEC_TYPE_VIDEO:\n                    if(amv_file_format){\n                        st->codec->width=avih_width;\n                        st->codec->height=avih_height;\n                        st->codec->codec_type = CODEC_TYPE_VIDEO;\n                        st->codec->codec_id = CODEC_ID_AMV;\n                        url_fskip(pb, size);\n                        break;\n                    }\n                    get_le32(pb);\n                    st->codec->width = get_le32(pb);\n                    st->codec->height = get_le32(pb);\n                    get_le16(pb);\n                    st->codec->bits_per_sample= get_le16(pb);\n                    tag1 = get_le32(pb);\n                    get_le32(pb);\n                    get_le32(pb);\n                    get_le32(pb);\n                    get_le32(pb);\n                    get_le32(pb);\n                    if (tag1 == MKTAG(\'D\', \'X\', \'S\', \'B\')) {\n                        st->codec->codec_type = CODEC_TYPE_SUBTITLE;\n                        st->codec->codec_tag = tag1;\n                        st->codec->codec_id = CODEC_ID_XSUB;\n                        break;\n                    }\n                    if(size > 10*4 && size<(1<<30)){\n                        st->codec->extradata_size= size - 10*4;\n                        st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);\n                        get_buffer(pb, st->codec->extradata, st->codec->extradata_size);\n                    }\n                    if(st->codec->extradata_size & 1)\n                        get_byte(pb);\n                    if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {\n                        st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));\n#ifdef WORDS_BIGENDIAN\n                        for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)\n                            st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);\n#else\n                        memcpy(st->codec->palctrl->palette, st->codec->extradata,\n                               FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));\n#endif\n                        st->codec->palctrl->palette_changed = 1;\n                    }\n#ifdef DEBUG\n                    print_tag("video", tag1, 0);\n#endif\n                    st->codec->codec_type = CODEC_TYPE_VIDEO;\n                    st->codec->codec_tag = tag1;\n                    st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);\n                    st->need_parsing = AVSTREAM_PARSE_HEADERS;\n                    break;\n                case CODEC_TYPE_AUDIO:\n                    get_wav_header(pb, st->codec, size);\n                    if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){\n                        av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\\n", ast->sample_size, st->codec->block_align);\n                        ast->sample_size= st->codec->block_align;\n                    }\n                    if (size%2)\n                        url_fskip(pb, 1);\n                    st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;\n                    if (st->codec->codec_id == CODEC_ID_AAC && st->codec->extradata_size)\n                        st->need_parsing = AVSTREAM_PARSE_NONE;\n                    if (st->codec->stream_codec_tag == ff_get_fourcc("Axan")){\n                        st->codec->codec_id  = CODEC_ID_XAN_DPCM;\n                        st->codec->codec_tag = 0;\n                    }\n                    if (amv_file_format)\n                        st->codec->codec_id  = CODEC_ID_ADPCM_IMA_AMV;\n                    break;\n                default:\n                    st->codec->codec_type = CODEC_TYPE_DATA;\n                    st->codec->codec_id= CODEC_ID_NONE;\n                    st->codec->codec_tag= 0;\n                    url_fskip(pb, size);\n                    break;\n                }\n            }\n            break;\n        case MKTAG(\'i\', \'n\', \'d\', \'x\'):\n            i= url_ftell(pb);\n            if(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX)){\n                read_braindead_odml_indx(s, 0);\n            }\n            url_fseek(pb, i+size, SEEK_SET);\n            break;\n        case MKTAG(\'v\', \'p\', \'r\', \'p\'):\n            if(stream_index < (unsigned)s->nb_streams && size > 9*4){\n                AVRational active, active_aspect;\n                st = s->streams[stream_index];\n                get_le32(pb);\n                get_le32(pb);\n                get_le32(pb);\n                get_le32(pb);\n                get_le32(pb);\n                active_aspect.den= get_le16(pb);\n                active_aspect.num= get_le16(pb);\n                active.num       = get_le32(pb);\n                active.den       = get_le32(pb);\n                get_le32(pb);\n                if(active_aspect.num && active_aspect.den && active.num && active.den){\n                    st->codec->sample_aspect_ratio= av_div_q(active_aspect, active);\n                }\n                size -= 9*4;\n            }\n            url_fseek(pb, size, SEEK_CUR);\n            break;\n        case MKTAG(\'I\', \'N\', \'A\', \'M\'):\n            avi_read_tag(pb, s->title, sizeof(s->title), size);\n            break;\n        case MKTAG(\'I\', \'A\', \'R\', \'T\'):\n            avi_read_tag(pb, s->author, sizeof(s->author), size);\n            break;\n        case MKTAG(\'I\', \'C\', \'O\', \'P\'):\n            avi_read_tag(pb, s->copyright, sizeof(s->copyright), size);\n            break;\n        case MKTAG(\'I\', \'C\', \'M\', \'T\'):\n            avi_read_tag(pb, s->comment, sizeof(s->comment), size);\n            break;\n        case MKTAG(\'I\', \'G\', \'N\', \'R\'):\n            avi_read_tag(pb, s->genre, sizeof(s->genre), size);\n            break;\n        case MKTAG(\'I\', \'P\', \'R\', \'D\'):\n            avi_read_tag(pb, s->album, sizeof(s->album), size);\n            break;\n        case MKTAG(\'I\', \'P\', \'R\', \'T\'):\n            avi_read_tag(pb, str_track, sizeof(str_track), size);\n            sscanf(str_track, "%d", &s->track);\n            break;\n        default:\n            if(size > 1000000){\n                av_log(s, AV_LOG_ERROR, "well something went wrong during header parsing, "\n                                        "ill ignore it and try to continue anyway\\n");\n                avi->movi_list = url_ftell(pb) - 4;\n                avi->movi_end  = url_fsize(pb);\n                goto end_of_header;\n            }\n            size += (size & 1);\n            url_fskip(pb, size);\n            break;\n        }\n    }\n end_of_header:\n    if (stream_index != s->nb_streams - 1) {\n    fail:\n        for(i=0;i<s->nb_streams;i++) {\n            av_freep(&s->streams[i]->codec->extradata);\n            av_freep(&s->streams[i]);\n        }\n        return -1;\n    }\n    if(!avi->index_loaded && !url_is_streamed(pb))\n        avi_load_index(s);\n    avi->index_loaded = 1;\n    avi->non_interleaved |= guess_ni_flag(s);\n    if(avi->non_interleaved)\n        clean_index(s);\n    return 0;\n}']