FFmpeg: libavfilter/vf_feedback.c Source File
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 * feedback video filter
22 */
23
32
35
38
41
43
46
48 {
49 if (
s->x +
s->w >
ctx->inputs[0]->w)
50 s->x =
ctx->inputs[0]->w -
s->w;
51 if (
s->y +
s->h >
ctx->inputs[0]->h)
52 s->y =
ctx->inputs[0]->h -
s->h;
53 }
54
56 {
57 if (
s->x >=
ctx->inputs[0]->w)
59 if (
s->y >=
ctx->inputs[0]->h)
61
63 s->w =
ctx->inputs[0]->w -
s->x;
65 s->h =
ctx->inputs[0]->h -
s->y;
66
67 if (
s->w >
ctx->inputs[0]->w)
68 s->w =
ctx->inputs[0]->w;
69 if (
s->h >
ctx->inputs[0]->h)
70 s->h =
ctx->inputs[0]->h;
71
73 }
74
76 {
80
83
85
87
88 ctx->inputs[1]->w =
s->w;
89 ctx->inputs[1]->h =
s->h;
90
91 return 0;
92 }
93
95 {
98
100
101 ctx->outputs[0]->w =
ctx->inputs[0]->w;
102 ctx->outputs[0]->h =
ctx->inputs[0]->h;
103 ctx->outputs[1]->w =
s->w;
104 ctx->outputs[1]->h =
s->h;
105
106 return 0;
107 }
108
112 {
117 }
118
120 {
124
126
127 for (
int i = 0;
i <
ctx->nb_outputs;
i++)
129
134 }
135
139
143
146
150 }
151
157 }
158
162 }
163
164 for (
int y = 0; y <
src->height; y++) {
165 memmove(
dst->data[0] + (
s->y + y) *
dst->linesize[0] +
s->x *
s->max_step[0],
166 src->data[0] + y *
src->linesize[0],
src->width *
s->max_step[0]);
167 }
168
169 for (
int i = 1;
i < 3;
i++) {
171 for (
int y = 0; y <
src->height; y++) {
172 memmove(
dst->data[
i] + ((
s->y + y) >>
s->vsub) *
dst->linesize[
i] + (
s->x >>
s->hsub) *
s->max_step[
i],
173 src->data[
i] + (y >>
s->vsub) *
src->linesize[
i], (
src->width >>
s->hsub) *
s->max_step[
i]);
174 }
175 }
176 }
177
179 for (
int y = 0; y <
src->height; y++) {
180 memmove(
dst->data[3] + (
s->y + y) *
dst->linesize[3] +
s->x *
s->max_step[3],
181 src->data[3] + y *
src->linesize[3],
src->width *
s->max_step[3]);
182 }
183 }
184
188 }
189
190 if (!
s->feed ||
ctx->is_disabled) {
192
196
197 if (
ret > 0 &&
ctx->is_disabled)
199
202
207 }
208
212
215
217 frame->data[0] +=
s->x *
s->max_step[0];
218
219 for (
int i = 1;
i < 3;
i ++) {
222 frame->data[
i] += (
s->x >>
s->hsub) *
s->max_step[
i];
223 }
224 }
225
226 if (
frame->data[3]) {
228 frame->data[3] +=
s->x *
s->max_step[3];
229 }
230
232 }
233 }
234
238 return 0;
239 }
240
244 return 0;
245 }
246
247 if (!
s->feed ||
ctx->is_disabled) {
250 if (!
ctx->is_disabled)
252 return 0;
253 }
254 }
255
257 }
258
260 {
262
266
267 return 0;
268 }
269
271 {
275
276 for (
size_t n = 0; n <
size; n++) {
278
280
282 }
283
285 }
286 }
287
289 {
293 },
294 {
295 .name = "feedin",
298 },
299 };
300
302 {
306 },
307 {
308 .name = "feedout",
311 },
312 };
313
314 #define OFFSET(x) offsetof(FeedbackContext, x)
315 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
316 #define TFLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM)
317
324 };
325
327
329 .
p.
name =
"feedback",
331 .p.priv_class = &feedback_class,
341 };
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int config_input(AVFilterLink *inlink)
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 all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
const FFFilter ff_vf_feedback
const char * name
Filter name.
A link between two filters.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
static int activate(AVFilterContext *ctx)
A filter pad used for either input or output.
static void adjust_parameters(AVFilterContext *ctx, FeedbackContext *s)
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define FILTER_OUTPUTS(array)
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
size_t av_fifo_can_read(const AVFifo *f)
AVFILTER_DEFINE_CLASS(feedback)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
static const AVOption feedback_options[]
static int config_output(AVFilterLink *outlink)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
#define i(width, name, range_min, range_max)
static const AVFilterPad inputs[]
#define FILTER_QUERY_FUNC2(func)
const char * name
Pad name.
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
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
static av_cold int init(AVFilterContext *ctx)
@ AV_OPT_TYPE_INT
Underlying C type is int.
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
AVFilter p
The public AVFilter.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
static const AVFilterPad outputs[]
static void adjust_pos(AVFilterContext *ctx, FeedbackContext *s)
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
static av_cold void uninit(AVFilterContext *ctx)
Generated on Sat Oct 18 2025 19:23:06 for FFmpeg by
doxygen
1.8.17