[FFmpeg-devel] [PATCH 5/7] avfilter/vf_framerate: fix scene change detection score

Marton Balint cus at passwd.hu
Mon Dec 11 00:11:20 EET 2017


- normalize score to [0..100] instead of [0..85]
- change the default score to 8.2 to roughly keep existing behaviour
- take into account bit depth
- do not truncate to integer

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 doc/filters.texi                           | 2 +-
 libavfilter/vf_framerate.c                 | 4 ++--
 tests/ref/fate/filter-framerate-12bit-down | 2 +-
 tests/ref/fate/filter-framerate-12bit-up   | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 3346438231..10bd80d5c2 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8933,7 +8933,7 @@ Specify the level at which a scene change is detected as a value between
 0 and 100 to indicate a new scene; a low value reflects a low
 probability for the current frame to introduce a new scene, while a higher
 value means the current frame is more likely to be one.
-The default is @code{7}.
+The default is @code{8.2}.
 
 @item flags
 Specify flags influencing the filter process.
diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c
index 1cad2305ad..dd106f8e5b 100644
--- a/libavfilter/vf_framerate.c
+++ b/libavfilter/vf_framerate.c
@@ -88,7 +88,7 @@ static const AVOption framerate_options[] = {
 
     {"interp_start",        "point to start linear interpolation",    OFFSET(interp_start),    AV_OPT_TYPE_INT,      {.i64=15},                 0,       255,     V|F },
     {"interp_end",          "point to end linear interpolation",      OFFSET(interp_end),      AV_OPT_TYPE_INT,      {.i64=240},                0,       255,     V|F },
-    {"scene",               "scene change level",                     OFFSET(scene_score),     AV_OPT_TYPE_DOUBLE,   {.dbl=7.0},                0,       INT_MAX, V|F },
+    {"scene",               "scene change level",                     OFFSET(scene_score),     AV_OPT_TYPE_DOUBLE,   {.dbl=8.2},                0,       INT_MAX, V|F },
 
     {"flags",               "set flags",                              OFFSET(flags),           AV_OPT_TYPE_FLAGS,    {.i64=1},                  0,       INT_MAX, V|F, "flags" },
     {"scene_change_detect", "enable scene change detection",          0,                       AV_OPT_TYPE_CONST,    {.i64=FRAMERATE_FLAG_SCD}, INT_MIN, INT_MAX, V|F, "flags" },
@@ -183,7 +183,7 @@ static double get_scene_score(AVFilterContext *ctx, AVFrame *crnt, AVFrame *next
         else
             sad = scene_sad16(s, (const uint16_t*)crnt->data[0], crnt->linesize[0] >> 1, (const uint16_t*)next->data[0], next->linesize[0] >> 1, crnt->height);
 
-        mafd = sad / (crnt->height * crnt->width * 3);
+        mafd = (double)sad * 100.0 / (crnt->height * crnt->width) / (1 << s->bitdepth);
         diff = fabs(mafd - s->prev_mafd);
         ret  = av_clipf(FFMIN(mafd, diff), 0, 100.0);
         s->prev_mafd = mafd;
diff --git a/tests/ref/fate/filter-framerate-12bit-down b/tests/ref/fate/filter-framerate-12bit-down
index 7a5a7b8e14..0a9aea0ce1 100644
--- a/tests/ref/fate/filter-framerate-12bit-down
+++ b/tests/ref/fate/filter-framerate-12bit-down
@@ -4,7 +4,7 @@
 #dimensions 0: 320x240
 #sar 0: 1/1
 0,          0,          0,        1,   307200, 0xb49cf016
-0,          1,          1,        1,   307200, 0xfe025c7f
+0,          1,          1,        1,   307200, 0xc3be6971
 0,          2,          2,        1,   307200, 0x4d458da1
 0,          3,          3,        1,   307200, 0x35d4d8ea
 0,          4,          4,        1,   307200, 0x88f88697
diff --git a/tests/ref/fate/filter-framerate-12bit-up b/tests/ref/fate/filter-framerate-12bit-up
index 8f57e6d066..8f5f95b275 100644
--- a/tests/ref/fate/filter-framerate-12bit-up
+++ b/tests/ref/fate/filter-framerate-12bit-up
@@ -4,7 +4,7 @@
 #dimensions 0: 320x240
 #sar 0: 1/1
 0,          0,          0,        1,   307200, 0xb49cf016
-0,          1,          1,        1,   307200, 0xc74259b4
+0,          1,          1,        1,   307200, 0x59cb92c7
 0,          2,          2,        1,   307200, 0xe4ca172c
 0,          3,          3,        1,   307200, 0x5378b13c
 0,          4,          4,        1,   307200, 0x2a7d4840
-- 
2.13.6



More information about the ffmpeg-devel mailing list