[FFmpeg-devel] [PATCH 1/2] avfilter/vf_framerate: calculate interpolation as integer

Marton Balint cus at passwd.hu
Sun Dec 24 00:17:38 EET 2017


It was truncated to int later on anyway. Fate test changes are due to rounding
instead of truncation.

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

diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c
index 1336ea0469..38f45a8033 100644
--- a/libavfilter/vf_framerate.c
+++ b/libavfilter/vf_framerate.c
@@ -47,8 +47,10 @@ typedef struct FrameRateContext {
     AVRational dest_frame_rate;         ///< output frames per second
     int flags;                          ///< flags affecting frame rate conversion algorithm
     double scene_score;                 ///< score that denotes a scene change has happened
-    int interp_start;                   ///< start of range to apply linear interpolation
-    int interp_end;                     ///< end of range to apply linear interpolation
+    int interp_start;                   ///< start of range to apply linear interpolation (same bitdepth as input)
+    int interp_end;                     ///< end of range to apply linear interpolation (same bitdepth as input)
+    int interp_start_param;             ///< start of range to apply linear interpolation
+    int interp_end_param;               ///< end of range to apply linear interpolation
 
     int line_size[4];                   ///< bytes of pixel data per line for each plane
     int vsub;
@@ -87,8 +89,8 @@ typedef struct FrameRateContext {
 static const AVOption framerate_options[] = {
     {"fps",                 "required output frames per second rate", OFFSET(dest_frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="50"},             0,       INT_MAX, V|F },
 
-    {"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 },
+    {"interp_start",        "point to start linear interpolation",    OFFSET(interp_start_param),AV_OPT_TYPE_INT,    {.i64=15},                 0,       255,     V|F },
+    {"interp_end",          "point to end linear interpolation",      OFFSET(interp_end_param),  AV_OPT_TYPE_INT,    {.i64=240},                0,       255,     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" },
@@ -305,7 +307,7 @@ static int filter_slice16(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
     return 0;
 }
 
-static int blend_frames(AVFilterContext *ctx, float interpolate,
+static int blend_frames(AVFilterContext *ctx, int interpolate,
                         int src1, int src2)
 {
     FrameRateContext *s = ctx->priv;
@@ -326,7 +328,7 @@ static int blend_frames(AVFilterContext *ctx, float interpolate,
         ThreadData td;
         td.copy_src1 = s->srce[src1];
         td.copy_src2 = s->srce[src2];
-        td.src2_factor = fabsf(interpolate) * (1 << (s->bitdepth - 8));
+        td.src2_factor = FFABS(interpolate);
         td.src1_factor = s->max - td.src2_factor;
 
         // get work-space for output frame
@@ -347,7 +349,7 @@ static int process_work_frame(AVFilterContext *ctx, int stop)
 {
     FrameRateContext *s = ctx->priv;
     int64_t work_next_pts;
-    float interpolate;
+    int interpolate;
     int src1, src2;
 
     ff_dlog(ctx, "process_work_frame()\n");
@@ -390,8 +392,8 @@ static int process_work_frame(AVFilterContext *ctx, int stop)
     }
 
     // calculate interpolation
-    interpolate = ((s->pts - s->srce_pts_dest[s->crnt]) * 256.0 / s->average_srce_pts_dest_delta);
-    ff_dlog(ctx, "process_work_frame() interpolate:%f/256\n", interpolate);
+    interpolate = av_rescale(s->pts - s->srce_pts_dest[s->crnt], s->max, s->average_srce_pts_dest_delta);
+    ff_dlog(ctx, "process_work_frame() interpolate:%d/%d\n", interpolate, s->max);
     src1 = s->crnt;
     if (interpolate > s->interp_end) {
         ff_dlog(ctx, "process_work_frame() source is:NEXT\n");
@@ -572,6 +574,8 @@ static int config_input(AVFilterLink *inlink)
 
     s->bitdepth = pix_desc->comp[0].depth;
     s->vsub = pix_desc->log2_chroma_h;
+    s->interp_start = s->interp_start_param << (s->bitdepth - 8);
+    s->interp_end = s->interp_end_param << (s->bitdepth - 8);
 
     s->sad = av_pixelutils_get_sad_fn(3, 3, 2, s); // 8x8 both sources aligned
     if (!s->sad)
diff --git a/tests/ref/fate/filter-framerate-12bit-down b/tests/ref/fate/filter-framerate-12bit-down
index 0a9aea0ce1..49dcb1e5fa 100644
--- a/tests/ref/fate/filter-framerate-12bit-down
+++ b/tests/ref/fate/filter-framerate-12bit-down
@@ -6,50 +6,50 @@
 0,          0,          0,        1,   307200, 0xb49cf016
 0,          1,          1,        1,   307200, 0xc3be6971
 0,          2,          2,        1,   307200, 0x4d458da1
-0,          3,          3,        1,   307200, 0x35d4d8ea
-0,          4,          4,        1,   307200, 0x88f88697
+0,          3,          3,        1,   307200, 0xb49ed940
+0,          4,          4,        1,   307200, 0x1577849f
 0,          5,          5,        1,   307200, 0xaf71e7fc
 0,          6,          6,        1,   307200, 0x1290a487
 0,          7,          7,        1,   307200, 0xaf0cf5ee
-0,          8,          8,        1,   307200, 0x9fe73a9b
-0,          9,          9,        1,   307200, 0xb7965b77
+0,          8,          8,        1,   307200, 0x6ffb3abb
+0,          9,          9,        1,   307200, 0x9e65597e
 0,         10,         10,        1,   307200, 0x9f84df5d
 0,         11,         11,        1,   307200, 0xf60b8c87
 0,         12,         12,        1,   307200, 0xe2eac3a7
-0,         13,         13,        1,   307200, 0xefbbc67a
-0,         14,         14,        1,   307200, 0xb293001a
+0,         13,         13,        1,   307200, 0x2c4ac771
+0,         14,         14,        1,   307200, 0xf4d9003d
 0,         15,         15,        1,   307200, 0xab2162fc
 0,         16,         16,        1,   307200, 0xdc90848a
 0,         17,         17,        1,   307200, 0x29f79f4b
-0,         18,         18,        1,   307200, 0x62aee029
-0,         19,         19,        1,   307200, 0xcb6de0e9
+0,         18,         18,        1,   307200, 0x45b1e01b
+0,         19,         19,        1,   307200, 0x43baddc2
 0,         20,         20,        1,   307200, 0xf2b12fe5
 0,         21,         21,        1,   307200, 0x1de67e13
 0,         22,         22,        1,   307200, 0xfc1f7774
-0,         23,         23,        1,   307200, 0x707fe832
-0,         24,         24,        1,   307200, 0xe2dc0742
+0,         23,         23,        1,   307200, 0x5552e7f2
+0,         24,         24,        1,   307200, 0xb1d60366
 0,         25,         25,        1,   307200, 0x4693ab03
 0,         26,         26,        1,   307200, 0x7295ef7a
 0,         27,         27,        1,   307200, 0xf442a5df
-0,         28,         28,        1,   307200, 0x3019dbbc
-0,         29,         29,        1,   307200, 0xd82a394d
+0,         28,         28,        1,   307200, 0x01e0dbb8
+0,         29,         29,        1,   307200, 0xf10c3549
 0,         30,         30,        1,   307200, 0x8a512668
 0,         31,         31,        1,   307200, 0x69e7b43e
 0,         32,         32,        1,   307200, 0x6c5343ca
-0,         33,         33,        1,   307200, 0x8aac4531
-0,         34,         34,        1,   307200, 0x4b7f5b63
+0,         33,         33,        1,   307200, 0xf323456c
+0,         34,         34,        1,   307200, 0xeead5632
 0,         35,         35,        1,   307200, 0x4e24d659
 0,         36,         36,        1,   307200, 0x7a25b546
 0,         37,         37,        1,   307200, 0x9b7e8e8f
-0,         38,         38,        1,   307200, 0x94ec9d3d
-0,         39,         39,        1,   307200, 0x856ea560
+0,         38,         38,        1,   307200, 0x9d059d4c
+0,         39,         39,        1,   307200, 0x21c4a16f
 0,         40,         40,        1,   307200, 0xb6505ff0
 0,         41,         41,        1,   307200, 0x12562a42
 0,         42,         42,        1,   307200, 0x3335e451
-0,         43,         43,        1,   307200, 0x7f0374c9
-0,         44,         44,        1,   307200, 0x487e798a
+0,         43,         43,        1,   307200, 0x6f1274cf
+0,         44,         44,        1,   307200, 0xa52e71d2
 0,         45,         45,        1,   307200, 0x4fda2634
 0,         46,         46,        1,   307200, 0x5b48d624
 0,         47,         47,        1,   307200, 0xa9505af8
-0,         48,         48,        1,   307200, 0xce7248b5
-0,         49,         49,        1,   307200, 0x8fbc1bec
+0,         48,         48,        1,   307200, 0xc2624880
+0,         49,         49,        1,   307200, 0x4eb317a5
diff --git a/tests/ref/fate/filter-framerate-12bit-up b/tests/ref/fate/filter-framerate-12bit-up
index 8f5f95b275..686fe8e82b 100644
--- a/tests/ref/fate/filter-framerate-12bit-up
+++ b/tests/ref/fate/filter-framerate-12bit-up
@@ -4,61 +4,61 @@
 #dimensions 0: 320x240
 #sar 0: 1/1
 0,          0,          0,        1,   307200, 0xb49cf016
-0,          1,          1,        1,   307200, 0x59cb92c7
+0,          1,          1,        1,   307200, 0xbe4390ed
 0,          2,          2,        1,   307200, 0xe4ca172c
 0,          3,          3,        1,   307200, 0x5378b13c
-0,          4,          4,        1,   307200, 0x2a7d4840
+0,          4,          4,        1,   307200, 0xe742454c
 0,          5,          5,        1,   307200, 0x68f620cd
 0,          6,          6,        1,   307200, 0x83dbe321
-0,          7,          7,        1,   307200, 0xcd73c6ab
+0,          7,          7,        1,   307200, 0x7135c77d
 0,          8,          8,        1,   307200, 0xc69a864a
 0,          9,          9,        1,   307200, 0xc5c8b0f8
-0,         10,         10,        1,   307200, 0xf08a6033
+0,         10,         10,        1,   307200, 0xf6ee5d1c
 0,         11,         11,        1,   307200, 0xab36763c
 0,         12,         12,        1,   307200, 0xcba4c6bb
-0,         13,         13,        1,   307200, 0x8dabc7b5
+0,         13,         13,        1,   307200, 0xb379c679
 0,         14,         14,        1,   307200, 0x63339757
 0,         15,         15,        1,   307200, 0x4bdfd3ca
-0,         16,         16,        1,   307200, 0x699c9c83
+0,         16,         16,        1,   307200, 0x14e09691
 0,         17,         17,        1,   307200, 0x5dc7c711
 0,         18,         18,        1,   307200, 0xda8c6c41
-0,         19,         19,        1,   307200, 0xeb4ac99c
+0,         19,         19,        1,   307200, 0xe187c6b6
 0,         20,         20,        1,   307200, 0x5d8b76ab
 0,         21,         21,        1,   307200, 0xe2337c57
-0,         22,         22,        1,   307200, 0x84531dcf
+0,         22,         22,        1,   307200, 0x492117d7
 0,         23,         23,        1,   307200, 0xf0df5ea3
 0,         24,         24,        1,   307200, 0x4237e892
-0,         25,         25,        1,   307200, 0xc111a9eb
+0,         25,         25,        1,   307200, 0x4f61a7d7
 0,         26,         26,        1,   307200, 0x2ba55745
 0,         27,         27,        1,   307200, 0x0e058165
-0,         28,         28,        1,   307200, 0xd184f860
+0,         28,         28,        1,   307200, 0xe371f352
 0,         29,         29,        1,   307200, 0xab562bfe
 0,         30,         30,        1,   307200, 0x0b58bcf7
-0,         31,         31,        1,   307200, 0x044f4a16
+0,         31,         31,        1,   307200, 0xf1a04a1e
 0,         32,         32,        1,   307200, 0xb466f1d6
 0,         33,         33,        1,   307200, 0x3ed6b5d8
-0,         34,         34,        1,   307200, 0xb8b82049
+0,         34,         34,        1,   307200, 0x05091a43
 0,         35,         35,        1,   307200, 0xbfb20efc
 0,         36,         36,        1,   307200, 0xbd67248a
-0,         37,         37,        1,   307200, 0x76e11928
+0,         37,         37,        1,   307200, 0x58001b29
 0,         38,         38,        1,   307200, 0x6ec5bbb1
 0,         39,         39,        1,   307200, 0x0e4455cd
-0,         40,         40,        1,   307200, 0x5ccf33fb
+0,         40,         40,        1,   307200, 0x5c2c3213
 0,         41,         41,        1,   307200, 0x976f6900
 0,         42,         42,        1,   307200, 0x58adad3f
-0,         43,         43,        1,   307200, 0x1f791403
+0,         43,         43,        1,   307200, 0x8dbb14f0
 0,         44,         44,        1,   307200, 0x49163226
 0,         45,         45,        1,   307200, 0xaac8e1ca
-0,         46,         46,        1,   307200, 0x7fe784f7
+0,         46,         46,        1,   307200, 0x07cc8404
 0,         47,         47,        1,   307200, 0xbf85c994
 0,         48,         48,        1,   307200, 0x22ed5b5a
-0,         49,         49,        1,   307200, 0xdbeee1f3
+0,         49,         49,        1,   307200, 0x1bf7df1e
 0,         50,         50,        1,   307200, 0x3a21b4d2
 0,         51,         51,        1,   307200, 0xbd5edb2d
-0,         52,         52,        1,   307200, 0xc66d8b27
+0,         52,         52,        1,   307200, 0x336a8437
 0,         53,         53,        1,   307200, 0x02c7e528
 0,         54,         54,        1,   307200, 0xba073e6f
-0,         55,         55,        1,   307200, 0xf745ded7
+0,         55,         55,        1,   307200, 0x9e25ddfe
 0,         56,         56,        1,   307200, 0x8cf55128
 0,         57,         57,        1,   307200, 0x4e740b42
-0,         58,         58,        1,   307200, 0x7906723a
+0,         58,         58,        1,   307200, 0x8e7e705c
diff --git a/tests/ref/fate/filter-framerate-up b/tests/ref/fate/filter-framerate-up
index b2af9cb879..15bf6d815b 100644
--- a/tests/ref/fate/filter-framerate-up
+++ b/tests/ref/fate/filter-framerate-up
@@ -6,10 +6,10 @@
 0,          0,          0,        1,   115200, 0x3744b3ed
 0,          1,          1,        1,   115200, 0xc44bdc65
 0,          2,          2,        1,   115200, 0xa17f0d74
-0,          3,          3,        1,   115200, 0xb0c83274
+0,          3,          3,        1,   115200, 0xd72532a9
 0,          4,          4,        1,   115200, 0x232d6368
 0,          5,          5,        1,   115200, 0x6e318ba0
 0,          6,          6,        1,   115200, 0x247e846e
 0,          7,          7,        1,   115200, 0x89e27599
-0,          8,          8,        1,   115200, 0x31c5704e
+0,          8,          8,        1,   115200, 0x68536eac
 0,          9,          9,        1,   115200, 0x97e45fec
-- 
2.13.6



More information about the ffmpeg-devel mailing list