From patchwork Fri May 5 19:09:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 41500 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp690457pzb; Fri, 5 May 2023 11:21:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XwlO716jr72fSmiQIaGZgZ5j2RiyVBbi20eTpbg2ge3lsezuajhldwxR+Om033WuYMV0O X-Received: by 2002:a17:907:74c:b0:953:37eb:7727 with SMTP id xc12-20020a170907074c00b0095337eb7727mr2134978ejb.43.1683310912187; Fri, 05 May 2023 11:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683310912; cv=none; d=google.com; s=arc-20160816; b=j4Cy84NLeCHilzTX/f58KZ08GB0ZpS0q9H7/9kPREZNBhuNw37UU2wlXgwv06siTlE X01QgfBkmxKm7JrmUVxR+oI9OdXpR0AMqdzKWhyNlcU2nUR1oahdpfRJu+r7RJ1755Wl qTm4B7pLA/UhjlWoiVLR4zI66kmchNR2tssdCU6v4WUhVXYemJQqNfhgVrgiKJgXLCsT vN6dra3kM0Oqq41O1D18HfqWTLrBDXG/D5EzlHp2VzjZiCnOjj2yj6Bc8KiC9dps4oiS 9OPweO8Bcwc+dvs4baj6M3h5wRrsc4I90J2rV/OwmzVY5AvBXZsOqUkSDKsmGODL0KvD rUhg== 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=OyBub1Xg+VFvNiP/+n0WtRAVGO+tM6fGawsnRuaLl90=; b=YVw8UukKJh97ktuq9+DaWJ2D24Smdq4Vg4TQ5gnr8aoZe7oBFmbUdF9Y1aliB1C66+ 44brvcHWuLjlPGy9RUbG8y92oYXqdUMDlnpumD1Cbbk4vgWwhrbpzkDk7GHpCO+K4gUn 4UmV83hmMQG7nml7R/bz+w0bZJICu3rFnwYRYH9iCep0XF7yjWKxxP8YQ+p+Lozz3ikJ x43jajelYTkR4FcS2w+6HKN5RW3wDfddy8D/0Kgndo+2+2QsiBHi5RtldKzR4L4RO2l7 N7muY2YLdnCar0DLHIpLUSaGHyQJGE+tJUNwf+INdIwlvBc+JHaFeAvckXjI/dFyLU/q jR7Q== 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=J0EtjJtR; 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 kl9-20020a170907994900b0094ae88a6e68si1759787ejc.743.2023.05.05.11.21.51; Fri, 05 May 2023 11:21:52 -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=J0EtjJtR; 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 36FDE68BFF3; Fri, 5 May 2023 21:21:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A6D8368BFAF for ; Fri, 5 May 2023 21:21:41 +0300 (EEST) Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7516d97a63aso190784385a.1 for ; Fri, 05 May 2023 11:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ltnglobal-com.20221208.gappssmtp.com; s=20221208; t=1683310900; x=1685902900; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=VK83yqMTe/l2pg95fYViHCLfcPSlu7eURCol8Hq+x0E=; b=J0EtjJtRG9OKJTfjXaBOj8gwLjN8F1OUHOQmenO90/k/h4nmMs9Mu0xAeRs1DwkJY1 aOqZMS/Q1rOhuqaIKgFW18RPUQUub14nyux9q111WcrUCCQMO7qYbP8UGHapJl87Xuba a68ZmCtrpLjNKms9qrk1kfQlzNrtgDaofPL1p5EwWh0J3+ryW2jlJ77G68TLjPs8TNiR 0lwcxs06Xb4WlYFx79v9GmqalDVf91q5GguFnAaTNi8LGFILWWo+Hnlf0TNV6QzQLzDR AkjFWL1qB39vq0FP2mM5TUxiii/g18qtnStqCKUkmwbwR+pvjrQz8r2wffewDD/KUHJp l7SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683310900; x=1685902900; 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=VK83yqMTe/l2pg95fYViHCLfcPSlu7eURCol8Hq+x0E=; b=hAcuf9rPKdbvpsUBFI8cTUBlXK0dV7qqokg+PZKy1s1v/HjTF6kn1knt7cullZU/z7 KH8UgFpZARmkZ84qF6q1aS9Y03MG9do4l4XQOnK2bjZtxBtf+CTsMDCJgqhLvmkSYkkk 5D8uw21N3rTsZ0p2kSLILJZbneZWG37EIdvZ09AwbT3nSiUumj6DOAXMQOhw211uIApW HgR7PKtvDeniCpbBi87AeWr2yEbbt0XFk4SHf/M8Z7UxKyDTlFCe/ScIt3OAYWbqYpgW 0O+rXXYXUbiK0aRqoEGBYU3u3ojTndYMYdaUmBFT+3CTvjxo7Ayl6DZqPMukbEBio41G /CvQ== X-Gm-Message-State: AC+VfDxefnjAeJ+k04lEAG4RFV2UNOCco8N4zVHgEV4VTZrxRhVo9h3i y41cHa1tYpvQFV6qT2cV43sXQBvok557T6ty9io= X-Received: by 2002:a05:622a:13cc:b0:3ef:2c3a:faa3 with SMTP id p12-20020a05622a13cc00b003ef2c3afaa3mr4372037qtk.17.1683310403569; Fri, 05 May 2023 11:13:23 -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.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2023 11:13:23 -0700 (PDT) From: Devin Heitmueller X-Google-Original-From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 May 2023 15:09:06 -0400 Message-Id: <1683313747-3775-6-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 5/6] 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: McOp4HeRjmyy 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 | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 libavfilter/vf_ccrepack.c diff --git a/doc/filters.texi b/doc/filters.texi index 9a0fe9c..d425081 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -9070,6 +9070,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 68c8f14..7c2195f 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -214,6 +214,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 6994124..ee2ac17 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -198,6 +198,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 0000000..e3fd67f --- /dev/null +++ b/libavfilter/vf_ccrepack.c @@ -0,0 +1,102 @@ +/* + * CEA-708 Closed Caption Repacker + * Copyright (c) 2023 LTN Global Communications + * + * Author: Devin Heitmueller + * + * 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 "ccfifo.h" +#include "libavutil/opt.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 = ff_ccfifo_alloc(link->frame_rate, ctx))) { + av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); + return AVERROR(ENOMEM); + } + + return 0; +} + +static int filter_frame(AVFilterLink *inlink, AVFrame *frame) +{ + CCRepackContext *ctx = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + + ff_ccfifo_extract(ctx->cc_fifo, frame); + ff_ccfifo_inject(ctx->cc_fifo, frame); + + return ff_filter_frame(outlink, frame); +} + +static av_cold void uninit(AVFilterContext *ctx) +{ + CCRepackContext *s = ctx->priv; + ff_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), +};