int mpeg4_decode_picture_header(MpegEncContext * s)

{

    int time_incr, startcode, state, v;



 redo:

    /* search next start code */

    align_get_bits(&s->gb);

    state = 0xff;

    for(;;) {

        v = get_bits(&s->gb, 8);

        if (state == 0x000001) {

            state = ((state << 8) | v) & 0xffffff;

            startcode = state;

            break;

        }

        state = ((state << 8) | v) & 0xffffff;

        if( get_bits_count(&s->gb) > s->gb.size*8-32){

            printf("no VOP startcode found\n");

            return -1;

        }

    }

//printf("startcode %X %d\n", startcode, get_bits_count(&s->gb));

    if (startcode == 0x120) { // Video Object Layer

        int width, height, vo_ver_id;



        /* vol header */

        skip_bits(&s->gb, 1); /* random access */

        skip_bits(&s->gb, 8); /* vo_type */

        if (get_bits1(&s->gb) != 0) { /* is_ol_id */

            vo_ver_id = get_bits(&s->gb, 4); /* vo_ver_id */

            skip_bits(&s->gb, 3); /* vo_priority */

        } else {

            vo_ver_id = 1;

        }

        

        s->aspect_ratio_info= get_bits(&s->gb, 4);

	if(s->aspect_ratio_info == EXTENDET_PAR){

            skip_bits(&s->gb, 8); //par_width

            skip_bits(&s->gb, 8); // par_height

        }

        if(get_bits1(&s->gb)){ /* vol control parameter */

            printf("vol control parameter not supported\n");

            return -1;   

        }

        s->shape = get_bits(&s->gb, 2); /* vol shape */

        if(s->shape != RECT_SHAPE) printf("only rectangular vol supported\n");

        if(s->shape == GRAY_SHAPE && vo_ver_id != 1){

            printf("Gray shape not supported\n");

            skip_bits(&s->gb, 4);  //video_object_layer_shape_extension

        }



        skip_bits1(&s->gb);   /* marker */

        

        s->time_increment_resolution = get_bits(&s->gb, 16);

        s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1;

        if (s->time_increment_bits < 1)

            s->time_increment_bits = 1;

        skip_bits1(&s->gb);   /* marker */



        if (get_bits1(&s->gb) != 0) {   /* fixed_vop_rate  */

            skip_bits(&s->gb, s->time_increment_bits);

        }



        if (s->shape != BIN_ONLY_SHAPE) {

            if (s->shape == RECT_SHAPE) {

                skip_bits1(&s->gb);   /* marker */

                width = get_bits(&s->gb, 13);

                skip_bits1(&s->gb);   /* marker */

                height = get_bits(&s->gb, 13);

                skip_bits1(&s->gb);   /* marker */

                if(width && height){ /* they should be non zero but who knows ... */

                    s->width = width;

                    s->height = height;

//                    printf("%d %d\n", width, height);

                }

            }

            

            if(get_bits1(&s->gb)) printf("interlaced not supported\n");   /* interlaced */

            if(!get_bits1(&s->gb)) printf("OBMC not supported\n");   /* OBMC Disable */

            if (vo_ver_id == 1) {

                s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */

            } else {

                s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */

            }

            if(s->vol_sprite_usage==STATIC_SPRITE) printf("Static Sprites not supported\n");

            if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){

                if(s->vol_sprite_usage==STATIC_SPRITE){

                    s->sprite_width = get_bits(&s->gb, 13);

                    skip_bits1(&s->gb); /* marker */

                    s->sprite_height= get_bits(&s->gb, 13);

                    skip_bits1(&s->gb); /* marker */

                    s->sprite_left  = get_bits(&s->gb, 13);

                    skip_bits1(&s->gb); /* marker */

                    s->sprite_top   = get_bits(&s->gb, 13);

                    skip_bits1(&s->gb); /* marker */

                }

                s->num_sprite_warping_points= get_bits(&s->gb, 6);

                s->sprite_warping_accuracy = get_bits(&s->gb, 2);

                s->sprite_brightness_change= get_bits1(&s->gb);

                if(s->vol_sprite_usage==STATIC_SPRITE)

                    s->low_latency_sprite= get_bits1(&s->gb);            

            }

            // FIXME sadct disable bit if verid!=1 && shape not rect

            

            if (get_bits1(&s->gb) == 1) {   /* not_8_bit */

                s->quant_precision = get_bits(&s->gb, 4); /* quant_precision */

                if(get_bits(&s->gb, 4)!=8) printf("N-bit not supported\n"); /* bits_per_pixel */

            } else {

                s->quant_precision = 5;

            }

            

            // FIXME a bunch of grayscale shape things

            if(get_bits1(&s->gb)) printf("Quant-Type not supported\n");  /* vol_quant_type */ //FIXME

            if(vo_ver_id != 1)

                 s->quarter_sample= get_bits1(&s->gb);

            else s->quarter_sample=0;



            if(!get_bits1(&s->gb)) printf("Complexity estimation not supported\n");

#if 0

            if(get_bits1(&s->gb)) printf("resync disable\n");

#else

            skip_bits1(&s->gb);   /* resync_marker_disabled */

#endif

            s->data_partioning= get_bits1(&s->gb);

            if(s->data_partioning){

                printf("data partitioning not supported\n");

                skip_bits1(&s->gb); // reversible vlc

            }

            

            if(vo_ver_id != 1) {

                s->new_pred= get_bits1(&s->gb);

                if(s->new_pred){

                    printf("new pred not supported\n");

                    skip_bits(&s->gb, 2); /* requested upstream message type */

                    skip_bits1(&s->gb); /* newpred segment type */

                }

                s->reduced_res_vop= get_bits1(&s->gb);

                if(s->reduced_res_vop) printf("reduced resolution VOP not supported\n");

            }

            else{

                s->new_pred=0;

                s->reduced_res_vop= 0;

            }



            s->scalability= get_bits1(&s->gb);

            if (s->scalability) {

                printf("bad scalability!!!\n");

                return -1;

            }

        }

//printf("end Data %X %d\n", show_bits(&s->gb, 32), get_bits_count(&s->gb)&0x7);

        goto redo;

    } else if (startcode == 0x1b2) { //userdata

        char buf[256];

        int i;

        int e;

        int ver, build;



//printf("user Data %X\n", show_bits(&s->gb, 32));

        buf[0]= show_bits(&s->gb, 8);

        for(i=1; i<256; i++){

            buf[i]= show_bits(&s->gb, 16)&0xFF;

            if(buf[i]==0) break;

            skip_bits(&s->gb, 8);

        }

        buf[255]=0;

        e=sscanf(buf, "DivX%dBuild%d", &ver, &build);

        if(e==2){

            s->divx_version= ver;

            s->divx_build= build;

            if(s->picture_number==0){

                printf("This file was encoded with DivX%d Build%d\n", ver, build);

                if(ver==500 && build==413){ //most likely all version are indeed totally buggy but i dunno for sure ...

                    printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n");

                }else{

                    printf("hmm, i havnt seen that version of divx yet, lets assume they fixed these bugs ...\n"

                           "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n");

                }

            }

        }

//printf("User Data: %s\n", buf);

        goto redo;

    } else if (startcode != 0x1b6) { //VOP

        goto redo;

    }



    s->pict_type = get_bits(&s->gb, 2) + 1;	/* pict type: I = 0 , P = 1 */

