[MPlayer-dev-eng] [PATCH] ve_xvid bug fixes, cleanup & enhancements

Rémi Guyomarch rguyom at pobox.com
Sat Nov 2 16:28:01 CET 2002


1) It seems the CONF_TYPE_SUBCONFIG array for the "mode" option eats
   all other -xvidencopts parameters. With it it wasn't possible to
   set the bitrate or in fact any other parameter beside "mode".

2) xvidenc_param declared static, no need to pollute the name space.
   It will be probably nicer to convert to a set of static variables
   like in ve_lavc.c (easier to initialize) but I will do it in
   another patch if needed.

3) xvidencopts_conf wasn't properly initialised for some of the
   lines. Probably didn't cause bugs but at least this patch shaves a
   few gcc warnings.

4) Added "lumi_mask" & "mpeg_quant" options.

5) Changed the interpretation of "br" to be consistent with lavc (now
   in kbits/s if <16000, else bits/s). Should be backward compatible.

6) Patched mplayer.1 too.



--- libmpcodecs/ve_xvid.c	21 Sep 2002 13:09:57 -0000	1.2
+++ libmpcodecs/ve_xvid.c	2 Nov 2002 15:15:11 -0000
@@ -46,7 +46,7 @@
 	XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
 };
 
-struct {
+static struct {
     int quality;
     int bitrate;
     int rc_reaction_delay_factor;
@@ -55,10 +55,13 @@
     int max_quantizer;
     int min_quantizer;
     int max_key_interval;
+    char *mode_string;
     enum {
 	XVID_MODE_CBR = 0, XVID_MODE_2PASS_1, XVID_MODE_2PASS_2, XVID_MODE_FIXED_QUANT,
 	XVID_MODE_UNSPEC = -1
     } mode;
+    int mpeg_quant;
+    int lumi_mask;
     int debug;
     char *stats_file;;
     int keyframe_boost;
@@ -68,41 +71,34 @@
     int fixed_quant;
 } xvidenc_param = {
     sizeof(divx4_motion_presets) / sizeof(divx4_motion_presets[0]) - 1, /* quality */
-    0, 0, 0, 0, 0, 0, 0,
-    XVID_MODE_CBR,
-    1,				/* debug */
-    NULL,			/* stats_file */
+    0,			/* bitrate */
+    0, 0, 0,		/* rc_reaction_delay_factor, rc_averaging_period, rc_buffer */
+    0, 0,		/* max_quantizer, min_quantizer */
+    0,			/* max_key_interval */
+    "cbr",		/* mode_string */
+    XVID_MODE_CBR,	/* mode */
+    0,			/* mpeg_quant */
+    0,			/* lumi_mask */
+    1,			/* debug */
+    NULL,		/* stats_file */
     -1, -1, -1,		/* keyframe_boost, kfthreshold, kfreduction */
-    -1,				/* min_key_interval */
-    -1,				/* fixed_quant */
-};
-
-static struct config mode_conf[] = {
-    /* cbr, vbrqual, vbrquant, 2pass-1, 2pass-2-int, 2pass-2-ext */
-    { "cbr", &xvidenc_param.mode, CONF_TYPE_FLAG, 0, 0, XVID_MODE_CBR, NULL},
-    { "fixedquant", &xvidenc_param.mode, CONF_TYPE_FLAG, 0, 0, XVID_MODE_FIXED_QUANT, NULL},
-    { "2pass-1", &xvidenc_param.mode, CONF_TYPE_FLAG, 0, 0, XVID_MODE_2PASS_1, NULL},
-    { "2pass-2", &xvidenc_param.mode, CONF_TYPE_FLAG, 0, 0, XVID_MODE_2PASS_2, NULL},
-    { "help", "\nAvailable modes: \n"
-      "    cbr         - Constant Bit Rate\n"
-      "    2pass-1     - First pass of two pass mode\n"
-      "    2pass-2     - Second pass of two pass mode\n"
-      "    fixedquant  - Fixed quantizer mode\n"
-      "\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-    { NULL, NULL, 0, 0, 0, 0, NULL}
+    -1,			/* min_key_interval */
+    -1,			/* fixed_quant */
 };
 
 struct config xvidencopts_conf[] = {
-    { "mode", mode_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
+    { "mode", &xvidenc_param.mode_string, CONF_TYPE_STRING, 0, 0, 0, NULL},
     { "quality", &xvidenc_param.quality, CONF_TYPE_INT, CONF_RANGE, 0,
       sizeof(divx4_motion_presets) / sizeof(divx4_motion_presets[0]) - 1, NULL},
-    { "br", &xvidenc_param.bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
-    { "rc_reaction_delay_factor", &xvidenc_param.rc_reaction_delay_factor, CONF_TYPE_INT, 0, 0, NULL},
-    { "rc_averaging_period", &xvidenc_param.rc_averaging_period, CONF_TYPE_INT, 0, 0, NULL},
-    { "rc_buffer", &xvidenc_param.rc_buffer, CONF_TYPE_INT, 0, 0, NULL},
-    { "max_quantizer", &xvidenc_param.max_quantizer, CONF_TYPE_INT, 0, 0, NULL},
-    { "min_quantizer", &xvidenc_param.max_quantizer, CONF_TYPE_INT, 0, 0, NULL},
-    { "max_key_interval", &xvidenc_param.max_key_interval, CONF_TYPE_INT, 0, 0, NULL},
+    { "br", &xvidenc_param.bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
+    { "rc_reaction_delay_factor", &xvidenc_param.rc_reaction_delay_factor, CONF_TYPE_INT, 0, 0, 0, NULL},
+    { "rc_averaging_period", &xvidenc_param.rc_averaging_period, CONF_TYPE_INT, 0, 0, 0, NULL},
+    { "rc_buffer", &xvidenc_param.rc_buffer, CONF_TYPE_INT, 0, 0, 0, NULL},
+    { "max_quantizer", &xvidenc_param.max_quantizer, CONF_TYPE_INT, 0, 0, 0, NULL},
+    { "min_quantizer", &xvidenc_param.max_quantizer, CONF_TYPE_INT, 0, 0, 0, NULL},
+    { "max_key_interval", &xvidenc_param.max_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL},
+    { "mpeg_quant", &xvidenc_param.mpeg_quant, CONF_TYPE_FLAG, 0, 0, 0, NULL},
+    { "lumi_mask", &xvidenc_param.lumi_mask, CONF_TYPE_FLAG, 0, 0, 0, NULL},
     { "nodebug", &xvidenc_param.debug, CONF_TYPE_FLAG, 0, 0, 0, NULL},
     { "debug", &xvidenc_param.debug, CONF_TYPE_FLAG, 0, 0, 1, NULL},
     { "statsfile", &xvidenc_param.stats_file, CONF_TYPE_STRING, 0, 0, 0, NULL},	/* for XVID_MODE_2PASS_1/22 */
@@ -111,6 +107,12 @@
     { "kfreduction", &xvidenc_param.kfreduction, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
     { "min_key_interval", &xvidenc_param.max_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
     { "fixed_quant", &xvidenc_param.fixed_quant, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, /* for XVID_MODE_FIXED_QUANT */
+    { "help", "\nAvailable modes: \n"
+      "    cbr         - Constant Bit Rate\n"
+      "    2pass-1     - First pass of two pass mode\n"
+      "    2pass-2     - Second pass of two pass mode\n"
+      "    fixedquant  - Fixed quantizer mode\n"
+      "\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
     { NULL, NULL, 0, 0, 0, 0, NULL}
 };
 
@@ -145,6 +147,15 @@
     vf->priv->mux->bih->biSizeImage = vf->priv->mux->bih->biWidth * vf->priv->mux->bih->biHeight * 3;
 
     memset(&enc_param, 0, sizeof(enc_param));
+    if( !strcasecmp( xvidenc_param.mode_string, "cbr" ) )
+	xvidenc_param.mode = XVID_MODE_CBR;
+    else if( !strcasecmp( xvidenc_param.mode_string, "fixedquant" ) )
+	xvidenc_param.mode = XVID_MODE_FIXED_QUANT;
+    else if( !strcasecmp( xvidenc_param.mode_string, "2pass-1" ) )
+	xvidenc_param.mode = XVID_MODE_2PASS_1;
+    else if( !strcasecmp( xvidenc_param.mode_string, "2pass-2" ) )
+	xvidenc_param.mode = XVID_MODE_2PASS_2;
+ 
     enc_param.width = width;
     enc_param.height = height;
     enc_param.fincr = vf->priv->mux->h.dwScale;
@@ -171,6 +182,13 @@
 
     vf->priv->enc_frame.general = divx4_general_presets[xvidenc_param.quality];
     vf->priv->enc_frame.motion = divx4_motion_presets[xvidenc_param.quality];
+    if (xvidenc_param.mpeg_quant) {
+	vf->priv->enc_frame.general &= ~XVID_H263QUANT;
+	vf->priv->enc_frame.general |= XVID_MPEGQUANT;
+    }
+    if (xvidenc_param.lumi_mask)
+	vf->priv->enc_frame.general |= XVID_LUMIMASKING;
+
     switch (outfmt) {
     case IMGFMT_YV12:
 	vf->priv->enc_frame.colorspace = XVID_CSP_YV12;
@@ -200,8 +218,10 @@
     vf->priv->vbr_state.fps = (double)enc_param.fbase / enc_param.fincr;
     if (xvidenc_param.stats_file)
 	vf->priv->vbr_state.filename = xvidenc_param.stats_file;
-    if (xvidenc_param.bitrate)
+    if (xvidenc_param.bitrate > 16000)
 	vf->priv->vbr_state.desired_bitrate = xvidenc_param.bitrate;
+    else if (xvidenc_param.bitrate > 0)
+	vf->priv->vbr_state.desired_bitrate = xvidenc_param.bitrate * 1000;
     if (xvidenc_param.keyframe_boost)
 	vf->priv->vbr_state.keyframe_boost = xvidenc_param.keyframe_boost;
     if (xvidenc_param.kfthreshold)
--- DOCS/mplayer.1	2 Nov 2002 05:42:11 -0000	1.258
+++ DOCS/mplayer.1	2 Nov 2002 15:26:46 -0000
@@ -2353,8 +2353,6 @@
 .IPs mode=<mode>
 specify the mode to be used for encoding
 .RSss
-help: show this help
-.br
 cbr: constant bit rate (default)
 .br
 2pass-1: first pass of two pass mode
@@ -2366,7 +2364,7 @@
 .IPs quality=<0\-6>
 specify the encoding quality
 .IPs br=<value>
-sets the bitrate to be used in bits/\:seconds
+sets the bitrate to be used in kbits/\:second (<16000) or in bits/\:second (>16000)
 .IPs rc_reaction_delay_factor=<value>
 specify how fast the rate control reacts, lower values are faster
 .IPs rc_averaging_period=<value>
@@ -2381,6 +2379,10 @@
 minimum interval between key frames (2pass only)
 .IPs max_key_interval=<value>
 maximum interval between key frames
+.IPs mpeg_quant
+use MPEG quantizers instead of H.263
+.IPs lumi_mask
+use a lumimasking algorithm
 .IPs (no)debug
 save or don't save debug messages in xvid.dbg (default: on)
 .IPs statsfile=<filename>


-- 
Rémi



More information about the MPlayer-dev-eng mailing list