diff mbox series

[FFmpeg-devel,v6,3/4] avfilter/vf_minterpolate: if metadata lavfi.scd.mafd exists, we'll use it first

Message ID 1589453053-8013-3-git-send-email-lance.lmwang@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,v6,1/4] avfilter/vf_scdet: add filter to detect scene change | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Lance Wang May 14, 2020, 10:44 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/vf_minterpolate.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Marton Balint May 14, 2020, 6:43 p.m. UTC | #1
On Thu, 14 May 2020, lance.lmwang@gmail.com wrote:

> From: Limin Wang <lance.lmwang@gmail.com>
>
> Reviewed-by: Paul B Mahol <onemda@gmail.com>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavfilter/vf_minterpolate.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/libavfilter/vf_minterpolate.c b/libavfilter/vf_minterpolate.c
> index b0bb238..db3d7d4 100644
> --- a/libavfilter/vf_minterpolate.c
> +++ b/libavfilter/vf_minterpolate.c
> @@ -832,11 +832,19 @@ static int detect_scene_change(MIContext *mi_ctx)
>     ptrdiff_t linesize2 = mi_ctx->frames[2].avf->linesize[0];
>
>     if (mi_ctx->scd_method == SCD_METHOD_FDIFF) {
> -        double ret = 0, mafd, diff;
> +        double ret = 0, mafd = HUGE_VAL, diff;
>         uint64_t sad;
> -        mi_ctx->sad(p1, linesize1, p2, linesize2, me_ctx->width, me_ctx->height, &sad);
> -        emms_c();
> -        mafd = (double) sad / (me_ctx->height * me_ctx->width * 3);
> +        AVDictionaryEntry *e_mafd = NULL;
> +        char *tail = NULL;
> +
> +        e_mafd = av_dict_get(mi_ctx->frames[2].avf->metadata, "lavfi.scd.mafd", NULL, AV_DICT_MATCH_CASE);
> +        if (e_mafd)
> +            mafd = strtod(e_mafd->value, &tail);
> +        if (*tail || mafd == HUGE_VAL) {
> +            mi_ctx->sad(p1, linesize1, p2, linesize2, me_ctx->width, me_ctx->height, &sad);
> +            emms_c();
> +            mafd = (double) sad / (me_ctx->height * me_ctx->width * 3);
> +        }

Same comments as with vf_framerate.

Regards,
Marton

>         diff = fabs(mafd - mi_ctx->prev_mafd);
>         ret  = av_clipf(FFMIN(mafd, diff), 0, 100.0);
>         mi_ctx->prev_mafd = mafd;
> -- 
> 1.8.3.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavfilter/vf_minterpolate.c b/libavfilter/vf_minterpolate.c
index b0bb238..db3d7d4 100644
--- a/libavfilter/vf_minterpolate.c
+++ b/libavfilter/vf_minterpolate.c
@@ -832,11 +832,19 @@  static int detect_scene_change(MIContext *mi_ctx)
     ptrdiff_t linesize2 = mi_ctx->frames[2].avf->linesize[0];
 
     if (mi_ctx->scd_method == SCD_METHOD_FDIFF) {
-        double ret = 0, mafd, diff;
+        double ret = 0, mafd = HUGE_VAL, diff;
         uint64_t sad;
-        mi_ctx->sad(p1, linesize1, p2, linesize2, me_ctx->width, me_ctx->height, &sad);
-        emms_c();
-        mafd = (double) sad / (me_ctx->height * me_ctx->width * 3);
+        AVDictionaryEntry *e_mafd = NULL;
+        char *tail = NULL;
+
+        e_mafd = av_dict_get(mi_ctx->frames[2].avf->metadata, "lavfi.scd.mafd", NULL, AV_DICT_MATCH_CASE);
+        if (e_mafd)
+            mafd = strtod(e_mafd->value, &tail);
+        if (*tail || mafd == HUGE_VAL) {
+            mi_ctx->sad(p1, linesize1, p2, linesize2, me_ctx->width, me_ctx->height, &sad);
+            emms_c();
+            mafd = (double) sad / (me_ctx->height * me_ctx->width * 3);
+        }
         diff = fabs(mafd - mi_ctx->prev_mafd);
         ret  = av_clipf(FFMIN(mafd, diff), 0, 100.0);
         mi_ctx->prev_mafd = mafd;