libavcodec/motion_est.c:1007: error: Null Dereference
  pointer `null` is dereferenced by call to `init_ref()` at line 1007, column 5.

libavcodec/motion_est.c:994:1: start of procedure ff_estimate_p_frame_motion()
992. }
993. 
994. void ff_estimate_p_frame_motion(MpegEncContext * s,
     ^
995.                                 int mb_x, int mb_y)
996. {

libavcodec/motion_est.c:997:5: 
995.                                 int mb_x, int mb_y)
996. {
997.     MotionEstContext * const c= &s->me;
         ^
998.     uint8_t *pix, *ppix;
999.     int sum, mx, my, dmin;

libavcodec/motion_est.c:1003:5: 
1001.     int vard;            ///< sum of squared differences with the estimated motion vector
1002.     int P[10][2];
1003.     const int shift= 1+s->quarter_sample;
          ^
1004.     int mb_type=0;
1005.     Picture * const pic= &s->current_picture;

libavcodec/motion_est.c:1004:5: 
1002.     int P[10][2];
1003.     const int shift= 1+s->quarter_sample;
1004.     int mb_type=0;
          ^
1005.     Picture * const pic= &s->current_picture;
1006. 

libavcodec/motion_est.c:1005:5: 
1003.     const int shift= 1+s->quarter_sample;
1004.     int mb_type=0;
1005.     Picture * const pic= &s->current_picture;
          ^
1006. 
1007.     init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);

libavcodec/motion_est.c:1007:5: 
1005.     Picture * const pic= &s->current_picture;
1006. 
1007.     init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);
          ^
1008. 
1009.     assert(s->quarter_sample==0 || s->quarter_sample==1);

