From patchwork Fri May 5 19:09:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 41497 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp685606pzb; Fri, 5 May 2023 11:13:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JmBlLvPt2eOHlcRnCdh8CRAvKwTEFJL2e+lr5lfvuouwpcx1yhtnX+4MAjgoZsnHyPpTY X-Received: by 2002:a17:907:c17:b0:965:ae3a:52c8 with SMTP id ga23-20020a1709070c1700b00965ae3a52c8mr3350295ejc.32.1683310434069; Fri, 05 May 2023 11:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683310434; cv=none; d=google.com; s=arc-20160816; b=UQu1aQ5Dba6GxL/BcgXTskfY2EnWxWy4TL2SQDoEmqoLY3BW9lvWqgOYlS47A/P6WA ykni5ACiEZcpI1DDN2h1/xuWTIOPj3cmX14PjQomkt63y651ZZGzoi9F2aBDSfO9yR8n im2yWPgGphSo/+i4fQtqADH8Vdm2aiJ7z4TgnAT9aIdduTJ9vBm69uP5dR6bymcKe330 oUuatqC9ne8Q1hYttAx5XrsgWZ0uCYRzfrYE0aAufmdcsVd7ngz//T0Vlwiozw8o2auq OJSVScttdR++7zmkC1Jb+2pQlwk8IkrI9Zhli+1kcxh8yHw/pR+hr9jG4Jr1OK4nImTL Rr1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=bcDlT4bS2F//ovCPqsEsS4Ld/G2EA1Xjznx7V/m2BfU=; b=nSher9GKh73u7eKCU/C4hcPAlg8GuMGSixjt1jGwqqDqZdXg6TQCwdro/KgOE6yVFQ mylrFxxJAXz6nGpdf4rAnJBHzYehogz2y1h0PR7rNg7Mv/T7x3VjHyA6GdvLxkR+q52P cDocQ7uZGdnzXR8TkZPFoVDq8F2mCgRedcXMVWsYawh6T3o3zKvepr8mgMTT44Qj6NUP meLpX3I9WvEBBHOgMPC3l1Iq9A1OBTcRQrBdSHGSF2RwulCLXdQb9fp32DvO/oM3oVH4 oDFu1yQYqFAlOUMAdquuQ/Py2VBLv6MwunYnZIXbuz8Gvo1hTZlB82hT/yr6oeoUTVQT /AUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ltnglobal-com.20221208.gappssmtp.com header.s=20221208 header.b=0LEUIPwV; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gv44-20020a1709072bec00b00965fac6722esi453631ejc.171.2023.05.05.11.13.53; Fri, 05 May 2023 11:13:54 -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=@ltnglobal-com.20221208.gappssmtp.com header.s=20221208 header.b=0LEUIPwV; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9EBDF68C18D; Fri, 5 May 2023 21:13:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E2AC068BF52 for ; Fri, 5 May 2023 21:13:23 +0300 (EEST) Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-74fb8677a36so108177785a.0 for ; Fri, 05 May 2023 11:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ltnglobal-com.20221208.gappssmtp.com; s=20221208; t=1683310402; x=1685902402; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=1icKU5ZG9Ueq6yYspjCh0KLlMAJMos3aHnhNpRwpoGA=; b=0LEUIPwV7jhn99p3H9fK6+pJbv0mrkDfi/oEuut9Pq951CFM9x/4+vScPW7P8PmI4o n6c0An+gfdCzln8CGzmcXEaTJEI31JgIiDjSGFtlGvxFsnqY9kuO/kaRZ2P/93nrXAAw +fH4UrOsIGks09dfCy1pBl6f8AiVANn7JpUI7dja0xY7X4SaHcAAIF+ewCgE7s33vsR+ qpf6JM0Z0Ka3PsYEGarbIVq8Lh1qTUeenOdnsHVnkbzsccpuO9inaCUb1UD6Ao1pDMVl +zzK9xIlEULGcbEu4p85ccV0aQZfcwQgDUFJHAngNDj7y6w9qtSPpgI0C8WNcsIW69Mz G5hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683310402; x=1685902402; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1icKU5ZG9Ueq6yYspjCh0KLlMAJMos3aHnhNpRwpoGA=; b=V8+9SahIFT9JwtxiDIkyu2Tk5ITGhEh1Zbkdd9ILY+MrbACU/E2fN+5SD8VdnNeeAf Exxm/UAD/HkKnSQERsKfy2YB5/CjQyUvcu0tqjwNQRFUqC1VjK6vAq4XNhWZrys/C8I6 7yrLU+YEqi1w8QslzzO9UBf0p2I84TrApAOEbFc0r7/dOVwQsthwzdYnuLvfW7Utp54V efvWQN3Z9yjL8cKdQrvydNKZSFFuLL285FDZjEluHcgNnbN1PAtscoHRFvcZXzVhQEjE aqexzv1DpyvFoQfjlwLR41QYYvAf9e2QUGqNZaBfKAZ+28PsMtxaaGosfdMW6U+uwhqv C5wA== X-Gm-Message-State: AC+VfDyYKY+7VobUyNiSHBdoYPmWJRCUF5n/az0g4wFxWj4tje64oGcv QAtRzi9BIdKL3VjZRV6shH8+qQb3r+3HLW1PM7k= X-Received: by 2002:a05:6214:5007:b0:61b:743c:34f6 with SMTP id jo7-20020a056214500700b0061b743c34f6mr3790188qvb.30.1683310402418; Fri, 05 May 2023 11:13:22 -0700 (PDT) Received: from ltnt-nyc-580testdevin.livetimenet.com (pool-71-105-132-214.nycmny.fios.verizon.net. [71.105.132.214]) by smtp.gmail.com with ESMTPSA id d1-20020a05620a166100b0074e26158cf2sm747289qko.93.2023.05.05.11.13.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2023 11:13:21 -0700 (PDT) From: Devin Heitmueller X-Google-Original-From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 May 2023 15:09:04 -0400 Message-Id: <1683313747-3775-4-git-send-email-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1683313747-3775-1-git-send-email-dheitmueller@ltnglobal.com> References: <1683313747-3775-1-git-send-email-dheitmueller@ltnglobal.com> Subject: [FFmpeg-devel] [PATCH v6 3/6] yadif: Properly preserve CEA-708 closed captions 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 Cc: Devin Heitmueller MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ceQnEN77AelF Various deinterlacing modes have the effect of doubling the framerate, and we need to ensure that the caption data isn't duplicated (or else you get double captions on-screen). Use the new ccfifo mechanism for yadif (and yadif_cuda and bwdif since they use the same yadif core) so that CEA-708 data is properly preserved through this filter. Signed-off-by: Devin Heitmueller --- libavfilter/vf_bwdif.c | 8 ++++++++ libavfilter/vf_yadif.c | 8 ++++++++ libavfilter/vf_yadif_cuda.c | 9 +++++++++ libavfilter/yadif.h | 2 ++ libavfilter/yadif_common.c | 5 +++++ 5 files changed, 32 insertions(+) diff --git a/libavfilter/vf_bwdif.c b/libavfilter/vf_bwdif.c index 34e8c5e..51e1e02 100644 --- a/libavfilter/vf_bwdif.c +++ b/libavfilter/vf_bwdif.c @@ -297,6 +297,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_frame_free(&yadif->prev); av_frame_free(&yadif->cur ); av_frame_free(&yadif->next); + ff_ccfifo_freep(&yadif->cc_fifo); } static const enum AVPixelFormat pix_fmts[] = { @@ -332,6 +333,13 @@ static int config_props(AVFilterLink *link) if(yadif->mode&1) link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1}); + else + link->frame_rate = ctx->inputs[0]->frame_rate; + + if (!(yadif->cc_fifo = ff_ccfifo_alloc(link->frame_rate, ctx))) { + av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); + return AVERROR(ENOMEM); + } if (link->w < 3 || link->h < 4) { av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or 4 lines is not supported\n"); diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 1be02de..f77f811 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -261,6 +261,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_frame_free(&yadif->prev); av_frame_free(&yadif->cur ); av_frame_free(&yadif->next); + ff_ccfifo_freep(&yadif->cc_fifo); } static const enum AVPixelFormat pix_fmts[] = { @@ -293,6 +294,13 @@ static int config_output(AVFilterLink *outlink) if(s->mode & 1) outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, (AVRational){2, 1}); + else + outlink->frame_rate = ctx->inputs[0]->frame_rate; + + if (!(s->cc_fifo = ff_ccfifo_alloc(outlink->frame_rate, ctx))) { + av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); + return AVERROR(ENOMEM); + } if (outlink->w < 3 || outlink->h < 3) { av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); diff --git a/libavfilter/vf_yadif_cuda.c b/libavfilter/vf_yadif_cuda.c index 685b8a2..f3f0b56 100644 --- a/libavfilter/vf_yadif_cuda.c +++ b/libavfilter/vf_yadif_cuda.c @@ -205,6 +205,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx) av_frame_free(&y->prev); av_frame_free(&y->cur); av_frame_free(&y->next); + ff_cc_fifo_freep(&y->cc_fifo); av_buffer_unref(&s->device_ref); s->hwctx = NULL; @@ -291,6 +292,14 @@ static int config_output(AVFilterLink *link) if(y->mode & 1) link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, (AVRational){2, 1}); + else + link->frame_rate = ctx->inputs[0]->frame_rate; + + if (!(s->cc_fifo = ff_cc_fifo_alloc(link->frame_rate, ctx))) { + av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); + ret = AVERROR(ENOMEM); + goto exit; + } if (link->w < 3 || link->h < 3) { av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h index c928911..1077576 100644 --- a/libavfilter/yadif.h +++ b/libavfilter/yadif.h @@ -22,6 +22,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "ccfifo.h" enum YADIFMode { YADIF_MODE_SEND_FRAME = 0, ///< send 1 frame for each frame @@ -76,6 +77,7 @@ typedef struct YADIFContext { int eof; uint8_t *temp_line; int temp_line_size; + AVCCFifo *cc_fifo; /* * An algorithm that treats first and/or last fields in a sequence diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c index a10cf7a..676853e 100644 --- a/libavfilter/yadif_common.c +++ b/libavfilter/yadif_common.c @@ -60,6 +60,8 @@ static int return_frame(AVFilterContext *ctx, int is_second) yadif->out->pts = AV_NOPTS_VALUE; } } + + ff_ccfifo_inject(yadif->cc_fifo, yadif->out); ret = ff_filter_frame(ctx->outputs[0], yadif->out); yadif->frame_pending = (yadif->mode&1) && !is_second; @@ -96,6 +98,8 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame) av_assert0(frame); + ff_ccfifo_extract(yadif->cc_fifo, frame); + if (yadif->frame_pending) return_frame(ctx, 1); @@ -137,6 +141,7 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame) if (!yadif->out) return AVERROR(ENOMEM); + ff_ccfifo_inject(yadif->cc_fifo, yadif->out); av_frame_free(&yadif->prev); if (yadif->out->pts != AV_NOPTS_VALUE) yadif->out->pts *= 2;