static void mpeg1_encode_sequence_header(MpegEncContext *s)

{

        unsigned int vbv_buffer_size;

        unsigned int fps, v;

        int n;

        UINT64 time_code;

        

        if ((s->picture_number % s->gop_size) == 0) {

            /* 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);

            put_bits(&s->pb, 4, 1); /* 1/1 aspect ratio */

            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 */

            /* vbv buffer size: slightly greater than an I frame. We add

               some margin just in case */

            vbv_buffer_size = (3 * s->I_frame_bits) / (2 * 8);

            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 = s->fake_picture_number * FRAME_RATE_BASE;

            s->gop_picture_number = s->fake_picture_number;

            put_bits(&s->pb, 5, (UINT32)((time_code / (fps * 3600)) % 24));

            put_bits(&s->pb, 6, (UINT32)((time_code / (fps * 60)) % 60));

            put_bits(&s->pb, 1, 1);

            put_bits(&s->pb, 6, (UINT32)((time_code / fps) % 60));

            put_bits(&s->pb, 6, (UINT32)((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 = ((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++;

            }



        }

        s->fake_picture_number++;

}

static void mpeg1_encode_sequence_header(MpegEncContext *s)

{

        unsigned int vbv_buffer_size;

        unsigned int fps, v;

        int n;

        UINT64 time_code;

        

        if ((s->picture_number % s->gop_size) == 0) {

            

            put_header(s, SEQ_START_CODE);

            

            

            {

                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);

            put_bits(&s->pb, 4, 1); 

            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); 

            



            vbv_buffer_size = (3 * s->I_frame_bits) / (2 * 8);

            put_bits(&s->pb, 10, (vbv_buffer_size + 16383) / 16384); 

            put_bits(&s->pb, 1, 1); 

            put_bits(&s->pb, 1, 0); 

            put_bits(&s->pb, 1, 0); 



            put_header(s, GOP_START_CODE);

            put_bits(&s->pb, 1, 0); 

            



            fps = frame_rate_tab[s->frame_rate_index];

            time_code = s->fake_picture_number * FRAME_RATE_BASE;

            s->gop_picture_number = s->fake_picture_number;

            put_bits(&s->pb, 5, (UINT32)((time_code / (fps * 3600)) % 24));

            put_bits(&s->pb, 6, (UINT32)((time_code / (fps * 60)) % 60));

            put_bits(&s->pb, 1, 1);

            put_bits(&s->pb, 6, (UINT32)((time_code / fps) % 60));

            put_bits(&s->pb, 6, (UINT32)((time_code % fps) / FRAME_RATE_BASE));

            put_bits(&s->pb, 1, 1); 

            put_bits(&s->pb, 1, 0); 

        }



        if (s->frame_rate < (24 * FRAME_RATE_BASE) && s->picture_number > 0) {

            



            fps = frame_rate_tab[s->frame_rate_index];

            n = ((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++;

            }



        }

        s->fake_picture_number++;

}

            time_code = s->fake_picture_number * FRAME_RATE_BASE;             n = ((s->picture_number * fps) / s->frame_rate) - 1;
static void FUNC_0(MpegEncContext *VAR_0)

{

        unsigned int VAR_1;

        unsigned int VAR_2, VAR_3;

        int VAR_4;

        UINT64 time_code;

        

        if ((VAR_0->picture_number % VAR_0->gop_size) == 0) {

            

            put_header(VAR_0, SEQ_START_CODE);

            

            

            {

                int VAR_5, VAR_6, VAR_7;

                VAR_0->frame_rate_index = 0;

                VAR_6 = 0x7fffffff;

                for(VAR_5=1;VAR_5<9;VAR_5++) {

                    VAR_7 = abs(VAR_0->frame_rate - frame_rate_tab[VAR_5]);

                    if (VAR_7 < VAR_6) {

                        VAR_6 = VAR_7;

                        VAR_0->frame_rate_index = VAR_5;

                    }

                }

            }

 

            put_bits(&VAR_0->pb, 12, VAR_0->width);

            put_bits(&VAR_0->pb, 12, VAR_0->height);

            put_bits(&VAR_0->pb, 4, 1); 

            put_bits(&VAR_0->pb, 4, VAR_0->frame_rate_index);

            VAR_3 = VAR_0->bit_rate / 400;

            if (VAR_3 > 0x3ffff)

                VAR_3 = 0x3ffff;

            put_bits(&VAR_0->pb, 18, VAR_3);

            put_bits(&VAR_0->pb, 1, 1); 

            



            VAR_1 = (3 * VAR_0->I_frame_bits) / (2 * 8);

            put_bits(&VAR_0->pb, 10, (VAR_1 + 16383) / 16384); 

            put_bits(&VAR_0->pb, 1, 1); 

            put_bits(&VAR_0->pb, 1, 0); 

            put_bits(&VAR_0->pb, 1, 0); 



            put_header(VAR_0, GOP_START_CODE);

            put_bits(&VAR_0->pb, 1, 0); 

            



            VAR_2 = frame_rate_tab[VAR_0->frame_rate_index];

            time_code = VAR_0->fake_picture_number * FRAME_RATE_BASE;

            VAR_0->gop_picture_number = VAR_0->fake_picture_number;

            put_bits(&VAR_0->pb, 5, (UINT32)((time_code / (VAR_2 * 3600)) % 24));

            put_bits(&VAR_0->pb, 6, (UINT32)((time_code / (VAR_2 * 60)) % 60));

            put_bits(&VAR_0->pb, 1, 1);

            put_bits(&VAR_0->pb, 6, (UINT32)((time_code / VAR_2) % 60));

            put_bits(&VAR_0->pb, 6, (UINT32)((time_code % VAR_2) / FRAME_RATE_BASE));

            put_bits(&VAR_0->pb, 1, 1); 

            put_bits(&VAR_0->pb, 1, 0); 

        }



        if (VAR_0->frame_rate < (24 * FRAME_RATE_BASE) && VAR_0->picture_number > 0) {

            



            VAR_2 = frame_rate_tab[VAR_0->frame_rate_index];

            VAR_4 = ((VAR_0->picture_number * VAR_2) / VAR_0->frame_rate) - 1;

            while (VAR_0->fake_picture_number < VAR_4) {

                mpeg1_skip_picture(VAR_0, VAR_0->fake_picture_number - 

                                   VAR_0->gop_picture_number); 

                VAR_0->fake_picture_number++;

            }



        }

        VAR_0->fake_picture_number++;

}

static void FUNC_0(MpegEncContext *VAR_0)
{ unsigned int VAR_1; unsigned int VAR_2, VAR_3; int VAR_4; UINT64 time_code; if ((VAR_0->picture_number % VAR_0->gop_size) == 0) { put_header(VAR_0, SEQ_START_CODE); { int VAR_5, VAR_6, VAR_7; VAR_0->frame_rate_index = 0; VAR_6 = 0x7fffffff; for(VAR_5=1;VAR_5<9;VAR_5++) { VAR_7 = abs(VAR_0->frame_rate - frame_rate_tab[VAR_5]); if (VAR_7 < VAR_6) { VAR_6 = VAR_7; VAR_0->frame_rate_index = VAR_5; } } } put_bits(&VAR_0->pb, 12, VAR_0->width); put_bits(&VAR_0->pb, 12, VAR_0->height); put_bits(&VAR_0->pb, 4, 1); put_bits(&VAR_0->pb, 4, VAR_0->frame_rate_index); VAR_3 = VAR_0->bit_rate / 400; if (VAR_3 > 0x3ffff)
VAR_3 = 0x3ffff; put_bits(&VAR_0->pb, 18, VAR_3); put_bits(&VAR_0->pb, 1, 1); VAR_1 = (3 * VAR_0->I_frame_bits) / (2 * 8); put_bits(&VAR_0->pb, 10, (VAR_1 + 16383) / 16384); put_bits(&VAR_0->pb, 1, 1); put_bits(&VAR_0->pb, 1, 0); put_bits(&VAR_0->pb, 1, 0); put_header(VAR_0, GOP_START_CODE); put_bits(&VAR_0->pb, 1, 0); VAR_2 = frame_rate_tab[VAR_0->frame_rate_index]; time_code = VAR_0->fake_picture_number * FRAME_RATE_BASE; VAR_0->gop_picture_number = VAR_0->fake_picture_number; put_bits(&VAR_0->pb, 5, (UINT32)((time_code / (VAR_2 * 3600)) % 24)); put_bits(&VAR_0->pb, 6, (UINT32)((time_code / (VAR_2 * 60)) % 60)); put_bits(&VAR_0->pb, 1, 1); put_bits(&VAR_0->pb, 6, (UINT32)((time_code / VAR_2) % 60)); put_bits(&VAR_0->pb, 6, (UINT32)((time_code % VAR_2) / FRAME_RATE_BASE)); put_bits(&VAR_0->pb, 1, 1); put_bits(&VAR_0->pb, 1, 0); } if (VAR_0->frame_rate < (24 * FRAME_RATE_BASE) && VAR_0->picture_number > 0) { VAR_2 = frame_rate_tab[VAR_0->frame_rate_index]; VAR_4 = ((VAR_0->picture_number * VAR_2) / VAR_0->frame_rate) - 1; while (VAR_0->fake_picture_number < VAR_4) { mpeg1_skip_picture(VAR_0, VAR_0->fake_picture_number -
VAR_0->gop_picture_number); VAR_0->fake_picture_number++; } } VAR_0->fake_picture_number++; }