Browse Source

lavc: Move scenechange_threshold to codec private options

This option is only used by mpegvideoenc, x264, and xavs.
It is a very codec-specific option, so deprecate the global variant.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
tags/n3.0
Vittorio Giovara 10 years ago
parent
commit
7c79587d74
6 changed files with 43 additions and 11 deletions
  1. +4
    -6
      libavcodec/avcodec.h
  2. +14
    -2
      libavcodec/libx264.c
  3. +10
    -1
      libavcodec/libxavs.c
  4. +3
    -0
      libavcodec/mpegvideo.h
  5. +10
    -2
      libavcodec/mpegvideo_enc.c
  6. +2
    -0
      libavcodec/options_table.h

+ 4
- 6
libavcodec/avcodec.h View File

@@ -1872,13 +1872,11 @@ typedef struct AVCodecContext {
*/ */
uint16_t *inter_matrix; uint16_t *inter_matrix;


/**
* scene change detection threshold
* 0 is default, larger means fewer detected scene changes.
* - encoding: Set by user.
* - decoding: unused
*/
#if FF_API_PRIVATE_OPT
/** @deprecated use encoder private options instead */
attribute_deprecated
int scenechange_threshold; int scenechange_threshold;
#endif


/** /**
* noise reduction strength * noise reduction strength


+ 14
- 2
libavcodec/libx264.c View File

@@ -81,6 +81,7 @@ typedef struct X264Context {
int coder; int coder;
int b_frame_strategy; int b_frame_strategy;
int chroma_offset; int chroma_offset;
int scenechange_threshold;


char *x264_params; char *x264_params;
} X264Context; } X264Context;
@@ -427,8 +428,16 @@ FF_ENABLE_DEPRECATION_WARNINGS
x4->params.i_keyint_max = avctx->gop_size; x4->params.i_keyint_max = avctx->gop_size;
if (avctx->max_b_frames >= 0) if (avctx->max_b_frames >= 0)
x4->params.i_bframe = avctx->max_b_frames; x4->params.i_bframe = avctx->max_b_frames;
if (avctx->scenechange_threshold >= 0)
x4->params.i_scenecut_threshold = avctx->scenechange_threshold;

#if FF_API_PRIVATE_OPT
FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->scenechange_threshold)
x4->scenechange_threshold = avctx->scenechange_threshold;
if (x4->scenechange_threshold >= 0)
FF_ENABLE_DEPRECATION_WARNINGS
#endif
x4->params.i_scenecut_threshold = x4->scenechange_threshold;

if (avctx->qmin >= 0) if (avctx->qmin >= 0)
x4->params.rc.i_qp_min = avctx->qmin; x4->params.rc.i_qp_min = avctx->qmin;
if (avctx->qmax >= 0) if (avctx->qmax >= 0)
@@ -749,6 +758,7 @@ static const AVOption options[] = {
{ "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" }, { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
{ "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE }, { "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE },
{ "chromaoffset", "QP difference between chroma and luma", OFFSET(chroma_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, VE }, { "chromaoffset", "QP difference between chroma and luma", OFFSET(chroma_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, VE },
{ "sc_threshold", "Scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },


{ "x264-params", "Override the x264 configuration using a :-separated list of key=value parameters", OFFSET(x264_params), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "x264-params", "Override the x264 configuration using a :-separated list of key=value parameters", OFFSET(x264_params), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
{ NULL }, { NULL },
@@ -765,7 +775,9 @@ static const AVCodecDefault x264_defaults[] = {
{ "qblur", "-1" }, { "qblur", "-1" },
{ "qcomp", "-1" }, { "qcomp", "-1" },
{ "refs", "-1" }, { "refs", "-1" },
#if FF_API_PRIVATE_OPT
{ "sc_threshold", "-1" }, { "sc_threshold", "-1" },
#endif
{ "trellis", "-1" }, { "trellis", "-1" },
{ "nr", "-1" }, { "nr", "-1" },
{ "me_range", "-1" }, { "me_range", "-1" },


+ 10
- 1
libavcodec/libxavs.c View File

@@ -58,6 +58,7 @@ typedef struct XavsContext {
int mixed_refs; int mixed_refs;
int b_frame_strategy; int b_frame_strategy;
int chroma_offset; int chroma_offset;
int scenechange_threshold;


int64_t *pts_buffer; int64_t *pts_buffer;
int out_frame_count; int out_frame_count;
@@ -330,7 +331,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (x4->params.i_keyint_min > x4->params.i_keyint_max) if (x4->params.i_keyint_min > x4->params.i_keyint_max)
x4->params.i_keyint_min = x4->params.i_keyint_max; x4->params.i_keyint_min = x4->params.i_keyint_max;


x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
#if FF_API_PRIVATE_OPT
FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->scenechange_threshold)
x4->scenechange_threshold = avctx->scenechange_threshold;
FF_ENABLE_DEPRECATION_WARNINGS
#endif

x4->params.i_scenecut_threshold = x4->scenechange_threshold;


// x4->params.b_deblocking_filter = avctx->flags & AV_CODEC_FLAG_LOOP_FILTER; // x4->params.b_deblocking_filter = avctx->flags & AV_CODEC_FLAG_LOOP_FILTER;


@@ -458,6 +466,7 @@ static const AVOption options[] = {
{ "tesa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_ME_TESA }, INT_MIN, INT_MAX, VE, "motion-est" }, { "tesa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_ME_TESA }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, VE}, { "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, VE},
{ "chromaoffset", "QP difference between chroma and luma", OFFSET(chroma_offset), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE}, { "chromaoffset", "QP difference between chroma and luma", OFFSET(chroma_offset), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE},
{ "sc_threshold", "Scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, VE},


{ NULL }, { NULL },
}; };


+ 3
- 0
libavcodec/mpegvideo.h View File

@@ -534,6 +534,8 @@ typedef struct MpegEncContext {
int frame_skip_factor; int frame_skip_factor;
int frame_skip_exp; int frame_skip_exp;
int frame_skip_cmp; int frame_skip_cmp;

int scenechange_threshold;
} MpegEncContext; } MpegEncContext;


/* mpegvideo_enc common options */ /* mpegvideo_enc common options */
@@ -606,6 +608,7 @@ FF_MPV_OPT_CMP_FUNC, \
{"skip_factor", "Frame skip factor", FF_MPV_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"skip_factor", "Frame skip factor", FF_MPV_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
{"skip_exp", "Frame skip exponent", FF_MPV_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"skip_exp", "Frame skip exponent", FF_MPV_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
{"skip_cmp", "Frame skip compare function", FF_MPV_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \ {"skip_cmp", "Frame skip compare function", FF_MPV_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
{"sc_threshold", "Scene change threshold", FF_MPV_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \


extern const AVOption ff_mpv_generic_options[]; extern const AVOption ff_mpv_generic_options[];




+ 10
- 2
libavcodec/mpegvideo_enc.c View File

@@ -468,7 +468,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
return -1; return -1;
} }


if (s->avctx->scenechange_threshold < 1000000000 &&
#if FF_API_PRIVATE_OPT
FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->scenechange_threshold)
s->scenechange_threshold = avctx->scenechange_threshold;
FF_ENABLE_DEPRECATION_WARNINGS
#endif

if (s->scenechange_threshold < 1000000000 &&
(s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)) { (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"closed gop with scene change detection are not supported yet, " "closed gop with scene change detection are not supported yet, "
@@ -3453,7 +3460,8 @@ static int encode_picture(MpegEncContext *s, int picture_number)
s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp;
emms_c(); emms_c();


if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == AV_PICTURE_TYPE_P){
if (s->me.scene_change_score > s->scenechange_threshold &&
s->pict_type == AV_PICTURE_TYPE_P) {
s->pict_type= AV_PICTURE_TYPE_I; s->pict_type= AV_PICTURE_TYPE_I;
for(i=0; i<s->mb_stride*s->mb_height; i++) for(i=0; i<s->mb_stride*s->mb_height; i++)
s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA;


+ 2
- 0
libavcodec/options_table.h View File

@@ -323,7 +323,9 @@ static const AVOption avcodec_options[] = {
#if FF_API_STREAM_CODEC_TAG #if FF_API_STREAM_CODEC_TAG
{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, {"stream_codec_tag", NULL, OFFSET(stream_codec_tag), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},
#endif #endif
#if FF_API_PRIVATE_OPT
{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
#endif
#if FF_API_MPV_OPT #if FF_API_MPV_OPT
{"lmin", "deprecated, use encoder private options instead", OFFSET(lmin), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, V|E}, {"lmin", "deprecated, use encoder private options instead", OFFSET(lmin), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, V|E},
{"lmax", "deprecated, use encoder private options instead", OFFSET(lmax), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, V|E}, {"lmax", "deprecated, use encoder private options instead", OFFSET(lmax), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, V|E},


Loading…
Cancel
Save