--- doc/encoders.texi | 37 +++++++++++++++++++++++++++++++++++++ libavcodec/libxvid.c | 19 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/doc/encoders.texi b/doc/encoders.texi index a42e7ba..6286b9c 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1356,6 +1356,43 @@ Variance masking. @end table +@item ssim +Set structural similarity (SSIM) displaying method. Possible values: + +@table @samp +@item off +Disable displaying of SSIM information. + +@item avg +Output average SSIM at the end of encoding to stdout. The format of +showing the average SSIM is: + +@example +Average SSIM: %f +@end example + +For users who are not familiar with C, %f means a float number, or +a decimal (e.g. 0.939232). + +@item frame +Output both per-frame SSIM data during encoding and average SSIM at +the end of encoding to stdout. The format of per-frame information +is: + +@example + SSIM: avg: %1.3f min: %1.3f max: %1.3f +@end example + +For users who are not familiar with C, %1.3f means a float number +rounded to 3 digits after the dot (e.g. 0.932). + +@end table + +@item ssim_acc +Set SSIM accuracy. Valid options are integers within the range of +0-4, while 0 gives the most accurate result and 4 computes the +fastest. + @end table @section png diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c index 15b3734..f3b3db5 100644 --- a/libavcodec/libxvid.c +++ b/libavcodec/libxvid.c @@ -64,6 +64,8 @@ struct xvid_context { unsigned char *intra_matrix; /**< P-Frame Quant Matrix */ unsigned char *inter_matrix; /**< I-Frame Quant Matrix */ int lumi_masking_mode; /**< Luminance masking mode */ + int ssim; /**< SSIM information display mode */ + int ssim_acc; /**< SSIM accuracy. 0: accurate. 4: fast. */ }; /** @@ -357,6 +359,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { struct xvid_ff_pass1 rc2pass1 = { 0 }; xvid_plugin_2pass2_t rc2pass2 = { 0 }; xvid_plugin_lumimasking_t masking = { 0 }; + xvid_plugin_ssim_t ssim = { 0 }; xvid_gbl_init_t xvid_gbl_init = { 0 }; xvid_enc_create_t xvid_enc_create = { 0 }; xvid_enc_plugin_t plugins[7]; @@ -538,6 +541,17 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { xvid_enc_create.num_plugins++; } + /* SSIM */ + if( x->ssim ) { + plugins[xvid_enc_create.num_plugins].func = xvid_plugin_ssim; + ssim.b_printstat = ( x->ssim == 2 ); + ssim.acc = x->ssim_acc; + ssim.cpu_flags = xvid_gbl_init.cpu_flags; + ssim.b_visualize = 0; + plugins[xvid_enc_create.num_plugins].param = &ssim; + xvid_enc_create.num_plugins++; + } + /* Frame Rate and Key Frames */ xvid_correct_framerate(avctx); xvid_enc_create.fincr = avctx->time_base.num; @@ -775,6 +789,11 @@ static const AVOption options[] = { { "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" }, + { "ssim", "Show SSIM information to stdout", OFFSET(ssim), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, VE, "ssim" }, + { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "ssim" }, + { "avg", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "ssim" }, + { "frame", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "ssim" }, + { "ssim_acc", "SSIM accuracy", OFFSET(ssim_acc), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, 4, VE }, { NULL }, }; -- 1.8.1.2