[MPlayer-dev-eng] [PATCH] Expose the VBV options of Xvid >= 1.1.0 in -xvidencopts

Lasse Collin lasse.collin at tukaani.org
Wed Nov 10 15:57:16 CET 2010


The VBV options allow restricting the peak bitrate for hardware 
player compatibility. Earlier the VBV options were only indirectly 
available via the profiles.

When using profiles, vbv_peakrate is no longer incorrectly 
multiplied by three (the incorrect code was copied from Xvid 
itself). It doesn't matter in practice at all though because 
Xvid uses vbv_peakrate only for some debug checks. It has no 
effect on the encoded output.

diff -ru mplayer-export-2010-11-08.orig/DOCS/man/en/mplayer.1 mplayer-export-2010-11-08/DOCS/man/en/mplayer.1
--- mplayer-export-2010-11-08.orig/DOCS/man/en/mplayer.1	2010-10-29 16:54:42.000000000 +0300
+++ mplayer-export-2010-11-08/DOCS/man/en/mplayer.1	2010-11-09 17:12:08.606668370 +0200
@@ -10276,7 +10276,7 @@
 .
 .PP
 .sp 1
-The following option is only available in Xvid 1.1.x.
+The following options are only available in Xvid 1.1.x and later.
 .
 .TP
 .B bvhq=<0|1>
@@ -10286,9 +10286,32 @@
 This produces nicer-looking B-frames while incurring almost no
 performance penalty (default: 1).
 .
+.TP
+.B vbv_bufsize=<0...> (two pass mode only)
+Specify the video buffering verifier (VBV) buffer size in bits
+(default: 0 \- VBV check disabled).
+VBV allows restricting peak bitrate to make the video play properly
+on hardware players.
+For example, the Home profile uses vbv_bufsize=3145728.
+If you set vbv_bufsize you should set also vbv_maxrate.
+Note that there is no vbv_peakrate because Xvid does not actually
+use it for bitrate controlling; the other VBV options are enough
+to restrict the peak bitrate.
+.
+.TP
+.B vbv_initial=<0...vbv_bufsize> (two pass mode only)
+Specify the initial fill of the VBV buffer in bits
+(default: 75% of vbv_bufsize).
+The default is probably what you want.
+.
+.TP
+.B vbv_maxrate=<0...> (two pass mode only)
+Specify the maximum processing rate in bits/s (default: 0).
+For example, the Home profile uses vbv_maxrate=4854000.
+.
 .PP
 .sp 1
-The following option is only available in the 1.2.x version of Xvid.
+The following option is only available in Xvid 1.2.x and later.
 .
 .TP
 .B threads=<0\-n>
diff -ru mplayer-export-2010-11-08.orig/libmpcodecs/ve_xvid4.c mplayer-export-2010-11-08/libmpcodecs/ve_xvid4.c
--- mplayer-export-2010-11-08.orig/libmpcodecs/ve_xvid4.c	2010-10-29 16:54:42.000000000 +0300
+++ mplayer-export-2010-11-08/libmpcodecs/ve_xvid4.c	2010-11-09 17:18:00.026668371 +0200
@@ -209,6 +209,10 @@
 static int xvidenc_vbr_kfthreshold = 0;
 static int xvidenc_vbr_container_frame_overhead = 24; /* mencoder uses AVI container */
 
+static int xvidenc_vbv_size = 0;
+static int xvidenc_vbv_initial = 0;
+static int xvidenc_vbv_maxrate = 0;
+
 // commandline profile option string - default to unrestricted
 static char *xvidenc_profile = "unrestricted";
 
@@ -296,6 +300,11 @@
 	{"kfthreshold", &xvidenc_vbr_kfthreshold, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
 	{"container_frame_overhead", &xvidenc_vbr_container_frame_overhead, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
 
+	/* section [vbv] */
+	{"vbv_bufsize", &xvidenc_vbv_size, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
+	{"vbv_initial", &xvidenc_vbv_initial, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
+	{"vbv_maxrate", &xvidenc_vbv_maxrate, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
+
 	/* Section Aspect Ratio */
 	{"par", &xvidenc_par, CONF_TYPE_STRING, 0, 0, 0, NULL},
 	{"par_width", &xvidenc_par_width, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL},
@@ -781,13 +790,44 @@
 	/* VBV */
 
 #if XVID_API >= XVID_MAKE_API(4,1)
-	pass2->vbv_size = selected_profile->max_vbv_size;
-	pass2->vbv_initial = (selected_profile->max_vbv_size*3)>>2; /* 75% */
-	pass2->vbv_maxrate = selected_profile->max_bitrate;
-	pass2->vbv_peakrate = selected_profile->vbv_peakrate*3;
+	if(xvidenc_vbv_size > 0) {
+		if(selected_profile->max_vbv_size > 0 && xvidenc_vbv_size > selected_profile->max_vbv_size) {
+			mp_msg(MSGT_MENCODER,MSGL_ERR,
+				"xvid:[ERROR] Selected profile limits vbv_bufsize <= %d\n", selected_profile->max_vbv_size);
+			return BAD;
+		}
+
+		pass2->vbv_size = xvidenc_vbv_size;
+	} else {
+		pass2->vbv_size = selected_profile->max_vbv_size;
+	}
+
+	if(xvidenc_vbv_initial > 0) {
+		if(xvidenc_vbv_initial > pass2->vbv_size) {
+			mp_msg(MSGT_MENCODER,MSGL_ERR,
+				"xvid:[ERROR] vbv_initial must be <= vbv_bufsize\n");
+			return BAD;
+		}
+
+		pass2->vbv_initial = xvidenc_vbv_initial;
+	} else {
+		pass2->vbv_initial = (pass2->vbv_size*3)>>2; /* 75% */
+	}
+
+	if(xvidenc_vbv_maxrate > 0) {
+		if(selected_profile->max_bitrate > 0 && xvidenc_vbv_maxrate > selected_profile->max_bitrate) {
+			mp_msg(MSGT_MENCODER,MSGL_ERR,
+				"xvid:[ERROR] Selected profile limits vbv_maxrate <= %d\n", selected_profile->max_bitrate);
+			return BAD;
+		}
+
+		pass2->vbv_maxrate = xvidenc_vbv_maxrate;
+	} else {
+		pass2->vbv_maxrate = selected_profile->max_bitrate;
+	}
+
+	pass2->vbv_peakrate = selected_profile->vbv_peakrate; /* Useless */
 #endif
-// XXX: xvidcore currently provides a "peak bits over 3 seconds" constraint.
-// according to the latest dxn literature, a 1 second constraint is now used
 
 	create->profile = selected_profile->id;
 

-- 
Lasse Collin  |  IRC: Larhzu @ IRCnet & Freenode


More information about the MPlayer-dev-eng mailing list