FFmpeg
Loading...
Searching...
No Matches
f_sidedata.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * @file
21 * filter for manipulating frame side data
22 */
23
24#include "config_components.h"
25
26#include "libavutil/avassert.h"
27#include "libavutil/internal.h"
28#include "libavutil/frame.h"
29#include "libavutil/opt.h"
30#include "avfilter.h"
31#include "filters.h"
32
38
39typedef struct SideDataContext {
40 const AVClass *class;
41
42 int mode;
43 int type; // enum AVFrameSideDataType or -1 for delete side data mode
45
46#define OFFSET(x) offsetof(SideDataContext, x)
47#define DEFINE_OPTIONS(filt_name, FLAGS) \
48static const AVOption filt_name##_options[] = { \
49 { "mode", "set a mode of operation", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, SIDEDATA_NB-1, FLAGS, .unit = "mode" }, \
50 { "select", "select frame", 0, AV_OPT_TYPE_CONST, {.i64 = SIDEDATA_SELECT }, 0, 0, FLAGS, .unit = "mode" }, \
51 { "delete", "delete side data", 0, AV_OPT_TYPE_CONST, {.i64 = SIDEDATA_DELETE }, 0, 0, FLAGS, .unit = "mode" }, \
52 { "type", "set side data type", OFFSET(type), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, INT_MAX, FLAGS, .unit = "type" }, \
53 { "PANSCAN", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_PANSCAN }, 0, 0, FLAGS, .unit = "type" }, \
54 { "A53_CC", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_A53_CC }, 0, 0, FLAGS, .unit = "type" }, \
55 { "STEREO3D", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_STEREO3D }, 0, 0, FLAGS, .unit = "type" }, \
56 { "MATRIXENCODING", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_MATRIXENCODING }, 0, 0, FLAGS, .unit = "type" }, \
57 { "DOWNMIX_INFO", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_DOWNMIX_INFO }, 0, 0, FLAGS, .unit = "type" }, \
58 { "REPLAYGAIN", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_REPLAYGAIN }, 0, 0, FLAGS, .unit = "type" }, \
59 { "DISPLAYMATRIX", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_DISPLAYMATRIX }, 0, 0, FLAGS, .unit = "type" }, \
60 { "AFD", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_AFD }, 0, 0, FLAGS, .unit = "type" }, \
61 { "MOTION_VECTORS", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_MOTION_VECTORS }, 0, 0, FLAGS, .unit = "type" }, \
62 { "SKIP_SAMPLES", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_SKIP_SAMPLES }, 0, 0, FLAGS, .unit = "type" }, \
63 { "AUDIO_SERVICE_TYPE", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_AUDIO_SERVICE_TYPE }, 0, 0, FLAGS, .unit = "type" }, \
64 { "MASTERING_DISPLAY_METADATA", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_MASTERING_DISPLAY_METADATA }, 0, 0, FLAGS, .unit = "type" }, \
65 { "GOP_TIMECODE", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_GOP_TIMECODE }, 0, 0, FLAGS, .unit = "type" }, \
66 { "SPHERICAL", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_SPHERICAL }, 0, 0, FLAGS, .unit = "type" }, \
67 { "CONTENT_LIGHT_LEVEL", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_CONTENT_LIGHT_LEVEL }, 0, 0, FLAGS, .unit = "type" }, \
68 { "ICC_PROFILE", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_ICC_PROFILE }, 0, 0, FLAGS, .unit = "type" }, \
69 { "S12M_TIMECOD", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_S12M_TIMECODE }, 0, 0, FLAGS | AV_OPT_FLAG_DEPRECATED, .unit = "type" }, \
70 { "S12M_TIMECODE", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_S12M_TIMECODE }, 0, 0, FLAGS, .unit = "type" }, \
71 { "DYNAMIC_HDR_PLUS", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_DYNAMIC_HDR_PLUS }, 0, 0, FLAGS, .unit = "type" }, \
72 { "REGIONS_OF_INTEREST", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_REGIONS_OF_INTEREST }, 0, 0, FLAGS, .unit = "type" }, \
73 { "VIDEO_ENC_PARAMS", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_VIDEO_ENC_PARAMS }, 0, 0, FLAGS, .unit = "type" }, \
74 { "SEI_UNREGISTERED", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_SEI_UNREGISTERED }, 0, 0, FLAGS, .unit = "type" }, \
75 { "FILM_GRAIN_PARAMS", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_FILM_GRAIN_PARAMS }, 0, 0, FLAGS, .unit = "type" }, \
76 { "DETECTION_BOUNDING_BOXES", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_DETECTION_BBOXES }, 0, 0, FLAGS, .unit = "type" }, \
77 { "DETECTION_BBOXES", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_DETECTION_BBOXES }, 0, 0, FLAGS, .unit = "type" }, \
78 { "DOVI_RPU_BUFFER", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_DOVI_RPU_BUFFER }, 0, 0, FLAGS, .unit = "type" }, \
79 { "DOVI_METADATA", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_DOVI_METADATA }, 0, 0, FLAGS, .unit = "type" }, \
80 { "DYNAMIC_HDR_VIVID", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_DYNAMIC_HDR_VIVID }, 0, 0, FLAGS, .unit = "type" }, \
81 { "AMBIENT_VIEWING_ENVIRONMENT","", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT}, 0, 0, FLAGS, .unit = "type" }, \
82 { "VIDEO_HINT", "", 0, AV_OPT_TYPE_CONST, {.i64 = AV_FRAME_DATA_VIDEO_HINT }, 0, 0, FLAGS, .unit = "type" }, \
83 { NULL } \
84}
85
87{
88 SideDataContext *s = ctx->priv;
89
90 if (s->type == -1 && s->mode != SIDEDATA_DELETE) {
91 av_log(ctx, AV_LOG_ERROR, "Side data type must be set\n");
92 return AVERROR(EINVAL);
93 }
94
95 return 0;
96}
97
98static int config_props(AVFilterLink *outlink)
99{
100 AVFilterContext *ctx = outlink->src;
101 SideDataContext *s = ctx->priv;
102 const AVFrameSideData *sd = NULL;
103
104 if (s->type != -1)
105 sd = av_frame_side_data_get(outlink->side_data, outlink->nb_side_data, s->type);
106
107 switch (s->mode) {
108 case SIDEDATA_SELECT:
109 break;
110 case SIDEDATA_DELETE:
111 if (s->type == -1)
112 av_frame_side_data_free(&outlink->side_data, &outlink->nb_side_data);
113 else if (sd)
114 av_frame_side_data_remove(&outlink->side_data, &outlink->nb_side_data, s->type);
115 break;
116 default:
117 av_assert0(0);
118 };
119
120 return 0;
121}
122
124{
125 AVFilterContext *ctx = inlink->dst;
126 AVFilterLink *outlink = ctx->outputs[0];
127 SideDataContext *s = ctx->priv;
128 AVFrameSideData *sd = NULL;
129
130 if (s->type != -1)
131 sd = av_frame_get_side_data(frame, s->type);
132
133 switch (s->mode) {
134 case SIDEDATA_SELECT:
135 if (sd) {
136 return ff_filter_frame(outlink, frame);
137 }
138 break;
139 case SIDEDATA_DELETE:
140 if (s->type == -1) {
141 while (frame->nb_side_data)
142 av_frame_remove_side_data(frame, frame->side_data[0]->type);
143 } else if (sd) {
145 }
146 return ff_filter_frame(outlink, frame);
147 break;
148 default:
149 av_assert0(0);
150 };
151
153
154 return 0;
155}
156
157#if CONFIG_ASIDEDATA_FILTER
158
160AVFILTER_DEFINE_CLASS(asidedata);
161
162static const AVFilterPad ainputs[] = {
163 {
164 .name = "default",
165 .type = AVMEDIA_TYPE_AUDIO,
166 .filter_frame = filter_frame,
167 },
168};
169
170static const AVFilterPad aoutputs[] = {
171 {
172 .name = "default",
173 .type = AVMEDIA_TYPE_AUDIO,
174 .config_props = config_props,
175 },
176};
177
179 .p.name = "asidedata",
180 .p.description = NULL_IF_CONFIG_SMALL("Manipulate audio frame side data."),
181 .p.priv_class = &asidedata_class,
184 .priv_size = sizeof(SideDataContext),
185 .init = init,
186 FILTER_INPUTS(ainputs),
187 FILTER_OUTPUTS(aoutputs),
188};
189#endif /* CONFIG_ASIDEDATA_FILTER */
190
191#if CONFIG_SIDEDATA_FILTER
192
194AVFILTER_DEFINE_CLASS(sidedata);
195
196static const AVFilterPad inputs[] = {
197 {
198 .name = "default",
199 .type = AVMEDIA_TYPE_VIDEO,
200 .filter_frame = filter_frame,
201 },
202};
203
204static const AVFilterPad outputs[] = {
205 {
206 .name = "default",
207 .type = AVMEDIA_TYPE_VIDEO,
208 .config_props = config_props,
209 },
210};
211
212const FFFilter ff_vf_sidedata = {
213 .p.name = "sidedata",
214 .p.description = NULL_IF_CONFIG_SMALL("Manipulate video frame side data."),
215 .p.priv_class = &sidedata_class,
218 .priv_size = sizeof(SideDataContext),
219 .init = init,
222};
223#endif /* CONFIG_SIDEDATA_FILTER */
static const AVFilterPad inputs[]
Definition af_aap.c:299
static const AVFilterPad outputs[]
Definition af_aap.c:310
const FFFilter ff_af_asidedata
const FFFilter ff_vf_sidedata
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
Main libavfilter public API header.
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static AVFrame * frame
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static int config_props(AVFilterLink *outlink)
Definition f_sidedata.c:98
SideDataMode
Definition f_sidedata.c:33
@ SIDEDATA_DELETE
Definition f_sidedata.c:35
@ SIDEDATA_SELECT
Definition f_sidedata.c:34
@ SIDEDATA_NB
Definition f_sidedata.c:36
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition f_sidedata.c:123
#define DEFINE_OPTIONS(filt_name, FLAGS)
Definition f_sidedata.c:47
reference-counted frame API
#define AV_OPT_FLAG_FILTERING_PARAM
A generic parameter which can be set by the user for filtering.
Definition opt.h:380
#define AV_OPT_FLAG_AUDIO_PARAM
Definition opt.h:356
#define AV_OPT_FLAG_VIDEO_PARAM
Definition opt.h:357
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition avfilter.h:196
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:182
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition frame.c:725
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
Definition side_data.c:139
void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type from an array.
Definition side_data.c:108
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
Definition frame.h:1196
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define av_cold
Definition attributes.h:117
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
AVOptions.
static int config_props(AVBitStreamFilterLink *link)
Definition source.c:181
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
A filter pad used for either input or output.
Definition filters.h:40
Structure to hold side data for an AVFrame.
Definition frame.h:327
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
#define av_log(a,...)