Libav
avconv_filter.c
Go to the documentation of this file.
1 /*
2  * avconv filter configuration
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdint.h>
22 
23 #include "avconv.h"
24 
25 #include "libavfilter/avfilter.h"
26 
28 
29 #include "libavutil/avassert.h"
30 #include "libavutil/avstring.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/pixfmt.h"
35 #include "libavutil/samplefmt.h"
36 
37 /* Define a function for building a string containing a list of
38  * allowed formats. */
39 #define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name) \
40 static char *choose_ ## var ## s(OutputStream *ost) \
41 { \
42  if (ost->enc_ctx->var != none) { \
43  get_name(ost->enc_ctx->var); \
44  return av_strdup(name); \
45  } else if (ost->enc && ost->enc->supported_list) { \
46  const type *p; \
47  AVIOContext *s = NULL; \
48  uint8_t *ret; \
49  int len; \
50  \
51  if (avio_open_dyn_buf(&s) < 0) \
52  exit(1); \
53  \
54  for (p = ost->enc->supported_list; *p != none; p++) { \
55  get_name(*p); \
56  avio_printf(s, "%s|", name); \
57  } \
58  len = avio_close_dyn_buf(s, &ret); \
59  ret[len - 1] = 0; \
60  return ret; \
61  } else \
62  return NULL; \
63 }
64 
67 
70 
71 DEF_CHOOSE_FORMAT(int, sample_rate, supported_samplerates, 0,
73 
74 DEF_CHOOSE_FORMAT(uint64_t, channel_layout, channel_layouts, 0,
76 
78 {
79  FilterGraph *fg = av_mallocz(sizeof(*fg));
80 
81  if (!fg)
82  exit(1);
83  fg->index = nb_filtergraphs;
84 
85  GROW_ARRAY(fg->outputs, fg->nb_outputs);
86  if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
87  exit(1);
88  fg->outputs[0]->ost = ost;
89  fg->outputs[0]->graph = fg;
90 
91  ost->filter = fg->outputs[0];
92 
93  GROW_ARRAY(fg->inputs, fg->nb_inputs);
94  if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
95  exit(1);
96  fg->inputs[0]->ist = ist;
97  fg->inputs[0]->graph = fg;
98 
99  GROW_ARRAY(ist->filters, ist->nb_filters);
100  ist->filters[ist->nb_filters - 1] = fg->inputs[0];
101 
103  filtergraphs[nb_filtergraphs - 1] = fg;
104 
105  return fg;
106 }
107 
109 {
110  InputStream *ist = NULL;
112  int i;
113 
114  // TODO: support other filter types
115  if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
116  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
117  "currently.\n");
118  exit(1);
119  }
120 
121  if (in->name) {
122  AVFormatContext *s;
123  AVStream *st = NULL;
124  char *p;
125  int file_idx = strtol(in->name, &p, 0);
126 
127  if (file_idx < 0 || file_idx >= nb_input_files) {
128  av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtegraph description %s.\n",
129  file_idx, fg->graph_desc);
130  exit(1);
131  }
132  s = input_files[file_idx]->ctx;
133 
134  for (i = 0; i < s->nb_streams; i++) {
135  if (s->streams[i]->codec->codec_type != type)
136  continue;
137  if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
138  st = s->streams[i];
139  break;
140  }
141  }
142  if (!st) {
143  av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
144  "matches no streams.\n", p, fg->graph_desc);
145  exit(1);
146  }
147  ist = input_streams[input_files[file_idx]->ist_index + st->index];
148  } else {
149  /* find the first unused stream of corresponding type */
150  for (i = 0; i < nb_input_streams; i++) {
151  ist = input_streams[i];
152  if (ist->dec_ctx->codec_type == type && ist->discard)
153  break;
154  }
155  if (i == nb_input_streams) {
156  av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
157  "unlabeled input pad %d on filter %s\n", in->pad_idx,
158  in->filter_ctx->name);
159  exit(1);
160  }
161  }
162  av_assert0(ist);
163 
164  ist->discard = 0;
165  ist->decoding_needed = 1;
166  ist->st->discard = AVDISCARD_NONE;
167 
168  GROW_ARRAY(fg->inputs, fg->nb_inputs);
169  if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
170  exit(1);
171  fg->inputs[fg->nb_inputs - 1]->ist = ist;
172  fg->inputs[fg->nb_inputs - 1]->graph = fg;
173 
174  GROW_ARRAY(ist->filters, ist->nb_filters);
175  ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
176 }
177 
178 static int insert_trim(int64_t start_time, int64_t duration,
179  AVFilterContext **last_filter, int *pad_idx,
180  const char *filter_name)
181 {
182  AVFilterGraph *graph = (*last_filter)->graph;
183  AVFilterContext *ctx;
184  const AVFilter *trim;
185  enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
186  const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
187  int ret = 0;
188 
189  if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
190  return 0;
191 
192  trim = avfilter_get_by_name(name);
193  if (!trim) {
194  av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
195  "recording time.\n", name);
197  }
198 
199  ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
200  if (!ctx)
201  return AVERROR(ENOMEM);
202 
203  if (duration != INT64_MAX) {
204  ret = av_opt_set_double(ctx, "duration", (double)duration / 1e6,
206  }
207  if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
208  ret = av_opt_set_double(ctx, "start", (double)start_time / 1e6,
210  }
211  if (ret < 0) {
212  av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
213  return ret;
214  }
215 
216  ret = avfilter_init_str(ctx, NULL);
217  if (ret < 0)
218  return ret;
219 
220  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
221  if (ret < 0)
222  return ret;
223 
224  *last_filter = ctx;
225  *pad_idx = 0;
226  return 0;
227 }
228 
230 {
231  char *pix_fmts;
232  OutputStream *ost = ofilter->ost;
233  OutputFile *of = output_files[ost->file_index];
234  AVCodecContext *codec = ost->enc_ctx;
235  AVFilterContext *last_filter = out->filter_ctx;
236  int pad_idx = out->pad_idx;
237  int ret;
238  char name[255];
239 
240  snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
241  ret = avfilter_graph_create_filter(&ofilter->filter,
242  avfilter_get_by_name("buffersink"),
243  name, NULL, NULL, fg->graph);
244  if (ret < 0)
245  return ret;
246 
247  if (codec->width || codec->height) {
248  char args[255];
250 
251  snprintf(args, sizeof(args), "%d:%d:0x%X",
252  codec->width,
253  codec->height,
254  (unsigned)ost->sws_flags);
255  snprintf(name, sizeof(name), "scaler for output stream %d:%d",
256  ost->file_index, ost->index);
257  if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
258  name, args, NULL, fg->graph)) < 0)
259  return ret;
260  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
261  return ret;
262 
263  last_filter = filter;
264  pad_idx = 0;
265  }
266 
267  if ((pix_fmts = choose_pix_fmts(ost))) {
269  snprintf(name, sizeof(name), "pixel format for output stream %d:%d",
270  ost->file_index, ost->index);
271  if ((ret = avfilter_graph_create_filter(&filter,
272  avfilter_get_by_name("format"),
273  "format", pix_fmts, NULL,
274  fg->graph)) < 0)
275  return ret;
276  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
277  return ret;
278 
279  last_filter = filter;
280  pad_idx = 0;
281  av_freep(&pix_fmts);
282  }
283 
284  if (ost->frame_rate.num) {
285  AVFilterContext *fps;
286  char args[255];
287 
288  snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
289  ost->frame_rate.den);
290  snprintf(name, sizeof(name), "fps for output stream %d:%d",
291  ost->file_index, ost->index);
293  name, args, NULL, fg->graph);
294  if (ret < 0)
295  return ret;
296 
297  ret = avfilter_link(last_filter, pad_idx, fps, 0);
298  if (ret < 0)
299  return ret;
300  last_filter = fps;
301  pad_idx = 0;
302  }
303 
304  snprintf(name, sizeof(name), "trim for output stream %d:%d",
305  ost->file_index, ost->index);
306  ret = insert_trim(of->start_time, of->recording_time,
307  &last_filter, &pad_idx, name);
308  if (ret < 0)
309  return ret;
310 
311 
312  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
313  return ret;
314 
315  return 0;
316 }
317 
319 {
320  OutputStream *ost = ofilter->ost;
321  OutputFile *of = output_files[ost->file_index];
322  AVCodecContext *codec = ost->enc_ctx;
323  AVFilterContext *last_filter = out->filter_ctx;
324  int pad_idx = out->pad_idx;
325  char *sample_fmts, *sample_rates, *channel_layouts;
326  char name[255];
327  int ret;
328 
329 
330  snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
331  ret = avfilter_graph_create_filter(&ofilter->filter,
332  avfilter_get_by_name("abuffersink"),
333  name, NULL, NULL, fg->graph);
334  if (ret < 0)
335  return ret;
336 
337  if (codec->channels && !codec->channel_layout)
339 
340  sample_fmts = choose_sample_fmts(ost);
341  sample_rates = choose_sample_rates(ost);
342  channel_layouts = choose_channel_layouts(ost);
343  if (sample_fmts || sample_rates || channel_layouts) {
344  AVFilterContext *format;
345  char args[256];
346  int len = 0;
347 
348  if (sample_fmts)
349  len += snprintf(args + len, sizeof(args) - len, "sample_fmts=%s:",
350  sample_fmts);
351  if (sample_rates)
352  len += snprintf(args + len, sizeof(args) - len, "sample_rates=%s:",
353  sample_rates);
354  if (channel_layouts)
355  len += snprintf(args + len, sizeof(args) - len, "channel_layouts=%s:",
356  channel_layouts);
357  args[len - 1] = 0;
358 
359  av_freep(&sample_fmts);
360  av_freep(&sample_rates);
361  av_freep(&channel_layouts);
362 
363  snprintf(name, sizeof(name), "audio format for output stream %d:%d",
364  ost->file_index, ost->index);
365  ret = avfilter_graph_create_filter(&format,
366  avfilter_get_by_name("aformat"),
367  name, args, NULL, fg->graph);
368  if (ret < 0)
369  return ret;
370 
371  ret = avfilter_link(last_filter, pad_idx, format, 0);
372  if (ret < 0)
373  return ret;
374 
375  last_filter = format;
376  pad_idx = 0;
377  }
378 
379  snprintf(name, sizeof(name), "trim for output stream %d:%d",
380  ost->file_index, ost->index);
381  ret = insert_trim(of->start_time, of->recording_time,
382  &last_filter, &pad_idx, name);
383  if (ret < 0)
384  return ret;
385 
386  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
387  return ret;
388 
389  return 0;
390 }
391 
392 #define DESCRIBE_FILTER_LINK(f, inout, in) \
393 { \
394  AVFilterContext *ctx = inout->filter_ctx; \
395  AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \
396  int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; \
397  AVIOContext *pb; \
398  \
399  if (avio_open_dyn_buf(&pb) < 0) \
400  exit(1); \
401  \
402  avio_printf(pb, "%s", ctx->filter->name); \
403  if (nb_pads > 1) \
404  avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
405  avio_w8(pb, 0); \
406  avio_close_dyn_buf(pb, &f->name); \
407 }
408 
410 {
411  av_freep(&ofilter->name);
412  DESCRIBE_FILTER_LINK(ofilter, out, 0);
413 
414  switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
415  case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
416  case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
417  default: av_assert0(0);
418  }
419 }
420 
422  AVFilterInOut *in)
423 {
424  AVFilterContext *last_filter;
425  const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
426  InputStream *ist = ifilter->ist;
427  InputFile *f = input_files[ist->file_index];
428  AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
429  ist->st->time_base;
430  AVRational sar;
431  char args[255], name[255];
432  int ret, pad_idx = 0;
433 
434  sar = ist->st->sample_aspect_ratio.num ?
435  ist->st->sample_aspect_ratio :
437  snprintf(args, sizeof(args), "%d:%d:%d:%d:%d:%d:%d", ist->dec_ctx->width,
438  ist->dec_ctx->height,
440  tb.num, tb.den, sar.num, sar.den);
441  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
442  ist->file_index, ist->st->index);
443 
444  if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
445  args, NULL, fg->graph)) < 0)
446  return ret;
447  last_filter = ifilter->filter;
448 
449  if (ist->framerate.num) {
450  AVFilterContext *setpts;
451 
452  snprintf(name, sizeof(name), "force CFR for input from stream %d:%d",
453  ist->file_index, ist->st->index);
454  if ((ret = avfilter_graph_create_filter(&setpts,
455  avfilter_get_by_name("setpts"),
456  name, "N", NULL,
457  fg->graph)) < 0)
458  return ret;
459 
460  if ((ret = avfilter_link(last_filter, 0, setpts, 0)) < 0)
461  return ret;
462 
463  last_filter = setpts;
464  }
465 
466  snprintf(name, sizeof(name), "trim for input stream %d:%d",
467  ist->file_index, ist->st->index);
468  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
469  AV_NOPTS_VALUE : 0, f->recording_time, &last_filter, &pad_idx, name);
470  if (ret < 0)
471  return ret;
472 
473  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
474  return ret;
475  return 0;
476 }
477 
479  AVFilterInOut *in)
480 {
481  AVFilterContext *last_filter;
482  const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
483  InputStream *ist = ifilter->ist;
484  InputFile *f = input_files[ist->file_index];
485  char args[255], name[255];
486  int ret, pad_idx = 0;
487 
488  snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s"
489  ":channel_layout=0x%"PRIx64,
490  1, ist->dec_ctx->sample_rate,
491  ist->dec_ctx->sample_rate,
493  ist->dec_ctx->channel_layout);
494  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
495  ist->file_index, ist->st->index);
496 
497  if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
498  name, args, NULL,
499  fg->graph)) < 0)
500  return ret;
501  last_filter = ifilter->filter;
502 
503  if (audio_sync_method > 0) {
504  AVFilterContext *async;
505  int len = 0;
506 
507  av_log(NULL, AV_LOG_WARNING, "-async has been deprecated. Used the "
508  "asyncts audio filter instead.\n");
509 
510  if (audio_sync_method > 1)
511  len += snprintf(args + len, sizeof(args) - len, "compensate=1:"
512  "max_comp=%d:", audio_sync_method);
513  snprintf(args + len, sizeof(args) - len, "min_delta=%f",
515 
516  snprintf(name, sizeof(name), "graph %d audio sync for input stream %d:%d",
517  fg->index, ist->file_index, ist->st->index);
518  ret = avfilter_graph_create_filter(&async,
519  avfilter_get_by_name("asyncts"),
520  name, args, NULL, fg->graph);
521  if (ret < 0)
522  return ret;
523 
524  ret = avfilter_link(last_filter, 0, async, 0);
525  if (ret < 0)
526  return ret;
527 
528  last_filter = async;
529  }
530  if (audio_volume != 256) {
531  AVFilterContext *volume;
532 
533  av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
534  "audio filter instead.\n");
535 
536  snprintf(args, sizeof(args), "volume=%f", audio_volume / 256.0);
537 
538  snprintf(name, sizeof(name), "graph %d volume for input stream %d:%d",
539  fg->index, ist->file_index, ist->st->index);
540  ret = avfilter_graph_create_filter(&volume,
541  avfilter_get_by_name("volume"),
542  name, args, NULL, fg->graph);
543  if (ret < 0)
544  return ret;
545 
546  ret = avfilter_link(last_filter, 0, volume, 0);
547  if (ret < 0)
548  return ret;
549 
550  last_filter = volume;
551  }
552 
553  snprintf(name, sizeof(name), "trim for input stream %d:%d",
554  ist->file_index, ist->st->index);
555  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
556  AV_NOPTS_VALUE : 0, f->recording_time, &last_filter, &pad_idx, name);
557  if (ret < 0)
558  return ret;
559 
560  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
561  return ret;
562 
563  return 0;
564 }
565 
567  AVFilterInOut *in)
568 {
569  av_freep(&ifilter->name);
570  DESCRIBE_FILTER_LINK(ifilter, in, 1);
571 
572  switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
573  case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
574  case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
575  default: av_assert0(0);
576  }
577 }
578 
580 {
581  AVFilterInOut *inputs, *outputs, *cur;
582  int ret, i, init = !fg->graph, simple = !fg->graph_desc;
583  const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
584  fg->graph_desc;
585 
587  if (!(fg->graph = avfilter_graph_alloc()))
588  return AVERROR(ENOMEM);
589 
590  if (simple) {
591  OutputStream *ost = fg->outputs[0]->ost;
592  char args[512];
593  AVDictionaryEntry *e = NULL;
594 
595  snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
596  fg->graph->scale_sws_opts = av_strdup(args);
597 
598  args[0] = '\0';
599  while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
601  av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
602  }
603  if (strlen(args))
604  args[strlen(args) - 1] = '\0';
605  fg->graph->resample_lavr_opts = av_strdup(args);
606  }
607 
608  if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
609  return ret;
610 
611  if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
612  av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' does not have "
613  "exactly one input and output.\n", graph_desc);
614  return AVERROR(EINVAL);
615  }
616 
617  for (cur = inputs; !simple && init && cur; cur = cur->next)
618  init_input_filter(fg, cur);
619 
620  for (cur = inputs, i = 0; cur; cur = cur->next, i++)
621  if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0)
622  return ret;
623  avfilter_inout_free(&inputs);
624 
625  if (!init || simple) {
626  /* we already know the mappings between lavfi outputs and output streams,
627  * so we can finish the setup */
628  for (cur = outputs, i = 0; cur; cur = cur->next, i++)
629  configure_output_filter(fg, fg->outputs[i], cur);
630  avfilter_inout_free(&outputs);
631 
632  if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
633  return ret;
634  } else {
635  /* wait until output mappings are processed */
636  for (cur = outputs; cur;) {
637  GROW_ARRAY(fg->outputs, fg->nb_outputs);
638  if (!(fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]))))
639  exit(1);
640  fg->outputs[fg->nb_outputs - 1]->graph = fg;
641  fg->outputs[fg->nb_outputs - 1]->out_tmp = cur;
642  cur = cur->next;
643  fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL;
644  }
645  }
646 
647  return 0;
648 }
649 
651 {
652  int i;
653  for (i = 0; i < fg->nb_inputs; i++)
654  if (fg->inputs[i]->ist == ist)
655  return 1;
656  return 0;
657 }
658 
uint64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
int nb_input_files
Definition: avconv.c:101
int64_t recording_time
Definition: avconv.h:367
int nb_input_streams
Definition: avconv.c:99
uint8_t * name
Definition: avconv.h:199
int nb_outputs
Definition: avconv.h:214
#define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name)
Definition: avconv_filter.c:39
AVRational frame_rate
Definition: avconv.h:323
int accurate_seek
Definition: avconv.h:287
static const char * filter_name(void *p)
Definition: avfilter.c:335
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:71
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:232
Main libavfilter public API header.
AVRational framerate
Definition: avconv.h:237
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:179
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
Definition: avfilter.h:1102
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:1506
AVFilterInOut * out_tmp
Definition: avconv.h:202
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:723
int decoding_needed
Definition: avconv.h:221
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:769
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:700
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
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_dlog(ac->avr,"%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
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1445
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1270
FilterGraph * init_simple_filtergraph(InputStream *ist, OutputStream *ost)
FilterGraph ** filtergraphs
Definition: avconv.c:108
int64_t start_time
Definition: avconv.h:368
int index
Definition: avconv.h:206
static int64_t duration
Definition: avplay.c:246
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:951
struct FilterGraph * graph
Definition: avconv.h:191
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
int configure_filtergraph(FilterGraph *fg)
Format I/O context.
Definition: avformat.h:922
struct InputStream * ist
Definition: avconv.h:190
char * name
name of this filter instance
Definition: avfilter.h:568
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVFilterGraph * graph
Definition: avconv.h:209
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:75
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:577
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1815
float audio_drift_threshold
Definition: avconv_opt.c:71
AVOptions.
InputFile ** input_files
Definition: avconv.c:100
const char * name
#define DESCRIBE_FILTER_LINK(f, inout, in)
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:990
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
Definition: opt.c:273
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
char * resample_lavr_opts
libavresample options to use for the auto-inserted resample filters
Definition: avfilter.h:952
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:38
AVDictionary * resample_opts
Definition: avconv.h:343
AVFilterContext * filter
Definition: avconv.h:196
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
Definition: graphparser.c:383
int file_index
Definition: avconv.h:218
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:570
static int64_t start_time
Definition: avplay.c:245
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
#define GET_CH_LAYOUT_NAME(ch_layout)
Definition: cmdutils.h:550
AVFilterContext * filter
Definition: avconv.h:189
#define AVERROR(e)
Definition: error.h:43
sample_fmts
Definition: avconv_filter.c:68
int64_t sws_flags
Definition: avconv.h:341
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1868
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:718
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:283
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:307
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:978
int nb_filtergraphs
Definition: avconv.c:109
audio channel layout utility functions
static int insert_trim(int64_t start_time, int64_t duration, AVFilterContext **last_filter, int *pad_idx, const char *filter_name)
external API header
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:383
struct OutputStream * ost
Definition: avconv.h:197
int width
picture width / height.
Definition: avcodec.h:1229
#define GET_PIX_FMT_NAME(pix_fmt)
Definition: cmdutils.h:540
int(* hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame)
Definition: avconv.h:262
enum AVPixelFormat pix_fmt
Definition: movenc.c:843
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
#define GET_SAMPLE_FMT_NAME(sample_fmt)
Definition: cmdutils.h:543
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1096
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:601
Stream structure.
Definition: avformat.h:699
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1091
int audio_sync_method
Definition: avconv_opt.c:75
InputFilter ** filters
Definition: avconv.h:250
#define GET_SAMPLE_RATE_NAME(rate)
Definition: cmdutils.h:546
int64_t recording_time
Definition: avconv.h:283
NULL
Definition: eval.c:55
sample_fmt
Definition: avconv_filter.c:68
OutputFile ** output_files
Definition: avconv.c:105
enum AVMediaType codec_type
Definition: avcodec.h:1058
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:61
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:213
AV_SAMPLE_FMT_NONE
Definition: avconv_filter.c:68
int sample_rate
samples per second
Definition: avcodec.h:1807
int ist_index
Definition: avconv.h:280
const char * graph_desc
Definition: avconv.h:207
int64_t start_time
Definition: avconv.h:282
main external API structure.
Definition: avcodec.h:1050
AVCodecContext * enc_ctx
Definition: avconv.h:317
AVCodecContext * dec_ctx
Definition: avconv.h:222
AVStream * st
Definition: avconv.h:219
Filter definition.
Definition: avfilter.h:421
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:221
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:1099
rational number numerator/denominator
Definition: rational.h:43
int file_index
Definition: avconv.h:300
AVMediaType
Definition: avutil.h:185
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:99
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
char * name
unique name for this input/output in the list
Definition: avfilter.h:1093
int nb_filters
Definition: avconv.h:251
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:122
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
Definition: error.h:53
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_dlog(ac->avr,"%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-> out
int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
struct FilterGraph * graph
Definition: avconv.h:198
InputStream ** input_streams
Definition: avconv.c:98
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
char * key
Definition: dict.h:75
int den
denominator
Definition: rational.h:45
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
AVFormatContext * ctx
Definition: avconv.h:277
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:537
pixel format definitions
char * avfilter
Definition: avconv.h:339
uint8_t * name
Definition: avconv.h:192
char * value
Definition: dict.h:76
int audio_volume
Definition: avconv_opt.c:74
int len
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
int channels
number of audio channels
Definition: avcodec.h:1808
OutputFilter ** outputs
Definition: avconv.h:213
An instance of a filter.
Definition: avfilter.h:563
InputFilter ** inputs
Definition: avconv.h:211
enum AVPixelFormat hwaccel_retrieved_pix_fmt
Definition: avconv.h:264
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:62
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:117
int discard
Definition: avconv.h:220
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:741
int nb_inputs
Definition: avconv.h:212
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:762
int index
Definition: avconv.h:301
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228
discard nothing
Definition: avcodec.h:563
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)