FFmpeg
avf_concat.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Nicolas George
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * concat audio-video filter
24  */
25 
26 #include "libavutil/avstring.h"
28 #include "libavutil/mem.h"
29 #include "libavutil/opt.h"
30 #include "avfilter.h"
31 #include "filters.h"
32 #include "formats.h"
33 #include "internal.h"
34 #include "video.h"
35 #include "audio.h"
36 
37 #define TYPE_ALL 2
38 
39 typedef struct ConcatContext {
40  const AVClass *class;
41  unsigned nb_streams[TYPE_ALL]; /**< number of out streams of each type */
42  unsigned nb_segments;
43  unsigned cur_idx; /**< index of the first input of current segment */
44  int64_t delta_ts; /**< timestamp to add to produce output timestamps */
45  unsigned nb_in_active; /**< number of active inputs in current segment */
46  unsigned unsafe;
47  struct concat_in {
48  int64_t pts;
49  int64_t nb_frames;
50  unsigned eof;
51  } *in;
53 
54 #define OFFSET(x) offsetof(ConcatContext, x)
55 #define A AV_OPT_FLAG_AUDIO_PARAM
56 #define F AV_OPT_FLAG_FILTERING_PARAM
57 #define V AV_OPT_FLAG_VIDEO_PARAM
58 
59 static const AVOption concat_options[] = {
60  { "n", "specify the number of segments", OFFSET(nb_segments),
61  AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, V|A|F},
62  { "v", "specify the number of video streams",
64  AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, V|F },
65  { "a", "specify the number of audio streams",
67  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A|F},
68  { "unsafe", "enable unsafe mode",
69  OFFSET(unsafe),
70  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, V|A|F},
71  { NULL }
72 };
73 
74 AVFILTER_DEFINE_CLASS(concat);
75 
77 {
78  ConcatContext *cat = ctx->priv;
79  unsigned type, nb_str, idx0 = 0, idx, str, seg;
82  int ret;
83 
84  for (type = 0; type < TYPE_ALL; type++) {
85  nb_str = cat->nb_streams[type];
86  for (str = 0; str < nb_str; str++) {
87  idx = idx0;
88 
89  /* Set the output formats */
91  if ((ret = ff_formats_ref(formats, &ctx->outputs[idx]->incfg.formats)) < 0)
92  return ret;
93 
94  if (type == AVMEDIA_TYPE_AUDIO) {
96  if ((ret = ff_formats_ref(rates, &ctx->outputs[idx]->incfg.samplerates)) < 0)
97  return ret;
99  if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->incfg.channel_layouts)) < 0)
100  return ret;
101  }
102 
103  /* Set the same formats for each corresponding input */
104  for (seg = 0; seg < cat->nb_segments; seg++) {
105  if ((ret = ff_formats_ref(formats, &ctx->inputs[idx]->outcfg.formats)) < 0)
106  return ret;
107  if (type == AVMEDIA_TYPE_AUDIO) {
108  if ((ret = ff_formats_ref(rates, &ctx->inputs[idx]->outcfg.samplerates)) < 0 ||
109  (ret = ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->outcfg.channel_layouts)) < 0)
110  return ret;
111  }
112  idx += ctx->nb_outputs;
113  }
114 
115  idx0++;
116  }
117  }
118  return 0;
119 }
120 
121 static int config_output(AVFilterLink *outlink)
122 {
123  AVFilterContext *ctx = outlink->src;
124  ConcatContext *cat = ctx->priv;
125  unsigned out_no = FF_OUTLINK_IDX(outlink);
126  unsigned in_no = out_no, seg;
127  AVFilterLink *inlink = ctx->inputs[in_no];
128 
129  /* enhancement: find a common one */
130  outlink->time_base = AV_TIME_BASE_Q;
131  outlink->w = inlink->w;
132  outlink->h = inlink->h;
133  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
134  outlink->format = inlink->format;
135  outlink->frame_rate = inlink->frame_rate;
136 
137  for (seg = 1; seg < cat->nb_segments; seg++) {
138  inlink = ctx->inputs[in_no + seg * ctx->nb_outputs];
139  if (outlink->frame_rate.num != inlink->frame_rate.num ||
140  outlink->frame_rate.den != inlink->frame_rate.den) {
142  "Video inputs have different frame rates, output will be VFR\n");
143  outlink->frame_rate = av_make_q(1, 0);
144  break;
145  }
146  }
147 
148  for (seg = 1; seg < cat->nb_segments; seg++) {
149  inlink = ctx->inputs[in_no + seg * ctx->nb_outputs];
150  if (!outlink->sample_aspect_ratio.num)
151  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
152  /* possible enhancement: unsafe mode, do not check */
153  if (outlink->w != inlink->w ||
154  outlink->h != inlink->h ||
155  outlink->sample_aspect_ratio.num != inlink->sample_aspect_ratio.num &&
156  inlink->sample_aspect_ratio.num ||
157  outlink->sample_aspect_ratio.den != inlink->sample_aspect_ratio.den) {
158  av_log(ctx, AV_LOG_ERROR, "Input link %s parameters "
159  "(size %dx%d, SAR %d:%d) do not match the corresponding "
160  "output link %s parameters (%dx%d, SAR %d:%d)\n",
161  ctx->input_pads[in_no].name, inlink->w, inlink->h,
162  inlink->sample_aspect_ratio.num,
163  inlink->sample_aspect_ratio.den,
164  ctx->input_pads[out_no].name, outlink->w, outlink->h,
165  outlink->sample_aspect_ratio.num,
166  outlink->sample_aspect_ratio.den);
167  if (!cat->unsafe)
168  return AVERROR(EINVAL);
169  }
170  }
171 
172  return 0;
173 }
174 
175 static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
176 {
177  ConcatContext *cat = ctx->priv;
178  unsigned out_no = in_no % ctx->nb_outputs;
179  AVFilterLink * inlink = ctx-> inputs[ in_no];
180  AVFilterLink *outlink = ctx->outputs[out_no];
181  struct concat_in *in = &cat->in[in_no];
182 
183  buf->pts = av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);
184  buf->duration = av_rescale_q(buf->duration, inlink->time_base, outlink->time_base);
185  in->pts = buf->pts;
186  in->nb_frames++;
187  /* add duration to input PTS */
188  if (inlink->sample_rate)
189  /* use number of audio samples */
190  in->pts += av_rescale_q(buf->nb_samples,
191  av_make_q(1, inlink->sample_rate),
192  outlink->time_base);
193  else if (in->nb_frames >= 2)
194  /* use mean duration */
195  in->pts = av_rescale(in->pts, in->nb_frames, in->nb_frames - 1);
196 
197  buf->pts += cat->delta_ts;
198  return ff_filter_frame(outlink, buf);
199 }
200 
202 {
203  AVFilterContext *ctx = inlink->dst;
204  unsigned in_no = FF_INLINK_IDX(inlink);
205  AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs];
206 
207  return ff_get_video_buffer(outlink, w, h);
208 }
209 
210 static AVFrame *get_audio_buffer(AVFilterLink *inlink, int nb_samples)
211 {
212  AVFilterContext *ctx = inlink->dst;
213  unsigned in_no = FF_INLINK_IDX(inlink);
214  AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs];
215 
216  return ff_get_audio_buffer(outlink, nb_samples);
217 }
218 
219 static void close_input(AVFilterContext *ctx, unsigned in_no)
220 {
221  ConcatContext *cat = ctx->priv;
222 
223  cat->in[in_no].eof = 1;
224  cat->nb_in_active--;
225  av_log(ctx, AV_LOG_VERBOSE, "EOF on %s, %d streams left in segment.\n",
226  ctx->input_pads[in_no].name, cat->nb_in_active);
227 }
228 
229 static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta)
230 {
231  ConcatContext *cat = ctx->priv;
232  unsigned i = cat->cur_idx;
233  unsigned imax = i + ctx->nb_outputs;
234  int64_t pts;
235 
236  pts = cat->in[i++].pts;
237  for (; i < imax; i++)
238  pts = FFMAX(pts, cat->in[i].pts);
239  cat->delta_ts += pts;
240  *seg_delta = pts;
241 }
242 
243 static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no,
244  int64_t seg_delta)
245 {
246  ConcatContext *cat = ctx->priv;
247  AVFilterLink *outlink = ctx->outputs[out_no];
248  int64_t base_pts = cat->in[in_no].pts + cat->delta_ts - seg_delta;
249  int64_t nb_samples, sent = 0;
250  int frame_nb_samples, ret;
251  AVRational rate_tb = { 1, ctx->inputs[in_no]->sample_rate };
252  AVFrame *buf;
253 
254  if (!rate_tb.den)
255  return AVERROR_BUG;
256  if (cat->in[in_no].pts < INT64_MIN + seg_delta)
257  return AVERROR_INVALIDDATA;
258  if (seg_delta < cat->in[in_no].pts)
259  return AVERROR_INVALIDDATA;
260  nb_samples = av_rescale_q(seg_delta - cat->in[in_no].pts,
261  outlink->time_base, rate_tb);
262  frame_nb_samples = FFMAX(9600, rate_tb.den / 5); /* arbitrary */
263  while (nb_samples) {
264  frame_nb_samples = FFMIN(frame_nb_samples, nb_samples);
265  buf = ff_get_audio_buffer(outlink, frame_nb_samples);
266  if (!buf)
267  return AVERROR(ENOMEM);
268  av_samples_set_silence(buf->extended_data, 0, frame_nb_samples,
269  outlink->ch_layout.nb_channels, outlink->format);
270  buf->pts = base_pts + av_rescale_q(sent, rate_tb, outlink->time_base);
271  ret = ff_filter_frame(outlink, buf);
272  if (ret < 0)
273  return ret;
274  sent += frame_nb_samples;
275  nb_samples -= frame_nb_samples;
276  }
277  return 0;
278 }
279 
281 {
282  int ret;
283  ConcatContext *cat = ctx->priv;
284  unsigned str, str_max;
285  int64_t seg_delta;
286 
287  find_next_delta_ts(ctx, &seg_delta);
288  cat->cur_idx += ctx->nb_outputs;
289  cat->nb_in_active = ctx->nb_outputs;
290  av_log(ctx, AV_LOG_VERBOSE, "Segment finished at pts=%"PRId64"\n",
291  cat->delta_ts);
292 
293  if (cat->cur_idx < ctx->nb_inputs) {
294  /* pad audio streams with silence */
295  str = cat->nb_streams[AVMEDIA_TYPE_VIDEO];
296  str_max = str + cat->nb_streams[AVMEDIA_TYPE_AUDIO];
297  for (; str < str_max; str++) {
298  ret = send_silence(ctx, cat->cur_idx - ctx->nb_outputs + str, str,
299  seg_delta);
300  if (ret < 0)
301  return ret;
302  }
303  }
304  return 0;
305 }
306 
308 {
309  ConcatContext *cat = ctx->priv;
310  unsigned seg, type, str;
311  int ret;
312 
313  /* create input pads */
314  for (seg = 0; seg < cat->nb_segments; seg++) {
315  for (type = 0; type < TYPE_ALL; type++) {
316  for (str = 0; str < cat->nb_streams[type]; str++) {
317  AVFilterPad pad = {
318  .type = type,
319  };
320  if (type == AVMEDIA_TYPE_VIDEO)
322  else
324  pad.name = av_asprintf("in%d:%c%d", seg, "va"[type], str);
325  if ((ret = ff_append_inpad_free_name(ctx, &pad)) < 0)
326  return ret;
327  }
328  }
329  }
330  /* create output pads */
331  for (type = 0; type < TYPE_ALL; type++) {
332  for (str = 0; str < cat->nb_streams[type]; str++) {
333  AVFilterPad pad = {
334  .type = type,
335  .config_props = config_output,
336  };
337  pad.name = av_asprintf("out:%c%d", "va"[type], str);
338  if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
339  return ret;
340  }
341  }
342 
343  cat->in = av_calloc(ctx->nb_inputs, sizeof(*cat->in));
344  if (!cat->in)
345  return AVERROR(ENOMEM);
346  cat->nb_in_active = ctx->nb_outputs;
347  return 0;
348 }
349 
351 {
352  ConcatContext *cat = ctx->priv;
353 
354  av_freep(&cat->in);
355 }
356 
358 {
359  ConcatContext *cat = ctx->priv;
360  AVFrame *frame;
361  unsigned i, j;
362  int ret, status;
363  int64_t pts;
364 
365  /* Forward status back */
366  for (i = 0; i < ctx->nb_outputs; i++) {
367  status = ff_outlink_get_status(ctx->outputs[i]);
368  if (!status)
369  continue;
370  for (j = i; j < ctx->nb_inputs; j += ctx->nb_outputs) {
371  if (!cat->in[j].eof) {
372  cat->in[j].eof = 1;
373  ff_inlink_set_status(ctx->inputs[j], status);
374  return 0;
375  }
376  }
377 
378  }
379 
380  /* Forward available frames */
381  if (cat->cur_idx < ctx->nb_inputs) {
382  for (i = 0; i < ctx->nb_outputs; i++) {
383  ret = ff_inlink_consume_frame(ctx->inputs[cat->cur_idx + i], &frame);
384  if (ret < 0)
385  return ret;
386  if (ret) {
388  return push_frame(ctx, cat->cur_idx + i, frame);
389  }
390  }
391  }
392 
393  /* Forward status change */
394  if (cat->cur_idx < ctx->nb_inputs) {
395  for (i = 0; i < ctx->nb_outputs; i++) {
396  AVFilterLink *inlink = ctx->inputs[cat->cur_idx + i];
397 
399  /* TODO use pts */
400  if (ret > 0) {
401  close_input(ctx, cat->cur_idx + i);
402  if (cat->cur_idx + ctx->nb_outputs >= ctx->nb_inputs) {
403  int64_t eof_pts = cat->delta_ts;
404 
405  eof_pts += av_rescale_q(pts, inlink->time_base, ctx->outputs[i]->time_base);
406  ff_outlink_set_status(ctx->outputs[i], status, eof_pts);
407  }
408  if (!cat->nb_in_active) {
409  ret = flush_segment(ctx);
410  if (ret < 0)
411  return ret;
412  }
414  return 0;
415  }
416  }
417  }
418 
420  for (i = 0; i < ctx->nb_outputs; i++) {
421  if (ff_outlink_frame_wanted(ctx->outputs[i])) {
422  if (cat->in[cat->cur_idx + i].eof) {
423  for (j = 0; j < ctx->nb_outputs; j++)
424  if (!cat->in[cat->cur_idx + j].eof)
425  ff_inlink_request_frame(ctx->inputs[cat->cur_idx + j]);
426  return 0;
427  } else {
428  ff_inlink_request_frame(ctx->inputs[cat->cur_idx + i]);
429  ret = 0;
430  }
431  }
432  }
433 
434  return ret;
435 }
436 
437 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
438  char *res, int res_len, int flags)
439 {
440  int ret = AVERROR(ENOSYS);
441 
442  if (!strcmp(cmd, "next")) {
443  av_log(ctx, AV_LOG_VERBOSE, "Command received: next\n");
444  return flush_segment(ctx);
445  }
446 
447  return ret;
448 }
449 
451  .name = "concat",
452  .description = NULL_IF_CONFIG_SMALL("Concatenate audio and video streams."),
453  .init = init,
454  .uninit = uninit,
455  .activate = activate,
456  .priv_size = sizeof(ConcatContext),
457  .inputs = NULL,
458  .outputs = NULL,
459  .priv_class = &concat_class,
462  .process_command = process_command,
463 };
formats
formats
Definition: signature.h:48
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:112
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:97
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
AVERROR
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
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:1015
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:781
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:674
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:337
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
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
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:115
ConcatContext::nb_segments
unsigned nb_segments
Definition: avf_concat.c:42
activate
static int activate(AVFilterContext *ctx)
Definition: avf_concat.c:357
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:375
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:487
w
uint8_t w
Definition: llviddspenc.c:38
av_samples_set_silence
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:246
AVOption
AVOption.
Definition: opt.h:346
ConcatContext::unsafe
unsigned unsafe
Definition: avf_concat.c:46
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:159
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
cat
#define cat(a, bpp, b)
Definition: vp9dsp_init.h:32
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_concat.c:121
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
ConcatContext::concat_in::eof
unsigned eof
Definition: avf_concat.c:50
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
video.h
TYPE_ALL
#define TYPE_ALL
Definition: avf_concat.c:37
flush_segment
static int flush_segment(AVFilterContext *ctx)
Definition: avf_concat.c:280
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1442
find_next_delta_ts
static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta)
Definition: avf_concat.c:229
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:644
AVFILTER_FLAG_DYNAMIC_INPUTS
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:106
ConcatContext::cur_idx
unsigned cur_idx
index of the first input of current segment
Definition: avf_concat.c:43
AVRational::num
int num
Numerator.
Definition: rational.h:59
ff_all_formats
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:536
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: avf_concat.c:76
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_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(concat)
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1568
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:679
FF_OUTLINK_IDX
#define FF_OUTLINK_IDX(link)
Definition: internal.h:332
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
nb_streams
static int nb_streams
Definition: ffprobe.c:384
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
ff_avf_concat
const AVFilter ff_avf_concat
Definition: avf_concat.c:450
V
#define V
Definition: avf_concat.c:57
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
A
#define A
Definition: avf_concat.c:55
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_append_inpad_free_name
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:132
inputs
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 inputs
Definition: filter_design.txt:243
concat_options
static const AVOption concat_options[]
Definition: avf_concat.c:59
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1389
AVFILTER_FLAG_DYNAMIC_OUTPUTS
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:112
ConcatContext::nb_in_active
unsigned nb_in_active
number of active inputs in current segment
Definition: avf_concat.c:45
get_audio_buffer
static AVFrame * get_audio_buffer(AVFilterLink *inlink, int nb_samples)
Definition: avf_concat.c:210
ff_inlink_set_status
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
Definition: avfilter.c:1577
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
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: avf_concat.c:437
F
#define F
Definition: avf_concat.c:56
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
ConcatContext::nb_streams
unsigned nb_streams[TYPE_ALL]
number of out streams of each type
Definition: avf_concat.c:41
concat_class
static const AVClass concat_class
Definition: concatdec.c:940
ff_all_channel_layouts
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:613
internal.h
close_input
static void close_input(AVFilterContext *ctx, unsigned in_no)
Definition: avf_concat.c:219
ConcatContext::concat_in
Definition: avf_concat.c:47
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:455
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:436
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ConcatContext::in
struct ConcatContext::concat_in * in
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
send_silence
static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no, int64_t seg_delta)
Definition: avf_concat.c:243
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
outputs
static const AVFilterPad outputs[]
Definition: af_aap.c:311
init
static av_cold int init(AVFilterContext *ctx)
Definition: avf_concat.c:307
AVFilter
Filter definition.
Definition: avfilter.h:166
ConcatContext::concat_in::nb_frames
int64_t nb_frames
Definition: avf_concat.c:49
ConcatContext
Definition: avf_concat.c:39
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:44
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
AVFilterPad::video
AVFrame *(* video)(AVFilterLink *link, int w, int h)
Definition: internal.h:74
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:607
status
ov_status_e status
Definition: dnn_backend_openvino.c:121
channel_layout.h
rates
static const int rates[]
Definition: swresample.c:103
ConcatContext::concat_in::pts
int64_t pts
Definition: avf_concat.c:48
AVRational::den
int den
Denominator.
Definition: rational.h:60
FF_INLINK_IDX
#define FF_INLINK_IDX(link)
Find the index of a link.
Definition: internal.h:331
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
avfilter.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_concat.c:350
ff_outlink_get_status
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
Definition: avfilter.c:1593
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
audio.h
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
AVFilterPad::audio
AVFrame *(* audio)(AVFilterLink *link, int nb_samples)
Definition: internal.h:75
ff_append_outpad_free_name
int ff_append_outpad_free_name(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:143
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
ConcatContext::delta_ts
int64_t delta_ts
timestamp to add to produce output timestamps
Definition: avf_concat.c:44
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2038
ff_outlink_frame_wanted
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
avstring.h
OFFSET
#define OFFSET(x)
Definition: avf_concat.c:54
get_video_buffer
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: avf_concat.c:201
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:235
push_frame
static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
Definition: avf_concat.c:175
AVFilterPad::get_buffer
union AVFilterPad::@263 get_buffer
Callback functions to get a video/audio buffers.