The old implementation does not specify the param and is not usable. --- doc/encoders.texi | 17 +++++++++++++++++ libavcodec/libxvid.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index c703000..a42e7ba 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1339,6 +1339,23 @@ distortion-based search using square pattern. @end table +@item lumi_masking_mode +Set human visual system masking mode. Possible values: + +@c FIXME: I'm not able to explain the difference between the modes. +@c Need someone who is more familiar with this. +@table @samp +@item off +Disable masking. + +@item lumi +Luminance masking. + +@item variance +Variance masking. + +@end table + @end table @section png diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c index 05a12db..15b3734 100644 --- a/libavcodec/libxvid.c +++ b/libavcodec/libxvid.c @@ -63,6 +63,7 @@ struct xvid_context { int twopassfd; unsigned char *intra_matrix; /**< P-Frame Quant Matrix */ unsigned char *inter_matrix; /**< I-Frame Quant Matrix */ + int lumi_masking_mode; /**< Luminance masking mode */ }; /** @@ -355,6 +356,7 @@ 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 = { 0 }; xvid_gbl_init_t xvid_gbl_init = { 0 }; xvid_enc_create_t xvid_enc_create = { 0 }; xvid_enc_plugin_t plugins[7]; @@ -526,9 +528,13 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { } /* Luminance Masking */ - if( 0.0 != avctx->lumi_masking ) { + if( avctx->lumi_masking != 0.0 || x->lumi_masking_mode ) { + masking.method = ( x->lumi_masking_mode == 2 ); 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_masking_mode ? &masking : NULL ; xvid_enc_create.num_plugins++; } @@ -762,6 +768,23 @@ 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_masking_mode", "HVS masking mode", OFFSET(lumi_masking_mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, VE, "lumi_masking_mode" }, + { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "lumi_masking_mode" }, + { "lumi", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "lumi_masking_mode" }, + { "variance", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "lumi_masking_mode" }, + { 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", .type = AVMEDIA_TYPE_VIDEO, @@ -772,4 +795,5 @@ AVCodec ff_libxvid_encoder = { .close = xvid_encode_close, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, .long_name = NULL_IF_CONFIG_SMALL("libxvidcore MPEG-4 part 2"), + .priv_class = &xvid_class, }; -- 1.8.1.2