41 #define P_TOPRIGHT P[3]
45 #define ME_MAP_SHIFT 3
46 #define ME_MAP_MV_BITS 11
49 int *mx_ptr,
int *my_ptr,
int dmin,
50 int src_index,
int ref_index,
77 #define FLAG_QPEL 1 //must be 1
89 c->
src[0][i]= src [i] + offset[i];
90 c->
ref[0][i]= ref [i] + offset[i];
94 c->
ref[ref_index][i]= ref2[i] + offset[i];
106 const int size,
const int h,
int ref_index,
int src_index,
110 const int hx= subx + (x<<(1+qpel));
111 const int hy= suby + (y<<(1+qpel));
112 uint8_t *
const *
const ref= c->
ref[ref_index];
116 av_assert2(x >= c->
xmin && hx <= c->xmax<<(qpel+1) && y >= c->
ymin && hy <= c->ymax<<(qpel+1));
117 if(x >= c->
xmin && hx <= c->xmax<<(qpel+1) && y >= c->
ymin && hy <= c->ymax<<(qpel+1)){
120 const int mask= 2*qpel+1;
128 int fxy= (fx&
mask) + ((fy&mask)<<(qpel+1));
129 int bxy= (bx&
mask) + ((by&mask)<<(qpel+1));
145 int fxy= (fx&
mask) + ((fy&mask)<<(qpel+1));
146 int bxy= (bx&
mask) + ((by&mask)<<(qpel+1));
178 const int size,
const int h,
int ref_index,
int src_index,
183 const int dxy= subx + (suby<<(1+qpel));
184 const int hx= subx + (x<<(1+qpel));
185 const int hy= suby + (y<<(1+qpel));
186 uint8_t *
const *
const ref= c->
ref[ref_index];
193 if (h << size == 16) {
195 }
else if (size == 0 && h == 8) {
205 uvdxy= (cx&1) + 2*(cy&1);
211 uvdxy= dxy | (x&1) | (2*(y&1));
215 d =
cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);
217 uvdxy= (x&1) + 2*(y&1);
221 c->
hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
222 c->
hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
223 d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1);
224 d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);
230 int ref_index,
int src_index,
232 return cmp_inline(s,x,y,0,0,0,16,ref_index,src_index, cmp_func, chroma_cmp_func, 0, 0);
236 const int size,
const int h,
int ref_index,
int src_index,
239 return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&
FLAG_QPEL);
241 return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&
FLAG_CHROMA);
246 const int size,
const int h,
int ref_index,
int src_index,
249 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&
FLAG_QPEL);
251 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&
FLAG_QPEL, flags&
FLAG_CHROMA);
259 const int size,
const int h,
int ref_index,
int src_index,
263 && flags==0 && h==16 && size==0 && subx==0 && suby==0){
264 return cmp_simple(s,x,y,ref_index,src_index, cmp_func, chroma_cmp_func);
266 && subx==0 && suby==0){
267 return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags);
269 return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags);
274 const int size,
const int h,
int ref_index,
int src_index,
277 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0);
279 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&
FLAG_CHROMA);
284 const int size,
const int h,
int ref_index,
int src_index,
287 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 1);
289 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 1, flags&
FLAG_CHROMA);
315 av_log(s->
avctx,
AV_LOG_ERROR,
"me_method is only allowed to be set to zero and epzs; for hex,umh,full and others see dia_size\n");
324 if(cache_size < 2*dia_size && !c->
stride){
388 #define CHECK_SAD_HALF_MV(suffix, x, y) \
390 d = s->mecc.pix_abs[size][(x ? 1 : 0) + (y ? 2 : 0)](NULL, pix, ptr + ((x) >> 1), stride, h); \
391 d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
392 COPY3_IF_LT(dminh, d, dx, x, dy, y)\
396 int *mx_ptr,
int *my_ptr,
int dmin,
397 int src_index,
int ref_index,
415 pix = c->
src[src_index][0];
419 ptr = c->
ref[ref_index][0] + (my *
stride) + mx;
423 if (mx > xmin && mx < xmax &&
424 my > ymin && my < ymax) {
429 const int l= score_map[(index- 1 )&(
ME_MAP_SIZE-1)];
543 c->
xmin = (x > 15) ? - 15 : 0;
544 c->
ymin = (y > 15) ? - 15 : 0;
553 if(!range || range > max_range)
566 c->
ref[1][0] = c->
ref[0][0] + 8;
568 c->
ref[3][0] = c->
ref[2][0] + 8;
569 c->
src[1][0] = c->
src[0][0] + 8;
571 c->
src[3][0] = c->
src[2][0] + 8;
581 int dmin_sum=0, mx4_sum=0, my4_sum=0, i;
589 for(block=0; block<4; block++){
591 int pred_x4, pred_y4;
593 static const int off[4]= {2, 1, 1, -1};
636 if(P[i][1] > (c->
ymax<<shift)) P[i][1]= (c->
ymax<<shift);
649 dxy = ((my4 & 3) << 2) | (mx4 & 3);
657 dxy = ((my4 & 1) << 1) | (mx4 & 1);
664 dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*c->
mb_penalty_factor;
679 if(mx4 != mx || my4 != my) same=0;
699 dxy = ((my & 1) << 1) | (mx & 1);
742 int16_t (*mv_tables[2][2])[2],
uint8_t *field_select_tables[2],
int mx,
int my,
int user_field_select)
754 const int xy= s->
mb_x + s->
mb_y*mot_stride;
762 for(block=0; block<2; block++){
764 int best_dmin= INT_MAX;
767 for(field_select=0; field_select<2; field_select++){
768 int dmin, mx_i, my_i;
769 int16_t (*mv_table)[2]= mv_tables[
block][field_select];
771 if(user_field_select){
772 av_assert1(field_select==0 || field_select==1);
773 av_assert1(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1);
774 if(field_select_tables[block][xy] != field_select)
778 P_LEFT[0] = mv_table[xy - 1][0];
779 P_LEFT[1] = mv_table[xy - 1][1];
786 P_TOP[0] = mv_table[xy - mot_stride][0];
787 P_TOP[1] = mv_table[xy - mot_stride][1];
788 P_TOPRIGHT[0] = mv_table[xy - mot_stride + 1][0];
789 P_TOPRIGHT[1] = mv_table[xy - mot_stride + 1][1];
801 dmin =
epzs_motion_search2(s, &mx_i, &my_i, P, block, field_select+ref_index, mv_table, (1<<16)>>1);
803 dmin= c->
sub_motion_search(s, &mx_i, &my_i, dmin, block, field_select+ref_index, size, h);
805 mv_table[xy][0]= mx_i;
806 mv_table[xy][1]= my_i;
812 uint8_t *ref= c->
ref[field_select+ref_index][0] + (mx_i>>1) + (my_i>>1)*
stride;
813 dxy = ((my_i & 1) << 1) | (mx_i & 1);
825 dmin += field_select !=
block;
827 if(dmin < best_dmin){
829 best_field= field_select;
833 int16_t (*mv_table)[2]= mv_tables[
block][best_field];
835 if(mv_table[xy][0] != mx) same=0;
836 if(mv_table[xy][1]&1) same=0;
837 if(mv_table[xy][1]*2 != my) same=0;
838 if(best_field != block) same=0;
841 field_select_tables[
block][xy]= best_field;
842 dmin_sum += best_dmin;
869 return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
892 int sum, mx, my, dmin;
918 (((unsigned) sum * sum) >> 8) + 500;
985 if (vard*2 + 200*256 > varc)
987 if (varc*2 + 200*256 > vard || s->
qscale > 24){
999 && !c->
skip && varc>50<<8 && vard>10<<8){
1020 && !c->
skip && varc>50<<8 && vard>10<<8){
1040 intra_score= varc - 500;
1042 unsigned mean = (sum+128)>>8;
1045 for(i=0; i<16; i++){
1056 if(intra_score < dmin){
1126 int16_t (*mv_table)[2],
int ref_index,
int f_code)
1133 const int mot_xy = mb_y*mot_stride + mb_x;
1153 P_LEFT[0] = mv_table[mot_xy - 1][0];
1154 P_LEFT[1] = mv_table[mot_xy - 1][1];
1160 P_TOP[0] = mv_table[mot_xy - mot_stride ][0];
1161 P_TOP[1] = mv_table[mot_xy - mot_stride ][1];
1162 P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0];
1163 P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1];
1191 mv_table[mot_xy][0]= mx;
1192 mv_table[mot_xy][1]= my;
1198 int motion_fx,
int motion_fy,
1199 int motion_bx,
int motion_by,
1200 int pred_fx,
int pred_fy,
1201 int pred_bx,
int pred_by,
1221 dxy = ((motion_fy & 3) << 2) | (motion_fx & 3);
1222 src_x = motion_fx >> 2;
1223 src_y = motion_fy >> 2;
1225 ptr = ref_data[0] + (src_y *
stride) + src_x;
1228 dxy = ((motion_by & 3) << 2) | (motion_bx & 3);
1229 src_x = motion_bx >> 2;
1230 src_y = motion_by >> 2;
1232 ptr = ref2_data[0] + (src_y *
stride) + src_x;
1235 dxy = ((motion_fy & 1) << 1) | (motion_fx & 1);
1236 src_x = motion_fx >> 1;
1237 src_y = motion_fy >> 1;
1239 ptr = ref_data[0] + (src_y *
stride) + src_x;
1242 dxy = ((motion_by & 1) << 1) | (motion_bx & 1);
1243 src_x = motion_bx >> 1;
1244 src_y = motion_by >> 1;
1246 ptr = ref2_data[0] + (src_y *
stride) + src_x;
1250 fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->
mb_penalty_factor
1251 +(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->
mb_penalty_factor
1266 const int xy = mb_y *mot_stride + mb_x;
1278 const int shift= 1+qpel;
1283 #define HASH(fx,fy,bx,by) ((fx)+17*(fy)+63*(bx)+117*(by))
1284 #define HASH8(fx,fy,bx,by) ((uint8_t)HASH(fx,fy,bx,by))
1285 int hashidx=
HASH(motion_fx,motion_fy, motion_bx, motion_by);
1288 map[hashidx&255] = 1;
1291 motion_bx, motion_by,
1298 static const uint8_t limittab[5]={0,8,32,64,80};
1300 static const int8_t vect[][4]={
1301 { 0, 0, 0, 1}, { 0, 0, 0,-1}, { 0, 0, 1, 0}, { 0, 0,-1, 0}, { 0, 1, 0, 0}, { 0,-1, 0, 0}, { 1, 0, 0, 0}, {-1, 0, 0, 0},
1303 { 0, 0, 1, 1}, { 0, 0,-1,-1}, { 0, 1, 1, 0}, { 0,-1,-1, 0}, { 1, 1, 0, 0}, {-1,-1, 0, 0}, { 1, 0, 0, 1}, {-1, 0, 0,-1},
1304 { 0, 1, 0, 1}, { 0,-1, 0,-1}, { 1, 0, 1, 0}, {-1, 0,-1, 0},
1305 { 0, 0,-1, 1}, { 0, 0, 1,-1}, { 0,-1, 1, 0}, { 0, 1,-1, 0}, {-1, 1, 0, 0}, { 1,-1, 0, 0}, { 1, 0, 0,-1}, {-1, 0, 0, 1},
1306 { 0,-1, 0, 1}, { 0, 1, 0,-1}, {-1, 0, 1, 0}, { 1, 0,-1, 0},
1308 { 0, 1, 1, 1}, { 0,-1,-1,-1}, { 1, 1, 1, 0}, {-1,-1,-1, 0}, { 1, 1, 0, 1}, {-1,-1, 0,-1}, { 1, 0, 1, 1}, {-1, 0,-1,-1},
1309 { 0,-1, 1, 1}, { 0, 1,-1,-1}, {-1, 1, 1, 0}, { 1,-1,-1, 0}, { 1, 1, 0,-1}, {-1,-1, 0, 1}, { 1, 0,-1, 1}, {-1, 0, 1,-1},
1310 { 0, 1,-1, 1}, { 0,-1, 1,-1}, { 1,-1, 1, 0}, {-1, 1,-1, 0}, {-1, 1, 0, 1}, { 1,-1, 0,-1}, { 1, 0, 1,-1}, {-1, 0,-1, 1},
1311 { 0, 1, 1,-1}, { 0,-1,-1, 1}, { 1, 1,-1, 0}, {-1,-1, 1, 0}, { 1,-1, 0, 1}, {-1, 1, 0,-1}, {-1, 0, 1, 1}, { 1, 0,-1,-1},
1313 { 1, 1, 1, 1}, {-1,-1,-1,-1},
1314 { 1, 1, 1,-1}, {-1,-1,-1, 1}, { 1, 1,-1, 1}, {-1,-1, 1,-1}, { 1,-1, 1, 1}, {-1, 1,-1,-1}, {-1, 1, 1, 1}, { 1,-1,-1,-1},
1315 { 1, 1,-1,-1}, {-1,-1, 1, 1}, { 1,-1,-1, 1}, {-1, 1, 1,-1}, { 1,-1, 1,-1}, {-1, 1,-1, 1},
1318 HASH8( 0, 0, 0, 1),
HASH8( 0, 0, 0,-1),
HASH8( 0, 0, 1, 0),
HASH8( 0, 0,-1, 0),
HASH8( 0, 1, 0, 0),
HASH8( 0,-1, 0, 0),
HASH8( 1, 0, 0, 0),
HASH8(-1, 0, 0, 0),
1320 HASH8( 0, 0, 1, 1),
HASH8( 0, 0,-1,-1),
HASH8( 0, 1, 1, 0),
HASH8( 0,-1,-1, 0),
HASH8( 1, 1, 0, 0),
HASH8(-1,-1, 0, 0),
HASH8( 1, 0, 0, 1),
HASH8(-1, 0, 0,-1),
1321 HASH8( 0, 1, 0, 1),
HASH8( 0,-1, 0,-1),
HASH8( 1, 0, 1, 0),
HASH8(-1, 0,-1, 0),
1322 HASH8( 0, 0,-1, 1),
HASH8( 0, 0, 1,-1),
HASH8( 0,-1, 1, 0),
HASH8( 0, 1,-1, 0),
HASH8(-1, 1, 0, 0),
HASH8( 1,-1, 0, 0),
HASH8( 1, 0, 0,-1),
HASH8(-1, 0, 0, 1),
1323 HASH8( 0,-1, 0, 1),
HASH8( 0, 1, 0,-1),
HASH8(-1, 0, 1, 0),
HASH8( 1, 0,-1, 0),
1325 HASH8( 0, 1, 1, 1),
HASH8( 0,-1,-1,-1),
HASH8( 1, 1, 1, 0),
HASH8(-1,-1,-1, 0),
HASH8( 1, 1, 0, 1),
HASH8(-1,-1, 0,-1),
HASH8( 1, 0, 1, 1),
HASH8(-1, 0,-1,-1),
1326 HASH8( 0,-1, 1, 1),
HASH8( 0, 1,-1,-1),
HASH8(-1, 1, 1, 0),
HASH8( 1,-1,-1, 0),
HASH8( 1, 1, 0,-1),
HASH8(-1,-1, 0, 1),
HASH8( 1, 0,-1, 1),
HASH8(-1, 0, 1,-1),
1327 HASH8( 0, 1,-1, 1),
HASH8( 0,-1, 1,-1),
HASH8( 1,-1, 1, 0),
HASH8(-1, 1,-1, 0),
HASH8(-1, 1, 0, 1),
HASH8( 1,-1, 0,-1),
HASH8( 1, 0, 1,-1),
HASH8(-1, 0,-1, 1),
1328 HASH8( 0, 1, 1,-1),
HASH8( 0,-1,-1, 1),
HASH8( 1, 1,-1, 0),
HASH8(-1,-1, 1, 0),
HASH8( 1,-1, 0, 1),
HASH8(-1, 1, 0,-1),
HASH8(-1, 0, 1, 1),
HASH8( 1, 0,-1,-1),
1331 HASH8( 1, 1, 1,-1),
HASH8(-1,-1,-1, 1),
HASH8( 1, 1,-1, 1),
HASH8(-1,-1, 1,-1),
HASH8( 1,-1, 1, 1),
HASH8(-1, 1,-1,-1),
HASH8(-1, 1, 1, 1),
HASH8( 1,-1,-1,-1),
1332 HASH8( 1, 1,-1,-1),
HASH8(-1,-1, 1, 1),
HASH8( 1,-1,-1, 1),
HASH8(-1, 1, 1,-1),
HASH8( 1,-1, 1,-1),
HASH8(-1, 1,-1, 1),
1335 #define CHECK_BIDIR(fx,fy,bx,by)\
1336 if( !map[(hashidx+HASH(fx,fy,bx,by))&255]\
1337 &&(fx<=0 || motion_fx+fx<=xmax) && (fy<=0 || motion_fy+fy<=ymax) && (bx<=0 || motion_bx+bx<=xmax) && (by<=0 || motion_by+by<=ymax)\
1338 &&(fx>=0 || motion_fx+fx>=xmin) && (fy>=0 || motion_fy+fy>=ymin) && (bx>=0 || motion_bx+bx>=xmin) && (by>=0 || motion_by+by>=ymin)){\
1340 map[(hashidx+HASH(fx,fy,bx,by))&255] = 1;\
1341 score= check_bidir_mv(s, motion_fx+fx, motion_fy+fy, motion_bx+bx, motion_by+by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);\
1343 hashidx += HASH(fx,fy,bx,by);\
1352 #define CHECK_BIDIR2(a,b,c,d)\
1353 CHECK_BIDIR(a,b,c,d)\
1354 CHECK_BIDIR(-(a),-(b),-(c),-(d))
1366 for(i=8; i<limit; i++){
1367 int fx= motion_fx+vect[i][0];
1368 int fy= motion_fy+vect[i][1];
1369 int bx= motion_bx+vect[i][2];
1370 int by= motion_by+vect[i][3];
1372 int a= (xmax -
FFMAX(fx,bx))|(
FFMIN(fx,bx) - xmin);
1373 int b= (ymax -
FFMAX(fy,by))|(
FFMIN(fy,by) - ymin);
1375 map[(hashidx+hash[i])&255] = 1;
1377 if(!map[(hashidx+hash[i])&255]){
1379 map[(hashidx+hash[i])&255] = 1;
1380 score=
check_bidir_mv(s, fx, fy, bx, by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);
1393 borderdist=
FFMIN(a,b);
1414 const int mot_xy = mb_y*mot_stride + mb_x;
1417 const int time_pp= s->
pp_time;
1418 const int time_pb= s->
pb_time;
1419 int mx, my, xmin, xmax, ymin, ymax;
1423 ymin= xmin=(-32)>>shift;
1424 ymax= xmax= 31>>
shift;
1448 xmin=
FFMAX(xmin, - 16 - min);
1455 ymin=
FFMAX(ymin, - 16 - min);
1460 av_assert2(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);
1462 if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){
1466 return 256*256*256*64;
1478 P_LEFT[0] = av_clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift);
1479 P_LEFT[1] = av_clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);
1483 P_TOP[0] = av_clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift);
1484 P_TOP[1] = av_clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift);
1485 P_TOPRIGHT[0] = av_clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift);
1486 P_TOPRIGHT[1] = av_clip(mv_table[mot_xy - mot_stride + 1 ][1], ymin<<shift, ymax<<shift);
1503 mv_table[mot_xy][0]= mx;
1504 mv_table[mot_xy][1]= my;
1516 int fmin, bmin, dmin, fbmin, bimin, fimin;
1518 const int xy = mb_y*s->
mb_stride + mb_x;
1529 score= ((unsigned)(score*score + 128*256))>>16;
1553 av_dlog(s,
"%d %d %d %d\n", dmin, fmin, bmin, fbmin);
1567 fimin= bimin= INT_MAX;
1594 score= ((unsigned)(score*score + 128*256))>>16;
1605 if(fimin < INT_MAX && bimin < INT_MAX){
1626 int best_score=-10000000;
1629 range=
FFMIN(range, 16);
1631 range=
FFMIN(range, 256);
1633 for(i=0; i<8; i++) score[i]= s->
mb_num*(8-i);
1640 int mx= mv_table[xy][0];
1641 int my= mv_table[xy][1];
1646 if(mx >= range || mx < -range ||
1647 my >= range || my < -range)
1650 for(j=0; j<fcode && j<8; j++){
1660 if(score[i] > best_score){
1661 best_score= score[i];
1675 const int f_code= s->
f_code;
1681 av_assert0(range <= 16 || !s->msmpeg4_version);
1698 for(block=0; block<4; block++){
1699 int off= (block& 1) + (block>>1)*
wrap;
1703 if( mx >=range || mx <-range
1704 || my >=range || my <-range){
1705 s->
mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V;
1723 int16_t (*mv_table)[2],
int f_code,
int type,
int truncate)
1726 int y, h_range, v_range;
1734 v_range= field_select_table ? range>>1 : range;
1742 if (!field_select_table || field_select_table[xy] == field_select) {
1743 if( mv_table[xy][0] >=h_range || mv_table[xy][0] <-h_range
1744 || mv_table[xy][1] >=v_range || mv_table[xy][1] <-v_range){
1747 if (mv_table[xy][0] > h_range-1) mv_table[xy][0]= h_range-1;
1748 else if(mv_table[xy][0] < -h_range ) mv_table[xy][0]= -h_range;
1749 if (mv_table[xy][1] > v_range-1) mv_table[xy][1]= v_range-1;
1750 else if(mv_table[xy][1] < -v_range ) mv_table[xy][1]= -v_range;
uint8_t * scratchpad
data area for the ME algo, so that the ME does not need to malloc/free
static int minima_cmp(const void *a, const void *b)
static int cmp_qpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
static unsigned update_map_generation(MotionEstContext *c)
void ff_estimate_b_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
qpel_mc_func avg_qpel_pixels_tab[2][16]
#define CANDIDATE_MB_TYPE_SKIPPED
static int shift(int a, int b)
static av_always_inline void mv_scale(Mv *dst, Mv *src, int td, int tb)
static int epzs_motion_search2(MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale)
static int check_bidir_mv(MpegEncContext *s, int motion_fx, int motion_fy, int motion_bx, int motion_by, int pred_fx, int pred_fy, int pred_bx, int pred_by, int size, int h)
int skip
set if ME is skipped for the current MB
int16_t(* p_mv_table)[2]
MV table (1MV per MB) p-frame encoding.
static void get_limits(MpegEncContext *s, int x, int y)
get fullpel ME search limits.
uint8_t * fcode_tab
smallest fcode needed for each MV
void ff_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
uint8_t * mb_mean
Table for MB luminance.
op_pixels_func avg_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
static void init_mv4_ref(MotionEstContext *c)
qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16]
#define CANDIDATE_MB_TYPE_INTER_I
uint16_t * mb_var
Table for MB variances.
uint8_t * current_mv_penalty
int msmpeg4_version
0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
#define CANDIDATE_MB_TYPE_BIDIR
enhanced predictive zonal search
static int cmp_simple(MpegEncContext *s, const int x, const int y, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func)
int16_t(*[2][2] p_field_mv_table)[2]
MV table (2MV per MB) interlaced p-frame encoding.
static int bidir_refine(MpegEncContext *s, int mb_x, int mb_y)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
int mpv_flags
flags set by private options
int mb_num
number of MBs of a picture
me_cmp_func me_pre_cmp[6]
int16_t(* b_back_mv_table)[2]
MV table (1MV per MB) backward mode b-frame encoding.
#define CODEC_FLAG_QPEL
Use qpel MC.
static int cmp_internal(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
#define CANDIDATE_MB_TYPE_INTER
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int zero_cmp(MpegEncContext *s, uint8_t *a, uint8_t *b, ptrdiff_t stride, int h)
op_pixels_func(* hpel_put)[4]
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define CANDIDATE_MB_TYPE_INTER4V
enum OutputFormat out_format
output format
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
#define CANDIDATE_MB_TYPE_FORWARD_I
static av_cold int end(AVCodecContext *avctx)
int pre_dia_size
ME prepass diamond size & shape.
Motion estimation context.
qpel_mc_func(* qpel_put)[16]
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
#define CANDIDATE_MB_TYPE_BACKWARD_I
int me_cmp
motion estimation comparison function
Picture current_picture
copy of the current picture structure.
int16_t(* b_bidir_forw_mv_table)[2]
MV table (1MV per MB) bidir mode b-frame encoding.
uint8_t(* mv_penalty)[MAX_MV *2+1]
amount of bits needed to encode a MV
static int get_flags(MotionEstContext *c, int direct, int chroma)
uint16_t pp_time
time distance between the last 2 p,s,i frames
op_pixels_func(* hpel_avg)[4]
int ff_epzs_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale, int size, int h)
int mb_height
number of MBs horizontally & vertically
#define CHECK_BIDIR2(a, b, c, d)
no search, that is use 0,0 vector whenever one is needed
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int ff_h263_round_chroma(int x)
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
static const uint16_t mask[17]
static int epzs_motion_search4(MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale)
static int no_sub_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
int me_sub_cmp
subpixel motion estimation comparison function
static uint8_t fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need.
int unrestricted_mv
mv can point outside of the coded picture
static int get_penalty_factor(int lambda, int lambda2, int type)
#define FF_COMPLIANCE_NORMAL
static void init_interlaced_ref(MpegEncContext *s, int ref_index)
MpegvideoEncDSPContext mpvencdsp
int quarter_sample
1->qpel, 0->half pel ME/MC
uint16_t * mb_type
Table for candidate MB types for encoding (defines in mpegutils.h)
qpel_mc_func put_qpel_pixels_tab[2][16]
uint8_t *[2][2] b_field_select_table
static const uint8_t offset[127][2]
Libavcodec external API header.
Motion estimation template.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int me_method
ME algorithm.
static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
Picture new_picture
copy of the source picture structure for encoding.
static int hpel_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
int(* pix_sum)(uint8_t *pix, int line_size)
int16_t(*[2] motion_val)[2]
static int interlaced_search(MpegEncContext *s, int ref_index, int16_t(*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
int(* me_cmp_func)(struct MpegEncContext *c, uint8_t *blk1, uint8_t *blk2, ptrdiff_t stride, int h)
int mb_decision
macroblock decision mode
static int get_mb_score(MpegEncContext *s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
preferred ID for MPEG-1/2 video decoding
int block_index[6]
index to current MB in block based arrays with edges
static int qpel_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
int penalty_factor
an estimate of the bits required to code a given mv value, e.g.
static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y, int16_t(*mv_table)[2], int ref_index, int f_code)
#define HASH8(fx, fy, bx, by)
#define MV_TYPE_16X16
1 vector for the whole mb
int first_slice_line
used in mpeg4 too to handle resync markers
static struct AVHashContext * hash
uint16_t * mc_mb_var
Table for motion compensated MB variances.
#define AV_LOG_INFO
Standard information.
unsigned int lambda2
(lambda*lambda) >> FF_LAMBDA_SHIFT
ptrdiff_t linesize
line size, in bytes, may be different from width
static av_const unsigned int ff_sqrt(unsigned int a)
void ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
#define CHECK_SAD_HALF_MV(suffix, x, y)
int(* cmp_func)(const void *, const void *)
int height
picture size. must be a multiple of 16
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
static int direct_search(MpegEncContext *s, int mb_x, int mb_y)
void ff_fix_long_p_mvs(MpegEncContext *s)
op_pixels_func put_no_rnd_pixels_tab[4][4]
Halfpel motion compensation with no rounding (a+b)>>1.
int16_t(*[2][2][2] b_field_mv_table)[2]
MV table (4MV per MB) interlaced b-frame encoding.
int(* pix_norm1)(uint8_t *pix, int line_size)
#define CANDIDATE_MB_TYPE_DIRECT
static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel)
ptrdiff_t uvlinesize
line size, for chroma in bytes, may be different from width
#define CANDIDATE_MB_TYPE_BIDIR_I
int f_code
forward MV resolution
int ff_pre_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
#define CANDIDATE_MB_TYPE_DIRECT0
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
static void set_p_mv_tables(MpegEncContext *s, int mx, int my, int mv4)
static int sad_hpel_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
int16_t(* b_bidir_back_mv_table)[2]
MV table (1MV per MB) bidir mode b-frame encoding.
int ff_init_me(MpegEncContext *s)
uint8_t *[2] p_field_select_table
int16_t(* b_direct_mv_table)[2]
MV table (1MV per MB) direct mode b-frame encoding.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define av_builtin_constant_p
qpel_mc_func(* qpel_avg)[16]
#define FF_MB_DECISION_SIMPLE
uses mb_cmp
int64_t mc_mb_var_sum_temp
int16_t(* b_forw_mv_table)[2]
MV table (1MV per MB) forward mode b-frame encoding.
static void zero_hpel(uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h)
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
struct AVCodecContext * avctx
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
GLint GLenum GLboolean GLsizei stride
int mb_cmp
macroblock comparison function (not supported yet)
int direct_basis_mv[4][2]
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
#define CANDIDATE_MB_TYPE_FORWARD
Picture last_picture
copy of the previous picture structure.
int co_located_mv[4][2]
mv from last P-frame for direct mode ME
me_cmp_func me_sub_cmp[6]
uint32_t * map
map to avoid duplicate evaluations
static int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
#define CANDIDATE_MB_TYPE_INTRA
int dia_size
ME diamond size & shape.
static void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index)
static int cmp_hpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
int ff_get_best_fcode(MpegEncContext *s, int16_t(*mv_table)[2], int type)
Picture next_picture
copy of the next picture structure.
void ff_fix_long_mvs(MpegEncContext *s, uint8_t *field_select_table, int field_select, int16_t(*mv_table)[2], int f_code, int type, int truncate)
int flags
AVCodecContext.flags (HQ, MV4, ...)
uint32_t * mb_type
types and macros are defined in mpegutils.h
static av_always_inline int cmp_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel, int chroma)
#define CANDIDATE_MB_TYPE_BACKWARD
#define MV_TYPE_8X8
4 vectors (h263, mpeg4 4MV)
int b_code
backward MV resolution for B Frames (mpeg4)
#define CODEC_FLAG_4MV
4 MV per MB allowed / advanced prediction for H.263.
int me_pre_cmp
motion estimation prepass comparison function
int(* sub_motion_search)(struct MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
unsigned int lambda
lagrange multipler used in rate distortion
#define HASH(fx, fy, bx, by)
uint16_t pb_time
time distance between the last b and p,s,i frame