[XviD-devel] Hinted-ME bug in stable tree : sample

Edouard Gomez xvid-devel@xvid.org
Mon, 23 Dec 2002 11:24:17 +0100


--Yylu36WmvOXNoKYn
Content-Type: multipart/mixed; boundary="Dxnq1zWXvFF0Q93v"
Content-Disposition: inline


--Dxnq1zWXvFF0Q93v
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

At last i reproduced the bug in transcode, so it's not mplayer's
fault. Your code seems right, mine is right for transcode.

So I'll have to dig out this bug deep into xvidcore.

However, the trancode errors seems more "verbose":

Error while decoding frame!
Error, header damaged or not MPEG4 header (f_code=3D0)

While your samples were just indicating "error decoding frame"

I hope this will help me tracking this bug.

PS: a transcode patch is attached. It adds Hinted ME support to teh
    stable xvid export module.

--=20
Edouard Gomez

--Dxnq1zWXvFF0Q93v
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="export_xvid.diff"
Content-Transfer-Encoding: quoted-printable

--- transcode.orig/export/export_xvid.c	2002-11-28 21:45:19.000000000 +0100
+++ transcode/export/export_xvid.c	2002-12-23 11:11:39.000000000 +0100
@@ -46,7 +46,7 @@
 #define DEVELOPER_USE /* Turns on/off transcode xvid.cfg option file */
 #endif
=20
-#include "xvidcvs.h"
+#include "xvid.h"
 #include "xvid_vbr.h"
=20
 #include "transcode.h"
@@ -75,6 +75,9 @@
 static int VbrMode =3D 0;
 static int encode_fields =3D 0;
 static avi_t *avifile =3D NULL;
+#define HINT_BUFFER_SIZE (50*1024) /* 50kb should be enough */
+#define HINT_FILE "xvid-me.hints"
+static FILE *hints_file =3D NULL;
  =20
 /* temporary audio/video buffer */
 static char *buffer;
@@ -259,6 +262,17 @@
 		vbr_state.fps =3D (float)((float)global_param.fbase/(float)global_param.=
fincr);
 		vbr_state.debug =3D (verbose_flag & TC_DEBUG)?1:0;
=20
+		/*
+		 * Take care of 1pass CBR | 2pass 1&2 | fixed quant
+		 *
+		 * We have also to take care of HINTED modes:
+		 *   GET for pass1
+		 *   SET for pass2
+		 *
+		 * Power Users should know about both flags but they can use
+		 * a shortcut using XVID_HINTEDME without specifying the action
+		 *
+		 */
 		switch(VbrMode) {
 		case 1:
 			/*
@@ -267,6 +281,7 @@
 			 */
 			vbr_state.mode =3D VBR_MODE_2PASS_1;
 			vbr_state.filename =3D vob->divxlogfile;
+			global_frame.general &=3D ~XVID_HINTEDME_SET;
 			break;
 		case 2:=09
 			/*
@@ -276,6 +291,7 @@
 			 */
 			vbr_state.mode =3D VBR_MODE_2PASS_2;
 			vbr_state.filename =3D vob->divxlogfile;
+			global_frame.general &=3D ~XVID_HINTEDME_GET;
=20
 			/* divxbitrate represents the desired file size in Mo */
 			vbr_state.desired_bitrate =3D vob->divxbitrate*1000;
@@ -300,6 +316,24 @@
 			break;
 		}
=20
+		/* Prepare things for Hinted ME */
+		if(global_frame.general & (XVID_HINTEDME_SET|XVID_HINTEDME_GET)) {
+			char *rights =3D "rb";
+
+			/*
+			 * If we are getting hints from core, we will have to
+			 * write them to hint file
+			 */
+			if(global_frame.general & XVID_HINTEDME_GET)
+				rights =3D "w+b";
+
+			/* Open the hint file */
+			hints_file =3D fopen(HINT_FILE, rights);
+			if(hints_file =3D=3D NULL) {
+				fprintf(stderr, "Error opening input file %s\n", HINT_FILE);
+				return(-1);
+			}
+		}
=20
 		/* Init the vbr state */
 		if(vbrInit(&vbr_state) !=3D 0)
@@ -400,7 +434,36 @@
 	xframe.quant =3D vbrGetQuant(&vbr_state);
 	xframe.intra =3D vbrGetIntra(&vbr_state);
