From patchwork Mon Mar 27 16:47: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: 40880 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1485660pzh; Mon, 27 Mar 2023 09:48:07 -0700 (PDT) X-Google-Smtp-Source: AK7set+MA0MeP3rivL0xCawcBGS1Hvm8EOwMC0Hhk8LRJeqQecApAxL3ZjGnqlK677zlYUIZYmlj X-Received: by 2002:a17:906:9b8f:b0:8af:22b4:99d2 with SMTP id dd15-20020a1709069b8f00b008af22b499d2mr21406985ejc.5.1679935686762; Mon, 27 Mar 2023 09:48:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679935686; cv=none; d=google.com; s=arc-20160816; b=lA7GdpLhY/bQ/OCQ5mIDfy2quFHMHR+pIPY6Ymi+V5BJSyxEvb8s9HNsrgyuf8Tmk3 MMHIuTQgoBI8ZhYB530DytchAtA4+RrcbuWPraPN7t03fyaLoCEOslYMWVmGUdxeoh0t pHHlfiBniDdc/xEf2Q+tavtfPfYkq0YmX+rgWY4d4f0ptFpzMZzx46wPa9U+LSGRD9gG 3lMJ8yUGTIgmB0SSHgLeL+2nQ/N9nuyNvFG38VrfRUE7nIwk3bW7pQXurZfwdm0/qImF g2AzRWQvK/exkhWeCZSSXs7rAsVgZ45XGg5yZZcCm07ybmyI8XZ8Ujvqir8X1kOh53QM sMOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=ka7FO+T1xh5XCZDnkghWnmEeoABBdiy1WdoWK2AwX1I=; b=qofTxOywmAxdSNJHWGiarf6Wsv2OcSCt2W+VY+eAuEJKJZfdlygtV0AvbdMwCOyu7X OBA37lNvVBvNB6q/RcJrazViTmKpKU+9ssWZrZ/Xsj5yTQHMYWrC9FQKjieYN7JW07F4 6kvgft7KbICev1KhGk1sVgdIJ+Ka0A2monER9nLUvoOitWoYbBpeABkH9TOGfdJMJQFU uVAsxaLI8qxPsQmqk2eg/168zraJXDDuHUPZnH0ad1km6Jb0IoVPoIPaxL3ab+0E2xyP N+cFqMIqV7nrQLkebMb1+7hd9fs8D8zVcMz1svP+3JPhEz1FDvNMBA4q21LQrPwAL56C uANg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ltnglobal-com.20210112.gappssmtp.com header.s=20210112 header.b=JXC95GY3; 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 hr19-20020a1709073f9300b0093549a153f9si25296502ejc.912.2023.03.27.09.48.06; Mon, 27 Mar 2023 09:48:06 -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.20210112.gappssmtp.com header.s=20210112 header.b=JXC95GY3; 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 1BEB168C600; Mon, 27 Mar 2023 19:47:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 33ABB68CB09 for ; Mon, 27 Mar 2023 19:47:13 +0300 (EEST) Received: by mail-qv1-f44.google.com with SMTP id jl13so7129558qvb.10 for ; Mon, 27 Mar 2023 09:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ltnglobal-com.20210112.gappssmtp.com; s=20210112; t=1679935632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=83dUY2NI/sip5h+TztFvCBw7Jk59lj0M3jhHRBSYSDg=; b=JXC95GY33e11qZZVqFPrGdRcTgEQeWEON8bDgWWV3eF+OMljaBu5BxjXxf3xSwFpu/ 45CIS8soAOoVs3Vfy0iN+jPNmIIjJZPON5ggOC5ZU4p0LuihjQJ74PjdGaGJOVkHv+bF 7kxGfm1/nLw6VPXfq5S+32p6bygXv+0aGaFg1MDolFTGQZTcmeEQkAfsMglm6GN3q+9l bzbI+IARazFlIht2n50W+NtR0JqdjBIVATQgKgk4uWo+fUzv9lQm9T3hCo4u6ZnuOfBG 1Uobqe9/oxigvJ4Wyqyeen+57z59e+PcZhOazMzncnlVEptqcA0ZfftEuxXiUfRgSqtH 0EhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679935632; h=content-transfer-encoding:mime-version: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=83dUY2NI/sip5h+TztFvCBw7Jk59lj0M3jhHRBSYSDg=; b=DHECHsghXfs6Uy+KajTUi95F5fYWO2+PfX3pNWre0YeRlSh+t+8D1W3/dFwxNXEGe5 FmG4aGrZJjYSSLeq1hRkf8KhQJALXXQawTtR1aUsSY45VSyK0Idf/S8dD+dhREuMY73J haWETr0IWpsTBaoiIZWEzNMItV4iBH9OhCXiRTu1Gk11ekpMMvCZSy+QAE98khx6dCBf mJp2/N0PVNGD8/T+2NFJWACu/zPo4JOLT566kGXFp3gH2M2jMLu5TBtPlq/GNcNdeh44 P2+bCGLR+TaPXTiL9zYQMLAvcHRvoInXmRRoDVtA1GxoU5LTOYTlPMBkUlgFj1sm+Nis s9MA== X-Gm-Message-State: AAQBX9fJ2ObQRRK5FJciMMJDMhMSR7NrrluBWDq9VFzukhPkG5CxRy7z msrlP48kSFUotNRB+Cs6j91S8GmrqgD5dWCIJ34= X-Received: by 2002:a05:6214:dc6:b0:5cd:3326:780 with SMTP id 6-20020a0562140dc600b005cd33260780mr24974399qvt.38.1679935631762; Mon, 27 Mar 2023 09:47:11 -0700 (PDT) Received: from klab-nyc-kernellabs2.localdomain (pool-71-105-132-214.nycmny.fios.verizon.net. [71.105.132.214]) by smtp.gmail.com with ESMTPSA id lf10-20020a0562142cca00b005dd8b9345e9sm3093100qvb.129.2023.03.27.09.47.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2023 09:47:11 -0700 (PDT) From: Devin Heitmueller X-Google-Original-From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:47:04 -0400 Message-Id: <20230327164704.12962-6-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 2.35.1.655.ga68dfadae5 In-Reply-To: <20230327164704.12962-1-dheitmueller@ltnglobal.com> References: <20230327164704.12962-1-dheitmueller@ltnglobal.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] vf_ccrepack: Add new filter to repack CEA-708 side data 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4e0gvx2WW8iz THis filter can correct certain issues seen from upstream sources where the cc_count is not properly set or the CEA-608 tuples are not at the start of the payload as expected. Make use of the ccfifo to extract and immediately repack the CEA-708 side data, thereby removing any extra padding and ensuring the 608 tuples are at the front of the payload. Signed-off-by: Devin Heitmueller --- doc/filters.texi | 10 +++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_ccrepack.c | 95 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 libavfilter/vf_ccrepack.c diff --git a/doc/filters.texi b/doc/filters.texi index 4449998ba4..d042b034f8 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -8901,6 +8901,16 @@ Only deinterlace frames marked as interlaced. The default value is @code{all}. @end table +@section ccrepack + +Repack CEA-708 closed captioning side data + +This filter fixes various issues seen with commerical encoders +related to upstream malformed CEA-708 payloads, specifically +incorrect number of tuples (wrong cc_count for the target FPS), +and incorrect ordering of tuples (i.e. the CEA-608 tuples are not at +the first entries in the payload). + @section cas Apply Contrast Adaptive Sharpen filter to video stream. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 71e198bbf9..6b0da0f34f 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -211,6 +211,7 @@ OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \ opencl/avgblur.o boxblur.o OBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o yadif_common.o OBJS-$(CONFIG_CAS_FILTER) += vf_cas.o +OBJS-$(CONFIG_CCREPACK_FILTER) += vf_ccrepack.o OBJS-$(CONFIG_CHROMABER_VULKAN_FILTER) += vf_chromaber_vulkan.o vulkan.o vulkan_filter.o OBJS-$(CONFIG_CHROMAHOLD_FILTER) += vf_chromakey.o OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index d7db46c2af..b38550b358 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -196,6 +196,7 @@ extern const AVFilter ff_vf_boxblur; extern const AVFilter ff_vf_boxblur_opencl; extern const AVFilter ff_vf_bwdif; extern const AVFilter ff_vf_cas; +extern const AVFilter ff_vf_ccrepack; extern const AVFilter ff_vf_chromaber_vulkan; extern const AVFilter ff_vf_chromahold; extern const AVFilter ff_vf_chromakey; diff --git a/libavfilter/vf_ccrepack.c b/libavfilter/vf_ccrepack.c new file mode 100644 index 0000000000..ab8473e7c1 --- /dev/null +++ b/libavfilter/vf_ccrepack.c @@ -0,0 +1,95 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * Repackage CEA-708 arrays, which deals with incorrect cc_count for a given + * output framerate, and incorrect 708 padding. + * + * See CEA CEA-10-A "EIA-708-B Implementation Guidance", Section 26.5 + * "Grouping DTVCC Data Within user_data() Structure" + */ + +#include "avfilter.h" +#include "internal.h" +#include "libavutil/opt.h" +#include "libavutil/ccfifo.h" + +typedef struct CCRepackContext +{ + const AVClass *class; + AVCCFifo *cc_fifo; +} CCRepackContext; + +static const AVOption ccrepack_options[] = { + { NULL } +}; + +AVFILTER_DEFINE_CLASS(ccrepack); + +static int config_input(AVFilterLink *link) +{ + CCRepackContext *ctx = link->dst->priv; + + if (!(ctx->cc_fifo = av_ccfifo_alloc(&link->frame_rate, ctx))) + av_log(ctx, AV_LOG_VERBOSE, "Failure to setup CC FIFO queue. Captions will be passed through\n"); + + return 0; +} + +static int filter_frame(AVFilterLink *inlink, AVFrame *frame) +{ + CCRepackContext *ctx = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + + av_ccfifo_extract(ctx->cc_fifo, frame); + av_ccfifo_inject(ctx->cc_fifo, frame); + + return ff_filter_frame(outlink, frame); +} + +static av_cold void uninit(AVFilterContext *ctx) +{ + CCRepackContext *s = ctx->priv; + av_ccfifo_freep(&s->cc_fifo); +} + +static const AVFilterPad avfilter_vf_ccrepack_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .filter_frame = filter_frame, + .config_props = config_input, + }, +}; + +static const AVFilterPad avfilter_vf_ccrepack_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + }, +}; + +AVFilter ff_vf_ccrepack = { + .name = "ccrepack", + .description = NULL_IF_CONFIG_SMALL("Repack CEA-708 closed caption metadata"), + .uninit = uninit, + .priv_size = sizeof(CCRepackContext), + .priv_class = &ccrepack_class, + FILTER_INPUTS(avfilter_vf_ccrepack_inputs), + FILTER_OUTPUTS(avfilter_vf_ccrepack_outputs), +};