Skip to content

Commit 0e12cdc

Browse files
dheitmuellerlance-lmwang
authored andcommitted
avfilter/vf_ccrepack: Add new filter to repack CEA-708 side data
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 <[email protected]> Signed-off-by: Limin Wang <[email protected]>
1 parent f304c3a commit 0e12cdc

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

doc/filters.texi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9083,6 +9083,16 @@ Only deinterlace frames marked as interlaced.
90839083
The default value is @code{all}.
90849084
@end table
90859085

9086+
@section ccrepack
9087+
9088+
Repack CEA-708 closed captioning side data
9089+
9090+
This filter fixes various issues seen with commerical encoders
9091+
related to upstream malformed CEA-708 payloads, specifically
9092+
incorrect number of tuples (wrong cc_count for the target FPS),
9093+
and incorrect ordering of tuples (i.e. the CEA-608 tuples are not at
9094+
the first entries in the payload).
9095+
90869096
@section cas
90879097

90889098
Apply Contrast Adaptive Sharpen filter to video stream.

libavfilter/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
214214
opencl/avgblur.o boxblur.o
215215
OBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o yadif_common.o
216216
OBJS-$(CONFIG_CAS_FILTER) += vf_cas.o
217+
OBJS-$(CONFIG_CCREPACK_FILTER) += vf_ccrepack.o
217218
OBJS-$(CONFIG_CHROMABER_VULKAN_FILTER) += vf_chromaber_vulkan.o vulkan.o vulkan_filter.o
218219
OBJS-$(CONFIG_CHROMAHOLD_FILTER) += vf_chromakey.o
219220
OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o

libavfilter/allfilters.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ extern const AVFilter ff_vf_boxblur;
198198
extern const AVFilter ff_vf_boxblur_opencl;
199199
extern const AVFilter ff_vf_bwdif;
200200
extern const AVFilter ff_vf_cas;
201+
extern const AVFilter ff_vf_ccrepack;
201202
extern const AVFilter ff_vf_chromaber_vulkan;
202203
extern const AVFilter ff_vf_chromahold;
203204
extern const AVFilter ff_vf_chromakey;

libavfilter/vf_ccrepack.c

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* CEA-708 Closed Caption Repacker
3+
* Copyright (c) 2023 LTN Global Communications
4+
*
5+
* Author: Devin Heitmueller <[email protected]>
6+
*
7+
* This file is part of FFmpeg.
8+
*
9+
* FFmpeg is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* FFmpeg is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with FFmpeg; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22+
*/
23+
24+
/*
25+
* Repackage CEA-708 arrays, which deals with incorrect cc_count for a given
26+
* output framerate, and incorrect 708 padding.
27+
*
28+
* See CEA CEA-10-A "EIA-708-B Implementation Guidance", Section 26.5
29+
* "Grouping DTVCC Data Within user_data() Structure"
30+
*/
31+
32+
#include "avfilter.h"
33+
#include "internal.h"
34+
#include "ccfifo.h"
35+
#include "libavutil/opt.h"
36+
37+
typedef struct CCRepackContext
38+
{
39+
const AVClass *class;
40+
AVCCFifo *cc_fifo;
41+
} CCRepackContext;
42+
43+
static const AVOption ccrepack_options[] = {
44+
{ NULL }
45+
};
46+
47+
AVFILTER_DEFINE_CLASS(ccrepack);
48+
49+
static int config_input(AVFilterLink *link)
50+
{
51+
CCRepackContext *ctx = link->dst->priv;
52+
53+
if (!(ctx->cc_fifo = ff_ccfifo_alloc(link->frame_rate, ctx))) {
54+
av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
55+
return AVERROR(ENOMEM);
56+
}
57+
58+
return 0;
59+
}
60+
61+
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
62+
{
63+
CCRepackContext *ctx = inlink->dst->priv;
64+
AVFilterLink *outlink = inlink->dst->outputs[0];
65+
66+
ff_ccfifo_extract(ctx->cc_fifo, frame);
67+
ff_ccfifo_inject(ctx->cc_fifo, frame);
68+
69+
return ff_filter_frame(outlink, frame);
70+
}
71+
72+
static av_cold void uninit(AVFilterContext *ctx)
73+
{
74+
CCRepackContext *s = ctx->priv;
75+
ff_ccfifo_freep(&s->cc_fifo);
76+
}
77+
78+
static const AVFilterPad avfilter_vf_ccrepack_inputs[] = {
79+
{
80+
.name = "default",
81+
.type = AVMEDIA_TYPE_VIDEO,
82+
.filter_frame = filter_frame,
83+
.config_props = config_input,
84+
},
85+
};
86+
87+
static const AVFilterPad avfilter_vf_ccrepack_outputs[] = {
88+
{
89+
.name = "default",
90+
.type = AVMEDIA_TYPE_VIDEO,
91+
},
92+
};
93+
94+
AVFilter ff_vf_ccrepack = {
95+
.name = "ccrepack",
96+
.description = NULL_IF_CONFIG_SMALL("Repack CEA-708 closed caption metadata"),
97+
.uninit = uninit,
98+
.priv_size = sizeof(CCRepackContext),
99+
.priv_class = &ccrepack_class,
100+
FILTER_INPUTS(avfilter_vf_ccrepack_inputs),
101+
FILTER_OUTPUTS(avfilter_vf_ccrepack_outputs),
102+
};

0 commit comments

Comments
 (0)