From patchwork Sat Jul 13 15:15:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13929 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 99100449866 for ; Sat, 13 Jul 2019 18:21:12 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 721A768ABB3; Sat, 13 Jul 2019 18:21:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7154068A77D for ; Sat, 13 Jul 2019 18:21:06 +0300 (EEST) Received: by mail-pl1-f195.google.com with SMTP id k8so6211757plt.3 for ; Sat, 13 Jul 2019 08:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=1jDoDVRnXJfCH6kfYoWfJfh7fXNI6BS8YEEhPIFQT4s=; b=R4vZV4v7DFJfyM0KW0AGBysfVYT0qvV7OcgHMmyaotOahUzwd7Kx00lAJU70nGx/6n DvLAhS1mbNyX6B1kIpACpkXNs3Er1zAvpSCibi0jITMeTLonvzUtpq4REeKVDQ8jGV72 1eEn3F0IK46rjOY9Og13kgUuPIjc3by9gRAtzgLfqWV0GDzP7IpbbI45wueqQ5k/Rsff Xidc2eFLEHTMnBogf78M+LV8WaLCNQ02IDSTqB0Fjm0SDZJy3GSkaTDG3FIXFqVjBqaU 1hgEzALB0ck2uwndmFXEgKXHV1mHEGGjEer7D0ShlpAXhuaxzeWy7cjI6IQBePJY7yqN zxCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1jDoDVRnXJfCH6kfYoWfJfh7fXNI6BS8YEEhPIFQT4s=; b=lOwhDLjzHkuN56OKf+KNkZz9ffJCQJULFgWRB+70ThyTxWvWsiUybw+67s+icBbs0z m/o0DxBQ1JbiP0F5v+7Ra414A73PiQQ+AA00S3WxmtFV8k4PmtT4aJfZ1tFWe2bJUS4F jdu9wlLu/QydYPXB6OCDAxYslgNEAqHFInQmz05eS4t/CJaLqxd2ThUh7KYHcygaYHuC ge9grvFWjAv4vFJv74V6765Tqwj1MGQOlMjVAsKfWnoD+Z2uvGHHhyCnVKtogiegkyxy ADF38m94Fxz84zg1ZEl8/qp7dh/q7k5cPO5/xEWkkOvmeV5oMoKjWa464St1iskrowXm 080A== X-Gm-Message-State: APjAAAWIyfAYvEsx9rzhiWrVgWakXdCDWR1LTobzXaQKl/3nrojVWh4N LQ9kImwGfbGHqnUN9qnat7p8eSRA X-Google-Smtp-Source: APXvYqzX6qkZjlOgybbXErE2jF0Lr4NUzLbaAtKCwU+Vl/Hgwn6jU+4L3w+Q1rYOavg+CbsCH3SNdQ== X-Received: by 2002:a17:902:aa03:: with SMTP id be3mr18153438plb.240.1563030914521; Sat, 13 Jul 2019 08:15:14 -0700 (PDT) Received: from izj6c97garwn1o4y2zidq0z.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id x26sm16162050pfq.69.2019.07.13.08.15.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Jul 2019 08:15:13 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Jul 2019 23:15:09 +0800 Message-Id: <1563030909-17535-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH] lavf/vf_freezedetect: improve for the freeze frame detection X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang I have samples failed to detect the freeze frame with the default -60dB noise(-40dB is OK to detect), after apply the patch, it's ok to detect. I run the testing with fate-suite sample for your testing: old: no freeze frame detect. with the patch: ./ffmpeg -i fate-suite/svq3/Vertical400kbit.sorenson3.mov -vf freezedetect=n=-60dB -an -f null - [freezedetect @ 0x7fe18a604900] lavfi.freezedetect.freeze_start: 38.7667 [freezedetect @ 0x7fe18a604900] lavfi.freezedetect.freeze_duration: 2.5 [freezedetect @ 0x7fe18a604900] lavfi.freezedetect.freeze_end: 41.2667 [freezedetect @ 0x7fe18a604900] lavfi.freezedetect.freeze_start: 41.2667 Have run make fate testing although haven't find any freezedetect checking for the fate. Signed-off-by: Limin Wang --- libavfilter/vf_freezedetect.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libavfilter/vf_freezedetect.c b/libavfilter/vf_freezedetect.c index cc086af..0288fb0 100644 --- a/libavfilter/vf_freezedetect.c +++ b/libavfilter/vf_freezedetect.c @@ -38,7 +38,9 @@ typedef struct FreezeDetectContext { ptrdiff_t height[4]; ff_scene_sad_fn sad; int bitdepth; + int nb_planes; AVFrame *reference_frame; + double prev_mafd; int64_t n; int64_t reference_n; int frozen; @@ -102,13 +104,15 @@ static int config_input(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; FreezeDetectContext *s = ctx->priv; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); + int vsub = pix_desc->log2_chroma_h; s->bitdepth = pix_desc->comp[0].depth; + s->nb_planes = av_pix_fmt_count_planes(inlink->format); - for (int plane = 0; plane < 4; plane++) { + for (int plane = 0; plane < s->nb_planes; plane++) { ptrdiff_t line_size = av_image_get_linesize(inlink->format, inlink->w, plane); - s->width[plane] = line_size >> (s->bitdepth > 8); - s->height[plane] = inlink->h >> ((plane == 1 || plane == 2) ? pix_desc->log2_chroma_h : 0); + s->width[plane] = line_size; + s->height[plane] = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(inlink->h, vsub) : inlink->h; } s->sad = ff_scene_sad_get_fn(s->bitdepth == 8 ? 8 : 16); @@ -129,7 +133,9 @@ static int is_frozen(FreezeDetectContext *s, AVFrame *reference, AVFrame *frame) uint64_t sad = 0; uint64_t count = 0; double mafd; - for (int plane = 0; plane < 4; plane++) { + double diff, cmp; + + for (int plane = 0; plane < s->nb_planes; plane++) { if (s->width[plane]) { uint64_t plane_sad; s->sad(frame->data[plane], frame->linesize[plane], @@ -140,8 +146,12 @@ static int is_frozen(FreezeDetectContext *s, AVFrame *reference, AVFrame *frame) } } emms_c(); - mafd = (double)sad / count / (1ULL << s->bitdepth); - return (mafd <= s->noise); + mafd = (double)sad /(count >> (s->bitdepth > 8)); + diff = fabs(mafd - s->prev_mafd); + cmp = av_clipf(FFMIN(mafd, diff) / 100., 0, 1); + s->prev_mafd = mafd; + + return (cmp <= s->noise); } static int set_meta(FreezeDetectContext *s, AVFrame *frame, const char *key, const char *value)