//printf("pic: %d\n", s->pict_type); 

    time_incr=0;

    while (get_bits1(&s->gb) != 0) 

        time_incr++;



    check_marker(&s->gb, "before time_increment");

    s->time_increment= get_bits(&s->gb, s->time_increment_bits);

    if(s->pict_type!=B_TYPE){

        s->time_base+= time_incr;

        s->last_non_b_time[1]= s->last_non_b_time[0];

        s->last_non_b_time[0]= s->time_base*s->time_increment_resolution + s->time_increment;

    }else{

        s->time= (s->last_non_b_time[1]/s->time_increment_resolution + time_incr)*s->time_increment_resolution;

        s->time+= s->time_increment;

    }



    if(check_marker(&s->gb, "before vop_coded")==0 && s->picture_number==0){

        printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n");

        for(s->time_increment_bits++ ;s->time_increment_bits<16; s->time_increment_bits++){

            if(get_bits1(&s->gb)) break;

        }

        printf("my guess is %d bits ;)\n",s->time_increment_bits);

    }

    /* vop coded */

    if (get_bits1(&s->gb) != 1)

        goto redo;

//printf("time %d %d %d || %d %d %d\n", s->time_increment_bits, s->time_increment, s->time_base,

//s->time, s->last_non_b_time[0], s->last_non_b_time[1]);  

    if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == P_TYPE

                          || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) {

        /* rounding type for motion estimation */

	s->no_rounding = get_bits1(&s->gb);

    } else {

	s->no_rounding = 0;

    }

//FIXME reduced res stuff



     if (s->shape != RECT_SHAPE) {

         if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) {

             int width, height, hor_spat_ref, ver_spat_ref;

 

             width = get_bits(&s->gb, 13);

             skip_bits1(&s->gb);   /* marker */

             height = get_bits(&s->gb, 13);

             skip_bits1(&s->gb);   /* marker */

             hor_spat_ref = get_bits(&s->gb, 13); /* hor_spat_ref */

             skip_bits1(&s->gb);   /* marker */

             ver_spat_ref = get_bits(&s->gb, 13); /* ver_spat_ref */

         }

         skip_bits1(&s->gb); /* change_CR_disable */

 

         if (get_bits1(&s->gb) != 0) {

             skip_bits(&s->gb, 8); /* constant_alpha_value */

         }

     }

//FIXME complexity estimation stuff

     

     if (s->shape != BIN_ONLY_SHAPE) {

         skip_bits(&s->gb, 3); /* intra dc VLC threshold */

         //FIXME interlaced specific bits

     }



     if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){

         if(s->num_sprite_warping_points){

             mpeg4_decode_sprite_trajectory(s);

         }

         if(s->sprite_brightness_change) printf("sprite_brightness_change not supported\n");

         if(s->vol_sprite_usage==STATIC_SPRITE) printf("static sprite not supported\n");

     }



     if (s->shape != BIN_ONLY_SHAPE) {

         /* note: we do not use quant_precision to avoid problem if no

            MPEG4 vol header as it is found on some old opendivx

            movies */

         s->qscale = get_bits(&s->gb, 5);

         if(s->qscale==0){

             printf("Error, header damaged or not MPEG4 header (qscale=0)\n");

             return -1; // makes no sense to continue, as there is nothing left from the image then

         }

  

         if (s->pict_type != I_TYPE) {

             s->f_code = get_bits(&s->gb, 3);	/* fcode_for */

             if(s->f_code==0){

                 printf("Error, header damaged or not MPEG4 header (f_code=0)\n");

                 return -1; // makes no sense to continue, as the MV decoding will break very quickly

             }

         }

         if (s->pict_type == B_TYPE) {

             s->b_code = get_bits(&s->gb, 3);

//printf("b-code %d\n", s->b_code);

         }

//printf("quant:%d fcode:%d\n", s->qscale, s->f_code);



         if(!s->scalability){

             if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) {

                 skip_bits1(&s->gb); // vop shape coding type

             }

         }

     }

     s->picture_number++; // better than pic number==0 allways ;)

     return 0;

}

