Merge commit '8769113accf1f3b78634dec60b37f7354ed6d88d'
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 19 Nov 2013 14:47:44 +0000 (15:47 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 19 Nov 2013 15:19:42 +0000 (16:19 +0100)
* commit '8769113accf1f3b78634dec60b37f7354ed6d88d':
  mpeg4videoenc: K&R formatting cosmetics

Conflicts:
libavcodec/mpeg4videoenc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/mpeg4videoenc.c

@@@ -35,26 -35,26 +35,26 @@@ static uint8_t  uni_DCtab_chrom_len[512
  static uint16_t uni_DCtab_lum_bits[512];
  static uint16_t uni_DCtab_chrom_bits[512];
  
- //unified encoding tables for run length encoding of coefficients
- //unified in the sense that the specification specifies the encoding in several steps.
- static uint32_t uni_mpeg4_intra_rl_bits[64*64*2*2];
- static uint8_t  uni_mpeg4_intra_rl_len [64*64*2*2];
- static uint32_t uni_mpeg4_inter_rl_bits[64*64*2*2];
- static uint8_t  uni_mpeg4_inter_rl_len [64*64*2*2];
- //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level))
- //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
- #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
+ /* Unified encoding tables for run length encoding of coefficients.
+  * Unified in the sense that the specification specifies the encoding in several steps. */
+ static uint32_t uni_mpeg4_intra_rl_bits[64 * 64 * 2 * 2];
+ static uint8_t  uni_mpeg4_intra_rl_len[64 * 64 * 2 * 2];
+ static uint32_t uni_mpeg4_inter_rl_bits[64 * 64 * 2 * 2];
+ static uint8_t  uni_mpeg4_inter_rl_len[64 * 64 * 2 * 2];
  
- /* mpeg4
- inter
- max level: 24/6
- max run: 53/63
- intra
- max level: 53/16
- max run: 29/41
- */
 -//#define UNI_MPEG4_ENC_INDEX(last, run, level) (last * 128 + run * 256 + level)
 -//#define UNI_MPEG4_ENC_INDEX(last, run, level) (last * 128 * 64 + run + level * 64)
 -#define UNI_MPEG4_ENC_INDEX(last, run, level) (last * 128 * 64 + run * 128 + (level))
++//#define UNI_MPEG4_ENC_INDEX(last, run, level) ((last) * 128 + (run) * 256 + (level))
++//#define UNI_MPEG4_ENC_INDEX(last, run, level) ((last) * 128 * 64 + (run) + (level) * 64)
++#define UNI_MPEG4_ENC_INDEX(last, run, level) ((last) * 128 * 64 + (run) * 128 + (level))
  
+ /* mpeg4
+  * inter
+  * max level: 24/6
+  * max run: 53/63
+  *
+  * intra
+  * max level: 53/16
+  * max run: 29/41
+  */
  
  /**
   * Return the number of bits that encoding the 8x8 block in block would need.
@@@ -200,11 -207,12 +207,12 @@@ static inline int decide_ac_pred(MpegEn
  }
  
  /**
 - * modify mb_type & qscale so that encoding is acually possible in mpeg4
 + * modify mb_type & qscale so that encoding is actually possible in mpeg4
   */
- void ff_clean_mpeg4_qscales(MpegEncContext *s){
+ void ff_clean_mpeg4_qscales(MpegEncContext *s)
+ {
      int i;
-     int8_t * const qscale_table = s->current_picture.qscale_table;
+     int8_t *const qscale_table = s->current_picture.qscale_table;
  
      ff_clean_h263_qscales(s);
  
@@@ -482,42 -511,42 +511,42 @@@ void ff_mpeg4_encode_mb(MpegEncContext 
      if (!s->mb_intra) {
          int i, cbp;
  
-         if(s->pict_type==AV_PICTURE_TYPE_B){
-             static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */
-             int mb_type=  mb_type_table[s->mv_dir];
-             if(s->mb_x==0){
-                 for(i=0; i<2; i++){
-                     s->last_mv[i][0][0]=
-                     s->last_mv[i][0][1]=
-                     s->last_mv[i][1][0]=
-                     s->last_mv[i][1][1]= 0;
-                 }
+         if (s->pict_type == AV_PICTURE_TYPE_B) {
+             /* convert from mv_dir to type */
+             static const int mb_type_table[8] = { -1, 3, 2, 1, -1, -1, -1, 0 };
+             int mb_type = mb_type_table[s->mv_dir];
+             if (s->mb_x == 0) {
+                 for (i = 0; i < 2; i++)
+                     s->last_mv[i][0][0] =
+                     s->last_mv[i][0][1] =
+                     s->last_mv[i][1][0] =
+                     s->last_mv[i][1][1] = 0;
              }
  
-             av_assert2(s->dquant>=-2 && s->dquant<=2);
-             av_assert2((s->dquant&1)==0);
-             av_assert2(mb_type>=0);
 -            assert(s->dquant >= -2 && s->dquant <= 2);
 -            assert((s->dquant & 1) == 0);
 -            assert(mb_type >= 0);
++            av_assert2(s->dquant >= -2 && s->dquant <= 2);
++            av_assert2((s->dquant & 1) == 0);
++            av_assert2(mb_type >= 0);
  
              /* nothing to do if this MB was skipped in the next P Frame */
-             if (s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]) { //FIXME avoid DCT & ...
+             if (s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]) {  // FIXME avoid DCT & ...
                  s->skip_count++;
-                 s->mv[0][0][0]=
-                 s->mv[0][0][1]=
-                 s->mv[1][0][0]=
-                 s->mv[1][0][1]= 0;
-                 s->mv_dir= MV_DIR_FORWARD; //doesn't matter
+                 s->mv[0][0][0] =
+                 s->mv[0][0][1] =
+                 s->mv[1][0][0] =
+                 s->mv[1][0][1] = 0;
+                 s->mv_dir  = MV_DIR_FORWARD;  // doesn't matter
                  s->qscale -= s->dquant;
- //                s->mb_skipped=1;
+ //                s->mb_skipped = 1;
  
                  return;
              }
  
-             cbp= get_b_cbp(s, block, motion_x, motion_y, mb_type);
+             cbp = get_b_cbp(s, block, motion_x, motion_y, mb_type);
  
-             if ((cbp | motion_x | motion_y | mb_type) ==0) {
+             if ((cbp | motion_x | motion_y | mb_type) == 0) {
                  /* direct MB with MV={0,0} */
-                 av_assert2(s->dquant==0);
 -                assert(s->dquant == 0);
++                av_assert2(s->dquant == 0);
  
                  put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */
  
                      put_bits(&s->pb, 1, s->mv_type == MV_TYPE_FIELD);
              }
  
-             if(interleaved_stats){
-                 s->misc_bits+= get_bits_diff(s);
-             }
+             if (interleaved_stats)
+                 s->misc_bits += get_bits_diff(s);
  
-             if(mb_type == 0){
+             if (!mb_type) {
 -                assert(s->mv_dir & MV_DIRECT);
 +                av_assert2(s->mv_dir & MV_DIRECT);
                  ff_h263_encode_motion_vector(s, motion_x, motion_y, 1);
                  s->b_count++;
                  s->f_count++;
-             }else{
+             } else {
 -                assert(mb_type > 0 && mb_type < 4);
 +                av_assert2(mb_type > 0 && mb_type < 4);
-                 if(s->mv_type != MV_TYPE_FIELD){
-                     if(s->mv_dir & MV_DIR_FORWARD){
-                         ff_h263_encode_motion_vector(s, s->mv[0][0][0] - s->last_mv[0][0][0],
-                                                         s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code);
-                         s->last_mv[0][0][0]= s->last_mv[0][1][0]= s->mv[0][0][0];
-                         s->last_mv[0][0][1]= s->last_mv[0][1][1]= s->mv[0][0][1];
+                 if (s->mv_type != MV_TYPE_FIELD) {
+                     if (s->mv_dir & MV_DIR_FORWARD) {
+                         ff_h263_encode_motion_vector(s,
+                                                      s->mv[0][0][0] - s->last_mv[0][0][0],
+                                                      s->mv[0][0][1] - s->last_mv[0][0][1],
+                                                      s->f_code);
+                         s->last_mv[0][0][0] =
+                         s->last_mv[0][1][0] = s->mv[0][0][0];
+                         s->last_mv[0][0][1] =
+                         s->last_mv[0][1][1] = s->mv[0][0][1];
                          s->f_count++;
                      }
-                     if(s->mv_dir & MV_DIR_BACKWARD){
-                         ff_h263_encode_motion_vector(s, s->mv[1][0][0] - s->last_mv[1][0][0],
-                                                         s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code);
-                         s->last_mv[1][0][0]= s->last_mv[1][1][0]= s->mv[1][0][0];
-                         s->last_mv[1][0][1]= s->last_mv[1][1][1]= s->mv[1][0][1];
+                     if (s->mv_dir & MV_DIR_BACKWARD) {
+                         ff_h263_encode_motion_vector(s,
+                                                      s->mv[1][0][0] - s->last_mv[1][0][0],
+                                                      s->mv[1][0][1] - s->last_mv[1][0][1],
+                                                      s->b_code);
+                         s->last_mv[1][0][0] =
+                         s->last_mv[1][1][0] = s->mv[1][0][0];
+                         s->last_mv[1][0][1] =
+                         s->last_mv[1][1][1] = s->mv[1][0][1];
                          s->b_count++;
                      }
-                 }else{
-                     if(s->mv_dir & MV_DIR_FORWARD){
+                 } else {
+                     if (s->mv_dir & MV_DIR_FORWARD) {
                          put_bits(&s->pb, 1, s->field_select[0][0]);
                          put_bits(&s->pb, 1, s->field_select[0][1]);
                      }
  
              mpeg4_encode_blocks(s, block, NULL, NULL, NULL, &s->pb);
  
-             if(interleaved_stats){
-                 s->p_tex_bits+= get_bits_diff(s);
-             }
-         }else{ /* s->pict_type==AV_PICTURE_TYPE_B */
-             cbp= get_p_cbp(s, block, motion_x, motion_y);
-             if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) {
-                 /* check if the B frames can skip it too, as we must skip it if we skip here
-                    why didn't they just compress the skip-mb bits instead of reusing them ?! */
-                 if(s->max_b_frames>0){
+             if (interleaved_stats)
+                 s->p_tex_bits += get_bits_diff(s);
+         } else { /* s->pict_type==AV_PICTURE_TYPE_B */
+             cbp = get_p_cbp(s, block, motion_x, motion_y);
+             if ((cbp | motion_x | motion_y | s->dquant) == 0 &&
+                 s->mv_type == MV_TYPE_16X16) {
+                 /* check if the B frames can skip it too, as we must skip it
+                  * if we skip here why didn't they just compress
+                  * the skip-mb bits instead of reusing them ?! */
+                 if (s->max_b_frames > 0) {
                      int i;
-                     int x,y, offset;
+                     int x, y, offset;
                      uint8_t *p_pic;
  
-                     x= s->mb_x*16;
-                     y= s->mb_y*16;
+                     x = s->mb_x * 16;
+                     y = s->mb_y * 16;
 -                    if (x + 16 > s->width)
 -                        x = s->width - 16;
 -                    if (y + 16 > s->height)
 -                        y = s->height - 16;
  
-                     offset= x + y*s->linesize;
-                     p_pic = s->new_picture.f.data[0] + offset;
+                     offset = x + y * s->linesize;
+                     p_pic  = s->new_picture.f.data[0] + offset;
  
-                     s->mb_skipped=1;
-                     for(i=0; i<s->max_b_frames; i++){
+                     s->mb_skipped = 1;
+                     for (i = 0; i < s->max_b_frames; i++) {
                          uint8_t *b_pic;
                          int diff;
-                         Picture *pic= s->reordered_input_picture[i+1];
+                         Picture *pic = s->reordered_input_picture[i + 1];
  
-                         if (pic == NULL || pic->f.pict_type != AV_PICTURE_TYPE_B)
+                         if (!pic || pic->f.pict_type != AV_PICTURE_TYPE_B)
                              break;
  
                          b_pic = pic->f.data[0] + offset;
                          if (!pic->shared)
-                             b_pic+= INPLACE_OFFSET;
-                         if(x+16 > s->width || y+16 > s->height){
-                             int x1,y1;
-                             int xe= FFMIN(16, s->width - x);
-                             int ye= FFMIN(16, s->height- y);
-                             diff=0;
-                             for(y1=0; y1<ye; y1++){
-                                 for(x1=0; x1<xe; x1++){
-                                     diff+= FFABS(p_pic[x1+y1*s->linesize] - b_pic[x1+y1*s->linesize]);
+                             b_pic += INPLACE_OFFSET;
 -                        diff = s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
++
++                        if (x + 16 > s->width || y + 16 > s->height) {
++                            int x1, y1;
++                            int xe = FFMIN(16, s->width - x);
++                            int ye = FFMIN(16, s->height - y);
++                            diff = 0;
++                            for (y1 = 0; y1 < ye; y1++) {
++                                for (x1 = 0; x1 < xe; x1++) {
++                                    diff += FFABS(p_pic[x1 + y1 * s->linesize] - b_pic[x1 + y1 * s->linesize]);
 +                                }
 +                            }
-                             diff= diff*256/(xe*ye);
-                         }else{
-                             diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
++                            diff = diff * 256 / (xe * ye);
++                        } else {
++                            diff = s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
 +                        }
-                         if(diff>s->qscale*70){ //FIXME check that 70 is optimal
-                             s->mb_skipped=0;
+                         if (diff > s->qscale * 70) {  // FIXME check that 70 is optimal
+                             s->mb_skipped = 0;
                              break;
                          }
                      }
                  /* motion vectors: 16x16 mode */
                  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
  
-                 ff_h263_encode_motion_vector(s, motion_x - pred_x,
-                                                 motion_y - pred_y, s->f_code);
-             }else if(s->mv_type==MV_TYPE_FIELD){
-                 if(s->dquant) cbpc+= 8;
+                 ff_h263_encode_motion_vector(s,
+                                              motion_x - pred_x,
+                                              motion_y - pred_y,
+                                              s->f_code);
+             } else if (s->mv_type == MV_TYPE_FIELD) {
+                 if (s->dquant)
+                     cbpc += 8;
                  put_bits(&s->pb,
-                         ff_h263_inter_MCBPC_bits[cbpc],
-                         ff_h263_inter_MCBPC_code[cbpc]);
+                          ff_h263_inter_MCBPC_bits[cbpc],
+                          ff_h263_inter_MCBPC_code[cbpc]);
  
                  put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
-                 if(s->dquant)
-                     put_bits(pb2, 2, dquant_code[s->dquant+2]);
+                 if (s->dquant)
+                     put_bits(pb2, 2, dquant_code[s->dquant + 2]);
  
 -                assert(!s->progressive_sequence);
 +                av_assert2(!s->progressive_sequence);
-                 if(cbp)
+                 if (cbp)
                      put_bits(pb2, 1, s->interlaced_dct);
                  put_bits(pb2, 1, 1);
  
                  put_bits(&s->pb, 1, s->field_select[0][0]);
                  put_bits(&s->pb, 1, s->field_select[0][1]);
  
-                 ff_h263_encode_motion_vector(s, s->mv[0][0][0] - pred_x,
-                                                 s->mv[0][0][1] - pred_y, s->f_code);
-                 ff_h263_encode_motion_vector(s, s->mv[0][1][0] - pred_x,
-                                                 s->mv[0][1][1] - pred_y, s->f_code);
-             }else{
-                 av_assert2(s->mv_type==MV_TYPE_8X8);
+                 ff_h263_encode_motion_vector(s,
+                                              s->mv[0][0][0] - pred_x,
+                                              s->mv[0][0][1] - pred_y,
+                                              s->f_code);
+                 ff_h263_encode_motion_vector(s,
+                                              s->mv[0][1][0] - pred_x,
+                                              s->mv[0][1][1] - pred_y,
+                                              s->f_code);
+             } else {
 -                assert(s->mv_type == MV_TYPE_8X8);
++                av_assert2(s->mv_type == MV_TYPE_8X8);
                  put_bits(&s->pb,
-                         ff_h263_inter_MCBPC_bits[cbpc+16],
-                         ff_h263_inter_MCBPC_code[cbpc+16]);
+                          ff_h263_inter_MCBPC_bits[cbpc + 16],
+                          ff_h263_inter_MCBPC_code[cbpc + 16]);
                  put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
  
-                 if(!s->progressive_sequence){
-                     if(cbp)
-                         put_bits(pb2, 1, s->interlaced_dct);
-                 }
+                 if (!s->progressive_sequence && cbp)
+                     put_bits(pb2, 1, s->interlaced_dct);
  
-                 if(interleaved_stats){
-                     s->misc_bits+= get_bits_diff(s);
-                 }
+                 if (interleaved_stats)
+                     s->misc_bits += get_bits_diff(s);
  
-                 for(i=0; i<4; i++){
+                 for (i = 0; i < 4; i++) {
                      /* motion vectors: 8x8 mode*/
                      ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
  
@@@ -854,12 -887,13 +897,13 @@@ void ff_mpeg4_stuffing(PutBitContext *p
  }
  
  /* must be called before writing the header */
- void ff_set_mpeg4_time(MpegEncContext * s){
-     if(s->pict_type==AV_PICTURE_TYPE_B){
+ void ff_set_mpeg4_time(MpegEncContext *s)
+ {
+     if (s->pict_type == AV_PICTURE_TYPE_B) {
          ff_mpeg4_init_direct_mv(s);
-     }else{
-         s->last_time_base= s->time_base;
-         s->time_base= FFUDIV(s->time, s->avctx->time_base.den);
+     } else {
+         s->last_time_base = s->time_base;
 -        s->time_base      = s->time / s->avctx->time_base.den;
++        s->time_base      = FFUDIV(s->time, s->avctx->time_base.den);
      }
  }
  
@@@ -871,24 -906,27 +916,24 @@@ static void mpeg4_encode_gop_header(Mpe
      put_bits(&s->pb, 16, GOP_STARTCODE);
  
      time = s->current_picture_ptr->f.pts;
-     if(s->reordered_input_picture[1])
+     if (s->reordered_input_picture[1])
          time = FFMIN(time, s->reordered_input_picture[1]->f.pts);
-     time= time*s->avctx->time_base.num;
-     s->last_time_base= FFUDIV(time, s->avctx->time_base.den);
+     time = time * s->avctx->time_base.num;
++    s->last_time_base = FFUDIV(time, s->avctx->time_base.den);
  
-     seconds= FFUDIV(time, s->avctx->time_base.den);
-     minutes= FFUDIV(seconds, 60); seconds = FFUMOD(seconds, 60);
-     hours  = FFUDIV(minutes, 60); minutes = FFUMOD(minutes, 60);
-     hours  = FFUMOD(hours  , 24);
 -    seconds  = time / s->avctx->time_base.den;
 -    minutes  = seconds / 60;
 -    seconds %= 60;
 -    hours    = minutes / 60;
 -    minutes %= 60;
 -    hours   %= 24;
++    seconds = FFUDIV(time, s->avctx->time_base.den);
++    minutes = FFUDIV(seconds, 60); seconds = FFUMOD(seconds, 60);
++    hours   = FFUDIV(minutes, 60); minutes = FFUMOD(minutes, 60);
++    hours   = FFUMOD(hours  , 24);
  
      put_bits(&s->pb, 5, hours);
      put_bits(&s->pb, 6, minutes);
      put_bits(&s->pb, 1, 1);
      put_bits(&s->pb, 6, seconds);
  
-     put_bits(&s->pb, 1, !!(s->flags&CODEC_FLAG_CLOSED_GOP));
-     put_bits(&s->pb, 1, 0); //broken link == NO
+     put_bits(&s->pb, 1, !!(s->flags & CODEC_FLAG_CLOSED_GOP));
+     put_bits(&s->pb, 1, 0);  // broken link == NO
  
 -    s->last_time_base = time / s->avctx->time_base.den;
 -
      ff_mpeg4_stuffing(&s->pb);
  }
  
@@@ -966,12 -1006,10 +1013,12 @@@ static void mpeg4_encode_vol_header(Mpe
          put_bits(&s->pb, 3, 1);         /* is obj layer priority */
      }
  
-     s->aspect_ratio_info= ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio);
+     s->aspect_ratio_info = ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio);
  
-     put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */
-     if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){
+     put_bits(&s->pb, 4, s->aspect_ratio_info); /* aspect ratio info */
+     if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {
 +        av_reduce(&s->avctx->sample_aspect_ratio.num, &s->avctx->sample_aspect_ratio.den,
 +                   s->avctx->sample_aspect_ratio.num,  s->avctx->sample_aspect_ratio.den, 255);
          put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num);
          put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
      }
@@@ -1063,11 -1099,12 +1108,11 @@@ void ff_mpeg4_encode_picture_header(Mpe
      put_bits(&s->pb, 16, VOP_STARTCODE);    /* vop header */
      put_bits(&s->pb, 2, s->pict_type - 1);  /* pict type: I = 0 , P = 1 */
  
-     time_div= FFUDIV(s->time, s->avctx->time_base.den);
-     time_mod= FFUMOD(s->time, s->avctx->time_base.den);
-     time_incr= time_div - s->last_time_base;
 -    assert(s->time >= 0);
 -    time_div  = s->time / s->avctx->time_base.den;
 -    time_mod  = s->time % s->avctx->time_base.den;
++    time_div  = FFUDIV(s->time, s->avctx->time_base.den);
++    time_mod  = FFUMOD(s->time, s->avctx->time_base.den);
+     time_incr = time_div - s->last_time_base;
 -    assert(time_incr >= 0);
 +    av_assert0(time_incr >= 0);
-     while(time_incr--)
+     while (time_incr--)
          put_bits(&s->pb, 1, 1);
  
      put_bits(&s->pb, 1, 0);
@@@ -1153,16 -1192,17 +1200,17 @@@ static av_cold void init_uni_mpeg4_rl_t
  {
      int slevel, run, last;
  
 -    assert(MAX_LEVEL >= 64);
 -    assert(MAX_RUN >= 63);
 +    av_assert0(MAX_LEVEL >= 64);
-     av_assert0(MAX_RUN   >= 63);
-     for(slevel=-64; slevel<64; slevel++){
-         if(slevel==0) continue;
-         for(run=0; run<64; run++){
-             for(last=0; last<=1; last++){
-                 const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64);
-                 int level= slevel < 0 ? -slevel : slevel;
-                 int sign= slevel < 0 ? 1 : 0;
++    av_assert0(MAX_RUN >= 63);
+     for (slevel = -64; slevel < 64; slevel++) {
+         if (slevel == 0)
+             continue;
+         for (run = 0; run < 64; run++) {
+             for (last = 0; last <= 1; last++) {
+                 const int index = UNI_MPEG4_ENC_INDEX(last, run, slevel + 64);
+                 int level       = slevel < 0 ? -slevel : slevel;
+                 int sign        = slevel < 0 ? 1 : 0;
                  int bits, len, code;
                  int level1, run1;
  
@@@ -1237,12 -1288,7 +1296,12 @@@ static av_cold int encode_init(AVCodecC
      int ret;
      static int done = 0;
  
-     if((ret=ff_MPV_encode_init(avctx)) < 0)
 +    if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) {
 +        av_log(avctx, AV_LOG_ERROR, "dimensions too large for MPEG-4\n");
 +        return AVERROR(EINVAL);
 +    }
 +
+     if ((ret = ff_MPV_encode_init(avctx)) < 0)
          return ret;
  
      if (!done) {