n = (((int64_t)s->picture_number * fps) / s->frame_rate) - 1;
n = av_rescale((int64_t)s->picture_number * s->avctx->frame_rate_base, fps, s->avctx->frame_rate) / MPEG1_FRAME_RATE_BASE - 1;
static void mpeg1_encode_sequence_header(MpegEncContext *s){        unsigned int vbv_buffer_size;        unsigned int fps, v;        int n, i;        uint64_t time_code;        float best_aspect_error= 1E10;        float aspect_ratio= s->avctx->aspect_ratio;                if(aspect_ratio==0.0) aspect_ratio= s->width / (float)s->height; //pixel aspect 1:1 (VGA)                if (s->current_picture.key_frame) {            /* mpeg1 header repeated every gop */            put_header(s, SEQ_START_CODE);                        /* search closest frame rate */            {                int i, dmin, d;                s->frame_rate_index = 0;                dmin = 0x7fffffff;                for(i=1;i<9;i++) {                    d = abs(s->frame_rate - frame_rate_tab[i]);                    if (d < dmin) {                        dmin = d;                        s->frame_rate_index = i;                    }                }            }             put_bits(&s->pb, 12, s->width);            put_bits(&s->pb, 12, s->height);                        for(i=1; i<15; i++){                float error= mpeg1_aspect[i] - s->width/(s->height*aspect_ratio);                error= ABS(error);                                if(error < best_aspect_error){                    best_aspect_error= error;                    s->aspect_ratio_info= i;                }            }                        put_bits(&s->pb, 4, s->aspect_ratio_info);            put_bits(&s->pb, 4, s->frame_rate_index);            v = s->bit_rate / 400;            if (v > 0x3ffff)                v = 0x3ffff;            put_bits(&s->pb, 18, v);            put_bits(&s->pb, 1, 1); /* marker */            if(s->avctx->rc_buffer_size)                vbv_buffer_size = s->avctx->rc_buffer_size;            else                /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */                vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024;	             put_bits(&s->pb, 10, (vbv_buffer_size + 16383) / 16384);             put_bits(&s->pb, 1, 1); /* constrained parameter flag */            put_bits(&s->pb, 1, 0); /* no custom intra matrix */            put_bits(&s->pb, 1, 0); /* no custom non intra matrix */            put_header(s, GOP_START_CODE);            put_bits(&s->pb, 1, 0); /* do drop frame */            /* time code : we must convert from the real frame rate to a               fake mpeg frame rate in case of low frame rate */            fps = frame_rate_tab[s->frame_rate_index];            time_code = (int64_t)s->fake_picture_number * FRAME_RATE_BASE;            s->gop_picture_number = s->fake_picture_number;            put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));            put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));            put_bits(&s->pb, 1, 1);            put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60));            put_bits(&s->pb, 6, (uint32_t)((time_code % fps) / FRAME_RATE_BASE));            put_bits(&s->pb, 1, 1); /* closed gop */            put_bits(&s->pb, 1, 0); /* broken link */        }        if (s->frame_rate < (24 * FRAME_RATE_BASE) && s->picture_number > 0) {            /* insert empty P pictures to slow down to the desired               frame rate. Each fake pictures takes about 20 bytes */            fps = frame_rate_tab[s->frame_rate_index];            n = (((int64_t)s->picture_number * fps) / s->frame_rate) - 1;            while (s->fake_picture_number < n) {                mpeg1_skip_picture(s, s->fake_picture_number -                                    s->gop_picture_number);                 s->fake_picture_number++;            }        }}