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 = NULL;
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  AVBufferRef *hw_device)
445 {
447  int ret;
448 
449  *inputs = NULL;
450  *outputs = NULL;
451 
452  ret = avfilter_graph_segment_parse(graph, desc, 0, &seg);
453  if (ret < 0)
454  return ret;
455 
457  if (ret < 0)
458  goto fail;
459 
460  if (hw_device) {
461  for (int i = 0; i < graph->nb_filters; i++) {
462  AVFilterContext *f = graph->filters[i];
463 
464  if (!(f->filter->flags & AVFILTER_FLAG_HWDEVICE))
465  continue;
466  f->hw_device_ctx = av_buffer_ref(hw_device);
467  if (!f->hw_device_ctx) {
468  ret = AVERROR(ENOMEM);
469  goto fail;
470  }
471  }
472  }
473 
474  ret = graph_opts_apply(seg);
475  if (ret < 0)
476  goto fail;
477 
479 
480 fail:
482  return ret;
483 }
484 
486 {
487  AVFilterInOut *inputs, *outputs, *cur;
488  AVFilterGraph *graph;
489  int ret = 0;
490 
491  /* this graph is only used for determining the kinds of inputs
492  * and outputs we have, and is discarded on exit from this function */
493  graph = avfilter_graph_alloc();
494  if (!graph)
495  return AVERROR(ENOMEM);
496  graph->nb_threads = 1;
497 
498  ret = graph_parse(graph, fg->graph_desc, &inputs, &outputs, NULL);
499  if (ret < 0)
500  goto fail;
501 
502  for (cur = inputs; cur; cur = cur->next)
503  init_input_filter(fg, cur);
504 
505  for (cur = outputs; cur;) {
506  OutputFilter *const ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
507 
508  ofilter->graph = fg;
509  ofilter->out_tmp = cur;
511  cur->pad_idx);
512  ofilter->name = describe_filter_link(fg, cur, 0);
513  cur = cur->next;
514  ofilter->out_tmp->next = NULL;
515  }
516 
517 fail:
519  avfilter_graph_free(&graph);
520  return ret;
521 }
522 
523 static int insert_trim(int64_t start_time, int64_t duration,
524  AVFilterContext **last_filter, int *pad_idx,
525  const char *filter_name)
526 {
527  AVFilterGraph *graph = (*last_filter)->graph;
529  const AVFilter *trim;
530  enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
531  const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
532  int ret = 0;
533 
534  if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
535  return 0;
536 
537  trim = avfilter_get_by_name(name);
538  if (!trim) {
539  av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
540  "recording time.\n", name);
542  }
543 
544  ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
545  if (!ctx)
546  return AVERROR(ENOMEM);
547 
548  if (duration != INT64_MAX) {
549  ret = av_opt_set_int(ctx, "durationi", duration,
551  }
552  if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
553  ret = av_opt_set_int(ctx, "starti", start_time,
555  }
556  if (ret < 0) {
557  av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
558  return ret;
559  }
560 
562  if (ret < 0)
563  return ret;
564 
565  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
566  if (ret < 0)
567  return ret;
568 
569  *last_filter = ctx;
570  *pad_idx = 0;
571  return 0;
572 }
573 
574 static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
575  const char *filter_name, const char *args)
576 {
577  AVFilterGraph *graph = (*last_filter)->graph;
579  int ret;
580 
582  avfilter_get_by_name(filter_name),
583  filter_name, args, NULL, graph);
584  if (ret < 0)
585  return ret;
586 
587  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
588  if (ret < 0)
589  return ret;
590 
591  *last_filter = ctx;
592  *pad_idx = 0;
593  return 0;
594 }
595 
597 {
598  OutputStream *ost = ofilter->ost;
599  OutputFile *of = output_files[ost->file_index];
600  AVFilterContext *last_filter = out->filter_ctx;
601  AVBPrint bprint;
602  int pad_idx = out->pad_idx;
603  int ret;
604  const char *pix_fmts;
605  char name[255];
606 
607  snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
609  avfilter_get_by_name("buffersink"),
610  name, NULL, NULL, fg->graph);
611 
612  if (ret < 0)
613  return ret;
614 
615  if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) {
616  char args[255];
618  const AVDictionaryEntry *e = NULL;
619 
620  snprintf(args, sizeof(args), "%d:%d",
621  ofilter->width, ofilter->height);
622 
623  while ((e = av_dict_iterate(ost->sws_dict, e))) {
624  av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
625  }
626 
627  snprintf(name, sizeof(name), "scaler_out_%d_%d",
628  ost->file_index, ost->index);
630  name, args, NULL, fg->graph)) < 0)
631  return ret;
632  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
633  return ret;
634 
635  last_filter = filter;
636  pad_idx = 0;
637  }
638 
640  if ((pix_fmts = choose_pix_fmts(ofilter, &bprint))) {
642 
644  avfilter_get_by_name("format"),
645  "format", pix_fmts, NULL, fg->graph);
646  av_bprint_finalize(&bprint, NULL);
647  if (ret < 0)
648  return ret;
649  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
650  return ret;
651 
652  last_filter = filter;
653  pad_idx = 0;
654  }
655 
656  if (ost->frame_rate.num && 0) {
657  AVFilterContext *fps;
658  char args[255];
659 
660  snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
661  ost->frame_rate.den);
662  snprintf(name, sizeof(name), "fps_out_%d_%d",
663  ost->file_index, ost->index);
665  name, args, NULL, fg->graph);
666  if (ret < 0)
667  return ret;
668 
669  ret = avfilter_link(last_filter, pad_idx, fps, 0);
670  if (ret < 0)
671  return ret;
672  last_filter = fps;
673  pad_idx = 0;
674  }
675 
676  snprintf(name, sizeof(name), "trim_out_%d_%d",
677  ost->file_index, ost->index);
679  &last_filter, &pad_idx, name);
680  if (ret < 0)
681  return ret;
682 
683 
684  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
685  return ret;
686 
687  return 0;
688 }
689 
691 {
692  OutputStream *ost = ofilter->ost;
693  OutputFile *of = output_files[ost->file_index];
694  AVCodecContext *codec = ost->enc_ctx;
695  AVFilterContext *last_filter = out->filter_ctx;
696  int pad_idx = out->pad_idx;
697  AVBPrint args;
698  char name[255];
699  int ret;
700 
701  snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
703  avfilter_get_by_name("abuffersink"),
704  name, NULL, NULL, fg->graph);
705  if (ret < 0)
706  return ret;
707  if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
708  return ret;
709 
710 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
711  AVFilterContext *filt_ctx; \
712  \
713  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
714  "similarly to -af " filter_name "=%s.\n", arg); \
715  \
716  ret = avfilter_graph_create_filter(&filt_ctx, \
717  avfilter_get_by_name(filter_name), \
718  filter_name, arg, NULL, fg->graph); \
719  if (ret < 0) \
720  goto fail; \
721  \
722  ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
723  if (ret < 0) \
724  goto fail; \
725  \
726  last_filter = filt_ctx; \
727  pad_idx = 0; \
728 } while (0)
730 #if FFMPEG_OPT_MAP_CHANNEL
731  if (ost->audio_channels_mapped) {
732  AVChannelLayout mapped_layout = { 0 };
733  int i;
734  av_channel_layout_default(&mapped_layout, ost->audio_channels_mapped);
735  av_channel_layout_describe_bprint(&mapped_layout, &args);
736  for (i = 0; i < ost->audio_channels_mapped; i++)
737  if (ost->audio_channels_map[i] != -1)
738  av_bprintf(&args, "|c%d=c%d", i, ost->audio_channels_map[i]);
739 
740  AUTO_INSERT_FILTER("-map_channel", "pan", args.str);
741  av_bprint_clear(&args);
742  }
743 #endif
744 
747 
748  choose_sample_fmts(ofilter, &args);
749  choose_sample_rates(ofilter, &args);
750  choose_channel_layouts(ofilter, &args);
751  if (!av_bprint_is_complete(&args)) {
752  ret = AVERROR(ENOMEM);
753  goto fail;
754  }
755  if (args.len) {
757 
758  snprintf(name, sizeof(name), "format_out_%d_%d",
759  ost->file_index, ost->index);
761  avfilter_get_by_name("aformat"),
762  name, args.str, NULL, fg->graph);
763  if (ret < 0)
764  goto fail;
765 
766  ret = avfilter_link(last_filter, pad_idx, format, 0);
767  if (ret < 0)
768  goto fail;
769 
770  last_filter = format;
771  pad_idx = 0;
772  }
773 
774  if (ost->apad && of->shortest) {
775  int i;
776 
777  for (i = 0; i < of->nb_streams; i++)
779  break;
780 
781  if (i < of->nb_streams) {
782  AUTO_INSERT_FILTER("-apad", "apad", ost->apad);
783  }
784  }
785 
786  snprintf(name, sizeof(name), "trim for output stream %d:%d",
787  ost->file_index, ost->index);
789  &last_filter, &pad_idx, name);
790  if (ret < 0)
791  goto fail;
792 
793  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
794  goto fail;
795 fail:
796  av_bprint_finalize(&args, NULL);
797 
798  return ret;
799 }
800 
803 {
804  if (!ofilter->ost) {
805  av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
806  exit_program(1);
807  }
808 
809  switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
810  case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
811  case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
812  default: av_assert0(0); return 0;
813  }
814 }
815 
817 {
818  int i;
819  for (i = 0; i < nb_filtergraphs; i++) {
820  int n;
821  for (n = 0; n < filtergraphs[i]->nb_outputs; n++) {
823  if (!output->ost) {
824  av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", output->name);
825  exit_program(1);
826  }
827  }
828  }
829 }
830 
831 static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
832 {
834  int i, w, h;
835 
836  /* Compute the size of the canvas for the subtitles stream.
837  If the subtitles codecpar has set a size, use it. Otherwise use the
838  maximum dimensions of the video streams in the same file. */
839  w = ifilter->width;
840  h = ifilter->height;
841  if (!(w && h)) {
842  for (i = 0; i < avf->nb_streams; i++) {
844  w = FFMAX(w, avf->streams[i]->codecpar->width);
845  h = FFMAX(h, avf->streams[i]->codecpar->height);
846  }
847  }
848  if (!(w && h)) {
849  w = FFMAX(w, 720);
850  h = FFMAX(h, 576);
851  }
852  av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
853  }
854  ist->sub2video.w = ifilter->width = w;
855  ist->sub2video.h = ifilter->height = h;
856 
857  ifilter->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w;
858  ifilter->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h;
859 
860  /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
861  palettes for all rectangles are identical or compatible */
862  ifilter->format = AV_PIX_FMT_RGB32;
863 
864  ist->sub2video.frame = av_frame_alloc();
865  if (!ist->sub2video.frame)
866  return AVERROR(ENOMEM);
867  ist->sub2video.last_pts = INT64_MIN;
868  ist->sub2video.end_pts = INT64_MIN;
869 
870  /* sub2video structure has been (re-)initialized.
871  Mark it as such so that the system will be
872  initialized with the first received heartbeat. */
873  ist->sub2video.initialize = 1;
874 
875  return 0;
876 }
877 
879  AVFilterInOut *in)
880 {
881  AVFilterContext *last_filter;
882  const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
883  const AVPixFmtDescriptor *desc;
884  InputStream *ist = ifilter->ist;
886  AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
887  ist->st->time_base;
888  AVRational fr = ist->framerate;
889  AVRational sar;
890  AVBPrint args;
891  char name[255];
892  int ret, pad_idx = 0;
893  int64_t tsoffset = 0;
895 
896  if (!par)
897  return AVERROR(ENOMEM);
898  memset(par, 0, sizeof(*par));
899  par->format = AV_PIX_FMT_NONE;
900 
901  if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
902  av_log(NULL, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
903  ret = AVERROR(EINVAL);
904  goto fail;
905  }
906 
907  if (!fr.num)
908  fr = ist->framerate_guessed;
909 
911  ret = sub2video_prepare(ist, ifilter);
912  if (ret < 0)
913  goto fail;
914  }
915 
916  sar = ifilter->sample_aspect_ratio;
917  if(!sar.den)
918  sar = (AVRational){0,1};
920  av_bprintf(&args,
921  "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
922  "pixel_aspect=%d/%d",
923  ifilter->width, ifilter->height, ifilter->format,
924  tb.num, tb.den, sar.num, sar.den);
925  if (fr.num && fr.den)
926  av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
927  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
928  ist->file_index, ist->st->index);
929 
930 
931  if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
932  args.str, NULL, fg->graph)) < 0)
933  goto fail;
934  par->hw_frames_ctx = ifilter->hw_frames_ctx;
935  ret = av_buffersrc_parameters_set(ifilter->filter, par);
936  if (ret < 0)
937  goto fail;
938  av_freep(&par);
939  last_filter = ifilter->filter;
940 
941  desc = av_pix_fmt_desc_get(ifilter->format);
942  av_assert0(desc);
943 
944  // TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
945  if (ist->autorotate && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
946  int32_t *displaymatrix = ifilter->displaymatrix;
947  double theta;
948 
949  if (!displaymatrix)
951  theta = get_rotation(displaymatrix);
952 
953  if (fabs(theta - 90) < 1.0) {
954  ret = insert_filter(&last_filter, &pad_idx, "transpose",
955  displaymatrix[3] > 0 ? "cclock_flip" : "clock");
956  } else if (fabs(theta - 180) < 1.0) {
957  if (displaymatrix[0] < 0) {
958  ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
959  if (ret < 0)
960  return ret;
961  }
962  if (displaymatrix[4] < 0) {
963  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
964  }
965  } else if (fabs(theta - 270) < 1.0) {
966  ret = insert_filter(&last_filter, &pad_idx, "transpose",
967  displaymatrix[3] < 0 ? "clock_flip" : "cclock");
968  } else if (fabs(theta) > 1.0) {
969  char rotate_buf[64];
970  snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
971  ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf);
972  } else if (fabs(theta) < 1.0) {
973  if (displaymatrix && displaymatrix[4] < 0) {
974  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
975  }
976  }
977  if (ret < 0)
978  return ret;
979  }
980 
981  snprintf(name, sizeof(name), "trim_in_%d_%d",
982  ist->file_index, ist->st->index);
983  if (copy_ts) {
984  tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
985  if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
986  tsoffset += f->ctx->start_time;
987  }
988  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
989  AV_NOPTS_VALUE : tsoffset, f->recording_time,
990  &last_filter, &pad_idx, name);
991  if (ret < 0)
992  return ret;
993 
994  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
995  return ret;
996  return 0;
997 fail:
998  av_freep(&par);
999 
1000  return ret;
1001 }
1002 
1004  AVFilterInOut *in)
1005 {
1006  AVFilterContext *last_filter;
1007  const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
1008  InputStream *ist = ifilter->ist;
1009  InputFile *f = input_files[ist->file_index];
1010  AVBPrint args;
1011  char name[255];
1012  int ret, pad_idx = 0;
1013  int64_t tsoffset = 0;
1014 
1015  if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
1016  av_log(NULL, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
1017  return AVERROR(EINVAL);
1018  }
1019 
1021  av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
1022  1, ifilter->sample_rate,
1023  ifilter->sample_rate,
1024  av_get_sample_fmt_name(ifilter->format));
1025  if (av_channel_layout_check(&ifilter->ch_layout) &&
1026  ifilter->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
1027  av_bprintf(&args, ":channel_layout=");
1028  av_channel_layout_describe_bprint(&ifilter->ch_layout, &args);
1029  } else
1030  av_bprintf(&args, ":channels=%d", ifilter->ch_layout.nb_channels);
1031  snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index,
1032  ist->file_index, ist->st->index);
1033 
1034  if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
1035  name, args.str, NULL,
1036  fg->graph)) < 0)
1037  return ret;
1038  last_filter = ifilter->filter;
1039 
1040 #define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
1041  AVFilterContext *filt_ctx; \
1042  \
1043  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
1044  "similarly to -af " filter_name "=%s.\n", arg); \
1045  \
1046  snprintf(name, sizeof(name), "graph_%d_%s_in_%d_%d", \
1047  fg->index, filter_name, ist->file_index, ist->st->index); \
1048  ret = avfilter_graph_create_filter(&filt_ctx, \
1049  avfilter_get_by_name(filter_name), \
1050  name, arg, NULL, fg->graph); \
1051  if (ret < 0) \
1052  return ret; \
1053  \
1054  ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
1055  if (ret < 0) \
1056  return ret; \
1057  \
1058  last_filter = filt_ctx; \
1059 } while (0)
1060 
1061  snprintf(name, sizeof(name), "trim for input stream %d:%d",
1062  ist->file_index, ist->st->index);
1063  if (copy_ts) {
1064  tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
1065  if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
1066  tsoffset += f->ctx->start_time;
1067  }
1068  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
1069  AV_NOPTS_VALUE : tsoffset, f->recording_time,
1070  &last_filter, &pad_idx, name);
1071  if (ret < 0)
1072  return ret;
1073 
1074  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
1075  return ret;
1076 
1077  return 0;
1078 }
1079 
1081  AVFilterInOut *in)
1082 {
1083  if (!ifilter->ist->dec) {
1085  "No decoder for stream #%d:%d, filtering impossible\n",
1086  ifilter->ist->file_index, ifilter->ist->st->index);
1088  }
1089  switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
1090  case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
1091  case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
1092  default: av_assert0(0); return 0;
1093  }
1094 }
1095 
1097 {
1098  int i;
1099  for (i = 0; i < fg->nb_outputs; i++)
1100  fg->outputs[i]->filter = (AVFilterContext *)NULL;
1101  for (i = 0; i < fg->nb_inputs; i++)
1102  fg->inputs[i]->filter = (AVFilterContext *)NULL;
1103  avfilter_graph_free(&fg->graph);
1104 }
1105 
1107 {
1108  return f->nb_inputs == 0 &&
1109  (!strcmp(f->filter->name, "buffer") ||
1110  !strcmp(f->filter->name, "abuffer"));
1111 }
1112 
1113 static int graph_is_meta(AVFilterGraph *graph)
1114 {
1115  for (unsigned i = 0; i < graph->nb_filters; i++) {
1116  const AVFilterContext *f = graph->filters[i];
1117 
1118  /* in addition to filters flagged as meta, also
1119  * disregard sinks and buffersources (but not other sources,
1120  * since they introduce data we are not aware of)
1121  */
1122  if (!((f->filter->flags & AVFILTER_FLAG_METADATA_ONLY) ||
1123  f->nb_outputs == 0 ||
1125  return 0;
1126  }
1127  return 1;
1128 }
1129 
1131 {
1132  AVBufferRef *hw_device;
1133  AVFilterInOut *inputs, *outputs, *cur;
1134  int ret, i, simple = filtergraph_is_simple(fg);
1135  const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
1136  fg->graph_desc;
1137 
1138  cleanup_filtergraph(fg);
1139  if (!(fg->graph = avfilter_graph_alloc()))
1140  return AVERROR(ENOMEM);
1141 
1142  if (simple) {
1143  OutputStream *ost = fg->outputs[0]->ost;
1144 
1145  if (filter_nbthreads) {
1146  ret = av_opt_set(fg->graph, "threads", filter_nbthreads, 0);
1147  if (ret < 0)
1148  goto fail;
1149  } else {
1150  const AVDictionaryEntry *e = NULL;
1151  e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
1152  if (e)
1153  av_opt_set(fg->graph, "threads", e->value, 0);
1154  }
1155 
1156  if (av_dict_count(ost->sws_dict)) {
1157  ret = av_dict_get_string(ost->sws_dict,
1158  &fg->graph->scale_sws_opts,
1159  '=', ':');
1160  if (ret < 0)
1161  goto fail;
1162  }
1163 
1164  if (av_dict_count(ost->swr_opts)) {
1165  char *args;
1166  ret = av_dict_get_string(ost->swr_opts, &args, '=', ':');
1167  if (ret < 0)
1168  goto fail;
1169  av_opt_set(fg->graph, "aresample_swr_opts", args, 0);
1170  av_free(args);
1171  }
1172  } else {
1174  }
1175 
1176  hw_device = hw_device_for_filter();
1177 
1178  if ((ret = graph_parse(fg->graph, graph_desc, &inputs, &outputs, hw_device)) < 0)
1179  goto fail;
1180 
1181  if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
1182  const char *num_inputs;
1183  const char *num_outputs;
1184  if (!outputs) {
1185  num_outputs = "0";
1186  } else if (outputs->next) {
1187  num_outputs = ">1";
1188  } else {
1189  num_outputs = "1";
1190  }
1191  if (!inputs) {
1192  num_inputs = "0";
1193  } else if (inputs->next) {
1194  num_inputs = ">1";
1195  } else {
1196  num_inputs = "1";
1197  }
1198  av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
1199  "to have exactly 1 input and 1 output."
1200  " However, it had %s input(s) and %s output(s)."
1201  " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
1202  graph_desc, num_inputs, num_outputs);
1203  ret = AVERROR(EINVAL);
1204  goto fail;
1205  }
1206 
1207  for (cur = inputs, i = 0; cur; cur = cur->next, i++)
1208  if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0) {
1211  goto fail;
1212  }
1214 
1215  for (cur = outputs, i = 0; cur; cur = cur->next, i++)
1216  configure_output_filter(fg, fg->outputs[i], cur);
1218 
1221  if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
1222  goto fail;
1223 
1224  fg->is_meta = graph_is_meta(fg->graph);
1225 
1226  /* limit the lists of allowed formats to the ones selected, to
1227  * make sure they stay the same if the filtergraph is reconfigured later */
1228  for (i = 0; i < fg->nb_outputs; i++) {
1229  OutputFilter *ofilter = fg->outputs[i];
1230  AVFilterContext *sink = ofilter->filter;
1231 
1232  ofilter->format = av_buffersink_get_format(sink);
1233 
1234  ofilter->width = av_buffersink_get_w(sink);
1235  ofilter->height = av_buffersink_get_h(sink);
1236 
1237  ofilter->sample_rate = av_buffersink_get_sample_rate(sink);
1239  ret = av_buffersink_get_ch_layout(sink, &ofilter->ch_layout);
1240  if (ret < 0)
1241  goto fail;
1242  }
1243 
1244  fg->reconfiguration = 1;
1245 
1246  for (i = 0; i < fg->nb_outputs; i++) {
1247  OutputStream *ost = fg->outputs[i]->ost;
1248  if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO &&
1249  !(ost->enc_ctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
1250  av_buffersink_set_frame_size(ost->filter->filter,
1251  ost->enc_ctx->frame_size);
1252  }
1253 
1254  for (i = 0; i < fg->nb_inputs; i++) {
1255  AVFrame *tmp;
1256  while (av_fifo_read(fg->inputs[i]->frame_queue, &tmp, 1) >= 0) {
1258  av_frame_free(&tmp);
1259  if (ret < 0)
1260  goto fail;
1261  }
1262  }
1263 
1264  /* send the EOFs for the finished inputs */
1265  for (i = 0; i < fg->nb_inputs; i++) {
1266  if (fg->inputs[i]->eof) {
1268  if (ret < 0)
1269  goto fail;
1270  }
1271  }
1272 
1273  /* process queued up subtitle packets */
1274  for (i = 0; i < fg->nb_inputs; i++) {
1275  InputStream *ist = fg->inputs[i]->ist;
1276  if (ist->sub2video.sub_queue && ist->sub2video.frame) {
1277  AVSubtitle tmp;
1278  while (av_fifo_read(ist->sub2video.sub_queue, &tmp, 1) >= 0) {
1279  sub2video_update(ist, INT64_MIN, &tmp);
1280  avsubtitle_free(&tmp);
1281  }
1282  }
1283  }
1284 
1285  return 0;
1286 
1287 fail:
1288  cleanup_filtergraph(fg);
1289  return ret;
1290 }
1291 
1293 {
1294  AVFrameSideData *sd;
1295  int ret;
1296 
1297  av_buffer_unref(&ifilter->hw_frames_ctx);
1298 
1299  ifilter->format = frame->format;
1300 
1301  ifilter->width = frame->width;
1302  ifilter->height = frame->height;
1303  ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
1304 
1305  ifilter->sample_rate = frame->sample_rate;
1306  ret = av_channel_layout_copy(&ifilter->ch_layout, &frame->ch_layout);
1307  if (ret < 0)
1308  return ret;
1309 
1310  av_freep(&ifilter->displaymatrix);
1312  if (sd)
1313  ifilter->displaymatrix = av_memdup(sd->data, sizeof(int32_t) * 9);
1314 
1315  if (frame->hw_frames_ctx) {
1316  ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
1317  if (!ifilter->hw_frames_ctx)
1318  return AVERROR(ENOMEM);
1319  }
1320 
1321  return 0;
1322 }
1323 
1325 {
1326  return !fg->graph_desc;
1327 }
AVSubtitle
Definition: avcodec.h:2342
formats
formats
Definition: signature.h:48
init_complex_filtergraph
int init_complex_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:485
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:890
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:925
InputStream::framerate_guessed
AVRational framerate_guessed
Definition: ffmpeg.h:360
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:686
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:355
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:341
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:101
OutputFile::start_time
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:705
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:1035
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:816
InputStream::nb_filters
int nb_filters
Definition: ffmpeg.h:414
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:408
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:342
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:700
configure_filtergraph
int configure_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:1130
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:2066
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:135
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
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:1113
InputStream::sub2video::last_pts
int64_t last_pts
Definition: ffmpeg.h:403
AVRational::num
int num
Numerator.
Definition: rational.h:59
InputFile
Definition: ffmpeg.h:447
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:89
AVFilterContext::input_pads
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:404
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:707
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:1211
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:390
configure_input_audio_filter
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:1003
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:631
ctx
AVFormatContext * ctx
Definition: movenc.c:48
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:413
nb_streams
static int nb_streams
Definition: ffprobe.c:315
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:854
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:407
AVFilterParams
Parameters describing a filter to be created in a filtergraph.
Definition: avfilter.h:1143
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:339
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:1154
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVFilterChain::nb_filters
size_t nb_filters
Definition: avfilter.h:1212
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:866
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:402
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:1235
AVFilterGraph
Definition: avfilter.h:864
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:405
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:408
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:699
FilterGraph
Definition: ffmpeg.h:319
AVFilterGraphSegment
A parsed representation of a filtergraph segment.
Definition: avfilter.h:1224
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:1032
AVFilterGraph::scale_sws_opts
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:869
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:338
AVFilterInOut::filter_ctx
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1029
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:326
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:138
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:523
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:76
graph_parse
static int graph_parse(AVFilterGraph *graph, const char *desc, AVFilterInOut **inputs, AVFilterInOut **outputs, AVBufferRef *hw_device)
Definition: ffmpeg_filter.c:442
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:1106
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:897
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:1292
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:344
configure_input_filter
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:1080
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:801
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:345
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:452
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:166
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:473
insert_filter
static int insert_filter(AVFilterContext **last_filter, int *pad_idx, const char *filter_name, const char *args)
Definition: ffmpeg_filter.c:574
AVFilterParams::opts
AVDictionary * opts
Options to be apllied to the filter.
Definition: avfilter.h:1195
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:930
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:878
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:1210
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:1236
InputStream::discard
int discard
Definition: ffmpeg.h:340
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
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:1096
InputStream::sub2video::frame
AVFrame * frame
Definition: ffmpeg.h:406
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
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
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:407
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:610
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:404
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:1324
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:1026
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:596
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
hw_device_for_filter
AVBufferRef * hw_device_for_filter(void)
Get a hardware device to be used with this filtergraph.
Definition: ffmpeg_hw.c:551
AVDictionaryEntry::value
char * value
Definition: dict.h:91
AVFilterGraph::nb_filters
unsigned nb_filters
Definition: avfilter.h:867
get_rotation
double get_rotation(int32_t *displaymatrix)
Definition: cmdutils.c:997
avstring.h
AVFILTER_AUTO_CONVERT_NONE
@ AVFILTER_AUTO_CONVERT_NONE
all automatic conversions disabled
Definition: avfilter.h:997
OutputFile::recording_time
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:704
AVFilterInOut
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1024
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:356
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:690
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:691
sub2video_prepare
static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
Definition: ffmpeg_filter.c:831
InputStream::autorotate
int autorotate
Definition: ffmpeg.h:393