FFmpeg
vf_ccrepack.c
Go to the documentation of this file.
1 /*
2  * CEA-708 Closed Caption Repacker
3  * Copyright (c) 2023 LTN Global Communications
4  *
5  * Author: Devin Heitmueller <dheitmueller@ltnglobal.com>
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 "video.h"
36 #include "libavutil/opt.h"
37 
38 typedef struct CCRepackContext
39 {
40  const AVClass *class;
43 
44 static const AVOption ccrepack_options[] = {
45  { NULL }
46 };
47 
48 AVFILTER_DEFINE_CLASS(ccrepack);
49 
51 {
52  CCRepackContext *ctx = link->dst->priv;
53 
54  int ret = ff_ccfifo_init(&ctx->cc_fifo, link->frame_rate, ctx);
55  if (ret < 0) {
56  av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
57  return ret;
58  }
59 
60  return 0;
61 }
62 
64 {
65  CCRepackContext *ctx = inlink->dst->priv;
66  AVFilterLink *outlink = inlink->dst->outputs[0];
67 
68  ff_ccfifo_extract(&ctx->cc_fifo, frame);
69  ff_ccfifo_inject(&ctx->cc_fifo, frame);
70 
71  return ff_filter_frame(outlink, frame);
72 }
73 
75 {
76  CCRepackContext *s = ctx->priv;
77  ff_ccfifo_uninit(&s->cc_fifo);
78 }
79 
81  {
82  .name = "default",
83  .type = AVMEDIA_TYPE_VIDEO,
84  .filter_frame = filter_frame,
85  .config_props = config_input,
86  },
87 };
88 
90  .name = "ccrepack",
91  .description = NULL_IF_CONFIG_SMALL("Repack CEA-708 closed caption metadata"),
92  .uninit = uninit,
93  .priv_size = sizeof(CCRepackContext),
94  .priv_class = &ccrepack_class,
97 };
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_ccrepack.c:74
opt.h
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
ff_vf_ccrepack
const AVFilter ff_vf_ccrepack
Definition: vf_ccrepack.c:89
AVOption
AVOption.
Definition: opt.h:346
config_input
static int config_input(AVFilterLink *link)
Definition: vf_ccrepack.c:50
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
video.h
avfilter_vf_ccrepack_inputs
static const AVFilterPad avfilter_vf_ccrepack_inputs[]
Definition: vf_ccrepack.c:80
ff_ccfifo_uninit
void ff_ccfifo_uninit(CCFifo *ccf)
Free all memory allocated in a CCFifo and clear the context.
Definition: ccfifo.c:46
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: vf_ccrepack.c:63
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
ff_ccfifo_inject
int ff_ccfifo_inject(CCFifo *ccf, AVFrame *frame)
Insert CC data from the FIFO into an AVFrame (as side data)
Definition: ccfifo.c:133
s
#define s(width, name)
Definition: cbs_vp9.c:198
ctx
AVFormatContext * ctx
Definition: movenc.c:48
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
frame
static AVFrame * frame
Definition: demux_decode.c:54
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
CCRepackContext::cc_fifo
CCFifo cc_fifo
Definition: vf_ccrepack.c:41
ff_ccfifo_extract
int ff_ccfifo_extract(CCFifo *ccf, AVFrame *frame)
Extract CC data from an AVFrame.
Definition: ccfifo.c:183
CCFifo
Definition: ccfifo.h:40
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(ccrepack)
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
internal.h
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
AVFilter
Filter definition.
Definition: avfilter.h:166
ff_ccfifo_init
int ff_ccfifo_init(CCFifo *ccf, AVRational framerate, void *log_ctx)
Initialize a CCFifo.
Definition: ccfifo.c:53
ccrepack_options
static const AVOption ccrepack_options[]
Definition: vf_ccrepack.c:44
ret
ret
Definition: filter_design.txt:187
avfilter.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ccfifo.h
CCRepackContext
Definition: vf_ccrepack.c:38