FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/avassert.h"
27 #include "libavutil/avstring.h"
29 #include "libavutil/opt.h"
30 #include "avfilter.h"
31 #include "filters.h"
32 #include "internal.h"
33 #include "video.h"
34 #include "audio.h"
35 
36 #define TYPE_ALL 2
37 
38 typedef struct ConcatContext {
39  const AVClass *class;
40  unsigned nb_streams[TYPE_ALL]; /**< number of out streams of each type */
41  unsigned nb_segments;
42  unsigned cur_idx; /**< index of the first input of current segment */
43  int64_t delta_ts; /**< timestamp to add to produce output timestamps */
44  unsigned nb_in_active; /**< number of active inputs in current segment */
45  unsigned unsafe;
46  struct concat_in {
47  int64_t pts;
48  int64_t nb_frames;
49  unsigned eof;
50  } *in;
52 
53 #define OFFSET(x) offsetof(ConcatContext, x)
54 #define A AV_OPT_FLAG_AUDIO_PARAM
55 #define F AV_OPT_FLAG_FILTERING_PARAM
56 #define V AV_OPT_FLAG_VIDEO_PARAM
57 
58 static const AVOption concat_options[] = {
59  { "n", "specify the number of segments", OFFSET(nb_segments),
60  AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, V|A|F},
61  { "v", "specify the number of video streams",
63  AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, V|F },
64  { "a", "specify the number of audio streams",
66  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A|F},
67  { "unsafe", "enable unsafe mode",
68  OFFSET(unsafe),
69  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, V|A|F},
70  { NULL }
71 };
72 
73 AVFILTER_DEFINE_CLASS(concat);
74 
76 {
77  ConcatContext *cat = ctx->priv;
78  unsigned type, nb_str, idx0 = 0, idx, str, seg;
81  int ret;
82 
83  for (type = 0; type < TYPE_ALL; type++) {
84  nb_str = cat->nb_streams[type];
85  for (str = 0; str < nb_str; str++) {
86  idx = idx0;
87 
88  /* Set the output formats */
89  formats = ff_all_formats(type);
90  if ((ret = ff_formats_ref(formats, &ctx->outputs[idx]->in_formats)) < 0)
91  return ret;
92 
93  if (type == AVMEDIA_TYPE_AUDIO) {
94  rates = ff_all_samplerates();
95  if ((ret = ff_formats_ref(rates, &ctx->outputs[idx]->in_samplerates)) < 0)
96  return ret;
97  layouts = ff_all_channel_layouts();
98  if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->in_channel_layouts)) < 0)
99  return ret;
100  }
101 
102  /* Set the same formats for each corresponding input */
103  for (seg = 0; seg < cat->nb_segments; seg++) {
104  if ((ret = ff_formats_ref(formats, &ctx->inputs[idx]->out_formats)) < 0)
105  return ret;
106  if (type == AVMEDIA_TYPE_AUDIO) {
107  if ((ret = ff_formats_ref(rates, &ctx->inputs[idx]->out_samplerates)) < 0 ||
108  (ret = ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->out_channel_layouts)) < 0)
109  return ret;
110  }
111  idx += ctx->nb_outputs;
112  }
113 
114  idx0++;
115  }
116  }
117  return 0;
118 }
119 
120 static int config_output(AVFilterLink *outlink)
121 {
122  AVFilterContext *ctx = outlink->src;
123  ConcatContext *cat = ctx->priv;
124  unsigned out_no = FF_OUTLINK_IDX(outlink);
125  unsigned in_no = out_no, seg;
126  AVFilterLink *inlink = ctx->inputs[in_no];
127 
128  /* enhancement: find a common one */
129  outlink->time_base = AV_TIME_BASE_Q;
130  outlink->w = inlink->w;
131  outlink->h = inlink->h;
132  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
133  outlink->format = inlink->format;
134  for (seg = 1; seg < cat->nb_segments; seg++) {
135  inlink = ctx->inputs[in_no += ctx->nb_outputs];
136  if (!outlink->sample_aspect_ratio.num)
137  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
138  /* possible enhancement: unsafe mode, do not check */
139  if (outlink->w != inlink->w ||
140  outlink->h != inlink->h ||
141  outlink->sample_aspect_ratio.num != inlink->sample_aspect_ratio.num &&
142  inlink->sample_aspect_ratio.num ||
143  outlink->sample_aspect_ratio.den != inlink->sample_aspect_ratio.den) {
144  av_log(ctx, AV_LOG_ERROR, "Input link %s parameters "
145  "(size %dx%d, SAR %d:%d) do not match the corresponding "
146  "output link %s parameters (%dx%d, SAR %d:%d)\n",
147  ctx->input_pads[in_no].name, inlink->w, inlink->h,
148  inlink->sample_aspect_ratio.num,
149  inlink->sample_aspect_ratio.den,
150  ctx->input_pads[out_no].name, outlink->w, outlink->h,
151  outlink->sample_aspect_ratio.num,
152  outlink->sample_aspect_ratio.den);
153  if (!cat->unsafe)
154  return AVERROR(EINVAL);
155  }
156  }
157 
158  return 0;
159 }
160 
161 static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
162 {
163  ConcatContext *cat = ctx->priv;
164  unsigned out_no = in_no % ctx->nb_outputs;
165  AVFilterLink * inlink = ctx-> inputs[ in_no];
166  AVFilterLink *outlink = ctx->outputs[out_no];
167  struct concat_in *in = &cat->in[in_no];
168 
169  buf->pts = av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);
170  in->pts = buf->pts;
171  in->nb_frames++;
172  /* add duration to input PTS */
173  if (inlink->sample_rate)
174  /* use number of audio samples */
175  in->pts += av_rescale_q(buf->nb_samples,
176  av_make_q(1, inlink->sample_rate),
177  outlink->time_base);
178  else if (in->nb_frames >= 2)
179  /* use mean duration */
180  in->pts = av_rescale(in->pts, in->nb_frames, in->nb_frames - 1);
181 
182  buf->pts += cat->delta_ts;
183  return ff_filter_frame(outlink, buf);
184 }
185 
186 static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
187 {
188  AVFilterContext *ctx = inlink->dst;
189  unsigned in_no = FF_INLINK_IDX(inlink);
190  AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs];
191 
192  return ff_get_video_buffer(outlink, w, h);
193 }
194 
195 static AVFrame *get_audio_buffer(AVFilterLink *inlink, int nb_samples)
196 {
197  AVFilterContext *ctx = inlink->dst;
198  unsigned in_no = FF_INLINK_IDX(inlink);
199  AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs];
200 
201  return ff_get_audio_buffer(outlink, nb_samples);
202 }
203 
204 static void close_input(AVFilterContext *ctx, unsigned in_no)
205 {
206  ConcatContext *cat = ctx->priv;
207 
208  cat->in[in_no].eof = 1;
209  cat->nb_in_active--;
210  av_log(ctx, AV_LOG_VERBOSE, "EOF on %s, %d streams left in segment.\n",
211  ctx->input_pads[in_no].name, cat->nb_in_active);
212 }
213 
214 static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta)
215 {
216  ConcatContext *cat = ctx->priv;
217  unsigned i = cat->cur_idx;
218  unsigned imax = i + ctx->nb_outputs;
219  int64_t pts;
220 
221  pts = cat->in[i++].pts;
222  for (; i < imax; i++)
223  pts = FFMAX(pts, cat->in[i].pts);
224  cat->delta_ts += pts;
225  *seg_delta = pts;
226 }
227 
228 static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no,
229  int64_t seg_delta)
230 {
231  ConcatContext *cat = ctx->priv;
232  AVFilterLink *outlink = ctx->outputs[out_no];
233  int64_t base_pts = cat->in[in_no].pts + cat->delta_ts - seg_delta;
234  int64_t nb_samples, sent = 0;
235  int frame_nb_samples, ret;
236  AVRational rate_tb = { 1, ctx->inputs[in_no]->sample_rate };
237  AVFrame *buf;
238 
239  if (!rate_tb.den)
240  return AVERROR_BUG;
241  nb_samples = av_rescale_q(seg_delta - cat->in[in_no].pts,
242  outlink->time_base, rate_tb);
243  frame_nb_samples = FFMAX(9600, rate_tb.den / 5); /* arbitrary */
244  while (nb_samples) {
245  frame_nb_samples = FFMIN(frame_nb_samples, nb_samples);
246  buf = ff_get_audio_buffer(outlink, frame_nb_samples);
247  if (!buf)
248  return AVERROR(ENOMEM);
249  av_samples_set_silence(buf->extended_data, 0, frame_nb_samples,
250  outlink->channels, outlink->format);
251  buf->pts = base_pts + av_rescale_q(sent, rate_tb, outlink->time_base);
252  ret = ff_filter_frame(outlink, buf);
253  if (ret < 0)
254  return ret;
255  sent += frame_nb_samples;
256  nb_samples -= frame_nb_samples;
257  }
258  return 0;
259 }
260 
262 {
263  int ret;
264  ConcatContext *cat = ctx->priv;
265  unsigned str, str_max;
266  int64_t seg_delta;
267 
268  find_next_delta_ts(ctx, &seg_delta);
269  cat->cur_idx += ctx->nb_outputs;
270  cat->nb_in_active = ctx->nb_outputs;
271  av_log(ctx, AV_LOG_VERBOSE, "Segment finished at pts=%"PRId64"\n",
272  cat->delta_ts);
273 
274  if (cat->cur_idx < ctx->nb_inputs) {
275  /* pad audio streams with silence */
276  str = cat->nb_streams[AVMEDIA_TYPE_VIDEO];
277  str_max = str + cat->nb_streams[AVMEDIA_TYPE_AUDIO];
278  for (; str < str_max; str++) {
279  ret = send_silence(ctx, cat->cur_idx - ctx->nb_outputs + str, str,
280  seg_delta);
281  if (ret < 0)
282  return ret;
283  }
284  }
285  return 0;
286 }
287 
289 {
290  ConcatContext *cat = ctx->priv;
291  unsigned seg, type, str;
292  int ret;
293 
294  /* create input pads */
295  for (seg = 0; seg < cat->nb_segments; seg++) {
296  for (type = 0; type < TYPE_ALL; type++) {
297  for (str = 0; str < cat->nb_streams[type]; str++) {
298  AVFilterPad pad = {
299  .type = type,
300  .get_video_buffer = get_video_buffer,
301  .get_audio_buffer = get_audio_buffer,
302  };
303  pad.name = av_asprintf("in%d:%c%d", seg, "va"[type], str);
304  if ((ret = ff_insert_inpad(ctx, ctx->nb_inputs, &pad)) < 0) {
305  av_freep(&pad.name);
306  return ret;
307  }
308  }
309  }
310  }
311  /* create output pads */
312  for (type = 0; type < TYPE_ALL; type++) {
313  for (str = 0; str < cat->nb_streams[type]; str++) {
314  AVFilterPad pad = {
315  .type = type,
316  .config_props = config_output,
317  };
318  pad.name = av_asprintf("out:%c%d", "va"[type], str);
319  if ((ret = ff_insert_outpad(ctx, ctx->nb_outputs, &pad)) < 0) {
320  av_freep(&pad.name);
321  return ret;
322  }
323  }
324  }
325 
326  cat->in = av_calloc(ctx->nb_inputs, sizeof(*cat->in));
327  if (!cat->in)
328  return AVERROR(ENOMEM);
329  cat->nb_in_active = ctx->nb_outputs;
330  return 0;
331 }
332 
334 {
335  ConcatContext *cat = ctx->priv;
336  unsigned i;
337 
338  for (i = 0; i < ctx->nb_inputs; i++)
339  av_freep(&ctx->input_pads[i].name);
340  for (i = 0; i < ctx->nb_outputs; i++)
341  av_freep(&ctx->output_pads[i].name);
342  av_freep(&cat->in);
343 }
344 
346 {
347  ConcatContext *cat = ctx->priv;
348  AVFrame *frame;
349  unsigned i, j;
350  int ret, status;
351  int64_t pts;
352 
353  /* Forward status back */
354  for (i = 0; i < ctx->nb_outputs; i++) {
355  status = ff_outlink_get_status(ctx->outputs[i]);
356  if (!status)
357  continue;
358  for (j = i; j < ctx->nb_inputs; j += ctx->nb_outputs) {
359  if (!cat->in[j].eof) {
360  cat->in[j].eof = 1;
361  ff_inlink_set_status(ctx->inputs[j], status);
362  return 0;
363  }
364  }
365 
366  }
367 
368  /* Forward available frames */
369  if (cat->cur_idx < ctx->nb_inputs) {
370  for (i = 0; i < ctx->nb_outputs; i++) {
371  ret = ff_inlink_consume_frame(ctx->inputs[cat->cur_idx + i], &frame);
372  if (ret < 0)
373  return ret;
374  if (ret) {
375  ff_filter_set_ready(ctx, 10);
376  return push_frame(ctx, cat->cur_idx + i, frame);
377  }
378  }
379  }
380 
381  /* Forward status change */
382  if (cat->cur_idx < ctx->nb_inputs) {
383  for (i = 0; i < ctx->nb_outputs; i++) {
384  ret = ff_inlink_acknowledge_status(ctx->inputs[cat->cur_idx + i], &status, &pts);
385  /* TODO use pts */
386  if (ret > 0) {
387  close_input(ctx, cat->cur_idx + i);
388  if (cat->cur_idx + ctx->nb_outputs >= ctx->nb_inputs) {
389  ff_outlink_set_status(ctx->outputs[i], status, pts);
390  }
391  if (!cat->nb_in_active) {
392  ret = flush_segment(ctx);
393  if (ret < 0)
394  return ret;
395  }
396  ff_filter_set_ready(ctx, 10);
397  return 0;
398  }
399  }
400  }
401 
402  ret = FFERROR_NOT_READY;
403  for (i = 0; i < ctx->nb_outputs; i++) {
404  if (ff_outlink_frame_wanted(ctx->outputs[i])) {
405  if (cat->in[cat->cur_idx + i].eof) {
406  for (j = 0; j < ctx->nb_outputs; j++)
407  if (!cat->in[cat->cur_idx + j].eof)
408  ff_inlink_request_frame(ctx->inputs[cat->cur_idx + j]);
409  return 0;
410  } else {
411  ff_inlink_request_frame(ctx->inputs[cat->cur_idx + i]);
412  ret = 0;
413  }
414  }
415  }
416 
417  return ret;
418 }
419 
420 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
421  char *res, int res_len, int flags)
422 {
423  int ret = AVERROR(ENOSYS);
424 
425  if (!strcmp(cmd, "next")) {
426  av_log(ctx, AV_LOG_VERBOSE, "Command received: next\n");
427  return flush_segment(ctx);
428  }
429 
430  return ret;
431 }
432 
434  .name = "concat",
435  .description = NULL_IF_CONFIG_SMALL("Concatenate audio and video streams."),
436  .init = init,
437  .uninit = uninit,
438  .query_formats = query_formats,
439  .activate = activate,
440  .priv_size = sizeof(ConcatContext),
441  .inputs = NULL,
442  .outputs = NULL,
443  .priv_class = &concat_class,
446 };
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:1481
#define NULL
Definition: coverity.c:32
static AVFrame * get_audio_buffer(AVFilterLink *inlink, int nb_samples)
Definition: avf_concat.c:195
static int flush_segment(AVFilterContext *ctx)
Definition: avf_concat.c:261
static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no, int64_t seg_delta)
Definition: avf_concat.c:228
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
static av_cold int init(AVFilterContext *ctx)
Definition: avf_concat.c:288
AVOption.
Definition: opt.h:246
unsigned nb_streams[TYPE_ALL]
number of out streams of each type
Definition: avf_concat.c:40
Main libavfilter public API header.
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:105
int num
Numerator.
Definition: rational.h:59
#define FFERROR_NOT_READY
Filters implementation helper functions.
Definition: filters.h:34
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
#define FF_OUTLINK_IDX(link)
Definition: internal.h:349
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
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
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1607
static int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Definition: filters.h:172
AVFilter ff_avf_concat
Definition: avf_concat.c:433
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
#define V
Definition: avf_concat.c:56
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_concat.c:333
const char * name
Pad name.
Definition: internal.h:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:349
static int nb_streams
Definition: ffprobe.c:276
#define av_cold
Definition: attributes.h:82
AVOptions.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:319
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: avf_concat.c:186
static AVFrame * frame
static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
Definition: avf_concat.c:161
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:111
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: avf_concat.c:420
#define av_log(a,...)
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:350
A filter pad used for either input or output.
Definition: internal.h:54
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
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:1436
static int activate(AVFilterContext *ctx)
Definition: avf_concat.c:345
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:345
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:237
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
#define AVERROR(e)
Definition: error.h:43
unsigned nb_outputs
number of output pads
Definition: avfilter.h:351
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define A
Definition: avf_concat.c:54
simple assert() macros that are a bit more flexible than ISO C assert().
#define FFMAX(a, b)
Definition: common.h:94
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
int64_t delta_ts
timestamp to add to produce output timestamps
Definition: avf_concat.c:43
audio channel layout utility functions
unsigned nb_inputs
number of input pads
Definition: avfilter.h:347
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
#define FFMIN(a, b)
Definition: common.h:96
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
static void close_input(AVFilterContext *ctx, unsigned in_no)
Definition: avf_concat.c:204
uint8_t w
Definition: llviddspenc.c:38
static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta)
Definition: avf_concat.c:214
unsigned nb_segments
Definition: avf_concat.c:41
static const AVClass concat_class
Definition: concatdec.c:765
AVFormatContext * ctx
Definition: movenc.c:48
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:401
#define cat(a, bpp, b)
Definition: vp9dsp_init.h:29
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
A list of supported channel layouts.
Definition: formats.h:85
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
unsigned cur_idx
index of the first input of current segment
Definition: avf_concat.c:42
void * buf
Definition: avisynth_c.h:690
#define OFFSET(x)
Definition: avf_concat.c:53
GLint GLenum type
Definition: opengl_enc.c:105
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
Definition: avfilter.c:1630
Rational number (pair of numerator and denominator).
Definition: rational.h:58
unsigned nb_in_active
number of active inputs in current segment
Definition: avf_concat.c:44
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
Definition: avfilter.c:1615
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
static int64_t pts
#define flags(name, subs,...)
Definition: cbs_av1.c:596
#define FF_INLINK_IDX(link)
Find the index of a link.
Definition: internal.h:348
static int query_formats(AVFilterContext *ctx)
Definition: avf_concat.c:75
#define TYPE_ALL
Definition: avf_concat.c:36
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:193
#define F
Definition: avf_concat.c:55
unsigned unsafe
Definition: avf_concat.c:45
int den
Denominator.
Definition: rational.h:60
static int config_output(AVFilterLink *outlink)
Definition: avf_concat.c:120
struct ConcatContext::concat_in * in
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
AVFILTER_DEFINE_CLASS(concat)
#define av_freep(p)
static const AVOption concat_options[]
Definition: avf_concat.c:58
formats
Definition: signature.h:48
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:273
static const int rates[]
Definition: avresample.c:176
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:285
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:292
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:277