Revision f20f8a8b

View differences:

ffmpeg.c
161 161
static int debug = 0;
162 162
static int debug_mv = 0;
163 163
static int me_threshold = 0;
164
static int mb_threshold = 0;
164 165
extern int loop_input; /* currently a hack */
165 166

  
166 167
static int gop_size = 12;
......
1866 1867
    me_threshold = atoi(arg);
1867 1868
}
1868 1869

  
1870
static void opt_mb_threshold(const char *arg)
1871
{
1872
    mb_threshold = atoi(arg);
1873
}
1869 1874

  
1870 1875
static void opt_error_resilience(const char *arg)
1871 1876
{
......
2873 2878
                video_enc->dct_algo = dct_algo;
2874 2879
                video_enc->idct_algo = idct_algo;
2875 2880
                video_enc->me_threshold= me_threshold;
2881
                video_enc->mb_threshold= mb_threshold;
2876 2882
                video_enc->strict_std_compliance = strict;
2877 2883
                video_enc->error_rate = error_rate;
2878 2884
                video_enc->noise_reduction= noise_reduction;
......
3494 3500
    { "dct_algo", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_dct_algo}, "set dct algo",  "algo" },
3495 3501
    { "idct_algo", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_idct_algo}, "set idct algo",  "algo" },
3496 3502
    { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold",  "" },
3503
    { "mb_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_threshold}, "macroblock threshold",  "" },
3497 3504
    { "er", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_error_resilience}, "set error resilience",  "n" },
3498 3505
    { "ec", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_error_concealment}, "set error concealment",  "bit_mask" },
3499 3506
    { "bf", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_frames}, "use 'frames' B frames", "frames" },
libavcodec/avcodec.h
17 17

  
18 18
#define FFMPEG_VERSION_INT     0x000408
19 19
#define FFMPEG_VERSION         "0.4.8"
20
#define LIBAVCODEC_BUILD       4709
20
#define LIBAVCODEC_BUILD       4710
21 21

  
22 22
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
23 23
#define LIBAVCODEC_VERSION     FFMPEG_VERSION
......
1570 1570
    void *thread_opaque;
1571 1571

  
1572 1572
    /**
1573
     * Motion estimation threshold.
1573
     * Motion estimation threshold. under which no motion estimation is 
1574
     * performed, but instead the user specified motion vectors are used
1574 1575
     * 
1575 1576
     * - encoding: set by user
1576
     * - decoding: set by user
1577
     * - decoding: unused
1577 1578
     */
1578 1579
     int me_threshold;
1580

  
1581
    /**
1582
     * Macroblock threshold. under which the user specified macroblock types will be used
1583
     * - encoding: set by user
1584
     * - decoding: unused
1585
     */
1586
     int mb_threshold;
