[FFmpeg-cvslog] libxvid: add working lumimasking and variance AQ
Timothy Gu
git at videolan.org
Mon Apr 7 03:18:17 CEST 2014
ffmpeg | branch: master | Timothy Gu <timothygu99 at gmail.com> | Tue Jul 30 19:39:06 2013 -0700| [5ce7ca68b86856ee8e9d6530dffdadc4eca4f8d1] | committer: Vittorio Giovara
libxvid: add working lumimasking and variance AQ
The old implementation is unusable due to changes in the Xvid API.
Further fixes by Michael Niedermayer <michaelni at gmx.at>.
Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5ce7ca68b86856ee8e9d6530dffdadc4eca4f8d1
---
doc/encoders.texi | 13 +++++++++++++
libavcodec/libxvid.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
libavcodec/version.h | 2 +-
3 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 24692b7..5c0e489 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -505,6 +505,19 @@ Small-sized colorful images
Text-like
@end table
+ at item lumi_aq
+Enable lumi masking adaptive quantization when set to 1. Default is 0
+(disabled).
+
+ at item variance_aq
+Enable variance adaptive quantization when set to 1. Default is 0
+(disabled).
+
+When combined with @option{lumi_aq}, the resulting quality will not
+be better than any of the two specified individually. In other
+words, the resulting quality will be the worse one of the two
+effects.
+
@end table
@section libx264
diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
index fe68c8e..42614ea 100644
--- a/libavcodec/libxvid.c
+++ b/libavcodec/libxvid.c
@@ -46,6 +46,7 @@
* This stores all the private context for the codec.
*/
struct xvid_context {
+ AVClass *class; /**< Handle for Xvid encoder */
void *encoder_handle; /**< Handle for Xvid encoder */
int xsize; /**< Frame x size */
int ysize; /**< Frame y size */
@@ -59,6 +60,8 @@ struct xvid_context {
char *twopassfile; /**< second pass temp file name */
unsigned char *intra_matrix; /**< P-Frame Quant Matrix */
unsigned char *inter_matrix; /**< I-Frame Quant Matrix */
+ int lumi_aq; /**< Lumi masking as an aq method */
+ int variance_aq; /**< Variance adaptive quantization */
};
/**
@@ -349,6 +352,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_plugin_single_t single = { 0 };
struct xvid_ff_pass1 rc2pass1 = { 0 };
xvid_plugin_2pass2_t rc2pass2 = { 0 };
+ xvid_plugin_lumimasking_t masking_l = { 0 }; /* For lumi masking */
+ xvid_plugin_lumimasking_t masking_v = { 0 }; /* For variance AQ */
xvid_gbl_init_t xvid_gbl_init = { 0 };
xvid_enc_create_t xvid_enc_create = { 0 };
xvid_enc_plugin_t plugins[7];
@@ -518,10 +523,32 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_enc_create.num_plugins++;
}
+ if (avctx->lumi_masking != 0.0)
+ x->lumi_aq = 1;
+
+ if (x->lumi_aq && x->variance_aq) {
+ x->variance_aq = 0
+ av_log(avctx, AV_LOG_WARNING,
+ "variance_aq is ignored when lumi_aq is set.\n");
+ }
+
/* Luminance Masking */
- if( 0.0 != avctx->lumi_masking ) {
+ if (x->lumi_aq) {
+ masking_l.method = 0;
plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
- plugins[xvid_enc_create.num_plugins].param = NULL;
+
+ /* The old behavior is that when avctx->lumi_masking is specified,
+ * plugins[...].param = NULL. Trying to keep the old behavior here. */
+ plugins[xvid_enc_create.num_plugins].param = avctx->lumi_masking ? NULL
+ : &masking_l;
+ xvid_enc_create.num_plugins++;
+ }
+
+ /* Variance AQ */
+ if (x->variance_aq) {
+ masking_v.method = 1;
+ plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
+ plugins[xvid_enc_create.num_plugins].param = &masking_v;
xvid_enc_create.num_plugins++;
}
@@ -748,6 +775,21 @@ static av_cold int xvid_encode_close(AVCodecContext *avctx) {
return 0;
}
+#define OFFSET(x) offsetof(struct xvid_context, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "lumi_aq", "Luminance masking AQ", OFFSET(lumi_aq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
+ { "variance_aq", "Variance AQ", OFFSET(variance_aq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
+ { NULL },
+};
+
+static const AVClass xvid_class = {
+ .class_name = "libxvid",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_libxvid_encoder = {
.name = "libxvid",
.long_name = NULL_IF_CONFIG_SMALL("libxvidcore MPEG-4 part 2"),
@@ -758,4 +800,5 @@ AVCodec ff_libxvid_encoder = {
.encode2 = xvid_encode_frame,
.close = xvid_encode_close,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
+ .priv_class = &xvid_class,
};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index deb0780..738b816 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
#define LIBAVCODEC_VERSION_MAJOR 55
#define LIBAVCODEC_VERSION_MINOR 45
-#define LIBAVCODEC_VERSION_MICRO 0
+#define LIBAVCODEC_VERSION_MICRO 1
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
More information about the ffmpeg-cvslog
mailing list