libavcodec/motion_est.c:80:1: start of procedure init_ref()
  78. #define FLAG_DIRECT 4
  79. 
  80. static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){
      ^
  81.     const int offset[3]= {
  82.           y*c->  stride + x,

libavcodec/motion_est.c:81:5: 
  79. 
  80. static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){
  81.     const int offset[3]= {
          ^
  82.           y*c->  stride + x,
  83.         ((y*c->uvstride + x)>>1),

libavcodec/motion_est.c:87:9: 
  85.     };
  86.     int i;
  87.     for(i=0; i<3; i++){
              ^
  88.         c->src[0][i]= src [i] + offset[i];
  89.         c->ref[0][i]= ref [i] + offset[i];

libavcodec/motion_est.c:87:14: Loop condition is true. Entering loop body
  85.     };
  86.     int i;
  87.     for(i=0; i<3; i++){
                   ^
  88.         c->src[0][i]= src [i] + offset[i];
  89.         c->ref[0][i]= ref [i] + offset[i];

libavcodec/motion_est.c:88:9: 
  86.     int i;
  87.     for(i=0; i<3; i++){
  88.         c->src[0][i]= src [i] + offset[i];
              ^
  89.         c->ref[0][i]= ref [i] + offset[i];
  90.     }

libavcodec/motion_est.c:89:9: 
  87.     for(i=0; i<3; i++){
  88.         c->src[0][i]= src [i] + offset[i];
  89.         c->ref[0][i]= ref [i] + offset[i];
              ^
  90.     }
  91.     if(ref_index){

libavcodec/motion_est.c:87:19: 
  85.     };
  86.     int i;
  87.     for(i=0; i<3; i++){
                        ^
  88.         c->src[0][i]= src [i] + offset[i];
  89.         c->ref[0][i]= ref [i] + offset[i];

libavcodec/motion_est.c:87:14: Loop condition is true. Entering loop body
  85.     };
  86.     int i;
  87.     for(i=0; i<3; i++){
                   ^
  88.         c->src[0][i]= src [i] + offset[i];
  89.         c->ref[0][i]= ref [i] + offset[i];

libavcodec/motion_est.c:88:9: 
  86.     int i;
  87.     for(i=0; i<3; i++){
  88.         c->src[0][i]= src [i] + offset[i];
              ^
  89.         c->ref[0][i]= ref [i] + offset[i];
  90.     }

libavcodec/motion_est.c:89:9: 
  87.     for(i=0; i<3; i++){
  88.         c->src[0][i]= src [i] + offset[i];
  89.         c->ref[0][i]= ref [i] + offset[i];
              ^
  90.     }
  91.     if(ref_index){

libavcodec/motion_est.c:87:19: 
  85.     };
  86.     int i;
  87.     for(i=0; i<3; i++){
                        ^
  88.         c->src[0][i]= src [i] + offset[i];
  89.         c->ref[0][i]= ref [i] + offset[i];

libavcodec/motion_est.c:87:14: Loop condition is false. Leaving loop
  85.     };
  86.     int i;
  87.     for(i=0; i<3; i++){
                   ^
  88.         c->src[0][i]= src [i] + offset[i];
  89.         c->ref[0][i]= ref [i] + offset[i];

libavcodec/motion_est.c:91:8: Taking true branch
  89.         c->ref[0][i]= ref [i] + offset[i];
  90.     }
  91.     if(ref_index){
             ^
  92.         for(i=0; i<3; i++){
  93.             c->ref[ref_index][i]= ref2[i] + offset[i];

libavcodec/motion_est.c:92:13: 
  90.     }
  91.     if(ref_index){
  92.         for(i=0; i<3; i++){
                  ^
  93.             c->ref[ref_index][i]= ref2[i] + offset[i];
  94.         }

libavcodec/motion_est.c:92:18: Loop condition is true. Entering loop body
  90.     }
  91.     if(ref_index){
  92.         for(i=0; i<3; i++){
                       ^
  93.             c->ref[ref_index][i]= ref2[i] + offset[i];
  94.         }

libavcodec/motion_est.c:93:13: 
  91.     if(ref_index){
  92.         for(i=0; i<3; i++){
  93.             c->ref[ref_index][i]= ref2[i] + offset[i];
                  ^
  94.         }
  95.     }

void ff_estimate_p_frame_motion(MpegEncContext * s,
                                int mb_x, int mb_y)
{
    MotionEstContext * const c= &s->me;
    uint8_t *pix, *ppix;
    int sum, mx, my, dmin;
    int varc;
    int vard;
    int P[10][2];
    const int shift= 1+s->quarter_sample;
    int mb_type=0;
    Picture * const pic= &s->current_picture;
    init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);
    assert(s->quarter_sample==0 || s->quarter_sample==1);
    assert(s->linesize == c->stride);
    assert(s->uvlinesize == c->uvstride);
    c->penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);
    c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);
    c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);
    c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
    get_limits(s, 16*mb_x, 16*mb_y);
    c->skip=0;
    pix = c->src[0][0];
    sum = s->dsp.pix_sum(pix, s->linesize);
    varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500;
    pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
    pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
    c->mb_var_sum_temp += (varc+128)>>8;
    if(c->avctx->me_threshold){
        vard= check_input_motion(s, mb_x, mb_y, 1);
        if((vard+128)>>8 < c->avctx->me_threshold){
            int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
            int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
            pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
            c->mc_mb_var_sum_temp += (vard+128)>>8;
            c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
            return;
        }
        if((vard+128)>>8 < c->avctx->mb_threshold)
            mb_type= s->mb_type[mb_x + mb_y*s->mb_stride];
    }
    switch(s->me_method) {
    case ME_ZERO:
    default:
        mx   = 0;
        my   = 0;
        dmin = 0;
        break;
    case ME_X1:
    case ME_EPZS:
       {
            const int mot_stride = s->b8_stride;
            const int mot_xy = s->block_index[0];
            P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0];
            P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1];
            if(P_LEFT[0]       > (c->xmax<<shift)) P_LEFT[0]       = (c->xmax<<shift);
            if(!s->first_slice_line) {
                P_TOP[0]      = s->current_picture.f.motion_val[0][mot_xy - mot_stride    ][0];
                P_TOP[1]      = s->current_picture.f.motion_val[0][mot_xy - mot_stride    ][1];
                P_TOPRIGHT[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][0];
                P_TOPRIGHT[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][1];
                if(P_TOP[1]      > (c->ymax<<shift)) P_TOP[1]     = (c->ymax<<shift);
                if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
                if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
                P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
                P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
                if(s->out_format == FMT_H263){
                    c->pred_x = P_MEDIAN[0];
                    c->pred_y = P_MEDIAN[1];
                }else {
                    c->pred_x= P_LEFT[0];
                    c->pred_y= P_LEFT[1];
                }
            }else{
                c->pred_x= P_LEFT[0];
                c->pred_y= P_LEFT[1];
            }
        }
        dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);
        break;
    }
    ppix = c->ref[0][0] + (my * s->linesize) + mx;
    vard = s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16);
    pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
    c->mc_mb_var_sum_temp += (vard+128)>>8;
    if(mb_type){
        int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
        int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
        c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
        if(mb_type == CANDIDATE_MB_TYPE_INTER){
            c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
            set_p_mv_tables(s, mx, my, 1);
        }else{
            mx <<=shift;
            my <<=shift;
        }
        if(mb_type == CANDIDATE_MB_TYPE_INTER4V){
            h263_mv4_search(s, mx, my, shift);
            set_p_mv_tables(s, mx, my, 0);
        }
        if(mb_type == CANDIDATE_MB_TYPE_INTER_I){
            interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 1);
        }
    }else if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
        int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
        int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
        c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
        if (vard*2 + 200*256 > varc)
            mb_type|= CANDIDATE_MB_TYPE_INTRA;
        if (varc*2 + 200*256 > vard || s->qscale > 24){
            mb_type|= CANDIDATE_MB_TYPE_INTER;
            c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
            if(s->flags&CODEC_FLAG_MV0)
                if(mx || my)
                    mb_type |= CANDIDATE_MB_TYPE_SKIPPED;
        }else{
            mx <<=shift;
            my <<=shift;
        }
        if((s->flags&CODEC_FLAG_4MV)
           && !c->skip && varc>50<<8 && vard>10<<8){
            if(h263_mv4_search(s, mx, my, shift) < INT_MAX)
                mb_type|=CANDIDATE_MB_TYPE_INTER4V;
            set_p_mv_tables(s, mx, my, 0);
        }else
            set_p_mv_tables(s, mx, my, 1);
        if((s->flags&CODEC_FLAG_INTERLACED_ME)
           && !c->skip){
            if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0) < INT_MAX)
                mb_type |= CANDIDATE_MB_TYPE_INTER_I;
        }
    }else{
        int intra_score, i;
        mb_type= CANDIDATE_MB_TYPE_INTER;
        dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
        if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
            dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
        if((s->flags&CODEC_FLAG_4MV)
           && !c->skip && varc>50<<8 && vard>10<<8){
            int dmin4= h263_mv4_search(s, mx, my, shift);
            if(dmin4 < dmin){
                mb_type= CANDIDATE_MB_TYPE_INTER4V;
                dmin=dmin4;
            }
        }
        if((s->flags&CODEC_FLAG_INTERLACED_ME)
           && !c->skip){
            int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0);
            if(dmin_i < dmin){
                mb_type = CANDIDATE_MB_TYPE_INTER_I;
                dmin= dmin_i;
            }
        }
        set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V);
        if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){
            intra_score= varc - 500;
        }else{
            unsigned mean = (sum+128)>>8;
            mean*= 0x01010101;
            for(i=0; i<16; i++){
                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 0]) = mean;
                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 4]) = mean;
                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 8]) = mean;
                *(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean;
            }
            intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
        }
        intra_score += c->mb_penalty_factor*16;
        if(intra_score < dmin){
            mb_type= CANDIDATE_MB_TYPE_INTRA;
            s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = CANDIDATE_MB_TYPE_INTRA;
        }else
            s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = 0;
        {
            int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
            int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
            c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
        }
    }
    s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type;
}
['void ff_estimate_p_frame_motion(MpegEncContext * s,\n                                int mb_x, int mb_y)\n{\n    MotionEstContext * const c= &s->me;\n    uint8_t *pix, *ppix;\n    int sum, mx, my, dmin;\n    int varc;\n    int vard;\n    int P[10][2];\n    const int shift= 1+s->quarter_sample;\n    int mb_type=0;\n    Picture * const pic= &s->current_picture;\n    init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);\n    assert(s->quarter_sample==0 || s->quarter_sample==1);\n    assert(s->linesize == c->stride);\n    assert(s->uvlinesize == c->uvstride);\n    c->penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);\n    c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);\n    c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);\n    c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;\n    get_limits(s, 16*mb_x, 16*mb_y);\n    c->skip=0;\n    pix = c->src[0][0];\n    sum = s->dsp.pix_sum(pix, s->linesize);\n    varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500;\n    pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;\n    pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;\n    c->mb_var_sum_temp += (varc+128)>>8;\n    if(c->avctx->me_threshold){\n        vard= check_input_motion(s, mb_x, mb_y, 1);\n        if((vard+128)>>8 < c->avctx->me_threshold){\n            int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);\n            int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;\n            pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;\n            c->mc_mb_var_sum_temp += (vard+128)>>8;\n            c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);\n            return;\n        }\n        if((vard+128)>>8 < c->avctx->mb_threshold)\n            mb_type= s->mb_type[mb_x + mb_y*s->mb_stride];\n    }\n    switch(s->me_method) {\n    case ME_ZERO:\n    default:\n        mx   = 0;\n        my   = 0;\n        dmin = 0;\n        break;\n    case ME_X1:\n    case ME_EPZS:\n       {\n            const int mot_stride = s->b8_stride;\n            const int mot_xy = s->block_index[0];\n            P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0];\n            P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1];\n            if(P_LEFT[0]       > (c->xmax<<shift)) P_LEFT[0]       = (c->xmax<<shift);\n            if(!s->first_slice_line) {\n                P_TOP[0]      = s->current_picture.f.motion_val[0][mot_xy - mot_stride    ][0];\n                P_TOP[1]      = s->current_picture.f.motion_val[0][mot_xy - mot_stride    ][1];\n                P_TOPRIGHT[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][0];\n                P_TOPRIGHT[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][1];\n                if(P_TOP[1]      > (c->ymax<<shift)) P_TOP[1]     = (c->ymax<<shift);\n                if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);\n                if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);\n                P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);\n                P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);\n                if(s->out_format == FMT_H263){\n                    c->pred_x = P_MEDIAN[0];\n                    c->pred_y = P_MEDIAN[1];\n                }else {\n                    c->pred_x= P_LEFT[0];\n                    c->pred_y= P_LEFT[1];\n                }\n            }else{\n                c->pred_x= P_LEFT[0];\n                c->pred_y= P_LEFT[1];\n            }\n        }\n        dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);\n        break;\n    }\n    ppix = c->ref[0][0] + (my * s->linesize) + mx;\n    vard = s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16);\n    pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;\n    c->mc_mb_var_sum_temp += (vard+128)>>8;\n    if(mb_type){\n        int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);\n        int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;\n        c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);\n        if(mb_type == CANDIDATE_MB_TYPE_INTER){\n            c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);\n            set_p_mv_tables(s, mx, my, 1);\n        }else{\n            mx <<=shift;\n            my <<=shift;\n        }\n        if(mb_type == CANDIDATE_MB_TYPE_INTER4V){\n            h263_mv4_search(s, mx, my, shift);\n            set_p_mv_tables(s, mx, my, 0);\n        }\n        if(mb_type == CANDIDATE_MB_TYPE_INTER_I){\n            interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 1);\n        }\n    }else if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){\n        int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);\n        int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;\n        c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);\n        if (vard*2 + 200*256 > varc)\n            mb_type|= CANDIDATE_MB_TYPE_INTRA;\n        if (varc*2 + 200*256 > vard || s->qscale > 24){\n            mb_type|= CANDIDATE_MB_TYPE_INTER;\n            c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);\n            if(s->flags&CODEC_FLAG_MV0)\n                if(mx || my)\n                    mb_type |= CANDIDATE_MB_TYPE_SKIPPED;\n        }else{\n            mx <<=shift;\n            my <<=shift;\n        }\n        if((s->flags&CODEC_FLAG_4MV)\n           && !c->skip && varc>50<<8 && vard>10<<8){\n            if(h263_mv4_search(s, mx, my, shift) < INT_MAX)\n                mb_type|=CANDIDATE_MB_TYPE_INTER4V;\n            set_p_mv_tables(s, mx, my, 0);\n        }else\n            set_p_mv_tables(s, mx, my, 1);\n        if((s->flags&CODEC_FLAG_INTERLACED_ME)\n           && !c->skip){\n            if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0) < INT_MAX)\n                mb_type |= CANDIDATE_MB_TYPE_INTER_I;\n        }\n    }else{\n        int intra_score, i;\n        mb_type= CANDIDATE_MB_TYPE_INTER;\n        dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);\n        if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)\n            dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1);\n        if((s->flags&CODEC_FLAG_4MV)\n           && !c->skip && varc>50<<8 && vard>10<<8){\n            int dmin4= h263_mv4_search(s, mx, my, shift);\n            if(dmin4 < dmin){\n                mb_type= CANDIDATE_MB_TYPE_INTER4V;\n                dmin=dmin4;\n            }\n        }\n        if((s->flags&CODEC_FLAG_INTERLACED_ME)\n           && !c->skip){\n            int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0);\n            if(dmin_i < dmin){\n                mb_type = CANDIDATE_MB_TYPE_INTER_I;\n                dmin= dmin_i;\n            }\n        }\n        set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V);\n        if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){\n            intra_score= varc - 500;\n        }else{\n            unsigned mean = (sum+128)>>8;\n            mean*= 0x01010101;\n            for(i=0; i<16; i++){\n                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 0]) = mean;\n                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 4]) = mean;\n                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 8]) = mean;\n                *(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean;\n            }\n            intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);\n        }\n        intra_score += c->mb_penalty_factor*16;\n        if(intra_score < dmin){\n            mb_type= CANDIDATE_MB_TYPE_INTRA;\n            s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = CANDIDATE_MB_TYPE_INTRA;\n        }else\n            s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = 0;\n        {\n            int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);\n            int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;\n            c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);\n        }\n    }\n    s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type;\n}', 'static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){\n    const int offset[3]= {\n          y*c->  stride + x,\n        ((y*c->uvstride + x)>>1),\n        ((y*c->uvstride + x)>>1),\n    };\n    int i;\n    for(i=0; i<3; i++){\n        c->src[0][i]= src [i] + offset[i];\n        c->ref[0][i]= ref [i] + offset[i];\n    }\n    if(ref_index){\n        for(i=0; i<3; i++){\n            c->ref[ref_index][i]= ref2[i] + offset[i];\n        }\n    }\n}']