int mpeg4_decode_picture_header(MpegEncContext * s)

{

    int time_incr, startcode, state, v;



 redo:

    

    align_get_bits(&s->gb);

    state = 0xff;

    for(;;) {

        v = get_bits(&s->gb, 8);

        if (state == 0x000001) {

            state = ((state << 8) | v) & 0xffffff;

            startcode = state;

            break;

        }

        state = ((state << 8) | v) & 0xffffff;

        if( get_bits_count(&s->gb) > s->gb.size*8-32){

            printf("no VOP startcode found\n");

            return -1;

        }

    }



    if (startcode == 0x120) { 

        int width, height, vo_ver_id;



        

        skip_bits(&s->gb, 1); 

        skip_bits(&s->gb, 8); 

        if (get_bits1(&s->gb) != 0) { 

            vo_ver_id = get_bits(&s->gb, 4); 

            skip_bits(&s->gb, 3); 

        } else {

            vo_ver_id = 1;

        }

        

        s->aspect_ratio_info= get_bits(&s->gb, 4);

	if(s->aspect_ratio_info == EXTENDET_PAR){

            skip_bits(&s->gb, 8); 

            skip_bits(&s->gb, 8); 

        }

        if(get_bits1(&s->gb)){ 

            printf("vol control parameter not supported\n");

            return -1;   

        }

        s->shape = get_bits(&s->gb, 2); 

        if(s->shape != RECT_SHAPE) printf("only rectangular vol supported\n");

        if(s->shape == GRAY_SHAPE && vo_ver_id != 1){

            printf("Gray shape not supported\n");

            skip_bits(&s->gb, 4);  

        }



        skip_bits1(&s->gb);   

        

        s->time_increment_resolution = get_bits(&s->gb, 16);

        s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1;

        if (s->time_increment_bits < 1)

            s->time_increment_bits = 1;

        skip_bits1(&s->gb);   



        if (get_bits1(&s->gb) != 0) {   

            skip_bits(&s->gb, s->time_increment_bits);

        }



        if (s->shape != BIN_ONLY_SHAPE) {

            if (s->shape == RECT_SHAPE) {

                skip_bits1(&s->gb);   

                width = get_bits(&s->gb, 13);

                skip_bits1(&s->gb);   

                height = get_bits(&s->gb, 13);

                skip_bits1(&s->gb);   

                if(width && height){ 

                    s->width = width;

                    s->height = height;



                }

            }

            

            if(get_bits1(&s->gb)) printf("interlaced not supported\n");   

            if(!get_bits1(&s->gb)) printf("OBMC not supported\n");   

            if (vo_ver_id == 1) {

                s->vol_sprite_usage = get_bits1(&s->gb); 

            } else {

                s->vol_sprite_usage = get_bits(&s->gb, 2); 

            }

            if(s->vol_sprite_usage==STATIC_SPRITE) printf("Static Sprites not supported\n");

            if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){

                if(s->vol_sprite_usage==STATIC_SPRITE){

                    s->sprite_width = get_bits(&s->gb, 13);

                    skip_bits1(&s->gb); 

                    s->sprite_height= get_bits(&s->gb, 13);

                    skip_bits1(&s->gb); 

                    s->sprite_left  = get_bits(&s->gb, 13);

                    skip_bits1(&s->gb); 

                    s->sprite_top   = get_bits(&s->gb, 13);

                    skip_bits1(&s->gb); 

                }

                s->num_sprite_warping_points= get_bits(&s->gb, 6);

                s->sprite_warping_accuracy = get_bits(&s->gb, 2);

                s->sprite_brightness_change= get_bits1(&s->gb);

                if(s->vol_sprite_usage==STATIC_SPRITE)

                    s->low_latency_sprite= get_bits1(&s->gb);            

            }

            

            

            if (get_bits1(&s->gb) == 1) {   

                s->quant_precision = get_bits(&s->gb, 4); 

                if(get_bits(&s->gb, 4)!=8) printf("N-bit not supported\n"); 

            } else {

                s->quant_precision = 5;

            }

            

            

            if(get_bits1(&s->gb)) printf("Quant-Type not supported\n");   

            if(vo_ver_id != 1)

                 s->quarter_sample= get_bits1(&s->gb);

            else s->quarter_sample=0;



            if(!get_bits1(&s->gb)) printf("Complexity estimation not supported\n");

#if 0

            if(get_bits1(&s->gb)) printf("resync disable\n");

#else

            skip_bits1(&s->gb);   

#endif

            s->data_partioning= get_bits1(&s->gb);

            if(s->data_partioning){

                printf("data partitioning not supported\n");

                skip_bits1(&s->gb); 

            }

            

            if(vo_ver_id != 1) {

                s->new_pred= get_bits1(&s->gb);

                if(s->new_pred){

                    printf("new pred not supported\n");

                    skip_bits(&s->gb, 2); 

                    skip_bits1(&s->gb); 

                }

                s->reduced_res_vop= get_bits1(&s->gb);

                if(s->reduced_res_vop) printf("reduced resolution VOP not supported\n");

            }

            else{

                s->new_pred=0;

                s->reduced_res_vop= 0;

            }



            s->scalability= get_bits1(&s->gb);

            if (s->scalability) {

                printf("bad scalability!!!\n");

                return -1;

            }

        }



        goto redo;

    } else if (startcode == 0x1b2) { 

        char buf[256];

        int i;

        int e;

        int ver, build;





        buf[0]= show_bits(&s->gb, 8);

        for(i=1; i<256; i++){

            buf[i]= show_bits(&s->gb, 16)&0xFF;

            if(buf[i]==0) break;

            skip_bits(&s->gb, 8);

        }

        buf[255]=0;

        e=sscanf(buf, "DivX%dBuild%d", &ver, &build);

        if(e==2){

            s->divx_version= ver;

            s->divx_build= build;

            if(s->picture_number==0){

                printf("This file was encoded with DivX%d Build%d\n", ver, build);

                if(ver==500 && build==413){ 

                    printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n");

                }else{

                    printf("hmm, i havnt seen that version of divx yet, lets assume they fixed these bugs ...\n"

                           "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n");

                }

            }

        }



        goto redo;

    } else if (startcode != 0x1b6) { 

        goto redo;

    }



    s->pict_type = get_bits(&s->gb, 2) + 1;	



    time_incr=0;

    while (get_bits1(&s->gb) != 0) 

        time_incr++;



    check_marker(&s->gb, "before time_increment");

    s->time_increment= get_bits(&s->gb, s->time_increment_bits);

    if(s->pict_type!=B_TYPE){

        s->time_base+= time_incr;

        s->last_non_b_time[1]= s->last_non_b_time[0];

        s->last_non_b_time[0]= s->time_base*s->time_increment_resolution + s->time_increment;

    }else{

        s->time= (s->last_non_b_time[1]/s->time_increment_resolution + time_incr)*s->time_increment_resolution;

        s->time+= s->time_increment;

    }



    if(check_marker(&s->gb, "before vop_coded")==0 && s->picture_number==0){

        printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n");

        for(s->time_increment_bits++ ;s->time_increment_bits<16; s->time_increment_bits++){

            if(get_bits1(&s->gb)) break;

        }

        printf("my guess is %d bits ;)\n",s->time_increment_bits);

    }

    

    if (get_bits1(&s->gb) != 1)

        goto redo;





    if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == P_TYPE

                          || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) {

        

	s->no_rounding = get_bits1(&s->gb);

    } else {

	s->no_rounding = 0;

    }

 reduced res stuff



     if (s->shape != RECT_SHAPE) {

         if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) {

             int width, height, hor_spat_ref, ver_spat_ref;

 

             width = get_bits(&s->gb, 13);

             skip_bits1(&s->gb);   

             height = get_bits(&s->gb, 13);

             skip_bits1(&s->gb);   

             hor_spat_ref = get_bits(&s->gb, 13); 

             skip_bits1(&s->gb);   

             ver_spat_ref = get_bits(&s->gb, 13); 

         }

         skip_bits1(&s->gb); 

 

         if (get_bits1(&s->gb) != 0) {

             skip_bits(&s->gb, 8); 

         }

     }

 complexity estimation stuff

     

     if (s->shape != BIN_ONLY_SHAPE) {

         skip_bits(&s->gb, 3); 

          interlaced specific bits

     }



     if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){

         if(s->num_sprite_warping_points){

             mpeg4_decode_sprite_trajectory(s);

         }

         if(s->sprite_brightness_change) printf("sprite_brightness_change not supported\n");

         if(s->vol_sprite_usage==STATIC_SPRITE) printf("static sprite not supported\n");

     }



     if (s->shape != BIN_ONLY_SHAPE) {

         





         s->qscale = get_bits(&s->gb, 5);

         if(s->qscale==0){

             printf("Error, header damaged or not MPEG4 header (qscale=0)\n");

             return -1; 

         }

  

         if (s->pict_type != I_TYPE) {

             s->f_code = get_bits(&s->gb, 3);	

             if(s->f_code==0){

                 printf("Error, header damaged or not MPEG4 header (f_code=0)\n");

                 return -1; 

             }

         }

         if (s->pict_type == B_TYPE) {

             s->b_code = get_bits(&s->gb, 3);



         }





         if(!s->scalability){

             if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) {

                 skip_bits1(&s->gb); 

             }

         }

     }

     s->picture_number++; 

     return 0;

}