1579 1587
} AVCodecContext;
1580 1588

  
1581 1589

  
libavcodec/motion_est.c
859 859
}
860 860

  
861 861
static int interlaced_search(MpegEncContext *s, int ref_index, 
862
                             int16_t (*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my)
862
                             int16_t (*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)
863 863
{
864 864
    MotionEstContext * const c= &s->me;
865 865
    const int size=0;
......
889 889
            int dmin, mx_i, my_i;
890 890
            int16_t (*mv_table)[2]= mv_tables[block][field_select];
891 891
            
892
            if(user_field_select){
893
                if(field_select_tables[block][xy] != field_select)
894
                    continue;
895
            }
896
            
892 897
            P_LEFT[0] = mv_table[xy - 1][0];
893 898
            P_LEFT[1] = mv_table[xy - 1][1];
894 899
            if(P_LEFT[0]       > (c->xmax<<1)) P_LEFT[0]       = (c->xmax<<1);
......
996 1001
        s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;
997 1002
        c->stride<<=1;
998 1003
        c->uvstride<<=1;
999
        init_interlaced_ref(s, 2);
1000 1004
        
1001 1005
        assert(s->flags & CODEC_FLAG_INTERLACED_ME);
1002 1006

  
......
1005 1009
            int field_select1= p->ref_index[0][xy2];
1006 1010
            assert(field_select0==0 ||field_select0==1);
1007 1011
            assert(field_select1==0 ||field_select1==1);
1012
            init_interlaced_ref(s, 0);
1013

  
1008 1014
            if(p_type){
1009 1015
                s->p_field_select_table[0][mb_xy]= field_select0;
1010 1016
                s->p_field_select_table[1][mb_xy]= field_select1;
......
1031 1037
            int field_select1= p->ref_index[1][xy2];
1032 1038
            assert(field_select0==0 ||field_select0==1);
1033 1039
            assert(field_select1==0 ||field_select1==1);
1040
            init_interlaced_ref(s, 2);
1041

  
1034 1042
            s->b_field_select_table[1][0][mb_xy]= field_select0;
1035 1043
            s->b_field_select_table[1][1][mb_xy]= field_select1;
1036 1044
            *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[1][xy ];
......
1097 1105
{
1098 1106
    MotionEstContext * const c= &s->me;
1099 1107
    uint8_t *pix, *ppix;
1100
    int sum, varc, vard, mx, my, dmin, xx, yy;
1108
    int sum, varc, vard, mx, my, dmin;
1101 1109
    int P[10][2];
1102 1110
    const int shift= 1+s->quarter_sample;
1103 1111
    int mb_type=0;
......
1117 1125
    get_limits(s, 16*mb_x, 16*mb_y);
1118 1126
    s->me.skip=0;
1119 1127

  
1128
    /* intra / predictive decision */
1129
    pix = c->src[0][0];
1130
    sum = s->dsp.pix_sum(pix, s->linesize);
1131
    varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;
1132

  
1133
    pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
1134
    pic->mb_var [s->mb_stride * mb_y + mb_x] = varc;
1135
    s->mb_var_sum_temp += varc;
1136

  
1120 1137
    if(s->avctx->me_threshold){
1121 1138
        vard= (check_input_motion(s, mb_x, mb_y, 1)+128)>>8;
1122 1139
        
1123 1140
        if(vard<s->avctx->me_threshold){
1124
            pix = c->src[0][0];
1125
            sum = s->dsp.pix_sum(pix, s->linesize);
1126
            varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;
1127
        
1128
            pic->mb_var   [s->mb_stride * mb_y + mb_x] = varc;
1129 1141
            pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = vard;
1130
            pic->mb_mean  [s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
1131
            s->mb_var_sum_temp    += varc;
1132 1142
            s->mc_mb_var_sum_temp += vard;
1133 1143
            if (vard <= 64 || vard < varc) { //FIXME
1134 1144
                s->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
......
1137 1147
            }
1138 1148
            return;
1139 1149
        }
1150
        if(vard<s->avctx->mb_threshold)
1151
            mb_type= s->mb_type[mb_x + mb_y*s->mb_stride];
1140 1152
    }
1141 1153

  
1142 1154
    switch(s->me_method) {
......
1205 1217
        break;
1206 1218
    }
1207 1219

  
1208
    /* intra / predictive decision */
1209
    xx = mb_x * 16;
1210
    yy = mb_y * 16;
1211

  
1212
    pix = c->src[0][0];
1213 1220
    /* At this point (mx,my) are full-pell and the relative displacement */
1214 1221
    ppix = c->ref[0][0] + (my * s->linesize) + mx;
1215
    
1216
    sum = s->dsp.pix_sum(pix, s->linesize);
1217
    
1218
    varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;
1222
        
1219 1223
    vard = (s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16)+128)>>8;
1220 1224

  
1221
//printf("%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout);
1222
    pic->mb_var   [s->mb_stride * mb_y + mb_x] = varc;
1223 1225
    pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = vard;
1224
    pic->mb_mean  [s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
1225 1226
//    pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; 
1226
    s->mb_var_sum_temp    += varc;
1227 1227
    s->mc_mb_var_sum_temp += vard;
1228
//printf("E%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout);
1229 1228
    
1230 1229
#if 0
1231 1230
    printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n",
1232 1231
	   varc, s->avg_mb_var, sum, vard, mx - xx, my - yy);
1233 1232
#endif
1234
    if(s->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
1233
    if(mb_type){
1234
        if (vard <= 64 || vard < varc)
1235
            s->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
1236
        else
1237
            s->scene_change_score+= s->qscale;
1238

  
1239
        if(mb_type == CANDIDATE_MB_TYPE_INTER){
1240
            s->me.sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1241
            set_p_mv_tables(s, mx, my, 1);
1242
        }else{
1243
            mx <<=shift;
1244
            my <<=shift;
1245
        }
1246
        if(mb_type == CANDIDATE_MB_TYPE_INTER4V){
1247
            h263_mv4_search(s, mx, my, shift);
1248

  
1249
            set_p_mv_tables(s, mx, my, 0);
1250
        }
1251
        if(mb_type == CANDIDATE_MB_TYPE_INTER_I){
1252
            interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 1);
1253
        }
1254
    }else if(s->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
1235 1255
        if (vard <= 64 || vard < varc)
1236 1256
            s->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
1237 1257
        else
......
1259 1279
            set_p_mv_tables(s, mx, my, 1);
1260 1280
        if((s->flags&CODEC_FLAG_INTERLACED_ME)
1261 1281
           && !s->me.skip){ //FIXME varc/d checks
1262
            if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my) < INT_MAX)
1282
            if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0) < INT_MAX)
1263 1283
                mb_type |= CANDIDATE_MB_TYPE_INTER_I;
1264 1284
        }
1265 1285
    }else{
......
1280 1300
        }
