From patchwork Fri Apr 21 14:24:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 41292 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1313132pzb; Fri, 21 Apr 2023 06:30:21 -0700 (PDT) X-Google-Smtp-Source: AKy350bj/yd8rKwQAYMbRX6++/JBm58rvm2mrnXspbf1LvmuWgkR80+eFiCo2byARMwIitWk+aM6 X-Received: by 2002:a17:907:2907:b0:953:93ab:50cf with SMTP id eq7-20020a170907290700b0095393ab50cfmr1783438ejc.70.1682083821024; Fri, 21 Apr 2023 06:30:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682083821; cv=none; d=google.com; s=arc-20160816; b=wKPNMt/5uJduxymBj9prhQPHYIVhHOdXvhacySlVwLqyGvrf/jBuVCSeD9jdOHdskh lKYI32juUdkrkLO33XHWLmbEc9+g/K5V+hamRql/7JxaqMHQdM9cMdafOimvytlRHBPT 1svzuVDc09D5+gsp8g7CmYEeKeSZ7e75vxQ722rkInzqNlQyB5R8V9MWbS/nJCHYAeeO Uv5DUrjZPSrwCZ5foz0JL8P7Lx2nUAby3OeoZXWFgydaD3UUdac4YlbXOwPPFEr4ECNb XJ83DqXRf3NpX3KIsyArHGVNo4jsXxJrrTmBf0nvgOJ3IqZXTgn2D8bzBSv6vGhsg+De LTzA== 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=x0vhOF7IeZmd7pWgNpvl1/S06ZipS/XiAJbsyVRM+fo=; b=jDoYl9ykRx+BAMr8JPinqsdxO+c9bIMn/VKV8JBmWXAAUheizICGitBKGj2vgfarhj 3NC25F0onGrPew5WKkFPrRu0voFAlcpX9FWwgwEcEb7GIAEO1NhmjVYNJ/0un0hyVuu3 nU2esU4DxI6h+4aY/rLzhY4Uj/OpWly4ZHhpIR+v1Mbo/Prc9U3/jdVhQxnmGbCgU/zA LrzPn27e3/7ANJppUzvLVpMa/RNmGWw0jfefgiixgqepJuQ4DQFdbu6klhHJ6dTCnbhA BPVJia48kp4Nf4nq0MyG4yDqBOuY12KmLy0eyJUr2RL62PasAoTgjeUEqmQLh9QecIk2 /Q1A== 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=Rsq4UZtY; 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 v22-20020a056402185600b0050697d54502si3573021edy.545.2023.04.21.06.30.20; Fri, 21 Apr 2023 06:30:21 -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=Rsq4UZtY; 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 0504468BF96; Fri, 21 Apr 2023 16:29:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 99E1E68BF7F for ; Fri, 21 Apr 2023 16:29:23 +0300 (EEST) Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-74e3cade11fso20082785a.2 for ; Fri, 21 Apr 2023 06:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ltnglobal-com.20221208.gappssmtp.com; s=20221208; t=1682083762; x=1684675762; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=gpkbLj99EbwL/CCVwH9gJNe35uA7okrY35JCwbgLoXk=; b=Rsq4UZtYvxSXlujlP6kZ3R47Ydx+F4vby3LG0NQfa2MYN0ZX3HerCYA5Awi8NSyoh4 uV8ieoCcZwk+ws27rsmyLpx0CjUsKFBRttDjzUUsvFBLhFt4w4cay9eq859Yt6HResVg qQuOc3gmh8NRqyV9sap9BsJTHH4a4diS0ZIyGF2wPMnAapWwrx2Fc+ge3tMc2HKk/MuS ZXjm6hQ6AIPe72k6aDcGjnYmZZ71npq/W5NmEq1EGAmcn3jJKQY6jeEepK2Yz6c8YbdV e+WZGlgKeHkgWM9tn/5AYxIMDG5ithmAscO9Ce07tEx2IoZAknC2K61HOqll3cdGs5gu +OLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682083762; x=1684675762; 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=gpkbLj99EbwL/CCVwH9gJNe35uA7okrY35JCwbgLoXk=; b=LefUXbLn/KlWS4IEODw6xyjKR9Fb/0uhoDAKfZ+4XF6Zls0nKHuatyR3tXVREiocI1 rpcu0HtWZS+fE7G6bD6Yii4HVksebz8HrxNXLijR86Xeuodp4QV5UlRCKK3tjpZcCnTV Bk8f8Z+9iInQLLClpiMQVpsCfuZAQgiBjYdWPZpbofNvhk8s7QbJuZMA0JuOgOTJTKIf iDBRNi9WAVXl/oWQL8+MfXFDgVtAdQsG0/WRdGT5mgU+hJA8t4o3xIRthoArW7YMkAcV qIi/Ii+fE6tX0MGxzE9uwJOnCDYC+FZotUY2AwV+hPTEQA4AxgFr6YfdlTvzvDebt0gq +CfA== X-Gm-Message-State: AAQBX9cGfSsxyR8G8UmLOGQj+vJ5jIHrSZk0wlD9LCh0ZCuwd7T9qrNp BkWNYBh/PAzzH3Xvob2zGQiJ9FgYfEoLpEmH+AM= X-Received: by 2002:ac8:5786:0:b0:3e3:8e1a:c313 with SMTP id v6-20020ac85786000000b003e38e1ac313mr8129517qta.61.1682083762157; Fri, 21 Apr 2023 06:29: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 b142-20020ae9eb94000000b0074abc456dddsm1305626qkg.134.2023.04.21.06.29.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Apr 2023 06:29:21 -0700 (PDT) From: Devin Heitmueller X-Google-Original-From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Apr 2023 10:24:55 -0400 Message-Id: <1682087095-582-6-git-send-email-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1682087095-582-1-git-send-email-dheitmueller@ltnglobal.com> References: <1682087095-582-1-git-send-email-dheitmueller@ltnglobal.com> Subject: [FFmpeg-devel] [PATCH v3 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: kT8Zv3S0qrxs 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 | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 libavfilter/vf_ccrepack.c diff --git a/doc/filters.texi b/doc/filters.texi index 120fe66..e72e73d 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -8930,6 +8930,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 628ade8..3d0b3ad 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -212,6 +212,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 d7db46c..b38550b 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 0000000..c6819b8 --- /dev/null +++ b/libavfilter/vf_ccrepack.c @@ -0,0 +1,100 @@ +/* + * 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_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]; + + 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), +};