int FUNC_0(MpegEncContext * VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_4;



 redo:

    

    align_get_bits(&VAR_0->gb);

    VAR_3 = 0xff;

    for(;;) {

        VAR_4 = get_bits(&VAR_0->gb, 8);

        if (VAR_3 == 0x000001) {

            VAR_3 = ((VAR_3 << 8) | VAR_4) & 0xffffff;

            VAR_2 = VAR_3;

            break;

        }

        VAR_3 = ((VAR_3 << 8) | VAR_4) & 0xffffff;

        if( get_bits_count(&VAR_0->gb) > VAR_0->gb.size*8-32){

            printf("no VOP VAR_2 found\n");

            return -1;

        }

    }



    if (VAR_2 == 0x120) { 

        int VAR_5, VAR_6, VAR_7;



        

        skip_bits(&VAR_0->gb, 1); 

        skip_bits(&VAR_0->gb, 8); 

        if (get_bits1(&VAR_0->gb) != 0) { 

            VAR_7 = get_bits(&VAR_0->gb, 4); 

            skip_bits(&VAR_0->gb, 3); 

        } else {

            VAR_7 = 1;

        }

        

        VAR_0->aspect_ratio_info= get_bits(&VAR_0->gb, 4);

	if(VAR_0->aspect_ratio_info == EXTENDET_PAR){

            skip_bits(&VAR_0->gb, 8); 

            skip_bits(&VAR_0->gb, 8); 

        }

        if(get_bits1(&VAR_0->gb)){ 

            printf("vol control parameter not supported\n");

            return -1;   

        }

        VAR_0->shape = get_bits(&VAR_0->gb, 2); 

        if(VAR_0->shape != RECT_SHAPE) printf("only rectangular vol supported\n");

        if(VAR_0->shape == GRAY_SHAPE && VAR_7 != 1){

            printf("Gray shape not supported\n");

            skip_bits(&VAR_0->gb, 4);  

        }



        skip_bits1(&VAR_0->gb);   

        

        VAR_0->time_increment_resolution = get_bits(&VAR_0->gb, 16);

        VAR_0->time_increment_bits = av_log2(VAR_0->time_increment_resolution - 1) + 1;

        if (VAR_0->time_increment_bits < 1)

            VAR_0->time_increment_bits = 1;

        skip_bits1(&VAR_0->gb);   



        if (get_bits1(&VAR_0->gb) != 0) {   

            skip_bits(&VAR_0->gb, VAR_0->time_increment_bits);

        }



        if (VAR_0->shape != BIN_ONLY_SHAPE) {

            if (VAR_0->shape == RECT_SHAPE) {

                skip_bits1(&VAR_0->gb);   

                VAR_5 = get_bits(&VAR_0->gb, 13);

                skip_bits1(&VAR_0->gb);   

                VAR_6 = get_bits(&VAR_0->gb, 13);

                skip_bits1(&VAR_0->gb);   

                if(VAR_5 && VAR_6){ 

                    VAR_0->VAR_5 = VAR_5;

                    VAR_0->VAR_6 = VAR_6;



                }

            }

            

            if(get_bits1(&VAR_0->gb)) printf("interlaced not supported\n");   

            if(!get_bits1(&VAR_0->gb)) printf("OBMC not supported\n");   

            if (VAR_7 == 1) {

                VAR_0->vol_sprite_usage = get_bits1(&VAR_0->gb); 

            } else {

                VAR_0->vol_sprite_usage = get_bits(&VAR_0->gb, 2); 

            }

            if(VAR_0->vol_sprite_usage==STATIC_SPRITE) printf("Static Sprites not supported\n");

            if(VAR_0->vol_sprite_usage==STATIC_SPRITE || VAR_0->vol_sprite_usage==GMC_SPRITE){

                if(VAR_0->vol_sprite_usage==STATIC_SPRITE){

                    VAR_0->sprite_width = get_bits(&VAR_0->gb, 13);

                    skip_bits1(&VAR_0->gb); 

                    VAR_0->sprite_height= get_bits(&VAR_0->gb, 13);

                    skip_bits1(&VAR_0->gb); 

                    VAR_0->sprite_left  = get_bits(&VAR_0->gb, 13);

                    skip_bits1(&VAR_0->gb); 

                    VAR_0->sprite_top   = get_bits(&VAR_0->gb, 13);

                    skip_bits1(&VAR_0->gb); 

                }

                VAR_0->num_sprite_warping_points= get_bits(&VAR_0->gb, 6);

                VAR_0->sprite_warping_accuracy = get_bits(&VAR_0->gb, 2);

                VAR_0->sprite_brightness_change= get_bits1(&VAR_0->gb);

                if(VAR_0->vol_sprite_usage==STATIC_SPRITE)

                    VAR_0->low_latency_sprite= get_bits1(&VAR_0->gb);            

            }

            

            

            if (get_bits1(&VAR_0->gb) == 1) {   

                VAR_0->quant_precision = get_bits(&VAR_0->gb, 4); 

                if(get_bits(&VAR_0->gb, 4)!=8) printf("N-bit not supported\n"); 

            } else {

                VAR_0->quant_precision = 5;

            }

            

            

            if(get_bits1(&VAR_0->gb)) printf("Quant-Type not supported\n");   

            if(VAR_7 != 1)

                 VAR_0->quarter_sample= get_bits1(&VAR_0->gb);

            else VAR_0->quarter_sample=0;



            if(!get_bits1(&VAR_0->gb)) printf("Complexity estimation not supported\n");

#if 0

            if(get_bits1(&VAR_0->gb)) printf("resync disable\n");

#else

            skip_bits1(&VAR_0->gb);   

#endif

            VAR_0->data_partioning= get_bits1(&VAR_0->gb);

            if(VAR_0->data_partioning){

                printf("data partitioning not supported\n");

                skip_bits1(&VAR_0->gb); 

            }

            

            if(VAR_7 != 1) {

                VAR_0->new_pred= get_bits1(&VAR_0->gb);

                if(VAR_0->new_pred){

                    printf("new pred not supported\n");

                    skip_bits(&VAR_0->gb, 2); 

                    skip_bits1(&VAR_0->gb); 

                }

                VAR_0->reduced_res_vop= get_bits1(&VAR_0->gb);

                if(VAR_0->reduced_res_vop) printf("reduced resolution VOP not supported\n");

            }

            else{

                VAR_0->new_pred=0;

                VAR_0->reduced_res_vop= 0;

            }



            VAR_0->scalability= get_bits1(&VAR_0->gb);

            if (VAR_0->scalability) {

                printf("bad scalability!!!\n");

                return -1;

            }

        }



        goto redo;

    } else if (VAR_2 == 0x1b2) { 

        char VAR_8[256];

        int VAR_9;

        int VAR_10;

        int VAR_11, VAR_12;





        VAR_8[0]= show_bits(&VAR_0->gb, 8);

        for(VAR_9=1; VAR_9<256; VAR_9++){

            VAR_8[VAR_9]= show_bits(&VAR_0->gb, 16)&0xFF;

            if(VAR_8[VAR_9]==0) break;

            skip_bits(&VAR_0->gb, 8);

        }

        VAR_8[255]=0;

        VAR_10=sscanf(VAR_8, "DivX%dBuild%d", &VAR_11, &VAR_12);

        if(VAR_10==2){

            VAR_0->divx_version= VAR_11;

            VAR_0->divx_build= VAR_12;

            if(VAR_0->picture_number==0){

                printf("This file was encoded with DivX%d Build%d\n", VAR_11, VAR_12);

                if(VAR_11==500 && VAR_12==413){ 

                    printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n");

                }else{

                    printf("hmm, VAR_9 havnt seen that version of divx yet, lets assume they fixed these bugs ...\n"

                           "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n");

                }

            }

        }



        goto redo;

    } else if (VAR_2 != 0x1b6) { 

        goto redo;

    }



    VAR_0->pict_type = get_bits(&VAR_0->gb, 2) + 1;	



    VAR_1=0;

    while (get_bits1(&VAR_0->gb) != 0) 

        VAR_1++;



    check_marker(&VAR_0->gb, "before time_increment");

    VAR_0->time_increment= get_bits(&VAR_0->gb, VAR_0->time_increment_bits);

    if(VAR_0->pict_type!=B_TYPE){

        VAR_0->time_base+= VAR_1;

        VAR_0->last_non_b_time[1]= VAR_0->last_non_b_time[0];

        VAR_0->last_non_b_time[0]= VAR_0->time_base*VAR_0->time_increment_resolution + VAR_0->time_increment;

    }else{

        VAR_0->time= (VAR_0->last_non_b_time[1]/VAR_0->time_increment_resolution + VAR_1)*VAR_0->time_increment_resolution;

        VAR_0->time+= VAR_0->time_increment;

    }



    if(check_marker(&VAR_0->gb, "before vop_coded")==0 && VAR_0->picture_number==0){

        printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n");

        for(VAR_0->time_increment_bits++ ;VAR_0->time_increment_bits<16; VAR_0->time_increment_bits++){

            if(get_bits1(&VAR_0->gb)) break;

        }

        printf("my guess is %d bits ;)\n",VAR_0->time_increment_bits);

    }

    

    if (get_bits1(&VAR_0->gb) != 1)

        goto redo;





    if (VAR_0->shape != BIN_ONLY_SHAPE && ( VAR_0->pict_type == P_TYPE

                          || (VAR_0->pict_type == S_TYPE && VAR_0->vol_sprite_usage==GMC_SPRITE))) {

        

	VAR_0->no_rounding = get_bits1(&VAR_0->gb);

    } else {

	VAR_0->no_rounding = 0;

    }

 reduced res stuff



     if (VAR_0->shape != RECT_SHAPE) {

         if (VAR_0->vol_sprite_usage != 1 || VAR_0->pict_type != I_TYPE) {

             int VAR_5, VAR_6, hor_spat_ref, ver_spat_ref;

 

             VAR_5 = get_bits(&VAR_0->gb, 13);

             skip_bits1(&VAR_0->gb);   

             VAR_6 = get_bits(&VAR_0->gb, 13);

             skip_bits1(&VAR_0->gb);   

             hor_spat_ref = get_bits(&VAR_0->gb, 13); 

             skip_bits1(&VAR_0->gb);   

             ver_spat_ref = get_bits(&VAR_0->gb, 13); 

         }

         skip_bits1(&VAR_0->gb); 

 

         if (get_bits1(&VAR_0->gb) != 0) {

             skip_bits(&VAR_0->gb, 8); 

         }

     }

 complexity estimation stuff

     

     if (VAR_0->shape != BIN_ONLY_SHAPE) {

         skip_bits(&VAR_0->gb, 3); 

          interlaced specific bits

     }



     if(VAR_0->pict_type == S_TYPE && (VAR_0->vol_sprite_usage==STATIC_SPRITE || VAR_0->vol_sprite_usage==GMC_SPRITE)){

         if(VAR_0->num_sprite_warping_points){

             mpeg4_decode_sprite_trajectory(VAR_0);

         }

         if(VAR_0->sprite_brightness_change) printf("sprite_brightness_change not supported\n");

         if(VAR_0->vol_sprite_usage==STATIC_SPRITE) printf("static sprite not supported\n");

     }



     if (VAR_0->shape != BIN_ONLY_SHAPE) {

         





         VAR_0->qscale = get_bits(&VAR_0->gb, 5);

         if(VAR_0->qscale==0){

             printf("Error, header damaged or not MPEG4 header (qscale=0)\n");

             return -1; 

         }

  

         if (VAR_0->pict_type != I_TYPE) {

             VAR_0->f_code = get_bits(&VAR_0->gb, 3);	

             if(VAR_0->f_code==0){

                 printf("Error, header damaged or not MPEG4 header (f_code=0)\n");

                 return -1; 

             }

         }

         if (VAR_0->pict_type == B_TYPE) {

             VAR_0->b_code = get_bits(&VAR_0->gb, 3);



         }





         if(!VAR_0->scalability){

             if (VAR_0->shape!=RECT_SHAPE && VAR_0->pict_type!=I_TYPE) {

                 skip_bits1(&VAR_0->gb); 

             }

         }

     }

     VAR_0->picture_number++; 

     return 0;

}

