gcd= av_gcd(FRAME_RATE_BASE, codec->frame_rate); put_be32(pb, FRAME_RATE_BASE / gcd); put_be32(pb, codec->frame_rate / gcd);
put_be32(pb, codec->frame_rate_base); put_be32(pb, codec->frame_rate);
static int ffm_write_header(AVFormatContext *s){    FFMContext *ffm = s->priv_data;    AVStream *st;    FFMStream *fst;    ByteIOContext *pb = &s->pb;    AVCodecContext *codec;    int bit_rate, i;    ffm->packet_size = FFM_PACKET_SIZE;    /* header */    put_tag(pb, "FFM1");    put_be32(pb, ffm->packet_size);    /* XXX: store write position in other file ? */    put_be64(pb, ffm->packet_size); /* current write position */    put_be32(pb, s->nb_streams);    bit_rate = 0;    for(i=0;i<s->nb_streams;i++) {        st = s->streams[i];        bit_rate += st->codec.bit_rate;    }    put_be32(pb, bit_rate);    /* list of streams */    for(i=0;i<s->nb_streams;i++) {        int gcd;            st = s->streams[i];        fst = av_mallocz(sizeof(FFMStream));        if (!fst)            goto fail;        st->priv_data = fst;        codec = &st->codec;        /* generic info */        put_be32(pb, codec->codec_id);        put_byte(pb, codec->codec_type);        put_be32(pb, codec->bit_rate);	put_be32(pb, st->quality);        put_be32(pb, codec->flags);        /* specific info */        switch(codec->codec_type) {        case CODEC_TYPE_VIDEO:            gcd= av_gcd(FRAME_RATE_BASE, codec->frame_rate);            put_be32(pb, FRAME_RATE_BASE / gcd);            put_be32(pb, codec->frame_rate / gcd);            put_be16(pb, codec->width);            put_be16(pb, codec->height);            put_be16(pb, codec->gop_size);            put_byte(pb, codec->qmin);            put_byte(pb, codec->qmax);            put_byte(pb, codec->max_qdiff);            put_be16(pb, (int) (codec->qcompress * 10000.0));            put_be16(pb, (int) (codec->qblur * 10000.0));            put_be32(pb, codec->bit_rate_tolerance);            put_strz(pb, codec->rc_eq);            put_be32(pb, codec->rc_max_rate);            put_be32(pb, codec->rc_min_rate);            put_be32(pb, codec->rc_buffer_size);            put_be64_double(pb, codec->i_quant_factor);            put_be64_double(pb, codec->b_quant_factor);            put_be64_double(pb, codec->i_quant_offset);            put_be64_double(pb, codec->b_quant_offset);            put_be32(pb, codec->dct_algo);            break;        case CODEC_TYPE_AUDIO:            put_be32(pb, codec->sample_rate);            put_le16(pb, codec->channels);            put_le16(pb, codec->frame_size);            break;        default:            av_abort();        }        /* hack to have real time */        if (ffm_nopts)            fst->pts = 0;        else            fst->pts = av_gettime();    }    /* flush until end of block reached */    while ((url_ftell(pb) % ffm->packet_size) != 0)        put_byte(pb, 0);    put_flush_packet(pb);    /* init packet mux */    ffm->packet_ptr = ffm->packet;    ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE;    ffm->frame_offset = 0;    ffm->pts = 0;    ffm->first_packet = 1;    return 0; fail:    for(i=0;i<s->nb_streams;i++) {        st = s->streams[i];        av_freep(&st->priv_data);    }    return -1;}