FFmpeg
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 <stdint.h>
22 
23 #include "ffmpeg.h"
24 
25 #include "libavfilter/avfilter.h"
26 #include "libavfilter/buffersink.h"
27 #include "libavfilter/buffersrc.h"
28 
29 #include "libavutil/avassert.h"
30 #include "libavutil/avstring.h"
31 #include "libavutil/bprint.h"
33 #include "libavutil/display.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/pixdesc.h"
36 #include "libavutil/pixfmt.h"
37 #include "libavutil/imgutils.h"
38 #include "libavutil/samplefmt.h"
39 
40 // FIXME: YUV420P etc. are actually supported with full color range,
41 // yet the latter information isn't available here.
42 static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[])
43 {
44  static const enum AVPixelFormat mjpeg_formats[] =
47 
48  if (!strcmp(codec->name, "mjpeg")) {
49  return mjpeg_formats;
50  } else {
51  return default_formats;
52  }
53 }
54 
55 static enum AVPixelFormat
56 choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target,
57  int strict_std_compliance)
58 {
59  if (codec && codec->pix_fmts) {
60  const enum AVPixelFormat *p = codec->pix_fmts;
62  //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
63  int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
64  enum AVPixelFormat best= AV_PIX_FMT_NONE;
65 
66  if (strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
67  p = get_compliance_normal_pix_fmts(codec, p);
68  }
69  for (; *p != AV_PIX_FMT_NONE; p++) {
70  best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
71  if (*p == target)
72  break;
73  }
74  if (*p == AV_PIX_FMT_NONE) {
75  if (target != AV_PIX_FMT_NONE)
77  "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
78  av_get_pix_fmt_name(target),
79  codec->name,
80  av_get_pix_fmt_name(best));
81  return best;
82  }
83  }
84  return target;
85 }
86 
87 /* May return NULL (no pixel format found), a static string or a string
88  * backed by the bprint. Nothing has been written to the AVBPrint in case
89  * NULL is returned. The AVBPrint provided should be clean. */
90 static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
91 {
92  OutputStream *ost = ofilter->ost;
93  AVCodecContext *enc = ost->enc_ctx;
94  const AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
95  if (strict_dict)
96  // used by choose_pixel_fmt() and below
97  av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
98 
99  if (ost->keep_pix_fmt) {
102  if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
103  return NULL;
104  return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt);
105  }
106  if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
108  ost->enc_ctx->strict_std_compliance));
109  } else if (enc->codec->pix_fmts) {
110  const enum AVPixelFormat *p;
111 
112  p = enc->codec->pix_fmts;
113  if (ost->enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
115  }
116 
117  for (; *p != AV_PIX_FMT_NONE; p++) {
118  const char *name = av_get_pix_fmt_name(*p);
119  av_bprintf(bprint, "%s%c", name, p[1] == AV_PIX_FMT_NONE ? '\0' : '|');
120  }
121  if (!av_bprint_is_complete(bprint))
122  report_and_exit(AVERROR(ENOMEM));
123  return bprint->str;
124  } else
125  return NULL;
126 }
127 
128 /* Define a function for appending a list of allowed formats
129  * to an AVBPrint. If nonempty, the list will have a header. */
130 #define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \
131 static void choose_ ## name (OutputFilter *ofilter, AVBPrint *bprint) \
132 { \
133  if (ofilter->var == none && !ofilter->supported_list) \
134  return; \
135  av_bprintf(bprint, #name "="); \
136  if (ofilter->var != none) { \
137  av_bprintf(bprint, printf_format, get_name(ofilter->var)); \
138  } else { \
139  const type *p; \
140  \
141  for (p = ofilter->supported_list; *p != none; p++) { \
142  av_bprintf(bprint, printf_format "|", get_name(*p)); \
143  } \
144  if (bprint->len > 0) \
145  bprint->str[--bprint->len] = '\0'; \
146  } \
147  av_bprint_chars(bprint, ':', 1); \
148 }
149 
150 //DEF_CHOOSE_FORMAT(pix_fmts, enum AVPixelFormat, format, formats, AV_PIX_FMT_NONE,
151 // GET_PIX_FMT_NAME)
152 
155 
157  "%d", )
158 
159 static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
160 {
161  if (av_channel_layout_check(&ofilter->ch_layout)) {
162  av_bprintf(bprint, "channel_layouts=");
163  av_channel_layout_describe_bprint(&ofilter->ch_layout, bprint);
164  } else if (ofilter->ch_layouts) {
165  const AVChannelLayout *p;
166 
167  av_bprintf(bprint, "channel_layouts=");
168  for (p = ofilter->ch_layouts; p->nb_channels; p++) {
170  av_bprintf(bprint, "|");
171  }
172  if (bprint->len > 0)
173  bprint->str[--bprint->len] = '\0';
174  } else
175  return;
176  av_bprint_chars(bprint, ':', 1);
177 }
178 
180 {
181  FilterGraph *fg = av_mallocz(sizeof(*fg));
182  OutputFilter *ofilter;
183  InputFilter *ifilter;
184 
185  if (!fg)
186  report_and_exit(AVERROR(ENOMEM));
187  fg->index = nb_filtergraphs;
188 
189  ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
190  ofilter->ost = ost;
191  ofilter->graph = fg;
192  ofilter->format = -1;
193 
194  ost->filter = ofilter;
195 
196  ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
197  ifilter->ist = ist;
198  ifilter->graph = fg;
199  ifilter->format = -1;
200 
201  ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
202  if (!ifilter->frame_queue)
203  report_and_exit(AVERROR(ENOMEM));
204 
205  GROW_ARRAY(ist->filters, ist->nb_filters);
206  ist->filters[ist->nb_filters - 1] = ifilter;
207 
209  filtergraphs[nb_filtergraphs - 1] = fg;
210 
211  return 0;
212 }
213 
214 static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
215 {
216  AVFilterContext *ctx = inout->filter_ctx;
217  AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads;
218  int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs;
219  char *res;
220 
221  if (nb_pads > 1)
222  res = av_strdup(ctx->filter->name);
223  else
224  res = av_asprintf("%s:%s", ctx->filter->name,
225  avfilter_pad_get_name(pads, inout->pad_idx));
226  if (!res)
227  report_and_exit(AVERROR(ENOMEM));
228  return res;
229 }
230 
232 {
233  InputStream *ist = NULL;
235  InputFilter *ifilter;
236  int i;
237 
238  // TODO: support other filter types
240  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
241  "currently.\n");
242  exit_program(1);
243  }
244 
245  if (in->name) {
247  AVStream *st = NULL;
248  char *p;
249  int file_idx = strtol(in->name, &p, 0);
250 
251  if (file_idx < 0 || file_idx >= nb_input_files) {
252  av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
253  file_idx, fg->graph_desc);
254  exit_program(1);
255  }
256  s = input_files[file_idx]->ctx;
257 
258  for (i = 0; i < s->nb_streams; i++) {
259  enum AVMediaType stream_type = s->streams[i]->codecpar->codec_type;
260  if (stream_type != type &&
261  !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
262  type == AVMEDIA_TYPE_VIDEO /* sub2video hack */))
263  continue;
264  if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
265  st = s->streams[i];
266  break;
267  }
268  }
269  if (!st) {
270  av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
271  "matches no streams.\n", p, fg->graph_desc);
272  exit_program(1);
273  }
274  ist = input_files[file_idx]->streams[st->index];
275  if (ist->user_set_discard == AVDISCARD_ALL) {
276  av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
277  "matches a disabled input stream.\n", p, fg->graph_desc);
278  exit_program(1);
279  }
280  } else {
281  /* find the first unused stream of corresponding type */
282  for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
283  if (ist->user_set_discard == AVDISCARD_ALL)
284  continue;
285  if (ist->dec_ctx->codec_type == type && ist->discard)
286  break;
287  }
288  if (!ist) {
289  av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
290  "unlabeled input pad %d on filter %s\n", in->pad_idx,
291  in->filter_ctx->name);
292  exit_program(1);
293  }
294  }
295  av_assert0(ist);
296 
297  ist->discard = 0;
299  ist->processing_needed = 1;
300  ist->st->discard = AVDISCARD_NONE;
301 
302  ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
303  ifilter->ist = ist;
304  ifilter->graph = fg;
305  ifilter->format = -1;
306  ifilter->type = ist->st->codecpar->codec_type;
307  ifilter->name = describe_filter_link(fg, in, 1);
308 
309  ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
310  if (!ifilter->frame_queue)
311  report_and_exit(AVERROR(ENOMEM));
312 
313  GROW_ARRAY(ist->filters, ist->nb_filters);
314  ist->filters[ist->nb_filters - 1] = ifilter;
315 }
316 
317 static int read_binary(const char *path, uint8_t **data, int *len)
318 {
319  AVIOContext *io = NULL;
320  int64_t fsize;
321  int ret;
322 
323  *data = NULL;
324  *len = 0;
325 
326  ret = avio_open2(&io, path, AVIO_FLAG_READ, &int_cb, NULL);
327  if (ret < 0) {
328  av_log(NULL, AV_LOG_ERROR, "Cannot open file '%s': %s\n",
329  path, av_err2str(ret));
330  return ret;
331  }
332 
333  fsize = avio_size(io);
334  if (fsize < 0 || fsize > INT_MAX) {
335  av_log(NULL, AV_LOG_ERROR, "Cannot obtain size of file %s\n", path);
336  ret = AVERROR(EIO);
337  goto fail;
338  }
339 
340  *data = av_malloc(fsize);
341  if (!*data) {
342  ret = AVERROR(ENOMEM);
343  goto fail;
344  }
345 
346  ret = avio_read(io, *data, fsize);
347  if (ret != fsize) {
348  av_log(NULL, AV_LOG_ERROR, "Error reading file %s\n", path);
349  ret = ret < 0 ? ret : AVERROR(EIO);
350  goto fail;
351  }
352 
353  *len = fsize;
354 
355  return 0;
356 fail:
357  avio_close(io);
358  av_freep(data);
359  *len = 0;
360  return ret;
361 }
362 
363 static int filter_opt_apply(AVFilterContext *f, const char *key, const char *val)
364 {
365  const AVOption *o;
366  int ret;
367 
369  if (ret >= 0)
370  return 0;
371 
372  if (ret == AVERROR_OPTION_NOT_FOUND && key[0] == '/')
374  if (!o)
375  goto err_apply;
376 
377  // key is a valid option name prefixed with '/'
378  // interpret value as a path from which to load the actual option value
379  key++;
380 
381  if (o->type == AV_OPT_TYPE_BINARY) {
382  uint8_t *data;
383  int len;
384 
385  ret = read_binary(val, &data, &len);
386  if (ret < 0)
387  goto err_load;
388 
390  av_freep(&data);
391  } else {
392  char *data = file_read(val);
393  if (!data) {
394  ret = AVERROR(EIO);
395  goto err_load;
396  }
397 
399  av_freep(&data);
400  }
401  if (ret < 0)
402  goto err_apply;
403 
404  return 0;
405 
406 err_apply:
408  "Error applying option '%s' to filter '%s': %s\n",
409  key, f->filter->name, av_err2str(ret));
410  return ret;
411 err_load:
413  "Error loading value for option '%s' from file '%s'\n",
414  key, val);
415  return ret;
416 }
417 
419 {
420  for (size_t i = 0; i < seg->nb_chains; i++) {
421  AVFilterChain *ch = seg->chains[i];
422 
423  for (size_t j = 0; j < ch->nb_filters; j++) {
424  AVFilterParams *p = ch->filters[j];
425  const AVDictionaryEntry *e = NULL;
426 
427  av_assert0(p->filter);
428 
429  while ((e = av_dict_iterate(p->opts, e))) {
430  int ret = filter_opt_apply(p->filter, e->key, e->value);
431  if (ret < 0)
432  return ret;
433  }
434 
435  av_dict_free(&p->opts);
436  }
437  }
438 
439  return 0;
440 }
441 
442 static int graph_parse(AVFilterGraph *graph, const char *desc,
444 {
446  int ret;
447 
448  ret = avfilter_graph_segment_parse(graph, desc, 0, &seg);
449  if (ret < 0)
450  return ret;
451 
453  if (ret < 0)
454  goto fail;
455 
456  ret = graph_opts_apply(seg);
457  if (ret < 0)
458  goto fail;
459 
461 
462 fail:
464  return ret;
465 }
466 
468 {
469  AVFilterInOut *inputs, *outputs, *cur;
470  AVFilterGraph *graph;
471  int ret = 0;
472 
473  /* this graph is only used for determining the kinds of inputs
474  * and outputs we have, and is discarded on exit from this function */
475  graph = avfilter_graph_alloc();
476  if (!graph)
477  return AVERROR(ENOMEM);
478  graph->nb_threads = 1;
479 
480  ret = graph_parse(graph, fg->graph_desc, &inputs, &outputs);
481  if (ret < 0)
482  goto fail;
483 
484  for (cur = inputs; cur; cur = cur->next)
485  init_input_filter(fg, cur);
486 
487  for (cur = outputs; cur;) {
488  OutputFilter *const ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
489 
490  ofilter->graph = fg;
491  ofilter->out_tmp = cur;
493  cur->pad_idx);
494  ofilter->name = describe_filter_link(fg, cur, 0);
495  cur = cur->next;
496  ofilter->out_tmp->next = NULL;
497  }
498 
499 fail:
501  avfilter_graph_free(&graph);
502  return ret;
503 }
504 
505 static int insert_trim(int64_t start_time, int64_t duration,
506  AVFilterContext **last_filter, int *pad_idx,
507  const char *filter_name)
508 {
509  AVFilterGraph *graph = (*last_filter)->graph;
511  const AVFilter *trim;
512  enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
513  const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
514  int ret = 0;
515 
516  if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
517  return 0;
518 
519  trim = avfilter_get_by_name(name);
520  if (!trim) {
521  av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
522  "recording time.\n", name);
524  }
525 
526  ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
527  if (!ctx)
528  return AVERROR(ENOMEM);
529 
530  if (duration != INT64_MAX) {
531  ret = av_opt_set_int(ctx, "durationi", duration,
533  }
534  if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
535  ret = av_opt_set_int(ctx, "starti", start_time,
537  }
538  if (ret < 0) {
539  av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
540  return ret;
541  }
542 
544  if (ret < 0)
545  return ret;
546 
547  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
548  if (ret < 0)
549  return ret;
550 
551  *last_filter = ctx;
552  *pad_idx = 0;
553  return 0;
554 }
555 
556 static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
557  const char *filter_name, const char *args)
558 {
559  AVFilterGraph *graph = (*last_filter)->graph;
561  int ret;
562 
564  avfilter_get_by_name(filter_name),
565  filter_name, args, NULL, graph);
566  if (ret < 0)
567  return ret;
568 
569  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
570  if (ret < 0)
571  return ret;
572 
573  *last_filter = ctx;
574  *pad_idx = 0;
575  return 0;
576 }
577 
579 {
580  OutputStream *ost = ofilter->ost;
581  OutputFile *of = output_files[ost->file_index];
582  AVFilterContext *last_filter = out->filter_ctx;
583  AVBPrint bprint;
584  int pad_idx = out->pad_idx;
585  int ret;
586  const char *pix_fmts;
587  char name[255];
588 
589  snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
591  avfilter_get_by_name("buffersink"),
592  name, NULL, NULL, fg->graph);
593 
594  if (ret < 0)
595  return ret;
596 
597  if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) {
598  char args[255];
600  const AVDictionaryEntry *e = NULL;
601 
602  snprintf(args, sizeof(args), "%d:%d",
603  ofilter->width, ofilter->height);
604 
605  while ((e = av_dict_iterate(ost->sws_dict, e))) {
606  av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
607  }
608 
609  snprintf(name, sizeof(name), "scaler_out_%d_%d",
610  ost->file_index, ost->index);
612  name, args, NULL, fg->graph)) < 0)
613  return ret;
614  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
615  return ret;
616 
617  last_filter = filter;
618  pad_idx = 0;
619  }
620 
622  if ((pix_fmts = choose_pix_fmts(ofilter, &bprint))) {
624 
626  avfilter_get_by_name("format"),
627  "format", pix_fmts, NULL, fg->graph);
628  av_bprint_finalize(&bprint, NULL);
629  if (ret < 0)
630  return ret;
631  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
632  return ret;
633 
634  last_filter = filter;
635  pad_idx = 0;
636  }
637 
638  if (ost->frame_rate.num && 0) {
639  AVFilterContext *fps;
640  char args[255];
641 
642  snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
643  ost->frame_rate.den);
644  snprintf(name, sizeof(name), "fps_out_%d_%d",
645  ost->file_index, ost->index);
647  name, args, NULL, fg->graph);
648  if (ret < 0)
649  return ret;
650 
651  ret = avfilter_link(last_filter, pad_idx, fps, 0);
652  if (ret < 0)
653  return ret;
654  last_filter = fps;
655  pad_idx = 0;
656  }
657 
658  snprintf(name, sizeof(name), "trim_out_%d_%d",
659  ost->file_index, ost->index);
661  &last_filter, &pad_idx, name);
662  if (ret < 0)
663  return ret;
664 
665 
666  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
667  return ret;
668 
669  return 0;
670 }
671 
673 {
674  OutputStream *ost = ofilter->ost;
675  OutputFile *of = output_files[ost->file_index];
676  AVCodecContext *codec = ost->enc_ctx;
677  AVFilterContext *last_filter = out->filter_ctx;
678  int pad_idx = out->pad_idx;
679  AVBPrint args;
680  char name[255];
681  int ret;
682 
683  snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
685  avfilter_get_by_name("abuffersink"),
686  name, NULL, NULL, fg->graph);
687  if (ret < 0)
688  return ret;
689  if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
690  return ret;
691 
692 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
693  AVFilterContext *filt_ctx; \
694  \
695  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
696  "similarly to -af " filter_name "=%s.\n", arg); \
697  \
698  ret = avfilter_graph_create_filter(&filt_ctx, \
699  avfilter_get_by_name(filter_name), \
700  filter_name, arg, NULL, fg->graph); \
701  if (ret < 0) \
702  goto fail; \
703  \
704  ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
705  if (ret < 0) \
706  goto fail; \
707  \
708  last_filter = filt_ctx; \
709  pad_idx = 0; \
710 } while (0)
712 #if FFMPEG_OPT_MAP_CHANNEL
713  if (ost->audio_channels_mapped) {
714  AVChannelLayout mapped_layout = { 0 };
715  int i;
716  av_channel_layout_default(&mapped_layout, ost->audio_channels_mapped);
717  av_channel_layout_describe_bprint(&mapped_layout, &args);
718  for (i = 0; i < ost->audio_channels_mapped; i++)
719  if (ost->audio_channels_map[i] != -1)
720  av_bprintf(&args, "|c%d=c%d", i, ost->audio_channels_map[i]);
721 
722  AUTO_INSERT_FILTER("-map_channel", "pan", args.str);
723  av_bprint_clear(&args);
724  }
725 #endif
726 
729 
730  choose_sample_fmts(ofilter, &args);
731  choose_sample_rates(ofilter, &args);
732  choose_channel_layouts(ofilter, &args);
733  if (!av_bprint_is_complete(&args)) {
734  ret = AVERROR(ENOMEM);
735  goto fail;
736  }
737  if (args.len) {
739 
740  snprintf(name, sizeof(name), "format_out_%d_%d",
741  ost->file_index, ost->index);
743  avfilter_get_by_name("aformat"),
744  name, args.str, NULL, fg->graph);
745  if (ret < 0)
746  goto fail;
747 
748  ret = avfilter_link(last_filter, pad_idx, format, 0);
749  if (ret < 0)
750  goto fail;
751 
752  last_filter = format;
753  pad_idx = 0;
754  }
755 
756  if (ost->apad && of->shortest) {
757  int i;
758 
759  for (i = 0; i < of->nb_streams; i++)
761  break;
762 
763  if (i < of->nb_streams) {
764  AUTO_INSERT_FILTER("-apad", "apad", ost->apad);
765  }
766  }
767 
768  snprintf(name, sizeof(name), "trim for output stream %d:%d",
769  ost->file_index, ost->index);
771  &last_filter, &pad_idx, name);
772  if (ret < 0)
773  goto fail;
774 
775  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
776  goto fail;
777 fail:
778  av_bprint_finalize(&args, NULL);
779 
780  return ret;
781 }
782 
785 {
786  if (!ofilter->ost) {
787  av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
788  exit_program(1);
789  }
790 
791  switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
792  case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
793  case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
794  default: av_assert0(0); return 0;
795  }
796 }
797 
799 {
800  int i;
801  for (i = 0; i < nb_filtergraphs; i++) {
802  int n;
803  for (n = 0; n < filtergraphs[i]->nb_outputs; n++) {
805  if (!output->ost) {
806  av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", output->name);
807  exit_program(1);
808  }
809  }
810  }
811 }
812 
813 static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
814 {
816  int i, w, h;
817 
818  /* Compute the size of the canvas for the subtitles stream.
819  If the subtitles codecpar has set a size, use it. Otherwise use the
820  maximum dimensions of the video streams in the same file. */
821  w = ifilter->width;
822  h = ifilter->height;
823  if (!(w && h)) {
824  for (i = 0; i < avf->nb_streams; i++) {
826  w = FFMAX(w, avf->streams[i]->codecpar->width);
827  h = FFMAX(h, avf->streams[i]->codecpar->height);
828  }
829  }
830  if (!(w && h)) {
831  w = FFMAX(w, 720);
832  h = FFMAX(h, 576);
833  }
834  av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
835  }
836  ist->sub2video.w = ifilter->width = w;
837  ist->sub2video.h = ifilter->height = h;
838 
839  ifilter->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w;
840  ifilter->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h;
841 
842  /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
843  palettes for all rectangles are identical or compatible */
844  ifilter->format = AV_PIX_FMT_RGB32;
845 
846  ist->sub2video.frame = av_frame_alloc();
847  if (!ist->sub2video.frame)
848  return AVERROR(ENOMEM);
849  ist->sub2video.last_pts = INT64_MIN;
850  ist->sub2video.end_pts = INT64_MIN;
851 
852  /* sub2video structure has been (re-)initialized.
853  Mark it as such so that the system will be
854  initialized with the first received heartbeat. */
855  ist->sub2video.initialize = 1;
856 
857  return 0;
858 }
859 
861  AVFilterInOut *in)
862 {
863  AVFilterContext *last_filter;
864  const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
865  const AVPixFmtDescriptor *desc;
866  InputStream *ist = ifilter->ist;
868  AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
869  ist->st->time_base;
870  AVRational fr = ist->framerate;
871  AVRational sar;
872  AVBPrint args;
873  char name[255];
874  int ret, pad_idx = 0;
875  int64_t tsoffset = 0;
877 
878  if (!par)
879  return AVERROR(ENOMEM);
880  memset(par, 0, sizeof(*par));
881  par->format = AV_PIX_FMT_NONE;
882 
883  if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
884  av_log(NULL, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
885  ret = AVERROR(EINVAL);
886  goto fail;
887  }
888 
889  if (!fr.num)
890  fr = ist->framerate_guessed;
891 
893  ret = sub2video_prepare(ist, ifilter);
894  if (ret < 0)
895  goto fail;
896  }
897 
898  sar = ifilter->sample_aspect_ratio;
899  if(!sar.den)
900  sar = (AVRational){0,1};
902  av_bprintf(&args,
903  "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
904  "pixel_aspect=%d/%d",
905  ifilter->width, ifilter->height, ifilter->format,
906  tb.num, tb.den, sar.num, sar.den);
907  if (fr.num && fr.den)
908  av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
909  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
910  ist->file_index, ist->st->index);
911 
912 
913  if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
914  args.str, NULL, fg->graph)) < 0)
915  goto fail;
916  par->hw_frames_ctx = ifilter->hw_frames_ctx;
917  ret = av_buffersrc_parameters_set(ifilter->filter, par);
918  if (ret < 0)
919  goto fail;
920  av_freep(&par);
921  last_filter = ifilter->filter;
922 
923  desc = av_pix_fmt_desc_get(ifilter->format);
924  av_assert0(desc);
925 
926  // TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
927  if (ist->autorotate && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
928  int32_t *displaymatrix = ifilter->displaymatrix;
929  double theta;
930 
931  if (!displaymatrix)
933  theta = get_rotation(displaymatrix);
934 
935  if (fabs(theta - 90) < 1.0) {
936  ret = insert_filter(&last_filter, &pad_idx, "transpose",
937  displaymatrix[3] > 0 ? "cclock_flip" : "clock");
938  } else if (fabs(theta - 180) < 1.0) {
939  if (displaymatrix[0] < 0) {
940  ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
941  if (ret < 0)
942  return ret;
943  }
944  if (displaymatrix[4] < 0) {
945  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
946  }
947  } else if (fabs(theta - 270) < 1.0) {
948  ret = insert_filter(&last_filter, &pad_idx, "transpose",
949  displaymatrix[3] < 0 ? "clock_flip" : "cclock");
950  } else if (fabs(theta) > 1.0) {
951  char rotate_buf[64];
952  snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
953  ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf);
954  } else if (fabs(theta) < 1.0) {
955  if (displaymatrix && displaymatrix[4] < 0) {
956  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
957  }
958  }
959  if (ret < 0)
960  return ret;
961  }
962 
963  snprintf(name, sizeof(name), "trim_in_%d_%d",
964  ist->file_index, ist->st->index);
965  if (copy_ts) {
966  tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
967  if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
968  tsoffset += f->ctx->start_time;
969  }
970  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
971  AV_NOPTS_VALUE : tsoffset, f->recording_time,
972  &last_filter, &pad_idx, name);
973  if (ret < 0)
974  return ret;
975 
976  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
977  return ret;
978  return 0;
979 fail:
980  av_freep(&par);
981 
982  return ret;
983 }
984 
986  AVFilterInOut *in)
987 {
988  AVFilterContext *last_filter;
989  const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
990  InputStream *ist = ifilter->ist;
992  AVBPrint args;
993  char name[255];
994  int ret, pad_idx = 0;
995  int64_t tsoffset = 0;
996 
997  if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
998  av_log(NULL, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
999  return AVERROR(EINVAL);
1000  }
1001 
1003  av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
1004  1, ifilter->sample_rate,
1005  ifilter->sample_rate,
1006  av_get_sample_fmt_name(ifilter->format));
1007  if (av_channel_layout_check(&ifilter->ch_layout) &&
1008  ifilter->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
1009  av_bprintf(&args, ":channel_layout=");
1010  av_channel_layout_describe_bprint(&ifilter->ch_layout, &args);
1011  } else
1012  av_bprintf(&args, ":channels=%d", ifilter->ch_layout.nb_channels);
1013  snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index,
1014  ist->file_index, ist->st->index);
1015 
1016  if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
1017  name, args.str, NULL,
1018  fg->graph)) < 0)
1019  return ret;
1020  last_filter = ifilter->filter;
1021 
1022 #define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
1023  AVFilterContext *filt_ctx; \
1024  \
1025  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
1026  "similarly to -af " filter_name "=%s.\n", arg); \
1027  \
1028  snprintf(name, sizeof(name), "graph_%d_%s_in_%d_%d", \
1029  fg->index, filter_name, ist->file_index, ist->st->index); \
1030  ret = avfilter_graph_create_filter(&filt_ctx, \
1031  avfilter_get_by_name(filter_name), \
1032  name, arg, NULL, fg->graph); \
1033  if (ret < 0) \
1034  return ret; \
1035  \
1036  ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
1037  if (ret < 0) \
1038  return ret; \
1039  \
1040  last_filter = filt_ctx; \
1041 } while (0)
1042 
1043  snprintf(name, sizeof(name), "trim for input stream %d:%d",
1044  ist->file_index, ist->st->index);
1045  if (copy_ts) {
1046  tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
1047  if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
1048  tsoffset += f->ctx->start_time;
1049  }
1050  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
1051  AV_NOPTS_VALUE : tsoffset, f->recording_time,
1052  &last_filter, &pad_idx, name);
1053  if (ret < 0)
1054  return ret;
1055 
1056  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
1057  return ret;
1058 
1059  return 0;
1060 }
1061 
1063  AVFilterInOut *in)
1064 {
1065  if (!ifilter->ist->dec) {
1067  "No decoder for stream #%d:%d, filtering impossible\n",
1068  ifilter->ist->file_index, ifilter->ist->st->index);
1070  }
1071  switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
1072  case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
1073  case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
1074  default: av_assert0(0); return 0;
1075  }
1076 }
1077 
1079 {
1080  int i;
1081  for (i = 0; i < fg->nb_outputs; i++)
1082  fg->outputs[i]->filter = (AVFilterContext *)NULL;
1083  for (i = 0; i < fg->nb_inputs; i++)
1084  fg->inputs[i]->filter = (AVFilterContext *)NULL;
1085  avfilter_graph_free(&fg->graph);
1086 }
1087 
1089 {
1090  return f->nb_inputs == 0 &&
1091  (!strcmp(f->filter->name, "buffer") ||
1092  !strcmp(f->filter->name, "abuffer"));
1093 }
1094 
1095 static int graph_is_meta(AVFilterGraph *graph)
1096 {
1097  for (unsigned i = 0; i < graph->nb_filters; i++) {
1098  const AVFilterContext *f = graph->filters[i];
1099 
1100  /* in addition to filters flagged as meta, also
1101  * disregard sinks and buffersources (but not other sources,
1102  * since they introduce data we are not aware of)
1103  */
1104  if (!((f->filter->flags & AVFILTER_FLAG_METADATA_ONLY) ||
1105  f->nb_outputs == 0 ||
1107  return 0;
1108  }
1109  return 1;
1110 }
1111 
1113 {
1114  AVFilterInOut *inputs, *outputs, *cur;
1115  int ret, i, simple = filtergraph_is_simple(fg);
1116  const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
1117  fg->graph_desc;
1118 
1119  cleanup_filtergraph(fg);
1120  if (!(fg->graph = avfilter_graph_alloc()))
1121  return AVERROR(ENOMEM);
1122 
1123  if (simple) {
1124  OutputStream *ost = fg->outputs[0]->ost;
1125 
1126  if (filter_nbthreads) {
1127  ret = av_opt_set(fg->graph, "threads", filter_nbthreads, 0);
1128  if (ret < 0)
1129  goto fail;
1130  } else {
1131  const AVDictionaryEntry *e = NULL;
1132  e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
1133  if (e)
1134  av_opt_set(fg->graph, "threads", e->value, 0);
1135  }
1136 
1137  if (av_dict_count(ost->sws_dict)) {
1138  ret = av_dict_get_string(ost->sws_dict,
1139  &fg->graph->scale_sws_opts,
1140  '=', ':');
1141  if (ret < 0)
1142  goto fail;
1143  }
1144 
1145  if (av_dict_count(ost->swr_opts)) {
1146  char *args;
1147  ret = av_dict_get_string(ost->swr_opts, &args, '=', ':');
1148  if (ret < 0)
1149  goto fail;
1150  av_opt_set(fg->graph, "aresample_swr_opts", args, 0);
1151  av_free(args);
1152  }
1153  } else {
1155  }
1156 
1157  if ((ret = graph_parse(fg->graph, graph_desc, &inputs, &outputs)) < 0)
1158  goto fail;
1159 
1161  if (ret < 0)
1162  goto fail;
1163 
1164  if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
1165  const char *num_inputs;
1166  const char *num_outputs;
1167  if (!outputs) {
1168  num_outputs = "0";
1169  } else if (outputs->next) {
1170  num_outputs = ">1";
1171  } else {
1172  num_outputs = "1";
1173  }
1174  if (!inputs) {
1175  num_inputs = "0";
1176  } else if (inputs->next) {
1177  num_inputs = ">1";
1178  } else {
1179  num_inputs = "1";
1180  }
1181  av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
1182  "to have exactly 1 input and 1 output."
1183  " However, it had %s input(s) and %s output(s)."
1184  " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
1185  graph_desc, num_inputs, num_outputs);
1186  ret = AVERROR(EINVAL);
1187  goto fail;
1188  }
1189 
1190  for (cur = inputs, i = 0; cur; cur = cur->next, i++)
1191  if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0) {
1194  goto fail;
1195  }
1197 
1198  for (cur = outputs, i = 0; cur; cur = cur->next, i++)
1199  configure_output_filter(fg, fg->outputs[i], cur);
1201 
1204  if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
1205  goto fail;
1206 
1207  fg->is_meta = graph_is_meta(fg->graph);
1208 
1209  /* limit the lists of allowed formats to the ones selected, to
1210  * make sure they stay the same if the filtergraph is reconfigured later */
1211  for (i = 0; i < fg->nb_outputs; i++) {
1212  OutputFilter *ofilter = fg->outputs[i];
1213  AVFilterContext *sink = ofilter->filter;
1214 
1215  ofilter->format = av_buffersink_get_format(sink);
1216 
1217  ofilter->width = av_buffersink_get_w(sink);
1218  ofilter->height = av_buffersink_get_h(sink);
1219 
1220  ofilter->sample_rate = av_buffersink_get_sample_rate(sink);
1222  ret = av_buffersink_get_ch_layout(sink, &ofilter->ch_layout);
1223  if (ret < 0)
1224  goto fail;
1225  }
1226 
1227  fg->reconfiguration = 1;
1228 
1229  for (i = 0; i < fg->nb_outputs; i++) {
1230  OutputStream *ost = fg->outputs[i]->ost;
1231  if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO &&
1232  !(ost->enc_ctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
1233  av_buffersink_set_frame_size(ost->filter->filter,
1234  ost->enc_ctx->frame_size);
1235  }
1236 
1237  for (i = 0; i < fg->nb_inputs; i++) {
1238  AVFrame *tmp;
1239  while (av_fifo_read(fg->inputs[i]->frame_queue, &tmp, 1) >= 0) {
1241  av_frame_free(&tmp);
1242  if (ret < 0)
1243  goto fail;
1244  }
1245  }
1246 
1247  /* send the EOFs for the finished inputs */
1248  for (i = 0; i < fg->nb_inputs; i++) {
1249  if (fg->inputs[i]->eof) {
1251  if (ret < 0)
1252  goto fail;
1253  }
1254  }
1255 
1256  /* process queued up subtitle packets */
1257  for (i = 0; i < fg->nb_inputs; i++) {
1258  InputStream *ist = fg->inputs[i]->ist;
1259  if (ist->sub2video.sub_queue && ist->sub2video.frame) {
1260  AVSubtitle tmp;
1261  while (av_fifo_read(ist->sub2video.sub_queue, &tmp, 1) >= 0) {
1262  sub2video_update(ist, INT64_MIN, &tmp);
1263  avsubtitle_free(&tmp);
1264  }
1265  }
1266  }
1267 
1268  return 0;
1269 
1270 fail:
1271  cleanup_filtergraph(fg);
1272  return ret;
1273 }
1274 
1276 {
1277  AVFrameSideData *sd;
1278  int ret;
1279 
1280  av_buffer_unref(&ifilter->hw_frames_ctx);
1281 
1282  ifilter->format = frame->format;
1283 
1284  ifilter->width = frame->width;
1285  ifilter->height = frame->height;
1286  ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
1287 
1288  ifilter->sample_rate = frame->sample_rate;
1289  ret = av_channel_layout_copy(&ifilter->ch_layout, &frame->ch_layout);
1290  if (ret < 0)
1291  return ret;
1292 
1293  av_freep(&ifilter->displaymatrix);
1295  if (sd)
1296  ifilter->displaymatrix = av_memdup(sd->data, sizeof(int32_t) * 9);
1297 
1298  if (frame->hw_frames_ctx) {
1299  ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
1300  if (!ifilter->hw_frames_ctx)
1301  return AVERROR(ENOMEM);
1302  }
1303 
1304  return 0;
1305 }
1306 
1308 {
1309  return !fg->graph_desc;
1310 }
AVSubtitle
Definition: avcodec.h:2330
formats
formats
Definition: signature.h:48
init_complex_filtergraph
int init_complex_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:467
InputFilter::sample_aspect_ratio
AVRational sample_aspect_ratio
Definition: ffmpeg.h:284
AVCodec
AVCodec.
Definition: codec.h:184
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
av_buffersink_get_ch_layout
int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out)
Definition: buffersink.c:219
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
OutputFilter::graph
struct FilterGraph * graph
Definition: ffmpeg.h:298
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:215
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
nb_input_files
int nb_input_files
Definition: ffmpeg.c:144
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:58
AVFilterGraph::nb_threads
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:881
avfilter_pad_get_name
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
Definition: avfilter.c:923
InputStream::framerate_guessed
AVRational framerate_guessed
Definition: ffmpeg.h:358
InputFilter::width
int width
Definition: ffmpeg.h:283
InputFilter::displaymatrix
int32_t * displaymatrix
Definition: ffmpeg.h:290
avfilter_graph_segment_create_filters
int avfilter_graph_segment_create_filters(AVFilterGraphSegment *seg, int flags)
Create filters specified in a graph segment.
Definition: graphparser.c:515
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1247
out
FILE * out
Definition: movenc.c:54
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:682
FilterGraph::graph_desc
const char * graph_desc
Definition: ffmpeg.h:321
ALLOC_ARRAY_ELEM
#define ALLOC_ARRAY_ELEM(array, nb_elems)
Definition: cmdutils.h:445
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:947
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2888
FilterGraph::inputs
InputFilter ** inputs
Definition: ffmpeg.h:329
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:909
av_dict_count
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:37
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg.h:353
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:339
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:116
ist_iter
InputStream * ist_iter(InputStream *prev)
Definition: ffmpeg.c:604
AVCodec::pix_fmts
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:206
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:99
OutputFile::start_time
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:706
InputFilter::ch_layout
AVChannelLayout ch_layout
Definition: ffmpeg.h:287
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVFilterInOut::next
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
Definition: avfilter.h:1026
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1172
init_simple_filtergraph
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
Definition: ffmpeg_filter.c:179
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:251
av_buffersrc_add_frame
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
Definition: buffersrc.c:156
FilterGraph::index
int index
Definition: ffmpeg.h:320
data
const char data[16]
Definition: mxf.c:146
check_filter_outputs
void check_filter_outputs(void)
Definition: ffmpeg_filter.c:798
InputStream::nb_filters
int nb_filters
Definition: ffmpeg.h:417
ffmpeg.h
FilterGraph::nb_inputs
int nb_inputs
Definition: ffmpeg.h:330
AV_FRAME_DATA_DISPLAYMATRIX
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:85
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:306
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilterContext::output_pads
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:403
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
InputStream::decoding_needed
int decoding_needed
Definition: ffmpeg.h:340
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:344
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:104
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
sample_rate
sample_rate
Definition: ffmpeg_filter.c:156
av_channel_layout_describe_bprint
int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, AVBPrint *bp)
bprint variant of av_channel_layout_describe().
Definition: channel_layout.c:732
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
avfilter_graph_free
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:119
InputFilter::ist
struct InputStream * ist
Definition: ffmpeg.h:273
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:701
configure_filtergraph
int configure_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:1112
AUTO_INSERT_FILTER
#define AUTO_INSERT_FILTER(opt_name, filter_name, arg)
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
exit_program
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:99
InputStream
Definition: ffmpeg.h:335
filter_nbthreads
char * filter_nbthreads
Definition: ffmpeg_opt.c:86
avfilter_graph_create_filter
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.
Definition: avfiltergraph.c:138
av_buffersink_set_frame_size
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
Definition: buffersink.c:182
avfilter_graph_alloc_filter
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
Definition: avfiltergraph.c:165
avio_open2
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1241
AV_OPT_TYPE_BINARY
@ AV_OPT_TYPE_BINARY
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:231
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:435
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2054
report_and_exit
void report_and_exit(int ret)
Reports an error corresponding to the provided AVERROR code and calls exit_program() with the corresp...
Definition: cmdutils.c:93
InputStream::sub2video
struct InputStream::sub2video sub2video
fail
#define fail()
Definition: checkasm.h:134
InputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:276
avfilter_graph_alloc
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:82
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
samplefmt.h
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:63
avfilter_graph_segment_free
void avfilter_graph_segment_free(AVFilterGraphSegment **seg)
Free the provided AVFilterGraphSegment and everything associated with it.
Definition: graphparser.c:275
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:70
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
OutputFilter::sample_rate
int sample_rate
Definition: ffmpeg.h:309
val
static double val(void *priv, double ch)
Definition: aeval.c:77
graph_parse
static int graph_parse(AVFilterGraph *graph, const char *desc, AVFilterInOut **inputs, AVFilterInOut **outputs)
Definition: ffmpeg_filter.c:442
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
avfilter_graph_segment_parse
int avfilter_graph_segment_parse(AVFilterGraph *graph, const char *graph_str, int flags, AVFilterGraphSegment **seg)
Parse a textual filtergraph description into an intermediate form.
Definition: graphparser.c:459
AV_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:109
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:487
graph_is_meta
static int graph_is_meta(AVFilterGraph *graph)
Definition: ffmpeg_filter.c:1095
InputStream::sub2video::last_pts
int64_t last_pts
Definition: ffmpeg.h:406
AVRational::num
int num
Numerator.
Definition: rational.h:59
InputFile
Definition: ffmpeg.h:450
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:409
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:87
AVFilterContext::input_pads
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:399
check_stream_specifier
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:887
OutputFile::shortest
int shortest
Definition: ffmpeg.h:708
avfilter_inout_free
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:75
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_fifo_read
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition: fifo.c:240
duration
int64_t duration
Definition: movenc.c:64
AVFilterChain::filters
AVFilterParams ** filters
Definition: avfilter.h:1202
av_dict_get
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:60
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
OutputFilter::width
int width
Definition: ffmpeg.h:306
s
#define s(width, name)
Definition: cbs_vp9.c:256
FilterGraph::outputs
OutputFilter ** outputs
Definition: ffmpeg.h:331
InputStream::framerate
AVRational framerate
Definition: ffmpeg.h:392
configure_input_audio_filter
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:985
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVDictionaryEntry::key
char * key
Definition: dict.h:90
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:128
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
InputFilter
Definition: ffmpeg.h:271
av_buffersink_get_format
int av_buffersink_get_format(const AVFilterContext *ctx)
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:172
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
OutputFilter::ost
struct OutputStream * ost
Definition: ffmpeg.h:297
OutputStream::avfilter
char * avfilter
Definition: ffmpeg.h:632
ctx
AVFormatContext * ctx
Definition: movenc.c:48
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:416
nb_streams
static int nb_streams
Definition: ffprobe.c:309
graph_opts_apply
static int graph_opts_apply(AVFilterGraphSegment *seg)
Definition: ffmpeg_filter.c:418
InputFilter::graph
struct FilterGraph * graph
Definition: ffmpeg.h:274
av_get_sample_fmt_name
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:51
key
const char * key
Definition: hwcontext_opencl.c:174
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1772
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:76
AVFormatContext
Format I/O context.
Definition: avformat.h:1104
avfilter_get_by_name
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: allfilters.c:611
OutputFilter::height
int height
Definition: ffmpeg.h:306
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:861
OutputFilter::name
uint8_t * name
Definition: ffmpeg.h:299
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
avfilter_graph_config
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
Definition: avfiltergraph.c:1167
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:877
avfilter_graph_segment_apply
int avfilter_graph_segment_apply(AVFilterGraphSegment *seg, int flags, AVFilterInOut **inputs, AVFilterInOut **outputs)
Apply all filter/link descriptions from a graph segment to the associated filtergraph.
Definition: graphparser.c:853
NULL
#define NULL
Definition: coverity.c:32
av_opt_set_bin
int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
Definition: opt.c:639
InputStream::sub2video::w
int w
Definition: ffmpeg.h:410
AVFilterParams
Parameters describing a filter to be created in a filtergraph.
Definition: avfilter.h:1134
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
InputStream::st
AVStream * st
Definition: ffmpeg.h:337
avfilter_graph_set_auto_convert
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
Enable or disable automatic format conversion inside the graph.
Definition: avfiltergraph.c:160
AVFilterParams::filter
AVFilterContext * filter
The filter context.
Definition: avfilter.h:1145
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVFilterChain::nb_filters
size_t nb_filters
Definition: avfilter.h:1203
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AVFilterGraph::filters
AVFilterContext ** filters
Definition: avfilter.h:857
filter_opt_apply
static int filter_opt_apply(AVFilterContext *f, const char *key, const char *val)
Definition: ffmpeg_filter.c:363
AVFilterContext::name
char * name
name of this filter instance
Definition: avfilter.h:397
InputFilter::eof
int eof
Definition: ffmpeg.h:292
AV_CODEC_CAP_VARIABLE_FRAME_SIZE
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: codec.h:125
AVFilterGraphSegment::chains
AVFilterChain ** chains
A list of filter chain contained in this segment.
Definition: avfilter.h:1226
AVFilterGraph
Definition: avfilter.h:855
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
InputStream::sub2video::sub_queue
AVFifo * sub_queue
queue of AVSubtitle* before filter init
Definition: ffmpeg.h:408
FilterGraph::nb_outputs
int nb_outputs
Definition: ffmpeg.h:332
InputStream::sub2video::initialize
unsigned int initialize
marks if sub2video_update should force an initialization
Definition: ffmpeg.h:411
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:624
input_files
InputFile ** input_files
Definition: ffmpeg.c:143
OutputFile::streams
OutputStream ** streams
Definition: ffmpeg.h:700
FilterGraph
Definition: ffmpeg.h:319
AVFilterGraphSegment
A parsed representation of a filtergraph segment.
Definition: avfilter.h:1215
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1160
InputFilter::filter
AVFilterContext * filter
Definition: ffmpeg.h:272
AVFilterInOut::pad_idx
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:1023
AVFilterGraph::scale_sws_opts
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:860
f
f
Definition: af_crystalizer.c:122
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
AVMediaType
AVMediaType
Definition: avutil.h:199
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:301
av_buffersrc_parameters_alloc
AVBufferSrcParameters * av_buffersrc_parameters_alloc(void)
Allocate a new AVBufferSrcParameters instance.
Definition: buffersrc.c:83
InputStream::file_index
int file_index
Definition: ffmpeg.h:336
AVFilterInOut::filter_ctx
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1020
output_files
OutputFile ** output_files
Definition: ffmpeg.c:146
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
avfilter_link
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:148
AVBufferSrcParameters::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Video with a hwaccel pixel format only.
Definition: buffersrc.h:106
start_time
static int64_t start_time
Definition: ffplay.c:331
FilterGraph::graph
AVFilterGraph * graph
Definition: ffmpeg.h:323
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
insert_trim
static int insert_trim(int64_t start_time, int64_t duration, AVFilterContext **last_filter, int *pad_idx, const char *filter_name)
Definition: ffmpeg_filter.c:505
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:76
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFrameSideData::data
uint8_t * data
Definition: frame.h:238
read_binary
static int read_binary(const char *path, uint8_t **data, int *len)
Definition: ffmpeg_filter.c:317
sub2video_update
void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
Definition: ffmpeg.c:228
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:563
OutputFilter::filter
AVFilterContext * filter
Definition: ffmpeg.h:296
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:432
filter_is_buffersrc
static int filter_is_buffersrc(const AVFilterContext *f)
Definition: ffmpeg_filter.c:1088
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
FF_COMPLIANCE_UNOFFICIAL
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: defs.h:61
OutputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:303
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
sample_rates
sample_rates
Definition: ffmpeg_filter.c:156
avfilter_init_str
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:895
buffersink.h
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:962
ifilter_parameters_from_frame
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
Definition: ffmpeg_filter.c:1275
av_buffersink_get_w
int av_buffersink_get_w(const AVFilterContext *ctx)
bprint.h
av_buffersrc_parameters_set
int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param)
Initialize the buffersrc or abuffersrc filter with the provided parameters.
Definition: buffersrc.c:94
DECODING_FOR_FILTER
#define DECODING_FOR_FILTER
Definition: ffmpeg.h:342
configure_input_filter
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:1062
choose_channel_layouts
static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
Definition: ffmpeg_filter.c:159
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
configure_output_filter
static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
Definition: ffmpeg_filter.c:783
AVCodecParameters::height
int height
Definition: codec_par.h:129
display.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
choose_pixel_fmt
static enum AVPixelFormat choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target, int strict_std_compliance)
Definition: ffmpeg_filter.c:56
InputStream::processing_needed
int processing_needed
Definition: ffmpeg.h:343
hw_device_setup_for_filter
int hw_device_setup_for_filter(FilterGraph *fg)
Definition: ffmpeg_hw.c:551
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:453
tb
#define tb
Definition: regdef.h:68
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:191
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
len
int len
Definition: vorbis_enc_data.h:426
init_input_filter
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
Definition: ffmpeg_filter.c:231
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:149
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:500
AVCodecContext::height
int height
Definition: avcodec.h:598
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:635
av_buffersink_get_h
int av_buffersink_get_h(const AVFilterContext *ctx)
AVFilter
Filter definition.
Definition: avfilter.h:161
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:838
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
pixfmt.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
InputFilter::name
uint8_t * name
Definition: ffmpeg.h:275
OutputFilter::ch_layout
AVChannelLayout ch_layout
Definition: ffmpeg.h:310
av_channel_layout_check
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
Definition: channel_layout.c:906
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:474
insert_filter
static int insert_filter(AVFilterContext **last_filter, int *pad_idx, const char *filter_name, const char *args)
Definition: ffmpeg_filter.c:556
AVFilterParams::opts
AVDictionary * opts
Options to be apllied to the filter.
Definition: avfilter.h:1186
av_stream_get_side_data
uint8_t * av_stream_get_side_data(const AVStream *st, enum AVPacketSideDataType type, size_t *size)
Get side information from stream.
Definition: avformat.c:141
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
AVOption::type
enum AVOptionType type
Definition: opt.h:265
get_compliance_normal_pix_fmts
static enum AVPixelFormat * get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[])
Definition: ffmpeg_filter.c:42
InputFilter::sample_rate
int sample_rate
Definition: ffmpeg.h:286
avfilter_pad_get_type
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:928
OutputFilter::format
int format
Definition: ffmpeg.h:308
configure_input_video_filter
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:860
AVCodecContext
main external API structure.
Definition: avcodec.h:426
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:844
av_find_best_pix_fmt_of_2
enum AVPixelFormat av_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)
Compute what kind of losses will occur when converting from one specific pixel format to another.
Definition: pixdesc.c:3167
DEF_CHOOSE_FORMAT
#define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name)
Definition: ffmpeg_filter.c:130
channel_layout.h
AVBufferSrcParameters
This structure contains the parameters describing the frames that will be passed to this filter.
Definition: buffersrc.h:73
av_buffersink_get_sample_rate
int av_buffersink_get_sample_rate(const AVFilterContext *ctx)
InputFilter::format
int format
Definition: ffmpeg.h:281
AVBufferSrcParameters::format
int format
video: the pixel format, value corresponds to enum AVPixelFormat audio: the sample format,...
Definition: buffersrc.h:78
describe_filter_link
static char * describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
Definition: ffmpeg_filter.c:214
AVRational::den
int den
Denominator.
Definition: rational.h:60
AVFilterChain
A filterchain is a list of filter specifications.
Definition: avfilter.h:1201
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
avfilter.h
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:227
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:632
FilterGraph::is_meta
int is_meta
Definition: ffmpeg.h:327
AVFILTER_FLAG_METADATA_ONLY
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition: avfilter.h:133
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:633
InputFilter::height
int height
Definition: ffmpeg.h:283
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:442
AVERROR_FILTER_NOT_FOUND
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
Definition: error.h:60
AVFilterGraphSegment::nb_chains
size_t nb_chains
Definition: avfilter.h:1227
InputStream::discard
int discard
Definition: ffmpeg.h:338
AVFilterContext
An instance of a filter.
Definition: avfilter.h:392
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:639
OutputFilter
Definition: ffmpeg.h:295
cleanup_filtergraph
static void cleanup_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:1078
InputStream::sub2video::frame
AVFrame * frame
Definition: ffmpeg.h:409
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:623
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:434
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
start_at_zero
int start_at_zero
Definition: ffmpeg_opt.c:77
OutputFilter::out_tmp
AVFilterInOut * out_tmp
Definition: ffmpeg.h:302
auto_conversion_filters
int auto_conversion_filters
Definition: ffmpeg_opt.c:89
InputStream::sub2video::h
int h
Definition: ffmpeg.h:410
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:236
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
OutputStream::autoscale
int autoscale
Definition: ffmpeg.h:611
InputFilter::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Definition: ffmpeg.h:289
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:89
InputStream::sub2video::end_pts
int64_t end_pts
Definition: ffmpeg.h:407
choose_pix_fmts
static const char * choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
Definition: ffmpeg_filter.c:90
FilterGraph::reconfiguration
int reconfiguration
Definition: ffmpeg.h:324
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_get_string
int av_dict_get_string(const AVDictionary *m, char **buffer, const char key_val_sep, const char pairs_sep)
Get dictionary entries as a string.
Definition: dict.c:250
filtergraph_is_simple
int filtergraph_is_simple(FilterGraph *fg)
Definition: ffmpeg_filter.c:1307
file_read
char * file_read(const char *filename)
Definition: ffmpeg_opt.c:700
InputFilter::frame_queue
AVFifo * frame_queue
Definition: ffmpeg.h:278
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:150
AVFilterInOut::name
char * name
unique name for this input/output in the list
Definition: avfilter.h:1017
d
d
Definition: ffmpeg_filter.c:156
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:598
int32_t
int32_t
Definition: audioconvert.c:56
imgutils.h
OutputStream
Definition: mux.c:53
OutputStream::st
AVStream * st
Definition: mux.c:54
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
configure_output_video_filter
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
Definition: ffmpeg_filter.c:578
h
h
Definition: vp9dsp_template.c:2038
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:140
AVFILTER_AUTO_CONVERT_NONE
@ AVFILTER_AUTO_CONVERT_NONE
all automatic conversions disabled
Definition: avfilter.h:988
AVDictionaryEntry::value
char * value
Definition: dict.h:91
AVFilterGraph::nb_filters
unsigned nb_filters
Definition: avfilter.h:858
get_rotation
double get_rotation(int32_t *displaymatrix)
Definition: cmdutils.c:997
avstring.h
OutputFile::recording_time
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:705
AVFilterInOut
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1015
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:354
snprintf
#define snprintf
Definition: snprintf.h:34
buffersrc.h
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42
configure_output_audio_filter
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
Definition: ffmpeg_filter.c:672
AV_FIFO_FLAG_AUTO_GROW
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition: fifo.h:67
av_get_pix_fmt_name
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:2808
filter_complex_nbthreads
int filter_complex_nbthreads
Definition: ffmpeg_opt.c:87
OutputFile
Definition: ffmpeg.h:692
sub2video_prepare
static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
Definition: ffmpeg_filter.c:813
InputStream::autorotate
int autorotate
Definition: ffmpeg.h:396