int FUNC_0(MpegEncContext * VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_4; redo:
align_get_bits(&VAR_0->gb); VAR_3 = 0xff; for(;;) { VAR_4 = get_bits(&VAR_0->gb, 8); if (VAR_3 == 0x000001) { VAR_3 = ((VAR_3 << 8) | VAR_4) & 0xffffff; VAR_2 = VAR_3; break; } VAR_3 = ((VAR_3 << 8) | VAR_4) & 0xffffff; if( get_bits_count(&VAR_0->gb) > VAR_0->gb.size*8-32){ printf("no VOP VAR_2 found\n"); return -1; } } if (VAR_2 == 0x120) { int VAR_5, VAR_6, VAR_7; skip_bits(&VAR_0->gb, 1); skip_bits(&VAR_0->gb, 8); if (get_bits1(&VAR_0->gb) != 0) { VAR_7 = get_bits(&VAR_0->gb, 4); skip_bits(&VAR_0->gb, 3); } else { VAR_7 = 1; } VAR_0->aspect_ratio_info= get_bits(&VAR_0->gb, 4); if(VAR_0->aspect_ratio_info == EXTENDET_PAR){ skip_bits(&VAR_0->gb, 8); skip_bits(&VAR_0->gb, 8); } if(get_bits1(&VAR_0->gb)){ printf("vol control parameter not supported\n"); return -1; } VAR_0->shape = get_bits(&VAR_0->gb, 2); if(VAR_0->shape != RECT_SHAPE) printf("only rectangular vol supported\n"); if(VAR_0->shape == GRAY_SHAPE && VAR_7 != 1){ printf("Gray shape not supported\n"); skip_bits(&VAR_0->gb, 4); } skip_bits1(&VAR_0->gb); VAR_0->time_increment_resolution = get_bits(&VAR_0->gb, 16); VAR_0->time_increment_bits = av_log2(VAR_0->time_increment_resolution - 1) + 1; if (VAR_0->time_increment_bits < 1)
VAR_0->time_increment_bits = 1; skip_bits1(&VAR_0->gb); if (get_bits1(&VAR_0->gb) != 0) { skip_bits(&VAR_0->gb, VAR_0->time_increment_bits); } if (VAR_0->shape != BIN_ONLY_SHAPE) { if (VAR_0->shape == RECT_SHAPE) { skip_bits1(&VAR_0->gb); VAR_5 = get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); VAR_6 = get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); if(VAR_5 && VAR_6){ VAR_0->VAR_5 = VAR_5; VAR_0->VAR_6 = VAR_6; } } if(get_bits1(&VAR_0->gb)) printf("interlaced not supported\n"); if(!get_bits1(&VAR_0->gb)) printf("OBMC not supported\n"); if (VAR_7 == 1) { VAR_0->vol_sprite_usage = get_bits1(&VAR_0->gb); } else { VAR_0->vol_sprite_usage = get_bits(&VAR_0->gb, 2); } if(VAR_0->vol_sprite_usage==STATIC_SPRITE) printf("Static Sprites not supported\n"); if(VAR_0->vol_sprite_usage==STATIC_SPRITE || VAR_0->vol_sprite_usage==GMC_SPRITE){ if(VAR_0->vol_sprite_usage==STATIC_SPRITE){ VAR_0->sprite_width = get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); VAR_0->sprite_height= get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); VAR_0->sprite_left  = get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); VAR_0->sprite_top   = get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); } VAR_0->num_sprite_warping_points= get_bits(&VAR_0->gb, 6); VAR_0->sprite_warping_accuracy = get_bits(&VAR_0->gb, 2); VAR_0->sprite_brightness_change= get_bits1(&VAR_0->gb); if(VAR_0->vol_sprite_usage==STATIC_SPRITE)
VAR_0->low_latency_sprite= get_bits1(&VAR_0->gb); } if (get_bits1(&VAR_0->gb) == 1) { VAR_0->quant_precision = get_bits(&VAR_0->gb, 4); if(get_bits(&VAR_0->gb, 4)!=8) printf("N-bit not supported\n"); } else { VAR_0->quant_precision = 5; } if(get_bits1(&VAR_0->gb)) printf("Quant-Type not supported\n"); if(VAR_7 != 1)
VAR_0->quarter_sample= get_bits1(&VAR_0->gb); else VAR_0->quarter_sample=0; if(!get_bits1(&VAR_0->gb)) printf("Complexity estimation not supported\n"); #if 0
if(get_bits1(&VAR_0->gb)) printf("resync disable\n"); #else
skip_bits1(&VAR_0->gb); #endif
VAR_0->data_partioning= get_bits1(&VAR_0->gb); if(VAR_0->data_partioning){ printf("data partitioning not supported\n"); skip_bits1(&VAR_0->gb); } if(VAR_7 != 1) { VAR_0->new_pred= get_bits1(&VAR_0->gb); if(VAR_0->new_pred){ printf("new pred not supported\n"); skip_bits(&VAR_0->gb, 2); skip_bits1(&VAR_0->gb); } VAR_0->reduced_res_vop= get_bits1(&VAR_0->gb); if(VAR_0->reduced_res_vop) printf("reduced resolution VOP not supported\n"); } else{ VAR_0->new_pred=0; VAR_0->reduced_res_vop= 0; } VAR_0->scalability= get_bits1(&VAR_0->gb); if (VAR_0->scalability) { printf("bad scalability!!!\n"); return -1; } } goto redo; } else if (VAR_2 == 0x1b2) { char VAR_8[256]; int VAR_9; int VAR_10; int VAR_11, VAR_12; VAR_8[0]= show_bits(&VAR_0->gb, 8); for(VAR_9=1; VAR_9<256; VAR_9++){ VAR_8[VAR_9]= show_bits(&VAR_0->gb, 16)&0xFF; if(VAR_8[VAR_9]==0) break; skip_bits(&VAR_0->gb, 8); } VAR_8[255]=0; VAR_10=sscanf(VAR_8, "DivX%dBuild%d", &VAR_11, &VAR_12); if(VAR_10==2){ VAR_0->divx_version= VAR_11; VAR_0->divx_build= VAR_12; if(VAR_0->picture_number==0){ printf("This file was encoded with DivX%d Build%d\n", VAR_11, VAR_12); if(VAR_11==500 && VAR_12==413){ printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n"); }else{ printf("hmm, VAR_9 havnt seen that version of divx yet, lets assume they fixed these bugs ...\n"
"using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n"); } } } goto redo; } else if (VAR_2 != 0x1b6) { goto redo; } VAR_0->pict_type = get_bits(&VAR_0->gb, 2) + 1; VAR_1=0; while (get_bits1(&VAR_0->gb) != 0)
VAR_1++; check_marker(&VAR_0->gb, "before time_increment"); VAR_0->time_increment= get_bits(&VAR_0->gb, VAR_0->time_increment_bits); if(VAR_0->pict_type!=B_TYPE){ VAR_0->time_base+= VAR_1; VAR_0->last_non_b_time[1]= VAR_0->last_non_b_time[0]; VAR_0->last_non_b_time[0]= VAR_0->time_base*VAR_0->time_increment_resolution + VAR_0->time_increment; }else{ VAR_0->time= (VAR_0->last_non_b_time[1]/VAR_0->time_increment_resolution + VAR_1)*VAR_0->time_increment_resolution; VAR_0->time+= VAR_0->time_increment; } if(check_marker(&VAR_0->gb, "before vop_coded")==0 && VAR_0->picture_number==0){ printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n"); for(VAR_0->time_increment_bits++ ;VAR_0->time_increment_bits<16; VAR_0->time_increment_bits++){ if(get_bits1(&VAR_0->gb)) break; } printf("my guess is %d bits ;)\n",VAR_0->time_increment_bits); } if (get_bits1(&VAR_0->gb) != 1)
goto redo; if (VAR_0->shape != BIN_ONLY_SHAPE && ( VAR_0->pict_type == P_TYPE
|| (VAR_0->pict_type == S_TYPE && VAR_0->vol_sprite_usage==GMC_SPRITE))) { VAR_0->no_rounding = get_bits1(&VAR_0->gb); } else { VAR_0->no_rounding = 0; } reduced res stuff
if (VAR_0->shape != RECT_SHAPE) { if (VAR_0->vol_sprite_usage != 1 || VAR_0->pict_type != I_TYPE) { int VAR_5, VAR_6, hor_spat_ref, ver_spat_ref; VAR_5 = get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); VAR_6 = get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); hor_spat_ref = get_bits(&VAR_0->gb, 13); skip_bits1(&VAR_0->gb); ver_spat_ref = get_bits(&VAR_0->gb, 13); } skip_bits1(&VAR_0->gb); if (get_bits1(&VAR_0->gb) != 0) { skip_bits(&VAR_0->gb, 8); } } complexity estimation stuff
if (VAR_0->shape != BIN_ONLY_SHAPE) { skip_bits(&VAR_0->gb, 3); interlaced specific bits
} if(VAR_0->pict_type == S_TYPE && (VAR_0->vol_sprite_usage==STATIC_SPRITE || VAR_0->vol_sprite_usage==GMC_SPRITE)){ if(VAR_0->num_sprite_warping_points){ mpeg4_decode_sprite_trajectory(VAR_0); } if(VAR_0->sprite_brightness_change) printf("sprite_brightness_change not supported\n"); if(VAR_0->vol_sprite_usage==STATIC_SPRITE) printf("static sprite not supported\n"); } if (VAR_0->shape != BIN_ONLY_SHAPE) { VAR_0->qscale = get_bits(&VAR_0->gb, 5); if(VAR_0->qscale==0){ printf("Error, header damaged or not MPEG4 header (qscale=0)\n"); return -1; } if (VAR_0->pict_type != I_TYPE) { VAR_0->f_code = get_bits(&VAR_0->gb, 3); if(VAR_0->f_code==0){ printf("Error, header damaged or not MPEG4 header (f_code=0)\n"); return -1; } } if (VAR_0->pict_type == B_TYPE) { VAR_0->b_code = get_bits(&VAR_0->gb, 3); } if(!VAR_0->scalability){ if (VAR_0->shape!=RECT_SHAPE && VAR_0->pict_type!=I_TYPE) { skip_bits1(&VAR_0->gb); } } } VAR_0->picture_number++; return 0; }