put_le32(pb, (uint32_t)(int64_t_C(1000000) * FRAME_RATE_BASE / video_enc->frame_rate));
put_le32(pb, (uint32_t)(int64_t_C(1000000) * video_enc->frame_rate_base / video_enc->frame_rate));
static int avi_write_header(AVFormatContext *s){    AVIContext *avi = s->priv_data;    ByteIOContext *pb = &s->pb;    int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;    AVCodecContext *stream, *video_enc;    offset_t list1, list2, strh, strf;    put_tag(pb, "RIFF");    put_le32(pb, 0); /* file length */    put_tag(pb, "AVI ");    /* header list */    list1 = start_tag(pb, "LIST");    put_tag(pb, "hdrl");    /* avi header */    put_tag(pb, "avih");    put_le32(pb, 14 * 4);    bitrate = 0;    video_enc = NULL;    for(n=0;n<s->nb_streams;n++) {        stream = &s->streams[n]->codec;        bitrate += stream->bit_rate;        if (stream->codec_type == CODEC_TYPE_VIDEO)            video_enc = stream;    }    /*	allowing audio-only AVI file         if (!video_enc) {        av_free(avi);        return -1;    }*/        nb_frames = 0;    if(video_enc){    put_le32(pb, (uint32_t)(int64_t_C(1000000) * FRAME_RATE_BASE / video_enc->frame_rate));    } else {	put_le32(pb, 0);    }    put_le32(pb, bitrate / 8); /* XXX: not quite exact */    put_le32(pb, 0); /* padding */    put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */    avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */    put_le32(pb, nb_frames); /* nb frames, filled later */    put_le32(pb, 0); /* initial frame */    put_le32(pb, s->nb_streams); /* nb streams */    put_le32(pb, 1024 * 1024); /* suggested buffer size */    if(video_enc){        put_le32(pb, video_enc->width);    put_le32(pb, video_enc->height);    } else {	put_le32(pb, 0);	put_le32(pb, 0);    }	    put_le32(pb, 0); /* reserved */    put_le32(pb, 0); /* reserved */    put_le32(pb, 0); /* reserved */    put_le32(pb, 0); /* reserved */        /* stream list */    for(i=0;i<n;i++) {        int gcd;            list2 = start_tag(pb, "LIST");        put_tag(pb, "strl");            stream = &s->streams[i]->codec;        /* stream generic header */        strh = start_tag(pb, "strh");        switch(stream->codec_type) {        case CODEC_TYPE_VIDEO:            put_tag(pb, "vids");            put_le32(pb, codec_get_bmp_tag(stream->codec_id));            put_le32(pb, 0); /* flags */            put_le16(pb, 0); /* priority */            put_le16(pb, 0); /* language */            put_le32(pb, 0); /* initial frame */                        gcd= av_gcd(stream->frame_rate, FRAME_RATE_BASE);                        put_le32(pb, FRAME_RATE_BASE / gcd); /* scale */            put_le32(pb, stream->frame_rate / gcd); /* rate */            put_le32(pb, 0); /* start */            avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */            put_le32(pb, nb_frames); /* length, XXX: fill later */            put_le32(pb, 1024 * 1024); /* suggested buffer size */            put_le32(pb, -1); /* quality */            put_le32(pb, stream->width * stream->height * 3); /* sample size */            put_le16(pb, 0);            put_le16(pb, 0);            put_le16(pb, stream->width);            put_le16(pb, stream->height);            break;        case CODEC_TYPE_AUDIO:            put_tag(pb, "auds");            put_le32(pb, 1); /* tag */            put_le32(pb, 0); /* flags */            put_le16(pb, 0); /* priority */            put_le16(pb, 0); /* language */            put_le32(pb, 0); /* initial frame */            parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);            put_le32(pb, au_scale); /* scale */            put_le32(pb, au_byterate); /* rate */            put_le32(pb, 0); /* start */            avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */            put_le32(pb, 0); /* length, XXX: filled later */            put_le32(pb, 12 * 1024); /* suggested buffer size */            put_le32(pb, -1); /* quality */            put_le32(pb, au_ssize); /* sample size */            put_le32(pb, 0);            put_le32(pb, 0);            break;        default:            av_abort();        }        end_tag(pb, strh);        strf = start_tag(pb, "strf");        switch(stream->codec_type) {        case CODEC_TYPE_VIDEO:	    put_bmp_header(pb, stream, codec_bmp_tags, 0);            break;        case CODEC_TYPE_AUDIO:            if (put_wav_header(pb, stream) < 0) {                av_free(avi);                return -1;            }            break;        default:            av_abort();        }        end_tag(pb, strf);        end_tag(pb, list2);    }    end_tag(pb, list1);        avi->movi_list = start_tag(pb, "LIST");    avi->first = NULL;    avi->last = NULL;    put_tag(pb, "movi");    put_flush_packet(pb);    return 0;}