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 #define FF_BUFQUEUE_SIZE 256
32 #include "bufferqueue.h"
33 #include "internal.h"
34 #include "video.h"
35 #include "audio.h"
36 
37 #define TYPE_ALL 2
38 
39 typedef struct {
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  struct FFBufQueue queue;
52  } *in;
54 
55 #define OFFSET(x) offsetof(ConcatContext, x)
56 #define A AV_OPT_FLAG_AUDIO_PARAM
57 #define F AV_OPT_FLAG_FILTERING_PARAM
58 #define V AV_OPT_FLAG_VIDEO_PARAM
59 
60 static const AVOption concat_options[] = {
61  { "n", "specify the number of segments", OFFSET(nb_segments),
62  AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, V|A|F},
63  { "v", "specify the number of video streams",
65  AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, V|F },
66  { "a", "specify the number of audio streams",
68  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A|F},
69  { "unsafe", "enable unsafe mode",
70  OFFSET(unsafe),
71  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, V|A|F},
72  { NULL }
73 };
74 
75 AVFILTER_DEFINE_CLASS(concat);
76 
78 {
79  ConcatContext *cat = ctx->priv;
80  unsigned type, nb_str, idx0 = 0, idx, str, seg;
83  int ret;
84 
85  for (type = 0; type < TYPE_ALL; type++) {
86  nb_str = cat->nb_streams[type];
87  for (str = 0; str < nb_str; str++) {
88  idx = idx0;
89 
90  /* Set the output formats */
91  formats = ff_all_formats(type);
92  if ((ret = ff_formats_ref(formats, &ctx->outputs[idx]->in_formats)) < 0)
93  return ret;
94 
95  if (type == AVMEDIA_TYPE_AUDIO) {
96  rates = ff_all_samplerates();
97  if ((ret = ff_formats_ref(rates, &ctx->outputs[idx]->in_samplerates)) < 0)
98  return ret;
99  layouts = ff_all_channel_layouts();
100  if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->in_channel_layouts)) < 0)
101  return ret;
102  }
103 
104  /* Set the same formats for each corresponding input */
105  for (seg = 0; seg < cat->nb_segments; seg++) {
106  if ((ret = ff_formats_ref(formats, &ctx->inputs[idx]->out_formats)) < 0)
107  return ret;
108  if (type == AVMEDIA_TYPE_AUDIO) {
109  if ((ret = ff_formats_ref(rates, &ctx->inputs[idx]->out_samplerates)) < 0 ||
110  (ret = ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->out_channel_layouts)) < 0)
111  return ret;
112  }
113  idx += ctx->nb_outputs;
114  }
115 
116  idx0++;
117  }
118  }
119  return 0;
120 }
121 
122 static int config_output(AVFilterLink *outlink)
123 {
124  AVFilterContext *ctx = outlink->src;
125  ConcatContext *cat = ctx->priv;
126  unsigned out_no = FF_OUTLINK_IDX(outlink);
127  unsigned in_no = out_no, seg;
128  AVFilterLink *inlink = ctx->inputs[in_no];
129 
130  /* enhancement: find a common one */
131  outlink->time_base = AV_TIME_BASE_Q;
132  outlink->w = inlink->w;
133  outlink->h = inlink->h;
134  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
135  outlink->format = inlink->format;
136  for (seg = 1; seg < cat->nb_segments; seg++) {
137  inlink = ctx->inputs[in_no += ctx->nb_outputs];
138  if (!outlink->sample_aspect_ratio.num)
139  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
140  /* possible enhancement: unsafe mode, do not check */
141  if (outlink->w != inlink->w ||
142  outlink->h != inlink->h ||
143  outlink->sample_aspect_ratio.num != inlink->sample_aspect_ratio.num &&
144  inlink->sample_aspect_ratio.num ||
145  outlink->sample_aspect_ratio.den != inlink->sample_aspect_ratio.den) {
146  av_log(ctx, AV_LOG_ERROR, "Input link %s parameters "
147  "(size %dx%d, SAR %d:%d) do not match the corresponding "
148  "output link %s parameters (%dx%d, SAR %d:%d)\n",
149  ctx->input_pads[in_no].name, inlink->w, inlink->h,
150  inlink->sample_aspect_ratio.num,
151  inlink->sample_aspect_ratio.den,
152  ctx->input_pads[out_no].name, outlink->w, outlink->h,
153  outlink->sample_aspect_ratio.num,
154  outlink->sample_aspect_ratio.den);
155  if (!cat->unsafe)
156  return AVERROR(EINVAL);
157  }
158  }
159 
160  return 0;
161 }
162 
163 static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
164 {
165  ConcatContext *cat = ctx->priv;
166  unsigned out_no = in_no % ctx->nb_outputs;
167  AVFilterLink * inlink = ctx-> inputs[ in_no];
168  AVFilterLink *outlink = ctx->outputs[out_no];
169  struct concat_in *in = &cat->in[in_no];
170 
171  buf->pts = av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);
172  in->pts = buf->pts;
173  in->nb_frames++;
174  /* add duration to input PTS */
175  if (inlink->sample_rate)
176  /* use number of audio samples */
177  in->pts += av_rescale_q(buf->nb_samples,
178  av_make_q(1, inlink->sample_rate),
179  outlink->time_base);
180  else if (in->nb_frames >= 2)
181  /* use mean duration */
182  in->pts = av_rescale(in->pts, in->nb_frames, in->nb_frames - 1);
183 
184  buf->pts += cat->delta_ts;
185  return ff_filter_frame(outlink, buf);
186 }
187 
188 static int process_frame(AVFilterLink *inlink, AVFrame *buf)
189 {
190  AVFilterContext *ctx = inlink->dst;
191  ConcatContext *cat = ctx->priv;
192  unsigned in_no = FF_INLINK_IDX(inlink);
193 
194  if (in_no < cat->cur_idx) {
195  av_log(ctx, AV_LOG_ERROR, "Frame after EOF on input %s\n",
196  ctx->input_pads[in_no].name);
197  av_frame_free(&buf);
198  } else if (in_no >= cat->cur_idx + ctx->nb_outputs) {
199  ff_bufqueue_add(ctx, &cat->in[in_no].queue, buf);
200  } else {
201  return push_frame(ctx, in_no, buf);
202  }
203  return 0;
204 }
205 
206 static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
207 {
208  AVFilterContext *ctx = inlink->dst;
209  unsigned in_no = FF_INLINK_IDX(inlink);
210  AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs];
211 
212  return ff_get_video_buffer(outlink, w, h);
213 }
214 
215 static AVFrame *get_audio_buffer(AVFilterLink *inlink, int nb_samples)
216 {
217  AVFilterContext *ctx = inlink->dst;
218  unsigned in_no = FF_INLINK_IDX(inlink);
219  AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs];
220 
221  return ff_get_audio_buffer(outlink, nb_samples);
222 }
223 
224 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
225 {
226  return process_frame(inlink, buf);
227 }
228 
229 static void close_input(AVFilterContext *ctx, unsigned in_no)
230 {
231  ConcatContext *cat = ctx->priv;
232 
233  cat->in[in_no].eof = 1;
234  cat->nb_in_active--;
235  av_log(ctx, AV_LOG_VERBOSE, "EOF on %s, %d streams left in segment.\n",
236  ctx->input_pads[in_no].name, cat->nb_in_active);
237 }
238 
239 static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta)
240 {
241  ConcatContext *cat = ctx->priv;
242  unsigned i = cat->cur_idx;
243  unsigned imax = i + ctx->nb_outputs;
244  int64_t pts;
245 
246  pts = cat->in[i++].pts;
247  for (; i < imax; i++)
248  pts = FFMAX(pts, cat->in[i].pts);
249  cat->delta_ts += pts;
250  *seg_delta = pts;
251 }
252 
253 static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no,
254  int64_t seg_delta)
255 {
256  ConcatContext *cat = ctx->priv;
257  AVFilterLink *outlink = ctx->outputs[out_no];
258  int64_t base_pts = cat->in[in_no].pts + cat->delta_ts - seg_delta;
259  int64_t nb_samples, sent = 0;
260  int frame_nb_samples, ret;
261  AVRational rate_tb = { 1, ctx->inputs[in_no]->sample_rate };
262  AVFrame *buf;
264 
265  if (!rate_tb.den)
266  return AVERROR_BUG;
267  nb_samples = av_rescale_q(seg_delta - cat->in[in_no].pts,
268  outlink->time_base, rate_tb);
269  frame_nb_samples = FFMAX(9600, rate_tb.den / 5); /* arbitrary */
270  while (nb_samples) {
271  frame_nb_samples = FFMIN(frame_nb_samples, nb_samples);
272  buf = ff_get_audio_buffer(outlink, frame_nb_samples);
273  if (!buf)
274  return AVERROR(ENOMEM);
275  av_samples_set_silence(buf->extended_data, 0, frame_nb_samples,
276  nb_channels, outlink->format);
277  buf->pts = base_pts + av_rescale_q(sent, rate_tb, outlink->time_base);
278  ret = ff_filter_frame(outlink, buf);
279  if (ret < 0)
280  return ret;
281  sent += frame_nb_samples;
282  nb_samples -= frame_nb_samples;
283  }
284  return 0;
285 }
286 
288 {
289  int ret;
290  ConcatContext *cat = ctx->priv;
291  unsigned str, str_max;
292  int64_t seg_delta;
293 
294  find_next_delta_ts(ctx, &seg_delta);
295  cat->cur_idx += ctx->nb_outputs;
296  cat->nb_in_active = ctx->nb_outputs;
297  av_log(ctx, AV_LOG_VERBOSE, "Segment finished at pts=%"PRId64"\n",
298  cat->delta_ts);
299 
300  if (cat->cur_idx < ctx->nb_inputs) {
301  /* pad audio streams with silence */
302  str = cat->nb_streams[AVMEDIA_TYPE_VIDEO];
303  str_max = str + cat->nb_streams[AVMEDIA_TYPE_AUDIO];
304  for (; str < str_max; str++) {
305  ret = send_silence(ctx, cat->cur_idx - ctx->nb_outputs + str, str,
306  seg_delta);
307  if (ret < 0)
308  return ret;
309  }
310  /* flush queued buffers */
311  /* possible enhancement: flush in PTS order */
312  str_max = cat->cur_idx + ctx->nb_outputs;
313  for (str = cat->cur_idx; str < str_max; str++) {
314  while (cat->in[str].queue.available) {
315  ret = push_frame(ctx, str, ff_bufqueue_get(&cat->in[str].queue));
316  if (ret < 0)
317  return ret;
318  }
319  }
320  }
321  return 0;
322 }
323 
324 static int request_frame(AVFilterLink *outlink)
325 {
326  AVFilterContext *ctx = outlink->src;
327  ConcatContext *cat = ctx->priv;
328  unsigned out_no = FF_OUTLINK_IDX(outlink);
329  unsigned in_no = out_no + cat->cur_idx;
330  unsigned str, str_max;
331  int ret;
332 
333  while (1) {
334  if (in_no >= ctx->nb_inputs)
335  return AVERROR_EOF;
336  if (!cat->in[in_no].eof) {
337  ret = ff_request_frame(ctx->inputs[in_no]);
338  if (ret != AVERROR_EOF)
339  return ret;
340  close_input(ctx, in_no);
341  }
342  /* cycle on all inputs to finish the segment */
343  /* possible enhancement: request in PTS order */
344  str_max = cat->cur_idx + ctx->nb_outputs - 1;
345  for (str = cat->cur_idx; cat->nb_in_active;
346  str = str == str_max ? cat->cur_idx : str + 1) {
347  if (cat->in[str].eof)
348  continue;
349  ret = ff_request_frame(ctx->inputs[str]);
350  if (ret != AVERROR_EOF)
351  return ret;
352  close_input(ctx, str);
353  }
354  ret = flush_segment(ctx);
355  if (ret < 0)
356  return ret;
357  in_no += ctx->nb_outputs;
358  }
359 }
360 
362 {
363  ConcatContext *cat = ctx->priv;
364  unsigned seg, type, str;
365 
366  /* create input pads */
367  for (seg = 0; seg < cat->nb_segments; seg++) {
368  for (type = 0; type < TYPE_ALL; type++) {
369  for (str = 0; str < cat->nb_streams[type]; str++) {
370  AVFilterPad pad = {
371  .type = type,
372  .get_video_buffer = get_video_buffer,
373  .get_audio_buffer = get_audio_buffer,
374  .filter_frame = filter_frame,
375  };
376  pad.name = av_asprintf("in%d:%c%d", seg, "va"[type], str);
377  ff_insert_inpad(ctx, ctx->nb_inputs, &pad);
378  }
379  }
380  }
381  /* create output pads */
382  for (type = 0; type < TYPE_ALL; type++) {
383  for (str = 0; str < cat->nb_streams[type]; str++) {
384  AVFilterPad pad = {
385  .type = type,
386  .config_props = config_output,
387  .request_frame = request_frame,
388  };
389  pad.name = av_asprintf("out:%c%d", "va"[type], str);
390  ff_insert_outpad(ctx, ctx->nb_outputs, &pad);
391  }
392  }
393 
394  cat->in = av_calloc(ctx->nb_inputs, sizeof(*cat->in));
395  if (!cat->in)
396  return AVERROR(ENOMEM);
397  cat->nb_in_active = ctx->nb_outputs;
398  return 0;
399 }
400 
402 {
403  ConcatContext *cat = ctx->priv;
404  unsigned i;
405 
406  for (i = 0; i < ctx->nb_inputs; i++) {
407  av_freep(&ctx->input_pads[i].name);
408  ff_bufqueue_discard_all(&cat->in[i].queue);
409  }
410  for (i = 0; i < ctx->nb_outputs; i++)
411  av_freep(&ctx->output_pads[i].name);
412  av_freep(&cat->in);
413 }
414 
416  .name = "concat",
417  .description = NULL_IF_CONFIG_SMALL("Concatenate audio and video streams."),
418  .init = init,
419  .uninit = uninit,
420  .query_formats = query_formats,
421  .priv_size = sizeof(ConcatContext),
422  .inputs = NULL,
423  .outputs = NULL,
424  .priv_class = &concat_class,
426 };
static AVFrame * ff_bufqueue_get(struct FFBufQueue *queue)
Get the first buffer from the queue and remove it.
Definition: bufferqueue.h:98
#define NULL
Definition: coverity.c:32
static AVFrame * get_audio_buffer(AVFilterLink *inlink, int nb_samples)
Definition: avf_concat.c:215
static int flush_segment(AVFilterContext *ctx)
Definition: avf_concat.c:287
static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no, int64_t seg_delta)
Definition: avf_concat.c:253
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
static av_cold int init(AVFilterContext *ctx)
Definition: avf_concat.c:361
AVOption.
Definition: opt.h:245
unsigned nb_streams[TYPE_ALL]
number of out streams of each type
Definition: avf_concat.c:41
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:103
static int request_frame(AVFilterLink *outlink)
Definition: avf_concat.c:324
int num
numerator
Definition: rational.h:44
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:64
#define FF_OUTLINK_IDX(link)
Definition: internal.h:354
static enum AVSampleFormat formats[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:76
static AVRational av_make_q(int num, int den)
Create a rational.
Definition: rational.h:53
AVFilter ff_avf_concat
Definition: avf_concat.c:415
#define V
Definition: avf_concat.c:58
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
Structure holding the queue.
Definition: bufferqueue.h:49
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_concat.c:401
const char * name
Pad name.
Definition: internal.h:59
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:313
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:1180
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:316
static int nb_streams
Definition: ffprobe.c:254
#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:268
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: avf_concat.c:206
static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
Definition: avf_concat.c:163
#define AVERROR_EOF
End of file.
Definition: error.h:55
#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:109
#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
static const int rates[]
A filter pad used for either input or output.
Definition: internal.h:53
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
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:312
#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:235
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:65
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:153
unsigned nb_outputs
number of output pads
Definition: avfilter.h:318
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: avf_concat.c:224
void * priv
private data for use by the filter
Definition: avfilter.h:320
#define A
Definition: avf_concat.c:56
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
AVFrame * queue[FF_BUFQUEUE_SIZE]
Definition: bufferqueue.h:50
#define cat(a, bpp, b)
Definition: vp9dsp_init.h:29
int64_t delta_ts
timestamp to add to produce output timestamps
Definition: avf_concat.c:44
audio channel layout utility functions
static int process_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: avf_concat.c:188
unsigned nb_inputs
number of input pads
Definition: avfilter.h:314
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:229
static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta)
Definition: avf_concat.c:239
unsigned nb_segments
Definition: avf_concat.c:42
static const AVClass concat_class
Definition: concatdec.c:766
AVFormatContext * ctx
Definition: movenc.c:48
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
static void ff_bufqueue_discard_all(struct FFBufQueue *queue)
Unref and remove all buffers from the queue.
Definition: bufferqueue.h:111
struct FFBufQueue queue
Definition: avf_concat.c:51
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:401
A list of supported channel layouts.
Definition: formats.h:85
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:252
unsigned short available
number of available buffers
Definition: bufferqueue.h:52
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:43
void * buf
Definition: avisynth_c.h:553
#define OFFSET(x)
Definition: avf_concat.c:55
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:142
rational number numerator/denominator
Definition: rational.h:43
unsigned nb_in_active
number of active inputs in current segment
Definition: avf_concat.c:45
const char * name
Filter name.
Definition: avfilter.h:146
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:317
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:260
static int64_t pts
Global timestamp for the audio frames.
static int flags
Definition: cpu.c:47
#define FF_INLINK_IDX(link)
Find the index of a link.
Definition: internal.h:353
static int query_formats(AVFilterContext *ctx)
Definition: avf_concat.c:77
#define TYPE_ALL
Definition: avf_concat.c:37
#define F
Definition: avf_concat.c:57
unsigned unsafe
Definition: avf_concat.c:46
int den
denominator
Definition: rational.h:45
static int config_output(AVFilterLink *outlink)
Definition: avf_concat.c:122
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:305
AVFILTER_DEFINE_CLASS(concat)
#define av_freep(p)
static const AVOption concat_options[]
Definition: avf_concat.c:60
static void ff_bufqueue_add(void *log, struct FFBufQueue *queue, AVFrame *buf)
Add a buffer to the queue.
Definition: bufferqueue.h:71
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:369
int nb_channels
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:231
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:291
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:241
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:283