diff mbox

[FFmpeg-devel,v2,2/3] avfilter/vf_framerate: if metadata lavfi.scd.mafd exists, we'll use it first

Message ID 20190929132515.4093-2-lance.lmwang@gmail.com
State Superseded
Headers show

Commit Message

Lance Wang Sept. 29, 2019, 1:25 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/vf_framerate.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Paul B Mahol Oct. 8, 2019, 9:17 a.m. UTC | #1
On 9/29/19, lance.lmwang@gmail.com <lance.lmwang@gmail.com> wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/vf_framerate.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c
> index 06e463e4d7..d7ae1ae850 100644
> --- a/libavfilter/vf_framerate.c
> +++ b/libavfilter/vf_framerate.c
> @@ -71,13 +71,20 @@ static double get_scene_score(AVFilterContext *ctx,
> AVFrame *crnt, AVFrame *next
>
>      if (crnt->height == next->height &&
>          crnt->width  == next->width) {
> +        AVDictionaryEntry *e_mafd = NULL;
>          uint64_t sad;
> -        double mafd, diff;
> +        double mafd = HUGE_VAL, diff;
> +        char *tail = NULL;
>
>          ff_dlog(ctx, "get_scene_score() process\n");
> -        s->sad(crnt->data[0], crnt->linesize[0], next->data[0],
> next->linesize[0], crnt->width, crnt->height, &sad);
> -        emms_c();
> -        mafd = (double)sad * 100.0 / (crnt->width * crnt->height) / (1 <<
> s->bitdepth);

Please use av_rescale_q()

> +        e_mafd = av_dict_get(next->metadata, "lavfi.scd.mafd", NULL,
> AV_DICT_MATCH_CASE);
> +        if (e_mafd)
> +            mafd = strtod(e_mafd->value, &tail);
> +        if (*tail || mafd == HUGE_VAL) {
> +            s->sad(crnt->data[0], crnt->linesize[0], next->data[0],
> next->linesize[0], crnt->width, crnt->height, &sad);
> +            emms_c();
> +            mafd = (double)sad * 100.0 / (crnt->width * crnt->height) / (1
> << s->bitdepth);

Ditto.

> +        }
>          diff = fabs(mafd - s->prev_mafd);
>          ret  = av_clipf(FFMIN(mafd, diff), 0, 100.0);
>          s->prev_mafd = mafd;
> --
> 2.21.0
>
> _______________________________________________
> 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

Patch

diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c
index 06e463e4d7..d7ae1ae850 100644
--- a/libavfilter/vf_framerate.c
+++ b/libavfilter/vf_framerate.c
@@ -71,13 +71,20 @@  static double get_scene_score(AVFilterContext *ctx, AVFrame *crnt, AVFrame *next
 
     if (crnt->height == next->height &&
         crnt->width  == next->width) {
+        AVDictionaryEntry *e_mafd = NULL;
         uint64_t sad;
-        double mafd, diff;
+        double mafd = HUGE_VAL, diff;
+        char *tail = NULL;
 
         ff_dlog(ctx, "get_scene_score() process\n");
-        s->sad(crnt->data[0], crnt->linesize[0], next->data[0], next->linesize[0], crnt->width, crnt->height, &sad);
-        emms_c();
-        mafd = (double)sad * 100.0 / (crnt->width * crnt->height) / (1 << s->bitdepth);
+        e_mafd = av_dict_get(next->metadata, "lavfi.scd.mafd", NULL, AV_DICT_MATCH_CASE);
+        if (e_mafd)
+            mafd = strtod(e_mafd->value, &tail);
+        if (*tail || mafd == HUGE_VAL) {
+            s->sad(crnt->data[0], crnt->linesize[0], next->data[0], next->linesize[0], crnt->width, crnt->height, &sad);
+            emms_c();
+            mafd = (double)sad * 100.0 / (crnt->width * crnt->height) / (1 << s->bitdepth);
+        }
         diff = fabs(mafd - s->prev_mafd);
         ret  = av_clipf(FFMIN(mafd, diff), 0, 100.0);
         s->prev_mafd = mafd;