CVS: ffmpeg/libavcodec motion_est.c, 1.113, 1.114 avcodec.h, 1.434, 1.435 utils.c, 1.165, 1.166
Update of /cvsroot/ffmpeg/ffmpeg/libavcodec In directory mail:/var2/tmp/cvs-serv7780 Modified Files: motion_est.c avcodec.h utils.c Log Message: bidir refine support Index: motion_est.c =================================================================== RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/motion_est.c,v retrieving revision 1.113 retrieving revision 1.114 diff -u -d -r1.113 -r1.114 --- motion_est.c 23 Dec 2005 00:40:52 -0000 1.113 +++ motion_est.c 23 Dec 2005 16:25:00 -0000 1.114 @@ -1617,6 +1617,7 @@ /* refine the bidir vectors in hq mode and return the score in both lq & hq mode*/ static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y) { + MotionEstContext * const c= &s->me; const int mot_stride = s->mb_stride; const int xy = mb_y *mot_stride + mb_x; int fbmin; @@ -1628,8 +1629,13 @@ int motion_fy= s->b_bidir_forw_mv_table[xy][1]= s->b_forw_mv_table[xy][1]; int motion_bx= s->b_bidir_back_mv_table[xy][0]= s->b_back_mv_table[xy][0]; int motion_by= s->b_bidir_back_mv_table[xy][1]= s->b_back_mv_table[xy][1]; - - //FIXME do refinement and add flag + const int flags= c->sub_flags; + const int qpel= flags&FLAG_QPEL; + const int shift= 1+qpel; + const int xmin= c->xmin<<shift; + const int ymin= c->ymin<<shift; + const int xmax= c->xmax<<shift; + const int ymax= c->ymax<<shift; fbmin= check_bidir_mv(s, motion_fx, motion_fy, motion_bx, motion_by, @@ -1637,7 +1643,61 @@ pred_bx, pred_by, 0, 16); - return fbmin; + if(s->avctx->bidir_refine){ + int score, end; +#define CHECK_BIDIR(fx,fy,bx,by)\ + 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);\ + if(score < fbmin){\ + fbmin= score;\ + motion_fx+=fx;\ + motion_fy+=fy;\ + motion_bx+=bx;\ + motion_by+=by;\ + end=0;\ + } +#define CHECK_BIDIR2(a,b,c,d)\ +CHECK_BIDIR(a,b,c,d)\ +CHECK_BIDIR(-a,-b,-c,-d) + +#define CHECK_BIDIRR(a,b,c,d)\ +CHECK_BIDIR2(a,b,c,d)\ +CHECK_BIDIR2(b,c,d,a)\ +CHECK_BIDIR2(c,d,a,b)\ +CHECK_BIDIR2(d,a,b,c) + + do{ + end=1; + + if( motion_fx >= xmax || motion_bx >= xmax || motion_fx <= xmin || motion_bx <= xmin + || motion_fy >= ymax || motion_by >= ymax || motion_fy <= ymin || motion_by <= ymin) + break; + + CHECK_BIDIRR( 0, 0, 0, 1) + if(s->avctx->bidir_refine > 1){ + CHECK_BIDIRR( 0, 0, 1, 1) + CHECK_BIDIR2( 0, 1, 0, 1) + CHECK_BIDIR2( 1, 0, 1, 0) + CHECK_BIDIRR( 0, 0,-1, 1) + CHECK_BIDIR2( 0,-1, 0, 1) + CHECK_BIDIR2(-1, 0, 1, 0) + if(s->avctx->bidir_refine > 2){ + CHECK_BIDIRR( 0, 1, 1, 1) + CHECK_BIDIRR( 0,-1, 1, 1) + CHECK_BIDIRR( 0, 1,-1, 1) + CHECK_BIDIRR( 0, 1, 1,-1) + if(s->avctx->bidir_refine > 3){ + CHECK_BIDIR2( 1, 1, 1, 1) + CHECK_BIDIRR( 1, 1, 1,-1) + CHECK_BIDIR2( 1, 1,-1,-1) + CHECK_BIDIR2( 1,-1,-1, 1) + CHECK_BIDIR2( 1,-1, 1,-1) + } + } + } + }while(!end); + } + + return fbmin; } static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y) Index: avcodec.h =================================================================== RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/avcodec.h,v retrieving revision 1.434 retrieving revision 1.435 diff -u -d -r1.434 -r1.435 --- avcodec.h 22 Dec 2005 01:10:06 -0000 1.434 +++ avcodec.h 23 Dec 2005 16:25:00 -0000 1.435 @@ -1862,6 +1862,13 @@ * - decoding: set by user. */ enum AVDiscard skip_frame; + + /** + * + * - encoding: set by user. + * - decoding: unused + */ + int bidir_refine; } AVCodecContext; /** Index: utils.c =================================================================== RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/utils.c,v retrieving revision 1.165 retrieving revision 1.166 diff -u -d -r1.165 -r1.166 --- utils.c 22 Dec 2005 01:10:09 -0000 1.165 +++ utils.c 23 Dec 2005 16:25:00 -0000 1.166 @@ -707,6 +707,7 @@ {"mb_lmin", NULL, OFFSET(mb_lmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"mb_lmax", NULL, OFFSET(mb_lmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"me_penalty_compensation", NULL, OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +{"bidir_refine", NULL, OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 0, 4, V|E}, {NULL}, };
Michael Niedermayer CVS wrote:
Update of /cvsroot/ffmpeg/ffmpeg/libavcodec In directory mail:/var2/tmp/cvs-serv7780
Modified Files: motion_est.c avcodec.h utils.c Log Message: bidir refine support
I tested this on The Matrix. MEncoder dev-CVS-060127-12:25-4.0.3 (C) 2000-2006 MPlayer Team for i in 1:turbo:vb_strategy=2 2 ; do mencoder matrix.vob -aid 128 -oac copy -vf \ crop=718:356:0:60,scale=640:272 -sws 9 -ovc lavc -lavcopts \ vcodec=mpeg4:vbitrate=581:psnr:vpass=$i:mbd=2:mv0:trell:cbp:\ precmp=2:cmp=2:subcmp=2:predia=2:dia=2:preme=2:vme=5:v4mv:\ last_pred=2:vqcomp=0.6:qpel:sc_factor=6 -ofps 24000/1001 -o test.avi done ...with the following values of bidir_refine bidir_refine=0 (default; disabled) pass 1: PSNR: Y:40.24, Cb:44.40, Cr:44.73, All:41.26 user 122m21.705s pass 2: PSNR: Y:42.18, Cb:45.16, Cr:45.86, All:43.03 user 180m3.776s frame counts: I: 3346 1% P: 81506 41% B: 111214 56% average qps: I: 3.053796 P: 3.132776 B: 4.977988 bidir_refine=1 pass 1: PSNR: Y:40.29, Cb:44.40, Cr:44.73, All:41.30 user 135m18.301s pass 2: PSNR: Y:42.19, Cb:45.16, Cr:45.86, All:43.04 user 204m10.938s frame counts: I: 3342 1% P: 81721 41% B: 111003 56% average qps: I: 3.057151 P: 3.127691 B: 4.965487 bidir_refine=2 pass 1: PSNR: Y:40.31, Cb:44.40, Cr:44.74, All:41.32 user 155m4.897s pass 2: PSNR: Y:42.20, Cb:45.16, Cr:45.85, All:43.05 user 254m6.514s frame counts: I: 3347 1% P: 81827 41% B: 110892 56% average qps: I: 3.053182 P: 3.128210 B: 4.957472 bidir_refine=3 pass 1: PSNR: Y:40.32, Cb:44.41, Cr:44.75, All:41.33 user 178m7.467s pass 2: PSNR: Y:42.21, Cb:45.17, Cr:45.87, All:43.05 user 317m59.722s frame counts: I: 3341 1% P: 81902 41% B: 110823 56% average qps: I: 3.044897 P: 3.126871 B: 4.958971 bidir_refine=4 pass 1: PSNR: Y:40.32, Cb:44.41, Cr:44.75, All:41.33 user 189m9.897s pass 2: PSNR: Y:42.21, Cb:45.17, Cr:45.87, All:43.06 user 350m32.745s frame counts: I: 3352 1% P: 81893 41% B: 110821 56% average qps: I: 3.041766 P: 3.131232 B: 4.957283 The actual quality effect is hard to discern. There was a definite change -- some frames (or parts of frames) I looked at were slightly better-looking, and some were slightly worse. Overall, there isn't really much difference, though. If encoding time is not an issue (at all), then I'd say using bidir_refine=4 is good simply because the PSNR is better. Otherwise, it's probably not worth it. -Corey
On Sun, 5 Feb 2006, Corey Hickey wrote:
Michael Niedermayer CVS wrote:
Update of /cvsroot/ffmpeg/ffmpeg/libavcodec In directory mail:/var2/tmp/cvs-serv7780
Modified Files: motion_est.c avcodec.h utils.c Log Message: bidir refine support
[...]
fyi: bidir_refine didn't really work with this revision, try with 1.118 --Loren Merritt
Loren Merritt wrote:
Update of /cvsroot/ffmpeg/ffmpeg/libavcodec In directory mail:/var2/tmp/cvs-serv7780
Modified Files: motion_est.c avcodec.h utils.c Log Message: bidir refine support
[...]
fyi: bidir_refine didn't really work with this revision, try with 1.118
Thanks for the pointer. My build is from 2006-01-27, though, and it looks like your 1.118 commit to motion_est.c was on 2006-01-08. I don't see any relevant changes since then, so the results I posted should be fine. -Corey
participants (3)
-
bugfood-ml@fatooh.org -
lorenm@u.washington.edu -
michael@mplayerhq.hu