diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2003-01-02 12:48:09 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2003-01-02 12:48:09 +0000 |
commit | f931ff7b9f535c122348b8569f2742cfbc480ccd (patch) | |
tree | 3c128e53d6655cec0123633207d9412e621402aa | |
parent | f5fb6b34fd1053d1fcb61e4f35de8fa8befb834b (diff) | |
download | ffmpeg-f931ff7b9f535c122348b8569f2742cfbc480ccd.tar.gz |
pre motion estimation cleanup/bugfix
Originally committed as revision 1390 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/motion_est.c | 31 | ||||
-rw-r--r-- | libavcodec/motion_est_template.c | 19 | ||||
-rw-r--r-- | libavcodec/mpegvideo.c | 4 | ||||
-rw-r--r-- | libavcodec/mpegvideo.h | 1 |
4 files changed, 30 insertions, 25 deletions
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 58128ea928..dcc31a4a1a 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -803,7 +803,7 @@ static inline int mv4_search(MpegEncContext *s, int xmin, int ymin, int xmax, in if(P_LEFT[0] > (rel_xmax4<<shift)) P_LEFT[0] = (rel_xmax4<<shift); /* special case for first line */ - if ((s->mb_y == 0 || s->first_slice_line) && block<2) { + if (s->mb_y == 0 && block<2) { pred_x4= P_LEFT[0]; pred_y4= P_LEFT[1]; } else { @@ -904,11 +904,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, if(P_LEFT[0] > (rel_xmax<<shift)) P_LEFT[0] = (rel_xmax<<shift); - /* special case for first line */ - if ((mb_y == 0 || s->first_slice_line)) { - pred_x= P_LEFT[0]; - pred_y= P_LEFT[1]; - } else { + if(mb_y) { P_TOP[0] = s->motion_val[mot_xy - mot_stride ][0]; P_TOP[1] = s->motion_val[mot_xy - mot_stride ][1]; P_TOPRIGHT[0] = s->motion_val[mot_xy - mot_stride + 2][0]; @@ -927,7 +923,11 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, pred_x= P_LEFT[0]; pred_y= P_LEFT[1]; } + }else{ + pred_x= P_LEFT[0]; + pred_y= P_LEFT[1]; } + } dmin = s->me.motion_search[0](s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty); @@ -1055,6 +1055,8 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s, if (mb_y == s->mb_height-1) { pred_x= P_LEFT[0]; pred_y= P_LEFT[1]; + P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]= + P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME } else { P_TOP[0] = s->p_mv_table[xy + mv_stride ][0]; P_TOP[1] = s->p_mv_table[xy + mv_stride ][1]; @@ -1067,17 +1069,12 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s, 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){ - pred_x = P_MEDIAN[0]; - pred_y = P_MEDIAN[1]; - }else { /* mpeg1 at least */ - pred_x= P_LEFT[0]; - pred_y= P_LEFT[1]; - } + pred_x = P_MEDIAN[0]; + pred_y = P_MEDIAN[1]; } dmin = s->me.motion_search[0](s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty); - + s->p_mv_table[xy][0] = mx<<shift; s->p_mv_table[xy][1] = my<<shift; @@ -1140,8 +1137,7 @@ int ff_estimate_motion_b(MpegEncContext * s, if(P_LEFT[0] > (rel_xmax<<shift)) P_LEFT[0] = (rel_xmax<<shift); /* special case for first line */ - if ((mb_y == 0 || s->first_slice_line)) { - } else { + if (mb_y) { P_TOP[0] = mv_table[mot_xy - mot_stride ][0]; P_TOP[1] = mv_table[mot_xy - mot_stride ][1]; P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0]; @@ -1332,8 +1328,7 @@ static inline int direct_search(MpegEncContext * s, P_LEFT[1] = clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift); /* special case for first line */ - if ((mb_y == 0 || s->first_slice_line)) { - } else { + if (mb_y) { P_TOP[0] = clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift); P_TOP[1] = clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift); P_TOPRIGHT[0] = clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift); diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c index f350986456..2325b166b5 100644 --- a/libavcodec/motion_est_template.c +++ b/libavcodec/motion_est_template.c @@ -835,7 +835,7 @@ static int RENAME(epzs_motion_search)(MpegEncContext * s, int block, score_map[0]= dmin; /* first line */ - if ((s->mb_y == 0 || s->first_slice_line)) { + if (s->mb_y == 0) { CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift) CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16) @@ -858,10 +858,17 @@ static int RENAME(epzs_motion_search)(MpegEncContext * s, int block, } } if(dmin>256*4){ - CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, - (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16) - CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, - (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) + if(s->me.pre_pass){ + CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16, + (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16) + CHECK_CLIPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, + (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) + }else{ + CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, + (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16) + CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, + (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) + } } if(s->avctx->last_predictor_count){ @@ -938,7 +945,7 @@ static int RENAME(epzs_motion_search4)(MpegEncContext * s, int block, dmin = 1000000; //printf("%d %d %d %d //",xmin, ymin, xmax, ymax); /* first line */ - if ((s->mb_y == 0 || s->first_slice_line) && block<2) { + if (s->mb_y == 0 && block<2) { CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift) CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index f773d9f306..fec95f4ca1 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -2789,9 +2789,10 @@ static void encode_picture(MpegEncContext *s, int picture_number) /* Estimate motion for every MB */ if(s->pict_type != I_TYPE){ - if(s->pict_type != B_TYPE){ if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){ + s->me.pre_pass=1; + for(mb_y=s->mb_height-1; mb_y >=0 ; mb_y--) { for(mb_x=s->mb_width-1; mb_x >=0 ; mb_x--) { s->mb_x = mb_x; @@ -2799,6 +2800,7 @@ static void encode_picture(MpegEncContext *s, int picture_number) ff_pre_estimate_p_frame_motion(s, mb_x, mb_y); } } + s->me.pre_pass=0; } } diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 1356e75c60..983e42dce5 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -141,6 +141,7 @@ typedef struct MotionEstContext{ int map_generation; int penalty_factor; int sub_penalty_factor; + int pre_pass; /* = 1 for the pre pass */ UINT16 (*mv_penalty)[MAX_MV*2+1]; /* amount of bits needed to encode a MV */ int (*sub_motion_search)(struct MpegEncContext * s, int *mx_ptr, int *my_ptr, int dmin, |