From patchwork Thu Nov 3 14:40:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mail@nodoa.me X-Patchwork-Id: 39143 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp583999pzb; Thu, 3 Nov 2022 07:40:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6sgrW9Vz+73FNfNNyJVntrMZKVPjgpyZM1SFMUGvCUWCqhxylLOm2SjtFX50Q+WXBXbrT6 X-Received: by 2002:a17:907:6e14:b0:7ad:b45c:7e0d with SMTP id sd20-20020a1709076e1400b007adb45c7e0dmr26781209ejc.413.1667486444187; Thu, 03 Nov 2022 07:40:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667486444; cv=none; d=google.com; s=arc-20160816; b=WU0Y4x31F8+g2ksDw1ZOCQk9831qjoSXOncbgUHXtMPh6z1YPuw3/l1863mALSrBWw 6Go0MyB2R44SVeT+HPi7bRR3BFCo5+5+kIawL/jQwXr4axDZkac0VK+ExpdBAcoyJkNX WjcpctDiNp7Gc8IAWBYLFSw62bv4CV4y6PnHY6BYOLo9IS0pQYl0qmukgN/jsWXcoQQJ AczEHoEwa1YBc+39HgsszMgNYl40zn2MO12RFwBEb2+TuLeAcF9vRoo7NiPNwz0HS/G5 EySuLi9MC53Jv/HqeewHM9MmtiENywiVNCuXxt3hnliaOth/J+dxV1NPVuwbm7mw4Pim 4XHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:to:message-id:from:date:dkim-signature :mime-version:delivered-to; bh=v6+aaWsEx7RVLX75JIxOKIgTJCwi/U0++5MQDBi3roo=; b=SUFHCIsJMWmg8DVffNEx/UFWjpir7tTgtyazSBFwSdZU5Qu0n89zakA9Vg4krSDazb HP1o6ridtTtcW8HU67jjDVB5nV58TfBRDE7DXg8Mj02hlX3gdo3gcEd6MtC71pR/Knou HxdZ/w0V+PXswzN6XEm0xoN2Y+H05JsrbrIZyi68gx+B9fTj75StrpfWQAa30jawkMLu QbZ1Fy/jUDF+r3yO7RT+RmJlwdEMj2VHyT/zw3Fsrkizslr2LGR7ipg5OcydQxjqzUQS UhCUB3K61U9URQP6Jggwon3VIvfjdkQbUOQ/2rgrWCnxu1xj+HYN2J2g90XgQ0De8NOP F2tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nodoa.me header.s=key1 header.b=mGUjuUwT; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=nodoa.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b11-20020a056402278b00b00460e1cc2d76si1831121ede.72.2022.11.03.07.40.43; Thu, 03 Nov 2022 07:40:44 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nodoa.me header.s=key1 header.b=mGUjuUwT; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=nodoa.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 056B868BF9D; Thu, 3 Nov 2022 16:40:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7EE7068B909 for ; Thu, 3 Nov 2022 16:40:33 +0200 (EET) MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nodoa.me; s=key1; t=1667486432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yyb7Xy0Y7QUl9cmCJimzmzyT00gspiPuXHb6Ey6Xx60=; b=mGUjuUwT/AgaODr4loOBXquGycF5QdMkFeHs5aLSYbAvn276QkNBxNrsbjLPDF1I9Bs08B gtsVzsUfDYks0HOtBsooJnEIjuGw8nlXUWhAIJu6aj6oLEXMGjWNw7LgRN2APekb2nMuQq 9HdriKMIkZGV2UCG3hCtqMCeoe7ggNU= Date: Thu, 03 Nov 2022 14:40:31 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: mail@nodoa.me Message-ID: <399842a707482604827e62860e98cb37@nodoa.me> To: ffmpeg-devel@ffmpeg.org X-Migadu-Flow: FLOW_OUT Subject: [FFmpeg-devel] [PATCH] lavfi/vf_fieldmatch: keep fields as-is if not matched properly X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vbJJviSpdBxr Makes it possible to use deinterlacers which output one frame for each field as fallback if field matching fails (combmatch=full). Currently, the documented example with fallback on a post-deinterlacer will only work in case the deinterlacer outputs one frame per first field (as yadif=mode=0). The reason for that is that fieldmatch will attempt to match the second field regardless of whether it recognizes the end result is still interlaced. This produces garbled output with for example mixed telecined 24fps and 60i content combined with a field-based deinterlaced such as yadif=mode=1. This patch orders fieldmatch to revert to using the second field of the current frame in case the end result is still interlaced and a post-deinterlacer is assumed to be used. Signed-off-by: lovesyk --- libavfilter/vf_fieldmatch.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_fieldmatch.c b/libavfilter/vf_fieldmatch.c index 40e559df9e..bf946beec9 100644 --- a/libavfilter/vf_fieldmatch.c +++ b/libavfilter/vf_fieldmatch.c @@ -680,7 +680,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFilterLink *outlink = ctx->outputs[0]; FieldMatchContext *fm = ctx->priv; int combs[] = { -1, -1, -1, -1, -1 }; - int order, field, i, match, sc = 0, ret = 0; + int order, field, i, match, interlaced_frame, sc = 0, ret = 0; const int *fxo; AVFrame *gen_frames[] = { NULL, NULL, NULL, NULL, NULL }; AVFrame *dst = NULL; @@ -793,6 +793,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } } + /* keep fields as-is if not matched properly */ + interlaced_frame = combs[match] >= fm->combpel; + if (interlaced_frame && fm->combmatch == COMBMATCH_FULL) { + match = mC; + } + /* get output frame and drop the others */ if (fm->ppsrc) { /* field matching was based on a filtered/post-processed input, we now @@ -813,7 +819,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) /* mark the frame we are unable to match properly as interlaced so a proper * de-interlacer can take the relay */ - dst->interlaced_frame = combs[match] >= fm->combpel; + dst->interlaced_frame = interlaced_frame; if (dst->interlaced_frame) { av_log(ctx, AV_LOG_WARNING, "Frame #%"PRId64" at %s is still interlaced\n", outlink->frame_count_in, av_ts2timestr(in->pts, &inlink->time_base));