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 "filters.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 {
53  CCRepackContext *ctx = link->dst->priv;
54 
55  int ret = ff_ccfifo_init(&ctx->cc_fifo, l->frame_rate, ctx);
56  if (ret < 0) {
57  av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
58  return ret;
59  }
60 
61  return 0;
62 }
63 
65 {
66  CCRepackContext *ctx = inlink->dst->priv;
67  AVFilterLink *outlink = inlink->dst->outputs[0];
68 
69  ff_ccfifo_extract(&ctx->cc_fifo, frame);
70  ff_ccfifo_inject(&ctx->cc_fifo, frame);
71 
72  return ff_filter_frame(outlink, frame);
73 }
74 
76 {
77  CCRepackContext *s = ctx->priv;
78  ff_ccfifo_uninit(&s->cc_fifo);
79 }
80 
82  {
83  .name = "default",
84  .type = AVMEDIA_TYPE_VIDEO,
85  .filter_frame = filter_frame,
86  .config_props = config_input,
87  },
88 };
89 
91  .name = "ccrepack",
92  .description = NULL_IF_CONFIG_SMALL("Repack CEA-708 closed caption metadata"),
93  .uninit = uninit,
94  .priv_size = sizeof(CCRepackContext),
95  .priv_class = &ccrepack_class,
98 };
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_ccrepack.c:75
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:1061
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
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
ff_vf_ccrepack
const AVFilter ff_vf_ccrepack
Definition: vf_ccrepack.c:90
AVOption
AVOption.
Definition: opt.h:429
config_input
static int config_input(AVFilterLink *link)
Definition: vf_ccrepack.c:50
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
video.h
avfilter_vf_ccrepack_inputs
static const AVFilterPad avfilter_vf_ccrepack_inputs[]
Definition: vf_ccrepack.c:81
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:64
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
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
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
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
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
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
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
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:94
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
AVFilter
Filter definition.
Definition: avfilter.h:201
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
avfilter.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ccfifo.h
CCRepackContext
Definition: vf_ccrepack.c:38