[MPlayer-dev-eng] [patch] lavc ME parameter handling cleanup & 2 little fixes

Rémi Guyomarch rguyom at pobox.com
Mon Apr 22 03:09:10 CEST 2002


Hi,

I'm cross-posting since this patch touch both mplayer and
libavcodec. Hope you don't mind ...

For libavcodec :
- move Motion_Est_QTab[] to mpegvideo.c, since there's no need to
  store it as many times as one include "avcodec.h" ;
- use symbolic names instead of numbers in this array.

For mplayer :
- use Motion_Est_QTab[] from libavcodec so that the "vme" parameter is
  now quality-oriented (0 = no ME, 1..5 = fastest to slowest, worst to
  best). IMHO it's way more intuitive than the previous ordering ;
- don't use 4MV with B frames as it's buggy right now.
- don't use 4MV in "-pass 1" since it's not supported by lavc
  (same problem as HQ mode). Symptoms : libavcodec refuse to allocate
  context in MPV_encode_init() and mencoder crash at the fist call to
  MPV_encode_picture().

PS: You are free to tell me that I'm on crack :-)

-- 
Rémi
-------------- next part --------------
Index: libmpcodecs/ve_lavc.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/ve_lavc.c,v
retrieving revision 1.11
diff -u -u -r1.11 ve_lavc.c
--- libmpcodecs/ve_lavc.c	21 Apr 2002 21:38:53 -0000	1.11
+++ libmpcodecs/ve_lavc.c	22 Apr 2002 01:13:54 -0000
@@ -142,6 +142,12 @@
     else
 	lavc_venc_context.flags = 0;
 
+    /* 4mv is currently buggy with B frames */
+    if (lavc_param_vmax_b_frames > 0 && lavc_param_v4mv) {
+        printf("4MV with B-Frames: 4MV disabled\n");
+        lavc_param_v4mv = 0;
+    }
+
     lavc_venc_context.flags|= lavc_param_v4mv ? CODEC_FLAG_4MV : 0;
 
     /* lavc internal 2pass bitrate control */
@@ -150,12 +156,8 @@
     else if(lavc_param_vpass==2)
         lavc_venc_context.flags|= CODEC_FLAG_PASS2;
 
-#ifdef ME_ZERO
-    // workaround Juanjo's stupid incompatible change:
-    motion_estimation_method = lavc_param_vme;
-#else
-    lavc_venc_context.me_method = ME_ZERO+lavc_param_vme;
-#endif
+    /* motion estimation algorithm */
+    lavc_venc_context.me_method = Motion_Est_QTab[lavc_param_vme];
 
     /* fixed qscale :p */
     if (lavc_param_vqscale)
@@ -171,7 +173,7 @@
 	    mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
 	    pass=0;
 	} else
-	    lavc_venc_context.flags &= ~CODEC_FLAG_HQ;
+	    lavc_venc_context.flags &= ~(CODEC_FLAG_HQ|CODEC_FLAG_4MV);
 	break;
     case 2:
         if (VbrControl_init_2pass_vbr_encoding(passtmpfile,
Index: DOCS/mencoder.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/mencoder.1,v
retrieving revision 1.36
diff -u -u -r1.36 mencoder.1
--- DOCS/mencoder.1	20 Apr 2002 06:40:47 -0000	1.36
+++ DOCS/mencoder.1	22 Apr 2002 01:13:55 -0000
@@ -203,6 +203,10 @@
                  (specify in frames)
   vhq            very high quality
   vme=XXX        motion estimation method
+                 0 = no motion estimation at all
+                 1 = fastest, worst ME algorithm
+                 5 = slowest, best ME algorithm
+                 (currently '5' is way too slow)
   vqmin=XXX      minimum quantizer
   vqmax=XXX      maximum quantizer
   vqdiff=XXX     quantizer difference. Limits the
Index: libavcodec/avcodec.h
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/avcodec.h,v
retrieving revision 1.33
diff -u -u -r1.33 avcodec.h
--- libavcodec/avcodec.h	21 Apr 2002 21:18:17 -0000	1.33
+++ libavcodec/avcodec.h	22 Apr 2002 01:07:39 -0000
@@ -75,7 +75,7 @@
 extern int motion_estimation_method;
 
 /* ME algos sorted by quality */
-static const int Motion_Est_QTab[] = { 1, 4, 3, 6, 5, 2 };
+extern const int Motion_Est_QTab[6];
 
 #define FF_MAX_B_FRAMES 4
 
Index: libavcodec/mpegvideo.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/mpegvideo.c,v
retrieving revision 1.78
diff -u -u -r1.78 mpegvideo.c
--- libavcodec/mpegvideo.c	21 Apr 2002 21:18:16 -0000	1.78
+++ libavcodec/mpegvideo.c	22 Apr 2002 01:07:43 -0000
@@ -77,6 +77,8 @@
 
 /* default motion estimation */
 int motion_estimation_method = ME_EPZS;
+/* motion estimation methods sorted by quality */
+const int Motion_Est_QTab[6] = { ME_ZERO, ME_PHODS, ME_LOG, ME_X1, ME_EPZS, ME_FULL };
 
 static void convert_matrix(int *qmat, UINT16 *qmat16, const UINT16 *quant_matrix, int qscale)
 {


More information about the MPlayer-dev-eng mailing list