FFmpeg  2.1.1
ffmpeg_filter.c
Go to the documentation of this file.
1 /*
2  * ffmpeg filter configuration
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. 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 FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "ffmpeg.h"
22 
23 #include "libavfilter/avfilter.h"
24 #include "libavfilter/buffersink.h"
25 
26 #include "libavresample/avresample.h"
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/bprint.h"
31 #include "libavutil/channel_layout.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/pixfmt.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/samplefmt.h"
37 
39 {
40  if (codec && codec->pix_fmts) {
41  const enum AVPixelFormat *p = codec->pix_fmts;
42  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
43  int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
44  enum AVPixelFormat best= AV_PIX_FMT_NONE;
46  if (st->codec->codec_id == AV_CODEC_ID_MJPEG) {
48  } else if (st->codec->codec_id == AV_CODEC_ID_LJPEG) {
51  }
52  }
53  for (; *p != AV_PIX_FMT_NONE; p++) {
54  best= avcodec_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
55  if (*p == target)
56  break;
57  }
58  if (*p == AV_PIX_FMT_NONE) {
59  if (target != AV_PIX_FMT_NONE)
60  av_log(NULL, AV_LOG_WARNING,
61  "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
62  av_get_pix_fmt_name(target),
63  codec->name,
64  av_get_pix_fmt_name(best));
65  return best;
66  }
67  }
68  return target;
69 }
70 
72 {
73  if (codec && codec->sample_fmts) {
74  const enum AVSampleFormat *p = codec->sample_fmts;
75  for (; *p != -1; p++) {
76  if (*p == st->codec->sample_fmt)
77  break;
78  }
79  if (*p == -1) {
81  av_log(NULL, AV_LOG_ERROR, "Conversion will not be lossless.\n");
83  av_log(NULL, AV_LOG_WARNING,
84  "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
86  codec->name,
88  st->codec->sample_fmt = codec->sample_fmts[0];
89  }
90  }
91 }
92 
93 static char *choose_pix_fmts(OutputStream *ost)
94 {
95  AVDictionaryEntry *strict_dict = av_dict_get(ost->opts, "strict", NULL, 0);
96  if (strict_dict)
97  // used by choose_pixel_fmt() and below
98  av_opt_set(ost->st->codec, "strict", strict_dict->value, 0);
99 
100  if (ost->keep_pix_fmt) {
101  if (ost->filter)
104  if (ost->st->codec->pix_fmt == AV_PIX_FMT_NONE)
105  return NULL;
106  return av_strdup(av_get_pix_fmt_name(ost->st->codec->pix_fmt));
107  }
108  if (ost->st->codec->pix_fmt != AV_PIX_FMT_NONE) {
109  return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc, ost->st->codec->pix_fmt)));
110  } else if (ost->enc && ost->enc->pix_fmts) {
111  const enum AVPixelFormat *p;
112  AVIOContext *s = NULL;
113  uint8_t *ret;
114  int len;
115 
116  if (avio_open_dyn_buf(&s) < 0)
117  exit_program(1);
118 
119  p = ost->enc->pix_fmts;
121  if (ost->st->codec->codec_id == AV_CODEC_ID_MJPEG) {
123  } else if (ost->st->codec->codec_id == AV_CODEC_ID_LJPEG) {
126  }
127  }
128 
129  for (; *p != AV_PIX_FMT_NONE; p++) {
130  const char *name = av_get_pix_fmt_name(*p);
131  avio_printf(s, "%s|", name);
132  }
133  len = avio_close_dyn_buf(s, &ret);
134  ret[len - 1] = 0;
135  return ret;
136  } else
137  return NULL;
138 }
139 
140 /* Define a function for building a string containing a list of
141  * allowed formats. */
142 #define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name) \
143 static char *choose_ ## var ## s(OutputStream *ost) \
144 { \
145  if (ost->st->codec->var != none) { \
146  get_name(ost->st->codec->var); \
147  return av_strdup(name); \
148  } else if (ost->enc && ost->enc->supported_list) { \
149  const type *p; \
150  AVIOContext *s = NULL; \
151  uint8_t *ret; \
152  int len; \
153  \
154  if (avio_open_dyn_buf(&s) < 0) \
155  exit_program(1); \
156  \
157  for (p = ost->enc->supported_list; *p != none; p++) { \
158  get_name(*p); \
159  avio_printf(s, "%s|", name); \
160  } \
161  len = avio_close_dyn_buf(s, &ret); \
162  ret[len - 1] = 0; \
163  return ret; \
164  } else \
165  return NULL; \
166 }
167 
168 // DEF_CHOOSE_FORMAT(enum AVPixelFormat, pix_fmt, pix_fmts, AV_PIX_FMT_NONE,
169 // GET_PIX_FMT_NAME)
170 
173 
176 
177 DEF_CHOOSE_FORMAT(uint64_t, channel_layout, channel_layouts, 0,
179 
181 {
182  FilterGraph *fg = av_mallocz(sizeof(*fg));
183 
184  if (!fg)
185  exit_program(1);
186  fg->index = nb_filtergraphs;
187 
188  GROW_ARRAY(fg->outputs, fg->nb_outputs);
189  if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
190  exit_program(1);
191  fg->outputs[0]->ost = ost;
192  fg->outputs[0]->graph = fg;
193 
194  ost->filter = fg->outputs[0];
195 
196  GROW_ARRAY(fg->inputs, fg->nb_inputs);
197  if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
198  exit_program(1);
199  fg->inputs[0]->ist = ist;
200  fg->inputs[0]->graph = fg;
201 
202  GROW_ARRAY(ist->filters, ist->nb_filters);
203  ist->filters[ist->nb_filters - 1] = fg->inputs[0];
204 
206  filtergraphs[nb_filtergraphs - 1] = fg;
207 
208  return fg;
209 }
210 
212 {
213  InputStream *ist = NULL;
215  int i;
216 
217  // TODO: support other filter types
218  if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
219  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
220  "currently.\n");
221  exit_program(1);
222  }
223 
224  if (in->name) {
226  AVStream *st = NULL;
227  char *p;
228  int file_idx = strtol(in->name, &p, 0);
229 
230  if (file_idx < 0 || file_idx >= nb_input_files) {
231  av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
232  file_idx, fg->graph_desc);
233  exit_program(1);
234  }
235  s = input_files[file_idx]->ctx;
236 
237  for (i = 0; i < s->nb_streams; i++) {
238  enum AVMediaType stream_type = s->streams[i]->codec->codec_type;
239  if (stream_type != type &&
240  !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
241  type == AVMEDIA_TYPE_VIDEO /* sub2video hack */))
242  continue;
243  if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
244  st = s->streams[i];
245  break;
246  }
247  }
248  if (!st) {
249  av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
250  "matches no streams.\n", p, fg->graph_desc);
251  exit_program(1);
252  }
253  ist = input_streams[input_files[file_idx]->ist_index + st->index];
254  } else {
255  /* find the first unused stream of corresponding type */
256  for (i = 0; i < nb_input_streams; i++) {
257  ist = input_streams[i];
258  if (ist->st->codec->codec_type == type && ist->discard)
259  break;
260  }
261  if (i == nb_input_streams) {
262  av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
263  "unlabeled input pad %d on filter %s\n", in->pad_idx,
264  in->filter_ctx->name);
265  exit_program(1);
266  }
267  }
268  av_assert0(ist);
269 
270  ist->discard = 0;
271  ist->decoding_needed++;
272  ist->st->discard = AVDISCARD_NONE;
273 
274  GROW_ARRAY(fg->inputs, fg->nb_inputs);
275  if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
276  exit_program(1);
277  fg->inputs[fg->nb_inputs - 1]->ist = ist;
278  fg->inputs[fg->nb_inputs - 1]->graph = fg;
279 
280  GROW_ARRAY(ist->filters, ist->nb_filters);
281  ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
282 }
283 
284 static int insert_trim(int64_t start_time, int64_t duration,
285  AVFilterContext **last_filter, int *pad_idx,
286  const char *filter_name)
287 {
288  AVFilterGraph *graph = (*last_filter)->graph;
289  AVFilterContext *ctx;
290  const AVFilter *trim;
291  enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
292  const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
293  int ret = 0;
294 
295  if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
296  return 0;
297 
298  trim = avfilter_get_by_name(name);
299  if (!trim) {
300  av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
301  "recording time.\n", name);
303  }
304 
305  ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
306  if (!ctx)
307  return AVERROR(ENOMEM);
308 
309  if (duration != INT64_MAX) {
310  ret = av_opt_set_int(ctx, "durationi", duration,
312  }
313  if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
314  ret = av_opt_set_int(ctx, "starti", start_time,
316  }
317  if (ret < 0) {
318  av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
319  return ret;
320  }
321 
322  ret = avfilter_init_str(ctx, NULL);
323  if (ret < 0)
324  return ret;
325 
326  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
327  if (ret < 0)
328  return ret;
329 
330  *last_filter = ctx;
331  *pad_idx = 0;
332  return 0;
333 }
334 
336 {
337  char *pix_fmts;
338  OutputStream *ost = ofilter->ost;
339  OutputFile *of = output_files[ost->file_index];
340  AVCodecContext *codec = ost->st->codec;
341  AVFilterContext *last_filter = out->filter_ctx;
342  int pad_idx = out->pad_idx;
343  int ret;
344  char name[255];
345 
346  snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
347  ret = avfilter_graph_create_filter(&ofilter->filter,
348  avfilter_get_by_name("buffersink"),
349  name, NULL, NULL, fg->graph);
350 
351  if (ret < 0)
352  return ret;
353 
354  if (codec->width || codec->height) {
355  char args[255];
357 
358  snprintf(args, sizeof(args), "%d:%d:0x%X",
359  codec->width,
360  codec->height,
361  (unsigned)ost->sws_flags);
362  snprintf(name, sizeof(name), "scaler for output stream %d:%d",
363  ost->file_index, ost->index);
364  if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
365  name, args, NULL, fg->graph)) < 0)
366  return ret;
367  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
368  return ret;
369 
370  last_filter = filter;
371  pad_idx = 0;
372  }
373 
374  if ((pix_fmts = choose_pix_fmts(ost))) {
376  snprintf(name, sizeof(name), "pixel format for output stream %d:%d",
377  ost->file_index, ost->index);
378  ret = avfilter_graph_create_filter(&filter,
379  avfilter_get_by_name("format"),
380  "format", pix_fmts, NULL,
381  fg->graph);
382  av_freep(&pix_fmts);
383  if (ret < 0)
384  return ret;
385  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
386  return ret;
387 
388  last_filter = filter;
389  pad_idx = 0;
390  }
391 
392  if (ost->frame_rate.num && 0) {
393  AVFilterContext *fps;
394  char args[255];
395 
396  snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
397  ost->frame_rate.den);
398  snprintf(name, sizeof(name), "fps for output stream %d:%d",
399  ost->file_index, ost->index);
401  name, args, NULL, fg->graph);
402  if (ret < 0)
403  return ret;
404 
405  ret = avfilter_link(last_filter, pad_idx, fps, 0);
406  if (ret < 0)
407  return ret;
408  last_filter = fps;
409  pad_idx = 0;
410  }
411 
412  snprintf(name, sizeof(name), "trim for output stream %d:%d",
413  ost->file_index, ost->index);
414  ret = insert_trim(of->start_time, of->recording_time,
415  &last_filter, &pad_idx, name);
416  if (ret < 0)
417  return ret;
418 
419 
420  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
421  return ret;
422 
423  return 0;
424 }
425 
427 {
428  OutputStream *ost = ofilter->ost;
429  OutputFile *of = output_files[ost->file_index];
430  AVCodecContext *codec = ost->st->codec;
431  AVFilterContext *last_filter = out->filter_ctx;
432  int pad_idx = out->pad_idx;
433  char *sample_fmts, *sample_rates, *channel_layouts;
434  char name[255];
435  int ret;
436 
437  snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
438  ret = avfilter_graph_create_filter(&ofilter->filter,
439  avfilter_get_by_name("abuffersink"),
440  name, NULL, NULL, fg->graph);
441  if (ret < 0)
442  return ret;
443  if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
444  return ret;
445 
446 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
447  AVFilterContext *filt_ctx; \
448  \
449  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
450  "similarly to -af " filter_name "=%s.\n", arg); \
451  \
452  ret = avfilter_graph_create_filter(&filt_ctx, \
453  avfilter_get_by_name(filter_name), \
454  filter_name, arg, NULL, fg->graph); \
455  if (ret < 0) \
456  return ret; \
457  \
458  ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
459  if (ret < 0) \
460  return ret; \
461  \
462  last_filter = filt_ctx; \
463  pad_idx = 0; \
464 } while (0)
465  if (ost->audio_channels_mapped) {
466  int i;
467  AVBPrint pan_buf;
468  av_bprint_init(&pan_buf, 256, 8192);
469  av_bprintf(&pan_buf, "0x%"PRIx64,
471  for (i = 0; i < ost->audio_channels_mapped; i++)
472  if (ost->audio_channels_map[i] != -1)
473  av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
474 
475  AUTO_INSERT_FILTER("-map_channel", "pan", pan_buf.str);
476  av_bprint_finalize(&pan_buf, NULL);
477  }
478 
479  if (codec->channels && !codec->channel_layout)
481 
482  sample_fmts = choose_sample_fmts(ost);
483  sample_rates = choose_sample_rates(ost);
484  channel_layouts = choose_channel_layouts(ost);
485  if (sample_fmts || sample_rates || channel_layouts) {
486  AVFilterContext *format;
487  char args[256];
488  args[0] = 0;
489 
490  if (sample_fmts)
491  av_strlcatf(args, sizeof(args), "sample_fmts=%s:",
492  sample_fmts);
493  if (sample_rates)
494  av_strlcatf(args, sizeof(args), "sample_rates=%s:",
495  sample_rates);
496  if (channel_layouts)
497  av_strlcatf(args, sizeof(args), "channel_layouts=%s:",
498  channel_layouts);
499 
500  av_freep(&sample_fmts);
501  av_freep(&sample_rates);
502  av_freep(&channel_layouts);
503 
504  snprintf(name, sizeof(name), "audio format for output stream %d:%d",
505  ost->file_index, ost->index);
506  ret = avfilter_graph_create_filter(&format,
507  avfilter_get_by_name("aformat"),
508  name, args, NULL, fg->graph);
509  if (ret < 0)
510  return ret;
511 
512  ret = avfilter_link(last_filter, pad_idx, format, 0);
513  if (ret < 0)
514  return ret;
515 
516  last_filter = format;
517  pad_idx = 0;
518  }
519 
520  if (audio_volume != 256 && 0) {
521  char args[256];
522 
523  snprintf(args, sizeof(args), "%f", audio_volume / 256.);
524  AUTO_INSERT_FILTER("-vol", "volume", args);
525  }
526 
527  if (ost->apad && of->shortest) {
528  char args[256];
529  int i;
530 
531  for (i=0; i<of->ctx->nb_streams; i++)
532  if (of->ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
533  break;
534 
535  if (i<of->ctx->nb_streams) {
536  snprintf(args, sizeof(args), "%s", ost->apad);
537  AUTO_INSERT_FILTER("-apad", "apad", args);
538  }
539  }
540 
541  snprintf(name, sizeof(name), "trim for output stream %d:%d",
542  ost->file_index, ost->index);
543  ret = insert_trim(of->start_time, of->recording_time,
544  &last_filter, &pad_idx, name);
545  if (ret < 0)
546  return ret;
547 
548  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
549  return ret;
550 
551  return 0;
552 }
553 
554 #define DESCRIBE_FILTER_LINK(f, inout, in) \
555 { \
556  AVFilterContext *ctx = inout->filter_ctx; \
557  AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \
558  int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; \
559  AVIOContext *pb; \
560  \
561  if (avio_open_dyn_buf(&pb) < 0) \
562  exit_program(1); \
563  \
564  avio_printf(pb, "%s", ctx->filter->name); \
565  if (nb_pads > 1) \
566  avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
567  avio_w8(pb, 0); \
568  avio_close_dyn_buf(pb, &f->name); \
569 }
570 
572 {
573  av_freep(&ofilter->name);
574  DESCRIBE_FILTER_LINK(ofilter, out, 0);
575 
576  switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
577  case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
578  case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
579  default: av_assert0(0);
580  }
581 }
582 
584 {
586  int i, w, h;
587 
588  /* Compute the size of the canvas for the subtitles stream.
589  If the subtitles codec has set a size, use it. Otherwise use the
590  maximum dimensions of the video streams in the same file. */
591  w = ist->st->codec->width;
592  h = ist->st->codec->height;
593  if (!(w && h)) {
594  for (i = 0; i < avf->nb_streams; i++) {
595  if (avf->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
596  w = FFMAX(w, avf->streams[i]->codec->width);
597  h = FFMAX(h, avf->streams[i]->codec->height);
598  }
599  }
600  if (!(w && h)) {
601  w = FFMAX(w, 720);
602  h = FFMAX(h, 576);
603  }
604  av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
605  }
606  ist->sub2video.w = ist->st->codec->width = ist->resample_width = w;
607  ist->sub2video.h = ist->st->codec->height = ist->resample_height = h;
608 
609  /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
610  palettes for all rectangles are identical or compatible */
612 
613  ist->sub2video.frame = av_frame_alloc();
614  if (!ist->sub2video.frame)
615  return AVERROR(ENOMEM);
616  return 0;
617 }
618 
620  AVFilterInOut *in)
621 {
622  AVFilterContext *last_filter;
623  const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
624  InputStream *ist = ifilter->ist;
625  InputFile *f = input_files[ist->file_index];
626  AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
627  ist->st->time_base;
628  AVRational fr = ist->framerate;
629  AVRational sar;
630  AVBPrint args;
631  char name[255];
632  int ret, pad_idx = 0;
633 
634  if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
635  av_log(NULL, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
636  return AVERROR(EINVAL);
637  }
638 
639  if (!fr.num)
640  fr = av_guess_frame_rate(input_files[ist->file_index]->ctx, ist->st, NULL);
641 
642  if (ist->st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
643  ret = sub2video_prepare(ist);
644  if (ret < 0)
645  return ret;
646  }
647 
648  sar = ist->st->sample_aspect_ratio.num ?
649  ist->st->sample_aspect_ratio :
651  if(!sar.den)
652  sar = (AVRational){0,1};
653  av_bprint_init(&args, 0, 1);
654  av_bprintf(&args,
655  "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
656  "pixel_aspect=%d/%d:sws_param=flags=%d", ist->resample_width,
658  tb.num, tb.den, sar.num, sar.den,
660  if (fr.num && fr.den)
661  av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
662  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
663  ist->file_index, ist->st->index);
664 
665  if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
666  args.str, NULL, fg->graph)) < 0)
667  return ret;
668  last_filter = ifilter->filter;
669 
670  if (ist->framerate.num) {
671  AVFilterContext *setpts;
672 
673  snprintf(name, sizeof(name), "force CFR for input from stream %d:%d",
674  ist->file_index, ist->st->index);
675  if ((ret = avfilter_graph_create_filter(&setpts,
676  avfilter_get_by_name("setpts"),
677  name, "N", NULL,
678  fg->graph)) < 0)
679  return ret;
680 
681  if ((ret = avfilter_link(last_filter, 0, setpts, 0)) < 0)
682  return ret;
683 
684  last_filter = setpts;
685  }
686 
687  if (do_deinterlace) {
688  AVFilterContext *yadif;
689 
690  snprintf(name, sizeof(name), "deinterlace input from stream %d:%d",
691  ist->file_index, ist->st->index);
692  if ((ret = avfilter_graph_create_filter(&yadif,
693  avfilter_get_by_name("yadif"),
694  name, "", NULL,
695  fg->graph)) < 0)
696  return ret;
697 
698  if ((ret = avfilter_link(last_filter, 0, yadif, 0)) < 0)
699  return ret;
700 
701  last_filter = yadif;
702  }
703 
704  snprintf(name, sizeof(name), "trim for input stream %d:%d",
705  ist->file_index, ist->st->index);
706  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
707  AV_NOPTS_VALUE : 0, f->recording_time, &last_filter, &pad_idx, name);
708  if (ret < 0)
709  return ret;
710 
711  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
712  return ret;
713  return 0;
714 }
715 
717  AVFilterInOut *in)
718 {
719  AVFilterContext *last_filter;
720  const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
721  InputStream *ist = ifilter->ist;
722  InputFile *f = input_files[ist->file_index];
723  AVBPrint args;
724  char name[255];
725  int ret, pad_idx = 0;
726 
727  if (ist->st->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
728  av_log(NULL, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
729  return AVERROR(EINVAL);
730  }
731 
733  av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
734  1, ist->st->codec->sample_rate,
735  ist->st->codec->sample_rate,
737  if (ist->st->codec->channel_layout)
738  av_bprintf(&args, ":channel_layout=0x%"PRIx64,
739  ist->st->codec->channel_layout);
740  else
741  av_bprintf(&args, ":channels=%d", ist->st->codec->channels);
742  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
743  ist->file_index, ist->st->index);
744 
745  if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
746  name, args.str, NULL,
747  fg->graph)) < 0)
748  return ret;
749  last_filter = ifilter->filter;
750 
751 #define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
752  AVFilterContext *filt_ctx; \
753  \
754  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
755  "similarly to -af " filter_name "=%s.\n", arg); \
756  \
757  snprintf(name, sizeof(name), "graph %d %s for input stream %d:%d", \
758  fg->index, filter_name, ist->file_index, ist->st->index); \
759  ret = avfilter_graph_create_filter(&filt_ctx, \
760  avfilter_get_by_name(filter_name), \
761  name, arg, NULL, fg->graph); \
762  if (ret < 0) \
763  return ret; \
764  \
765  ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
766  if (ret < 0) \
767  return ret; \
768  \
769  last_filter = filt_ctx; \
770 } while (0)
771 
772  if (audio_sync_method > 0) {
773  char args[256] = {0};
774 
775  av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method);
776  if (audio_drift_threshold != 0.1)
777  av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", audio_drift_threshold);
778  if (!fg->reconfiguration)
779  av_strlcatf(args, sizeof(args), ":first_pts=0");
780  AUTO_INSERT_FILTER_INPUT("-async", "aresample", args);
781  }
782 
783 // if (ost->audio_channels_mapped) {
784 // int i;
785 // AVBPrint pan_buf;
786 // av_bprint_init(&pan_buf, 256, 8192);
787 // av_bprintf(&pan_buf, "0x%"PRIx64,
788 // av_get_default_channel_layout(ost->audio_channels_mapped));
789 // for (i = 0; i < ost->audio_channels_mapped; i++)
790 // if (ost->audio_channels_map[i] != -1)
791 // av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
792 // AUTO_INSERT_FILTER_INPUT("-map_channel", "pan", pan_buf.str);
793 // av_bprint_finalize(&pan_buf, NULL);
794 // }
795 
796  if (audio_volume != 256) {
797  char args[256];
798 
799  av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
800  "audio filter instead.\n");
801 
802  snprintf(args, sizeof(args), "%f", audio_volume / 256.);
803  AUTO_INSERT_FILTER_INPUT("-vol", "volume", args);
804  }
805 
806  snprintf(name, sizeof(name), "trim for input stream %d:%d",
807  ist->file_index, ist->st->index);
808  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
809  AV_NOPTS_VALUE : 0, f->recording_time, &last_filter, &pad_idx, name);
810  if (ret < 0)
811  return ret;
812 
813  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
814  return ret;
815 
816  return 0;
817 }
818 
820  AVFilterInOut *in)
821 {
822  av_freep(&ifilter->name);
823  DESCRIBE_FILTER_LINK(ifilter, in, 1);
824 
825  switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
826  case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
827  case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
828  default: av_assert0(0);
829  }
830 }
831 
833 {
834  AVFilterInOut *inputs, *outputs, *cur;
835  int ret, i, init = !fg->graph, simple = !fg->graph_desc;
836  const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
837  fg->graph_desc;
838 
840  if (!(fg->graph = avfilter_graph_alloc()))
841  return AVERROR(ENOMEM);
842 
843  if (simple) {
844  OutputStream *ost = fg->outputs[0]->ost;
845  char args[512];
846  AVDictionaryEntry *e = NULL;
847 
848  snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
849  fg->graph->scale_sws_opts = av_strdup(args);
850 
851  args[0] = 0;
852  while ((e = av_dict_get(ost->swr_opts, "", e,
854  av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
855  }
856  if (strlen(args))
857  args[strlen(args)-1] = 0;
858  av_opt_set(fg->graph, "aresample_swr_opts", args, 0);
859 
860  args[0] = '\0';
861  while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
863  av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
864  }
865  if (strlen(args))
866  args[strlen(args) - 1] = '\0';
867  fg->graph->resample_lavr_opts = av_strdup(args);
868 
869  e = av_dict_get(ost->opts, "threads", NULL, 0);
870  if (e)
871  av_opt_set(fg->graph, "threads", e->value, 0);
872  }
873 
874  if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
875  return ret;
876 
877  if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
878  av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' does not have "
879  "exactly one input and output.\n", graph_desc);
880  return AVERROR(EINVAL);
881  }
882 
883  for (cur = inputs; !simple && init && cur; cur = cur->next)
884  init_input_filter(fg, cur);
885 
886  for (cur = inputs, i = 0; cur; cur = cur->next, i++)
887  if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0)
888  return ret;
889  avfilter_inout_free(&inputs);
890 
891  if (!init || simple) {
892  /* we already know the mappings between lavfi outputs and output streams,
893  * so we can finish the setup */
894  for (cur = outputs, i = 0; cur; cur = cur->next, i++)
895  configure_output_filter(fg, fg->outputs[i], cur);
896  avfilter_inout_free(&outputs);
897 
898  if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
899  return ret;
900  } else {
901  /* wait until output mappings are processed */
902  for (cur = outputs; cur;) {
903  GROW_ARRAY(fg->outputs, fg->nb_outputs);
904  if (!(fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]))))
905  exit_program(1);
906  fg->outputs[fg->nb_outputs - 1]->graph = fg;
907  fg->outputs[fg->nb_outputs - 1]->out_tmp = cur;
908  cur = cur->next;
909  fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL;
910  }
911  }
912 
913  fg->reconfiguration = 1;
914  return 0;
915 }
916 
918 {
919  int i;
920  for (i = 0; i < fg->nb_inputs; i++)
921  if (fg->inputs[i]->ist == ist)
922  return 1;
923  return 0;
924 }
925 
const char * name
Definition: avisynth_c.h:675
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
Enable or disable automatic format conversion inside the graph.
int keep_pix_fmt
Definition: ffmpeg.h:375
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:382
all automatic conversions disabled
Definition: avfilter.h:1311
uint8_t * name
Definition: ffmpeg.h:198
int nb_outputs
Definition: ffmpeg.h:214
char * key
Definition: dict.h:81
AVDictionary * swr_opts
Definition: ffmpeg.h:365
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:1169
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
AVRational frame_rate
Definition: ffmpeg.h:339
int accurate_seek
Definition: ffmpeg.h:294
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:2945
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: avcodec.h:4153
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
#define AVERROR_FILTER_NOT_FOUND
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
Definition: mem.c:256
AVStream * st
Definition: ffmpeg.h:321
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVRational framerate
Definition: ffmpeg.h:243
void choose_sample_fmt(AVStream *st, AVCodec *codec)
Definition: ffmpeg_filter.c:71
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:180
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:1881
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
AVFilterInOut * out_tmp
Definition: ffmpeg.h:201
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:686
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:982
#define CODEC_CAP_LOSSLESS
Codec is lossless.
Definition: avcodec.h:835
int decoding_needed
Definition: ffmpeg.h:221
static int insert_trim(int64_t start_time, int64_t duration, AVFilterContext **last_filter, int *pad_idx, const char *filter_name)
planar YUV 4:2:2, 16bpp, (1 Cr &amp; Cb sample per 2x1 Y samples)
Definition: avcodec.h:4538
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:733
int num
numerator
Definition: rational.h:44
FilterGraph * init_simple_filtergraph(InputStream *ist, OutputStream *ost)
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
int index
stream index in AVFormatContext
Definition: avformat.h:668
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1860
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:1517
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1342
#define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name)
char * resample_lavr_opts
libavresample options to use for the auto-inserted resample filters
Definition: avfilter.h:1170
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1343
int nb_input_streams
Definition: ffmpeg.c:145
Pixel format.
Definition: avcodec.h:4533
AVCodec.
Definition: avcodec.h:2922
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:383
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
int index
Definition: ffmpeg.h:205
struct FilterGraph * graph
Definition: ffmpeg.h:190
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:234
Format I/O context.
Definition: avformat.h:968
AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
Definition: utils.c:4117
struct InputStream * ist
Definition: ffmpeg.h:189
AVFilterGraph * graph
Definition: ffmpeg.h:208
supported_samplerates
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:128
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
static int64_t start_time
Definition: ffplay.c:305
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1881
uint8_t
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
AVDictionary * opts
Definition: ffmpeg.h:364
const char * name
Name of the codec implementation.
Definition: avcodec.h:2929
int audio_sync_method
Definition: ffmpeg_opt.c:72
int shortest
Definition: ffmpeg.h:386
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.
#define SWS_BITEXACT
Definition: swscale.h:84
AVDictionary * resample_opts
Definition: ffmpeg.h:366
AVFilterContext * filter
Definition: ffmpeg.h:195
int nb_input_files
Definition: ffmpeg.c:147
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:714
static int64_t duration
Definition: ffplay.c:306
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:384
int file_index
Definition: ffmpeg.h:218
struct InputStream::sub2video sub2video
int resample_pix_fmt
Definition: ffmpeg.h:249
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1030
int resample_height
Definition: ffmpeg.h:247
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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
#define GET_CH_LAYOUT_NAME(ch_layout)
Definition: cmdutils.h:563
FilterGraph ** filtergraphs
Definition: ffmpeg.c:154
AVFilterContext * filter
Definition: ffmpeg.h:188
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: avcodec.h:4548
int64_t sws_flags
Definition: ffmpeg.h:363
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:110
int capabilities
Codec capabilities.
Definition: avcodec.h:2941
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1234
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:426
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
static const int sample_rates[]
Definition: dcaenc.h:32
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1934
OutputFilter * filter
Definition: ffmpeg.h:360
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
Definition: bprint.c:69
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:312
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:1015
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:59
Buffer to print data progressively.
Definition: bprint.h:77
char * name
name of this filter instance
Definition: avfilter.h:632
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:540
struct OutputStream * ost
Definition: ffmpeg.h:196
ret
Definition: avfilter.c:961
int width
picture width / height.
Definition: avcodec.h:1314
char * apad
Definition: ffmpeg.h:367
AVStream ** streams
Definition: avformat.h:1016
AVS_Value args
Definition: avisynth_c.h:603
char * value
Definition: dict.h:82
#define AV_PIX_FMT_RGB32
Definition: avcodec.h:4928
int nb_filtergraphs
Definition: ffmpeg.c:155
#define AV_BPRINT_SIZE_AUTOMATIC
Definition: bprint.h:92
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:77
int audio_channels_mapped
Definition: ffmpeg.h:355
char * name
unique name for this input/output in the list
Definition: avfilter.h:1340
#define GET_SAMPLE_FMT_NAME(sample_fmt)
Definition: cmdutils.h:556
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:122
int avfilter_init_str(AVFilterContext *ctx, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:855
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
int audio_volume
Definition: ffmpeg_opt.c:71
Stream structure.
Definition: avformat.h:667
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: avcodec.h:4546
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1338
InputFilter ** filters
Definition: ffmpeg.h:274
enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
Find the best pixel format to convert to given a certain source pixel format and a selection of two d...
Definition: imgconvert.c:221
#define GET_SAMPLE_RATE_NAME(rate)
Definition: cmdutils.h:559
int64_t recording_time
Definition: ffmpeg.h:289
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
planar YUV 4:2:0, 12bpp, (1 Cr &amp; Cb sample per 2x2 Y samples)
Definition: avcodec.h:4534
sample_rate
#define AV_LOG_INFO
Standard information.
Definition: avcodec.h:4158
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
enum AVMediaType codec_type
Definition: avcodec.h:1154
#define FFMAX(a, b)
Definition: avcodec.h:923
enum AVCodecID codec_id
Definition: avcodec.h:1157
int sample_rate
samples per second
Definition: avcodec.h:1873
static char * choose_pix_fmts(OutputStream *ost)
Definition: ffmpeg_filter.c:93
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:634
int ist_index
Definition: ffmpeg.h:284
const char * graph_desc
Definition: ffmpeg.h:206
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum AVPixelFormat target)
Definition: ffmpeg_filter.c:38
int64_t start_time
Definition: ffmpeg.h:288
main external API structure.
Definition: avcodec.h:1146
static int sub2video_prepare(InputStream *ist)
int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
#define AUTO_INSERT_FILTER(opt_name, filter_name, arg)
int audio_channels_map[SWR_CH_MAX]
Definition: ffmpeg.h:354
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1018
AVStream * st
Definition: ffmpeg.h:219
int configure_filtergraph(FilterGraph *fg)
Filter definition.
Definition: avfilter.h:464
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: avcodec.h:2425
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:1346
rational number numerator/denominator
Definition: rational.h:43
int file_index
Definition: ffmpeg.h:318
AVMediaType
Definition: avutil.h:180
planar YUV 4:4:4, 24bpp, (1 Cr &amp; Cb sample per 1x1 Y samples)
Definition: avcodec.h:4539
#define snprintf
Definition: snprintf.h:34
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:460
#define type
float audio_drift_threshold
Definition: ffmpeg_opt.c:67
int nb_filters
Definition: ffmpeg.h:275
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:122
int resample_width
Definition: ffmpeg.h:248
int reconfiguration
Definition: ffmpeg.h:209
struct FilterGraph * graph
Definition: ffmpeg.h:197
#define DESCRIBE_FILTER_LINK(f, inout, in)
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: avcodec.h:4565
#define SWS_BILINEAR
Definition: swscale.h:59
int den
denominator
Definition: rational.h:45
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:2943
AVFormatContext * ctx
Definition: ffmpeg.h:281
AVCodec * enc
Definition: ffmpeg.h:334
void av_bprintf(AVBPrint *buf, const char *fmt,...) av_printf_format(2
Append a formatted string to a print buffer.
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
Definition: avfilter.h:1349
int do_deinterlace
Definition: ffmpeg_opt.c:74
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:550
char * avfilter
Definition: ffmpeg.h:361
uint8_t * name
Definition: ffmpeg.h:191
int len
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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 channels
number of audio channels
Definition: avcodec.h:1874
OutputFilter ** outputs
Definition: ffmpeg.h:213
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:641
InputFile ** input_files
Definition: ffmpeg.c:146
AVFormatContext * ctx
Definition: ffmpeg.h:379
#define AVERROR(e)
An instance of a filter.
Definition: avfilter.h:627
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:700
InputFilter ** inputs
Definition: ffmpeg.h:211
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68
OutputFile ** output_files
Definition: ffmpeg.c:151
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: avcodec.h:4141
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int discard
Definition: ffmpeg.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:703
int nb_inputs
Definition: ffmpeg.h:212
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:726
int index
Definition: ffmpeg.h:319
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: avcodec.h:4547
#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg)
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:255
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
Definition: avcodec.h:2421
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...) av_printf_format(3
Append output to a string, according to a format.
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avcodec.h:2278
#define tb
Definition: regdef.h:68
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:241
InputStream ** input_streams
Definition: ffmpeg.c:144
discard nothing
Definition: avcodec.h:613
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.