summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2018-01-15 22:19:46 +0100
committerMarton Balint <cus@passwd.hu>2018-01-28 18:50:50 +0100
commit2cbe6bac0337939f023bd1c37a9c455e6d535f3a (patch)
treeb648ae97976e20afcf2351a14cff180fd3e07d61
parent1b6ffe9aca1bdcc0bf2249c8c1314faa1ab0dae6 (diff)
downloadffmpeg-streaming-2cbe6bac0337939f023bd1c37a9c455e6d535f3a.zip
ffmpeg-streaming-2cbe6bac0337939f023bd1c37a9c455e6d535f3a.tar.gz
avfilter/vf_framerate: change blend factor precision
This is done mainly in preparation for the SIMD patches. - for the 8-bit input, decrease the blend factor precision to 7-bit. - for the 16-bit input, increase the blend factor precision to 15-bit. - make sure the blend functions are not called with 0 or maximum blending factors, because we don't want the signed factor integers to overflow. Fate test changes are due to different rounding. Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r--libavfilter/vf_framerate.c54
-rw-r--r--tests/ref/fate/filter-framerate-12bit-down80
-rw-r--r--tests/ref/fate/filter-framerate-12bit-up78
-rw-r--r--tests/ref/fate/filter-framerate-up8
4 files changed, 109 insertions, 111 deletions
diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c
index 2a6d692..8119fe2 100644
--- a/libavfilter/vf_framerate.c
+++ b/libavfilter/vf_framerate.c
@@ -43,7 +43,10 @@
const uint8_t *src2, ptrdiff_t src2_linesize, \
uint8_t *dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
- int factor1, int factor2, int half, int shift
+ int factor1, int factor2, int half
+
+#define BLEND_FACTOR_DEPTH8 7
+#define BLEND_FACTOR_DEPTH16 15
typedef void (*blend_func)(BLEND_FUNC_PARAMS);
@@ -53,10 +56,8 @@ 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 (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 interp_start; ///< start of range to apply linear interpolation
+ int interp_end; ///< end of range to apply linear interpolation
int line_size[4]; ///< bytes of pixel data per line for each plane
int vsub;
@@ -67,7 +68,7 @@ typedef struct FrameRateContext {
av_pixelutils_sad_fn sad; ///< Sum of the absolute difference function (scene detect only)
double prev_mafd; ///< previous MAFD (scene detect only)
- int max;
+ int blend_factor_max;
int bitdepth;
AVFrame *work;
@@ -92,8 +93,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_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 },
+ {"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=8.2}, 0, INT_MAX, V|F },
{"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, INT_MAX, V|F, "flags" },
@@ -210,7 +211,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
cpy_src2_data, cpy_src2_line_size,
cpy_dst_data, cpy_dst_line_size,
cpy_line_width, end - start,
- src1_factor, src2_factor, s->max / 2, s->bitdepth);
+ src1_factor, src2_factor, s->blend_factor_max >> 1);
}
return 0;
@@ -235,7 +236,7 @@ static int blend_frames(AVFilterContext *ctx, int interpolate)
td.copy_src1 = s->f0;
td.copy_src2 = s->f1;
td.src2_factor = interpolate;
- td.src1_factor = s->max - td.src2_factor;
+ td.src1_factor = s->blend_factor_max - td.src2_factor;
// get work-space for output frame
s->work = ff_get_video_buffer(outlink, outlink->w, outlink->h);
@@ -255,7 +256,7 @@ static int process_work_frame(AVFilterContext *ctx)
{
FrameRateContext *s = ctx->priv;
int64_t work_pts;
- int interpolate;
+ int64_t interpolate, interpolate8;
int ret;
if (!s->f1)
@@ -274,18 +275,19 @@ static int process_work_frame(AVFilterContext *ctx)
if (work_pts >= s->pts1 + s->delta && s->flush)
return 0;
- interpolate = av_rescale(work_pts - s->pts0, s->max, s->delta);
- ff_dlog(ctx, "process_work_frame() interpolate:%d/%d\n", interpolate, s->max);
- if (interpolate > s->interp_end) {
+ interpolate = av_rescale(work_pts - s->pts0, s->blend_factor_max, s->delta);
+ interpolate8 = av_rescale(work_pts - s->pts0, 256, s->delta);
+ ff_dlog(ctx, "process_work_frame() interpolate: %"PRId64"/256\n", interpolate8);
+ if (interpolate >= s->blend_factor_max || interpolate8 > s->interp_end) {
s->work = av_frame_clone(s->f1);
- } else if (interpolate < s->interp_start) {
+ } else if (interpolate <= 0 || interpolate8 < s->interp_start) {
s->work = av_frame_clone(s->f0);
} else {
ret = blend_frames(ctx, interpolate);
if (ret < 0)
return ret;
if (ret == 0)
- s->work = av_frame_clone(interpolate > (s->max >> 1) ? s->f1 : s->f0);
+ s->work = av_frame_clone(interpolate > (s->blend_factor_max >> 1) ? s->f1 : s->f0);
}
}
@@ -337,12 +339,8 @@ static void blend_frames_c(BLEND_FUNC_PARAMS)
{
int line, pixel;
for (line = 0; line < height; line++) {
- for (pixel = 0; pixel < width; pixel++) {
- // integer version of (src1 * factor1) + (src2 * factor2) + 0.5
- // 0.5 is for rounding
- // 128 is the integer representation of 0.5 << 8
- dst[pixel] = ((src1[pixel] * factor1) + (src2[pixel] * factor2) + 128) >> 8;
- }
+ for (pixel = 0; pixel < width; pixel++)
+ dst[pixel] = ((src1[pixel] * factor1) + (src2[pixel] * factor2) + half) >> BLEND_FACTOR_DEPTH8;
src1 += src1_linesize;
src2 += src2_linesize;
dst += dst_linesize;
@@ -361,7 +359,7 @@ static void blend_frames16_c(BLEND_FUNC_PARAMS)
dst_linesize /= 2;
for (line = 0; line < height; line++) {
for (pixel = 0; pixel < width; pixel++)
- dstw[pixel] = ((src1w[pixel] * factor1) + (src2w[pixel] * factor2) + half) >> shift;
+ dstw[pixel] = ((src1w[pixel] * factor1) + (src2w[pixel] * factor2) + half) >> BLEND_FACTOR_DEPTH16;
src1w += src1_linesize;
src2w += src2_linesize;
dstw += dst_linesize;
@@ -382,8 +380,6 @@ 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)
@@ -391,11 +387,13 @@ static int config_input(AVFilterLink *inlink)
s->srce_time_base = inlink->time_base;
- s->max = 1 << (s->bitdepth);
- if (s->bitdepth == 8)
+ if (s->bitdepth == 8) {
+ s->blend_factor_max = 1 << BLEND_FACTOR_DEPTH8;
s->blend = blend_frames_c;
- else
+ } else {
+ s->blend_factor_max = 1 << BLEND_FACTOR_DEPTH16;
s->blend = blend_frames16_c;
+ }
return 0;
}
diff --git a/tests/ref/fate/filter-framerate-12bit-down b/tests/ref/fate/filter-framerate-12bit-down
index 49dcb1e..25a3c0a 100644
--- a/tests/ref/fate/filter-framerate-12bit-down
+++ b/tests/ref/fate/filter-framerate-12bit-down
@@ -4,52 +4,52 @@
#dimensions 0: 320x240
#sar 0: 1/1
0, 0, 0, 1, 307200, 0xb49cf016
-0, 1, 1, 1, 307200, 0xc3be6971
-0, 2, 2, 1, 307200, 0x4d458da1
-0, 3, 3, 1, 307200, 0xb49ed940
-0, 4, 4, 1, 307200, 0x1577849f
+0, 1, 1, 1, 307200, 0xbccf696d
+0, 2, 2, 1, 307200, 0x709c8dd1
+0, 3, 3, 1, 307200, 0xb948d907
+0, 4, 4, 1, 307200, 0x850f849a
0, 5, 5, 1, 307200, 0xaf71e7fc
-0, 6, 6, 1, 307200, 0x1290a487
-0, 7, 7, 1, 307200, 0xaf0cf5ee
-0, 8, 8, 1, 307200, 0x6ffb3abb
-0, 9, 9, 1, 307200, 0x9e65597e
+0, 6, 6, 1, 307200, 0x0a1ba486
+0, 7, 7, 1, 307200, 0x0601f62a
+0, 8, 8, 1, 307200, 0x2c6d3a59
+0, 9, 9, 1, 307200, 0xed03597b
0, 10, 10, 1, 307200, 0x9f84df5d
-0, 11, 11, 1, 307200, 0xf60b8c87
-0, 12, 12, 1, 307200, 0xe2eac3a7
-0, 13, 13, 1, 307200, 0x2c4ac771
-0, 14, 14, 1, 307200, 0xf4d9003d
+0, 11, 11, 1, 307200, 0x9fbe8c84
+0, 12, 12, 1, 307200, 0x8f7bc394
+0, 13, 13, 1, 307200, 0x5113c787
+0, 14, 14, 1, 307200, 0x41e8002f
0, 15, 15, 1, 307200, 0xab2162fc
-0, 16, 16, 1, 307200, 0xdc90848a
-0, 17, 17, 1, 307200, 0x29f79f4b
-0, 18, 18, 1, 307200, 0x45b1e01b
-0, 19, 19, 1, 307200, 0x43baddc2
+0, 16, 16, 1, 307200, 0xbf8f847c
+0, 17, 17, 1, 307200, 0x832d9ef7
+0, 18, 18, 1, 307200, 0xd2f5e043
+0, 19, 19, 1, 307200, 0xceeaddb8
0, 20, 20, 1, 307200, 0xf2b12fe5
-0, 21, 21, 1, 307200, 0x1de67e13
-0, 22, 22, 1, 307200, 0xfc1f7774
-0, 23, 23, 1, 307200, 0x5552e7f2
-0, 24, 24, 1, 307200, 0xb1d60366
+0, 21, 21, 1, 307200, 0xf3477e11
+0, 22, 22, 1, 307200, 0xdf387773
+0, 23, 23, 1, 307200, 0x273be7e2
+0, 24, 24, 1, 307200, 0x68cd0360
0, 25, 25, 1, 307200, 0x4693ab03
-0, 26, 26, 1, 307200, 0x7295ef7a
-0, 27, 27, 1, 307200, 0xf442a5df
-0, 28, 28, 1, 307200, 0x01e0dbb8
-0, 29, 29, 1, 307200, 0xf10c3549
+0, 26, 26, 1, 307200, 0xe2baef73
+0, 27, 27, 1, 307200, 0x0c9fa60a
+0, 28, 28, 1, 307200, 0x6e4ddbc5
+0, 29, 29, 1, 307200, 0xd1b2353c
0, 30, 30, 1, 307200, 0x8a512668
-0, 31, 31, 1, 307200, 0x69e7b43e
-0, 32, 32, 1, 307200, 0x6c5343ca
-0, 33, 33, 1, 307200, 0xf323456c
-0, 34, 34, 1, 307200, 0xeead5632
+0, 31, 31, 1, 307200, 0x7224b439
+0, 32, 32, 1, 307200, 0x7a9243e2
+0, 33, 33, 1, 307200, 0x9a7e4553
+0, 34, 34, 1, 307200, 0x4d795626
0, 35, 35, 1, 307200, 0x4e24d659
-0, 36, 36, 1, 307200, 0x7a25b546
-0, 37, 37, 1, 307200, 0x9b7e8e8f
-0, 38, 38, 1, 307200, 0x9d059d4c
-0, 39, 39, 1, 307200, 0x21c4a16f
+0, 36, 36, 1, 307200, 0xa230b54b
+0, 37, 37, 1, 307200, 0x14598ea5
+0, 38, 38, 1, 307200, 0x21619cf3
+0, 39, 39, 1, 307200, 0x5220a167
0, 40, 40, 1, 307200, 0xb6505ff0
-0, 41, 41, 1, 307200, 0x12562a42
-0, 42, 42, 1, 307200, 0x3335e451
-0, 43, 43, 1, 307200, 0x6f1274cf
-0, 44, 44, 1, 307200, 0xa52e71d2
+0, 41, 41, 1, 307200, 0x0a482a3d
+0, 42, 42, 1, 307200, 0x6bdce40c
+0, 43, 43, 1, 307200, 0x3c6074f3
+0, 44, 44, 1, 307200, 0x369c71c8
0, 45, 45, 1, 307200, 0x4fda2634
-0, 46, 46, 1, 307200, 0x5b48d624
-0, 47, 47, 1, 307200, 0xa9505af8
-0, 48, 48, 1, 307200, 0xc2624880
-0, 49, 49, 1, 307200, 0x4eb317a5
+0, 46, 46, 1, 307200, 0x4df2d619
+0, 47, 47, 1, 307200, 0x21205aab
+0, 48, 48, 1, 307200, 0xe00f48c2
+0, 49, 49, 1, 307200, 0xe3b11798
diff --git a/tests/ref/fate/filter-framerate-12bit-up b/tests/ref/fate/filter-framerate-12bit-up
index ef709a8..15bf9be 100644
--- a/tests/ref/fate/filter-framerate-12bit-up
+++ b/tests/ref/fate/filter-framerate-12bit-up
@@ -4,62 +4,62 @@
#dimensions 0: 320x240
#sar 0: 1/1
0, 0, 0, 1, 307200, 0xb49cf016
-0, 1, 1, 1, 307200, 0xbe4390ed
-0, 2, 2, 1, 307200, 0xe4ca172c
+0, 1, 1, 1, 307200, 0x95d191b2
+0, 2, 2, 1, 307200, 0x20e5173b
0, 3, 3, 1, 307200, 0x5378b13c
-0, 4, 4, 1, 307200, 0xe742454c
-0, 5, 5, 1, 307200, 0x68f620cd
+0, 4, 4, 1, 307200, 0x3e304543
+0, 5, 5, 1, 307200, 0x2f131cdb
0, 6, 6, 1, 307200, 0x83dbe321
-0, 7, 7, 1, 307200, 0x7135c77d
-0, 8, 8, 1, 307200, 0xc69a864a
+0, 7, 7, 1, 307200, 0xb81fc682
+0, 8, 8, 1, 307200, 0xb32a8644
0, 9, 9, 1, 307200, 0xc5c8b0f8
-0, 10, 10, 1, 307200, 0xf6ee5d1c
-0, 11, 11, 1, 307200, 0xab36763c
+0, 10, 10, 1, 307200, 0x27945d0a
+0, 11, 11, 1, 307200, 0x444c7640
0, 12, 12, 1, 307200, 0xcba4c6bb
-0, 13, 13, 1, 307200, 0xb379c679
-0, 14, 14, 1, 307200, 0x63339757
+0, 13, 13, 1, 307200, 0xf923c7a3
+0, 14, 14, 1, 307200, 0x88149757
0, 15, 15, 1, 307200, 0x4bdfd3ca
-0, 16, 16, 1, 307200, 0x14e09691
-0, 17, 17, 1, 307200, 0x5dc7c711
+0, 16, 16, 1, 307200, 0x1c279695
+0, 17, 17, 1, 307200, 0x634cc809
0, 18, 18, 1, 307200, 0xda8c6c41
-0, 19, 19, 1, 307200, 0xe187c6b6
-0, 20, 20, 1, 307200, 0x5d8b76ab
+0, 19, 19, 1, 307200, 0x2136c986
+0, 20, 20, 1, 307200, 0x457576a8
0, 21, 21, 1, 307200, 0xe2337c57
-0, 22, 22, 1, 307200, 0x492117d7
-0, 23, 23, 1, 307200, 0xf0df5ea3
+0, 22, 22, 1, 307200, 0x8ed517c9
+0, 23, 23, 1, 307200, 0x4fd35f99
0, 24, 24, 1, 307200, 0x4237e892
-0, 25, 25, 1, 307200, 0x4f61a7d7
-0, 26, 26, 1, 307200, 0x2ba55745
+0, 25, 25, 1, 307200, 0x1383a9d8
+0, 26, 26, 1, 307200, 0xc7195735
0, 27, 27, 1, 307200, 0x0e058165
-0, 28, 28, 1, 307200, 0xe371f352
-0, 29, 29, 1, 307200, 0xab562bfe
+0, 28, 28, 1, 307200, 0x0b81f345
+0, 29, 29, 1, 307200, 0x2ddf2f0a
0, 30, 30, 1, 307200, 0x0b58bcf7
-0, 31, 31, 1, 307200, 0xf1a04a1e
-0, 32, 32, 1, 307200, 0xb466f1d6
+0, 31, 31, 1, 307200, 0x1b684a1d
+0, 32, 32, 1, 307200, 0x1e44f1cf
0, 33, 33, 1, 307200, 0x3ed6b5d8
-0, 34, 34, 1, 307200, 0x05091a43
-0, 35, 35, 1, 307200, 0xbfb20efc
+0, 34, 34, 1, 307200, 0x00881a40
+0, 35, 35, 1, 307200, 0x2c3d1406
0, 36, 36, 1, 307200, 0xbd67248a
-0, 37, 37, 1, 307200, 0x58001b29
-0, 38, 38, 1, 307200, 0x6ec5bbb1
+0, 37, 37, 1, 307200, 0x46261913
+0, 38, 38, 1, 307200, 0xe5b2bbaa
0, 39, 39, 1, 307200, 0x0e4455cd
-0, 40, 40, 1, 307200, 0x5c2c3213
-0, 41, 41, 1, 307200, 0x976f6900
+0, 40, 40, 1, 307200, 0xb4943212
+0, 41, 41, 1, 307200, 0xf96b6808
0, 42, 42, 1, 307200, 0x58adad3f
-0, 43, 43, 1, 307200, 0x8dbb14f0
-0, 44, 44, 1, 307200, 0x49163226
+0, 43, 43, 1, 307200, 0x978413f0
+0, 44, 44, 1, 307200, 0x0037320a
0, 45, 45, 1, 307200, 0xaac8e1ca
-0, 46, 46, 1, 307200, 0x07cc8404
-0, 47, 47, 1, 307200, 0xbf85c994
+0, 46, 46, 1, 307200, 0xc3578407
+0, 47, 47, 1, 307200, 0xfc29c675
0, 48, 48, 1, 307200, 0x22ed5b5a
-0, 49, 49, 1, 307200, 0x1bf7df1e
-0, 50, 50, 1, 307200, 0x3a21b4d2
+0, 49, 49, 1, 307200, 0x6d58e21e
+0, 50, 50, 1, 307200, 0xbf62b4c3
0, 51, 51, 1, 307200, 0xbd5edb2d
-0, 52, 52, 1, 307200, 0x336a8437
-0, 53, 53, 1, 307200, 0x02c7e528
+0, 52, 52, 1, 307200, 0x55528432
+0, 53, 53, 1, 307200, 0xa3f1e514
0, 54, 54, 1, 307200, 0xba073e6f
-0, 55, 55, 1, 307200, 0x9e25ddfe
-0, 56, 56, 1, 307200, 0x8cf55128
+0, 55, 55, 1, 307200, 0x29b8df00
+0, 56, 56, 1, 307200, 0x1517512b
0, 57, 57, 1, 307200, 0x4e740b42
-0, 58, 58, 1, 307200, 0x8e7e705c
+0, 58, 58, 1, 307200, 0xbd6b7053
0, 59, 59, 1, 307200, 0xe73f29ef
diff --git a/tests/ref/fate/filter-framerate-up b/tests/ref/fate/filter-framerate-up
index 15bf6d8..a276bf6 100644
--- a/tests/ref/fate/filter-framerate-up
+++ b/tests/ref/fate/filter-framerate-up
@@ -4,12 +4,12 @@
#dimensions 0: 320x240
#sar 0: 1/1
0, 0, 0, 1, 115200, 0x3744b3ed
-0, 1, 1, 1, 115200, 0xc44bdc65
+0, 1, 1, 1, 115200, 0xec1fdfa0
0, 2, 2, 1, 115200, 0xa17f0d74
0, 3, 3, 1, 115200, 0xd72532a9
-0, 4, 4, 1, 115200, 0x232d6368
+0, 4, 4, 1, 115200, 0x032e60f8
0, 5, 5, 1, 115200, 0x6e318ba0
-0, 6, 6, 1, 115200, 0x247e846e
+0, 6, 6, 1, 115200, 0x76018292
0, 7, 7, 1, 115200, 0x89e27599
0, 8, 8, 1, 115200, 0x68536eac
-0, 9, 9, 1, 115200, 0x97e45fec
+0, 9, 9, 1, 115200, 0xc3ac62a8
OpenPOWER on IntegriCloud