1281 1301
        if((s->flags&CODEC_FLAG_INTERLACED_ME)
1282 1302
           && !s->me.skip){ //FIXME varc/d checks
1283
            int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my);
1303
            int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0);
1284 1304
            if(dmin_i < dmin){
1285 1305
                mb_type = CANDIDATE_MB_TYPE_INTER_I;
1286 1306
                dmin= dmin_i;
......
1690 1710
    const int penalty_factor= s->me.mb_penalty_factor;
1691 1711
    int fmin, bmin, dmin, fbmin, bimin, fimin;
1692 1712
    int type=0;
1713
    const int xy = mb_y*s->mb_stride + mb_x;
1693 1714
    init_ref(s, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);
1715

  
1694 1716
    
1695 1717
    s->me.skip=0;
1696 1718
    if(s->avctx->me_threshold){
......
1713 1735
            }*/
1714 1736
            return;
1715 1737
        }
1738
        if(vard<s->avctx->mb_threshold){
1739
            type= s->mb_type[mb_y*s->mb_stride + mb_x];
1740
            if(type == CANDIDATE_MB_TYPE_DIRECT){
1741
                direct_search(s, mb_x, mb_y);
1742
            }
1743
            if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){
1744
                s->me.skip=0;
1745
                ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code);
1746
            }
1747
            if(type == CANDIDATE_MB_TYPE_BACKWARD || type == CANDIDATE_MB_TYPE_BIDIR){
1748
                s->me.skip=0;
1749
                ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code);
1750
            }
1751
            if(type == CANDIDATE_MB_TYPE_FORWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){
1752
                s->me.skip=0;
1753
                s->me.current_mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
1754
                interlaced_search(s, 0,
1755
                                        s->b_field_mv_table[0], s->b_field_select_table[0],
1756
                                        s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 1);
1757
            }
1758
            if(type == CANDIDATE_MB_TYPE_BACKWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){
1759
                s->me.skip=0;
1760
                s->me.current_mv_penalty= s->me.mv_penalty[s->b_code] + MAX_MV;
1761
                interlaced_search(s, 2,
1762
                                        s->b_field_mv_table[1], s->b_field_select_table[1],
1763
                                        s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 1);
1764
            }
1765
            return;
1766
        }
1716 1767
    }
1717 1768

  
1718 1769
    if (s->codec_id == CODEC_ID_MPEG4)
......
1732 1783
//printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin);
1733 1784
    
1734 1785
    if(s->flags & CODEC_FLAG_INTERLACED_ME){
1735
        const int xy = mb_y*s->mb_stride + mb_x;
1736

  
1737 1786
//FIXME mb type penalty
1738 1787
        s->me.skip=0;
1739 1788
        s->me.current_mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
1740 1789
        fimin= interlaced_search(s, 0,
1741 1790
                                 s->b_field_mv_table[0], s->b_field_select_table[0],
1742
                                 s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);
1791
                                 s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 0);
1743 1792
        s->me.current_mv_penalty= s->me.mv_penalty[s->b_code] + MAX_MV;
1744 1793
        bimin= interlaced_search(s, 2,
1745 1794
                                 s->b_field_mv_table[1], s->b_field_select_table[1],
1746
                                 s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1]);
1795
                                 s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 0);
1747 1796
    }else
1748 1797
        fimin= bimin= INT_MAX;
1749 1798

  
libavcodec/mpegvideo.h
229 229
/*    cmp, chroma_cmp;*/
230 230
    op_pixels_func (*hpel_put)[4];
231 231
    op_pixels_func (*hpel_avg)[4];
232
    op_pixels_func (*chroma_hpel_put)[4];
233 232
    qpel_mc_func (*qpel_put)[16];
234 233
    qpel_mc_func (*qpel_avg)[16];
235 234
    uint8_t (*mv_penalty)[MAX_MV*2+1];  ///< amount of bits needed to encode a MV 

Also available in: Unified diff