=20
-  	/* Encode the frame */
+  	/* Hinted ME stuff */
+	if(xframe.general & (XVID_HINTEDME_GET|XVID_HINTEDME_SET)) {
+		long size =3D HINT_BUFFER_SIZE;
+
+		/*
+		 * If we are setting ME hints, we have to read data from
+		 * the file - first the hints size
+		 */
+		if(xframe.general & XVID_HINTEDME_SET)
+			fread(&size, 1, sizeof(long), hints_file);
+
+		/* Initialise hints in the frame structure */
+		xframe.hint.rawhints =3D 0;
+		xframe.hint.hintstream =3D malloc(size);
+
+		if(xframe.hint.hintstream =3D=3D NULL) {
+			fprintf(stderr, "Could not allocate memory for ME hints\n");
+			return(TC_EXPORT_ERROR);
+		}
+
+		/*
+		 * If we are setting ME hints, we have to read data from
+		 * the file - then the hints
+		 */
+		if(xframe.general & XVID_HINTEDME_SET)
+			fread(xframe.hint.hintstream, 1, size, hints_file);
+
+	}
+
+	/* Encode the frame */
 	xerr =3D XviD_encore(XviD_encore_handle, XVID_ENC_ENCODE, &xframe,
 			   &xstats);
=20
@@ -410,12 +473,28 @@
 		return(TC_EXPORT_ERROR);=20
     	}
=20
+	/* Hinted ME stuff - The come back :-) */
+	if(xframe.general & (XVID_HINTEDME_GET|XVID_HINTEDME_SET)) {
+
+		/* If we are getting ME hints - write them to file */
+		if(xframe.general & XVID_HINTEDME_GET) {
+			long size;
+			size =3D xframe.hint.hintlength;
+			fwrite(&size, 1, sizeof(long), hints_file);
+			fwrite(xframe.hint.hintstream, 1, size, hints_file);
+		}
+
+		/* Free the buffer */
+		if(xframe.hint.hintstream) free(xframe.hint.hintstream);
+
+	}
+
 	/* Update the VBR controler */
 	vbrUpdate(&vbr_state, xstats.quant, xframe.intra, xstats.hlength,
 		  xframe.length, xstats.kblks, xstats.mblks, xstats.ublks);
=20
=20
-	//0.6.2: switch outfile on "C" and -J pv
+	/* 0.6.2: switch outfile on "C" and -J pv */
 	if(xframe.intra) tc_outstream_rotate();
=20
 	/* Write bitstream */
@@ -442,7 +521,9 @@
 		AVI_close(vob->avifile_out);
 		vob->avifile_out=3DNULL;
 	}
- =20
+
+	if(hints_file !=3D NULL) fclose(hints_file);
+
 	if(param->flag =3D=3D TC_VIDEO) return(0);
  =20
 	return(TC_EXPORT_ERROR);
@@ -749,15 +830,12 @@
 	{ "XVID_CPU_3DNOW",    XVID_CPU_3DNOW},
 	{ "XVID_CPU_3DNOWEXT", XVID_CPU_3DNOWEXT},
 	{ "XVID_CPU_TSC",      XVID_CPU_TSC},
-//	{ "XVID_CPU_IA64",     XVID_CPU_IA64},
-//	{ "XVID_CPU_CHKONLY",  XVID_CPU_CHKONLY},
 	{ "XVID_CPU_FORCE",    XVID_CPU_FORCE},
 	{ NULL,                0}
 };
=20
 static config_flag_t const general_flags[] =3D {
 	{ "XVID_VALID_FLAGS",    XVID_VALID_FLAGS},
-//	{ "XVID_CUSTOM_QMATRIX", XVID_CUSTOM_QMATRIX},
 	{ "XVID_H263QUANT",      XVID_H263QUANT},
 	{ "XVID_MPEGQUANT",      XVID_MPEGQUANT},
 	{ "XVID_HALFPEL",        XVID_HALFPEL},
@@ -769,6 +847,7 @@
 	{ "XVID_ALTERNATESCAN",  XVID_ALTERNATESCAN},
 	{ "XVID_HINTEDME_GET",   XVID_HINTEDME_GET},
 	{ "XVID_HINTEDME_SET",   XVID_HINTEDME_SET},
+	{ "XVID_HINTEDME",       XVID_HINTEDME_SET|XVID_HINTEDME_GET},
 	{ "XVID_INTER4V",        XVID_INTER4V},
 	{ "XVID_ME_ZERO",        XVID_ME_ZERO},
 	{ "XVID_ME_LOGARITHMIC", XVID_ME_LOGARITHMIC},

--Dxnq1zWXvFF0Q93v--

--Yylu36WmvOXNoKYn
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+BuRQR5dTYz5sWMcRAgvBAKDl7FGcUEph+VedenDDobhX+DhGogCgnR6k
/dW7nPcBeVViLos6OnYwrjE=
=hUlJ
-----END PGP SIGNATURE-----

--Yylu36WmvOXNoKYn--