[MPlayer-dev-eng] Re: xvid patch

Marco "elcabesa" Belli elcabesa at inwind.it
Sat Dec 14 17:27:53 CET 2002


before the 2 diff a question.
Is possible to send params to decoder like to the encoder? this mena can i set 
at runtime some flag ofr xvid decoder??


these are the diff for
vd_xvid.c

--- main/libmpcodecs/vd_xvid.c	2002-08-30 23:44:20.000000000 +0200
+++ MPlayer-0.90rc1/libmpcodecs/vd_xvid.c	2002-12-14 14:48:14.000000000 +0100
@@ -165,6 +165,10 @@

   dec.bitstream = data;
   dec.length = len;
+  dec.general |= XVID_DEC_LOWDELAY;
+  dec.general |= XVID_DEC_DEBLOCKY;
+  dec.general |= XVID_DEC_DEBLOCKUV;
+
   switch(p->cs) {
   case XVID_CSP_USER:
     dec.image = &d4_pic;

and ve_xvid.c

--- main/libmpcodecs/ve_xvid.c	2002-11-22 09:19:08.000000000 +0100
+++ MPlayer-0.90rc1/libmpcodecs/ve_xvid.c	2002-12-14 14:21:12.000000000 +0100
@@ -25,19 +25,17 @@
 #include "cfgparser.h"

 /**********************************************************************/
-/* Divx4 quality to XviD encoder motion flag presets */
 static int const divx4_motion_presets[7] = {
         0,
 	PMV_QUICKSTOP16,
-	PMV_EARLYSTOP16,
-	PMV_EARLYSTOP16 | PMV_EARLYSTOP8,
-        PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | 
PMV_HALFPELDIAMOND8,
-        PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | 
PMV_HALFPELDIAMOND8 | PMV_ADVANCEDDIAMOND16,
-	PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 | 
PMV_HALFPELREFINE8 |
+	PMV_EXTSEARCH16,
+	PMV_EXTSEARCH16 | PMV_EXTSEARCH8,
+        PMV_EXTSEARCH16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH8 | 
PMV_HALFPELDIAMOND8,
+        PMV_EXTSEARCH16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH8 | 
PMV_HALFPELDIAMOND8 | PMV_ADVANCEDDIAMOND16,
+	PMV_EXTSEARCH16 | PMV_QUARTERPELREFINE16 | PMV_EXTSEARCH16 | PMV_EXTSEARCH8 
| PMV_QUARTERPELREFINE8 |
 	PMV_HALFPELDIAMOND8 | PMV_USESQUARES16
 
 };
-
 /* Divx4 quality to general encoder flag presets */
 static int const divx4_general_presets[7] = {
 	0,
@@ -48,7 +46,6 @@
 	XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
 	XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
 };
-
 extern char* passtmpfile;
 extern void mencoder_write_chunk(aviwrite_stream_t *s,int len,unsigned int 
flags);
 
@@ -58,19 +55,24 @@
 static int xvidenc_rc_reaction_delay_factor = -1;
 static int xvidenc_rc_averaging_period = -1;
 static int xvidenc_rc_buffer = -1;
-static char* xvidenc_quant_range = "2-31/2-31";
-static int xvidenc_min_key_interval = -1;
+static int xvidenc_min_quantizer = 1;
+static int xvidenc_max_quantizer = -1;
+static int xvidenc_min_key_interval = 0;
 static int xvidenc_max_key_interval = -1;
+static int xvidenc_max_bframes=-1;
+static int xvidenc_bquant_ratio=200;
 static int xvidenc_mpeg_quant = 0;
-static int xvidenc_mod_quant = 0;
 static int xvidenc_lumi_mask = 0;
-static int xvidenc_keyframe_boost = -1;
-static int xvidenc_kfthreshold = -1;
-static int xvidenc_kfreduction = -1;
+static int xvidenc_keyframe_boost = 0;
+static int xvidenc_kfthreshold = 0;
+static int xvidenc_kfreduction = 0;
 static int xvidenc_fixed_quant = 0;
 static int xvidenc_debug = 0;
 static int xvidenc_hintedme = 0;
 static char* xvidenc_hintfile = "xvid_hint_me.dat";
+static int xvidenc_gmc = 0;
+static int xvidenc_me_colour=0;
+static int xvid_reduced=0;

 struct config xvidencopts_conf[] = {
     { "pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
@@ -80,15 +82,20 @@
     { "rc_reaction_delay_factor", &xvidenc_rc_reaction_delay_factor, 
CONF_TYPE_INT, 0, 0, 0, NULL},
     { "rc_averaging_period", &xvidenc_rc_averaging_period, CONF_TYPE_INT, 0, 
0, 0, NULL},
     { "rc_buffer", &xvidenc_rc_buffer, CONF_TYPE_INT, 0, 0, 0, NULL},
-    { "quant_range", &xvidenc_quant_range, CONF_TYPE_STRING, 0, 0, 0, NULL},
+    { "min_quantizer", &xvidenc_min_quantizer, CONF_TYPE_INT, CONF_RANGE, 1, 
31, NULL},
+    { "max_quantizer", &xvidenc_max_quantizer, CONF_TYPE_INT, CONF_RANGE, 1, 
31, NULL},
     { "min_key_interval", &xvidenc_min_key_interval, CONF_TYPE_INT, 0, 0, 0, 
NULL}, /* for XVID_MODE_2PASS_2 */
     { "max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, 0, 0, 0, 
NULL},
+    { "max_bframe", &xvidenc_max_bframes, CONF_TYPE_INT, 0, 0, 0, NULL}, /* 
for xvid B_frame */
+    { "bquant_ratio", &xvidenc_bquant_ratio, CONF_TYPE_INT, 0, 0, 0, NULL}, 
/* for Xvid Bframe compression ratio */
     { "mpeg_quant", &xvidenc_mpeg_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL},
-    { "mod_quant", &xvidenc_mod_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL},
     { "lumi_mask", &xvidenc_lumi_mask, CONF_TYPE_FLAG, 0, 0, 1, NULL},
-    { "keyframe_boost", &xvidenc_keyframe_boost, CONF_TYPE_INT, CONF_RANGE, 
0, 1000, NULL}, /* for XVID_MODE_2PASS_2 */
+    { "reduced", &xvid_reduced, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+    { "gmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+    { "me_colour", &xvidenc_me_colour, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+    { "keyframe_boost", &xvidenc_keyframe_boost, CONF_TYPE_INT, 0, 0, 0, 
NULL}, /* for XVID_MODE_2PASS_2 */
     { "kfthreshold", &xvidenc_kfthreshold, CONF_TYPE_INT, 0, 0, 0, NULL}, /* 
for XVID_MODE_2PASS_2 */
-    { "kfreduction", &xvidenc_kfreduction, CONF_TYPE_INT, CONF_RANGE, 0, 100, 
NULL}, /* for XVID_MODE_2PASS_2 */
+    { "kfreduction", &xvidenc_kfreduction, CONF_TYPE_INT, 0, 0, 0, NULL}, /* 
for XVID_MODE_2PASS_2 */
     { "fixed_quant", &xvidenc_fixed_quant, CONF_TYPE_INT, CONF_RANGE, 1, 31, 
NULL}, /* for XVID_MODE_FIXED_QUANT */
     { "debug", &xvidenc_debug, CONF_TYPE_FLAG, 0, 0, 1, NULL},
     { "hintedme", &xvidenc_hintedme, CONF_TYPE_FLAG, 0, 0, 1, NULL},
@@ -112,7 +119,6 @@
 {
     XVID_ENC_PARAM enc_param;
     struct vf_priv_s *fp = vf->priv;
-    unsigned int min_iq, max_iq, min_pq, max_pq;

     fp->mux->bih->biWidth = width;
     fp->mux->bih->biHeight = height;
@@ -120,21 +126,6 @@
     mp_msg(MSGT_MENCODER,MSGL_INFO,"videocodec: XViD (%dx%d fourcc=%x 
[%.4s])\n",
 	width, height, fp->mux->bih->biCompression, (char 
*)&fp->mux->bih->biCompression);

-    // {min,max}_{i,p}quantizer parsing & validation
-    if (sscanf (xvidenc_quant_range, "%u-%u/%u-%u", &min_iq, &max_iq, 
&min_pq, &max_pq) < 4) {
-	mp_msg (MSGT_MENCODER, MSGL_ERR, 
-		"xvid: ERROR: cannot parse \"quant_range=%s\"\n", xvidenc_quant_range);
-	return 0;
-    }
-    if (min_iq < 1 || min_iq > 31 || max_iq < 1 || max_iq > 31 || min_iq > 
max_iq ||
-	min_pq < 1 || min_pq > 31 || max_pq < 1 || max_pq > 31 || min_pq > max_pq) {
-	mp_msg (MSGT_MENCODER, MSGL_ERR,
-		"xvid: ERROR: {min,max} {I,P} quantizer must be in [1,31] and min must be 
<= max.\n");
-	mp_msg (MSGT_MENCODER, MSGL_ERR,
-		"xvid: ERROR: cannot use \"quant_range=%s\"\n", xvidenc_quant_range);
-	return -1;
-    }
-
     // initialize XViD core parameters
     // ===============================
     memset(&enc_param, 0, sizeof(enc_param));
@@ -151,11 +142,20 @@
     enc_param.rc_reaction_delay_factor = xvidenc_rc_reaction_delay_factor;
     enc_param.rc_averaging_period = xvidenc_rc_averaging_period;
     enc_param.rc_buffer = xvidenc_rc_buffer;
-    enc_param.min_quantizer = min_iq;
-    enc_param.max_quantizer = max_iq;
-    if( xvidenc_max_key_interval <= 0 )
-	xvidenc_max_key_interval = 10 * enc_param.fbase / enc_param.fincr;
-    enc_param.max_key_interval = xvidenc_max_key_interval;
+    enc_param.min_quantizer = xvidenc_min_quantizer;
+    enc_param.max_quantizer = xvidenc_max_quantizer;
+    enc_param.max_bframes=xvidenc_max_bframes;
+    enc_param.bquant_ratio=xvidenc_bquant_ratio;
+    if(xvid_reduced==1)
+    {
+       enc_param.global=XVID_GLOBAL_REDUCED;
+    }
+
+
+    if( xvidenc_max_key_interval > 0 )
+	enc_param.max_key_interval = xvidenc_max_key_interval;
+    else
+	enc_param.max_key_interval = 10 * enc_param.fbase / enc_param.fincr;
     switch (xvid_encore(NULL, XVID_ENC_CREATE, &enc_param, NULL)) {
     case XVID_ERR_FAIL:
 	mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed\n");
@@ -167,6 +167,8 @@
 	mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed, bad 
format\n");
 	return 0;
     }
+
+
     fp->enc_handle = enc_param.handle;

     // initialize XViD per-frame static parameters
@@ -179,6 +181,14 @@
     }
     if (xvidenc_lumi_mask)
 	fp->enc_frame.general |= XVID_LUMIMASKING;
+    if (xvidenc_gmc)
+	fp->enc_frame.general |= XVID_GMC;
+    if (xvidenc_me_colour)
+	fp->enc_frame.general |= XVID_ME_COLOUR;
+    if(xvid_reduced==1)
+    {
+       fp->enc_frame.general |= XVID_REDUCED;
+    }
 
     switch (outfmt) {
     case IMGFMT_YV12:
@@ -225,10 +235,6 @@
     // initialize VBR engine
     // =====================
     vbrSetDefaults(&fp->vbr_state);
-    if (xvidenc_min_key_interval < 0)
-	xvidenc_min_key_interval = fp->vbr_state.min_key_interval;
-
-    // pass
     if (xvidenc_pass == 0) {
 	if (xvidenc_fixed_quant >= 1) {
 	    fp->vbr_state.mode = VBR_MODE_FIXED_QUANT;
@@ -242,26 +248,21 @@
 	fp->vbr_state.mode = VBR_MODE_2PASS_2;
     else
 	return -1;
-
-    // misc
     fp->vbr_state.fps = (double)enc_param.fbase / enc_param.fincr;
     fp->vbr_state.filename = passtmpfile;
     fp->vbr_state.desired_bitrate = enc_param.rc_bitrate;
-    fp->vbr_state.min_iquant = min_iq;
-    fp->vbr_state.max_iquant = max_iq;
-    fp->vbr_state.min_pquant = min_pq;
-    fp->vbr_state.max_pquant = max_pq;
-    if (xvidenc_keyframe_boost >= 0)
+    fp->vbr_state.min_iquant = fp->vbr_state.min_pquant = 
enc_param.min_quantizer;
+    fp->vbr_state.max_iquant = fp->vbr_state.max_pquant = 
enc_param.max_quantizer;
+    if (xvidenc_keyframe_boost)
 	fp->vbr_state.keyframe_boost = xvidenc_keyframe_boost;
-    if (xvidenc_kfthreshold >= 0)
+    if (xvidenc_kfthreshold)
 	fp->vbr_state.kftreshold = xvidenc_kfthreshold;
-    if (xvidenc_kfreduction >= 0)
+    if (xvidenc_kfreduction)
 	fp->vbr_state.kfreduction = xvidenc_kfreduction;
-    if (xvidenc_min_key_interval >= 0)
+    if (xvidenc_min_key_interval)
 	fp->vbr_state.min_key_interval = xvidenc_min_key_interval;
     fp->vbr_state.max_key_interval = enc_param.max_key_interval;
     fp->vbr_state.debug = xvidenc_debug;
-
     vbrInit(&fp->vbr_state);

     return 1;
@@ -308,18 +309,8 @@
     fp->enc_frame.bitstream = fp->mux->buffer;
     fp->enc_frame.length = -1 /* fp->mux->buffer_size */;
     fp->enc_frame.image = mpi->planes[0];
-
-    // get quantizers & I/P decision from the VBR engine
     fp->enc_frame.quant = vbrGetQuant(&fp->vbr_state);
     fp->enc_frame.intra = vbrGetIntra(&fp->vbr_state);
-
-    // modulated quantizer type
-    if (xvidenc_mod_quant && xvidenc_pass == 2) {
-	fp->enc_frame.general |= (fp->enc_frame.quant < 4) ? XVID_MPEGQUANT : 
XVID_H263QUANT;
-	fp->enc_frame.general &= (fp->enc_frame.quant < 4) ? ~XVID_H263QUANT : 
~XVID_MPEGQUANT;
-    }
-
-    // hinted ME, 1st part
     if (xvidenc_hintedme && xvidenc_pass == 1) {
 	fp->enc_frame.hint.hintstream = fp->hintstream;
 	fp->enc_frame.hint.rawhints = 0;
@@ -337,15 +328,13 @@
 		fp->enc_frame.hint.hintlength = 0;
 		fp->enc_frame.hint.rawhints = 0;
 		fp->enc_frame.general |= XVID_HINTEDME_SET;
-	    } 
+	    }
 	    else
 		perror("xvid: hint file read block failure");
-	} 
+	}
 	else
 	    perror("xvid: hint file read failure");
     }
-
-    // encode frame
     switch (xvid_encore(fp->enc_handle, XVID_ENC_ENCODE, &fp->enc_frame, 
&enc_stats)) {
     case XVID_ERR_OK:
 	break;
@@ -359,15 +348,9 @@
 	mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: failure\n");
 	break;
     }
-    
-    // write output
     mencoder_write_chunk(fp->mux, fp->enc_frame.length, fp->enc_frame.intra ? 
0x10 : 0);
-
-    // update the VBR engine
     vbrUpdate(&fp->vbr_state, enc_stats.quant, fp->enc_frame.intra,
 	      enc_stats.hlength, fp->enc_frame.length, enc_stats.kblks, 
enc_stats.mblks, enc_stats.ublks);
-
-    // hinted ME, 2nd part
     if (fp->enc_frame.general & XVID_HINTEDME_GET) {
 	size_t wrote = fwrite(&fp->enc_frame.hint.hintlength, 
sizeof(fp->enc_frame.hint.hintlength), 1, fp->hintfile);
 	if (wrote == 1) {





More information about the MPlayer-dev-eng mailing list