Commit ccb212b6 authored by Timothy Gu's avatar Timothy Gu Committed by Michael Niedermayer

libxvid: add working lumimasking and variance AQ

The old implementation is unusable due to change in the Xvid API.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 95960027
...@@ -1323,6 +1323,19 @@ half pixel and quarter pixel refinement for 8x8 blocks, and rate ...@@ -1323,6 +1323,19 @@ half pixel and quarter pixel refinement for 8x8 blocks, and rate
distortion-based search using square pattern. distortion-based search using square pattern.
@end table @end table
@item lumi_aq
Enable lumi masking adaptive quantization when set to 1. Default is 0
(disabled).
@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 @end table
@section png @section png
......
...@@ -63,6 +63,8 @@ struct xvid_context { ...@@ -63,6 +63,8 @@ struct xvid_context {
int twopassfd; int twopassfd;
unsigned char *intra_matrix; /**< P-Frame Quant Matrix */ unsigned char *intra_matrix; /**< P-Frame Quant Matrix */
unsigned char *inter_matrix; /**< I-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 */
}; };
/** /**
...@@ -355,6 +357,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { ...@@ -355,6 +357,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_plugin_single_t single = { 0 }; xvid_plugin_single_t single = { 0 };
struct xvid_ff_pass1 rc2pass1 = { 0 }; struct xvid_ff_pass1 rc2pass1 = { 0 };
xvid_plugin_2pass2_t rc2pass2 = { 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_gbl_init_t xvid_gbl_init = { 0 };
xvid_enc_create_t xvid_enc_create = { 0 }; xvid_enc_create_t xvid_enc_create = { 0 };
xvid_enc_plugin_t plugins[7]; xvid_enc_plugin_t plugins[7];
...@@ -526,12 +530,29 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { ...@@ -526,12 +530,29 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
} }
/* Luminance Masking */ /* Luminance Masking */
if( 0.0 != avctx->lumi_masking ) { if( avctx->lumi_masking != 0.0 || x->lumi_aq ) {
masking_l.method = 0;
plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking; 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 = x->lumi_aq ? &masking_l : NULL ;
xvid_enc_create.num_plugins++; 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++;
}
if( x->lumi_aq && x->variance_aq )
av_log(avctx, AV_LOG_INFO,
"Both lumi_aq and variance_aq are enabled. The resulting quality"
"will be the worse one of the two effects made by the AQ.\n");
/* Frame Rate and Key Frames */ /* Frame Rate and Key Frames */
xvid_correct_framerate(avctx); xvid_correct_framerate(avctx);
xvid_enc_create.fincr = avctx->time_base.num; xvid_enc_create.fincr = avctx->time_base.num;
...@@ -762,6 +783,21 @@ static av_cold int xvid_encode_close(AVCodecContext *avctx) { ...@@ -762,6 +783,21 @@ static av_cold int xvid_encode_close(AVCodecContext *avctx) {
return 0; 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 = { AVCodec ff_libxvid_encoder = {
.name = "libxvid", .name = "libxvid",
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
...@@ -772,4 +808,5 @@ AVCodec ff_libxvid_encoder = { ...@@ -772,4 +808,5 @@ AVCodec ff_libxvid_encoder = {
.close = xvid_encode_close, .close = xvid_encode_close,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
.long_name = NULL_IF_CONFIG_SMALL("libxvidcore MPEG-4 part 2"), .long_name = NULL_IF_CONFIG_SMALL("libxvidcore MPEG-4 part 2"),
.priv_class = &xvid_class,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment