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 
56  const AVCodec *codec, enum AVPixelFormat target)
57 {
58  if (codec && codec->pix_fmts) {
59  const enum AVPixelFormat *p = codec->pix_fmts;
61  //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
62  int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
63  enum AVPixelFormat best= AV_PIX_FMT_NONE;
64 
66  p = get_compliance_normal_pix_fmts(codec, p);
67  }
68  for (; *p != AV_PIX_FMT_NONE; p++) {
69  best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
70  if (*p == target)
71  break;
72  }
73  if (*p == AV_PIX_FMT_NONE) {
74  if (target != AV_PIX_FMT_NONE)
76  "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
77  av_get_pix_fmt_name(target),
78  codec->name,
79  av_get_pix_fmt_name(best));
80  return best;
81  }
82  }
83  return target;
84 }
85 
86 /* May return NULL (no pixel format found), a static string or a string
87  * backed by the bprint. Nothing has been written to the AVBPrint in case
88  * NULL is returned. The AVBPrint provided should be clean. */
89 static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
90 {
91  OutputStream *ost = ofilter->ost;
92  const AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
93  if (strict_dict)
94  // used by choose_pixel_fmt() and below
95  av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
96 
97  if (ost->keep_pix_fmt) {
100  if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
101  return NULL;
102  return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt);
103  }
104  if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
105  return av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc_ctx, ost->enc, ost->enc_ctx->pix_fmt));
106  } else if (ost->enc && ost->enc->pix_fmts) {
107  const enum AVPixelFormat *p;
108 
109  p = ost->enc->pix_fmts;
110  if (ost->enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
111  p = get_compliance_normal_pix_fmts(ost->enc, p);
112  }
113 
114  for (; *p != AV_PIX_FMT_NONE; p++) {
115  const char *name = av_get_pix_fmt_name(*p);
116  av_bprintf(bprint, "%s%c", name, p[1] == AV_PIX_FMT_NONE ? '\0' : '|');
117  }
118  if (!av_bprint_is_complete(bprint))
119  exit_program(1);
120  return bprint->str;
121  } else
122  return NULL;
123 }
124 
125 /* Define a function for appending a list of allowed formats
126  * to an AVBPrint. If nonempty, the list will have a header. */
127 #define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \
128 static void choose_ ## name (OutputFilter *ofilter, AVBPrint *bprint) \
129 { \
130  if (ofilter->var == none && !ofilter->supported_list) \
131  return; \
132  av_bprintf(bprint, #name "="); \
133  if (ofilter->var != none) { \
134  av_bprintf(bprint, printf_format, get_name(ofilter->var)); \
135  } else { \
136  const type *p; \
137  \
138  for (p = ofilter->supported_list; *p != none; p++) { \
139  av_bprintf(bprint, printf_format "|", get_name(*p)); \
140  } \
141  if (bprint->len > 0) \
142  bprint->str[--bprint->len] = '\0'; \
143  } \
144  av_bprint_chars(bprint, ':', 1); \
145 }
146 
147 //DEF_CHOOSE_FORMAT(pix_fmts, enum AVPixelFormat, format, formats, AV_PIX_FMT_NONE,
148 // GET_PIX_FMT_NAME)
149 
152 
154  "%d", )
155 
156 static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
157 {
158  if (av_channel_layout_check(&ofilter->ch_layout)) {
159  av_bprintf(bprint, "channel_layouts=");
160  av_channel_layout_describe_bprint(&ofilter->ch_layout, bprint);
161  } else if (ofilter->ch_layouts) {
162  const AVChannelLayout *p;
163 
164  av_bprintf(bprint, "channel_layouts=");
165  for (p = ofilter->ch_layouts; p->nb_channels; p++) {
167  av_bprintf(bprint, "|");
168  }
169  if (bprint->len > 0)
170  bprint->str[--bprint->len] = '\0';
171  } else
172  return;
173  av_bprint_chars(bprint, ':', 1);
174 }
175 
177 {
178  FilterGraph *fg = av_mallocz(sizeof(*fg));
179  OutputFilter *ofilter;
180  InputFilter *ifilter;
181 
182  if (!fg)
183  exit_program(1);
184  fg->index = nb_filtergraphs;
185 
186  ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
187  ofilter->ost = ost;
188  ofilter->graph = fg;
189  ofilter->format = -1;
190 
191  ost->filter = ofilter;
192 
193  ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
194  ifilter->ist = ist;
195  ifilter->graph = fg;
196  ifilter->format = -1;
197 
198  ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
199  if (!ifilter->frame_queue)
200  exit_program(1);
201 
202  GROW_ARRAY(ist->filters, ist->nb_filters);
203  ist->filters[ist->nb_filters - 1] = ifilter;
204 
206  filtergraphs[nb_filtergraphs - 1] = fg;
207 
208  return 0;
209 }
210 
211 static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
212 {
213  AVFilterContext *ctx = inout->filter_ctx;
214  AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads;
215  int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs;
216  char *res;
217 
218  if (nb_pads > 1)
219  res = av_strdup(ctx->filter->name);
220  else
221  res = av_asprintf("%s:%s", ctx->filter->name,
222  avfilter_pad_get_name(pads, inout->pad_idx));
223  if (!res)
224  exit_program(1);
225  return res;
226 }
227 
229 {
230  InputStream *ist = NULL;
232  InputFilter *ifilter;
233  int i;
234 
235  // TODO: support other filter types
237  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
238  "currently.\n");
239  exit_program(1);
240  }
241 
242  if (in->name) {
244  AVStream *st = NULL;
245  char *p;
246  int file_idx = strtol(in->name, &p, 0);
247 
248  if (file_idx < 0 || file_idx >= nb_input_files) {
249  av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
250  file_idx, fg->graph_desc);
251  exit_program(1);
252  }
253  s = input_files[file_idx]->ctx;
254 
255  for (i = 0; i < s->nb_streams; i++) {
256  enum AVMediaType stream_type = s->streams[i]->codecpar->codec_type;
257  if (stream_type != type &&
258  !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
259  type == AVMEDIA_TYPE_VIDEO /* sub2video hack */))
260  continue;
261  if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
262  st = s->streams[i];
263  break;
264  }
265  }
266  if (!st) {
267  av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
268  "matches no streams.\n", p, fg->graph_desc);
269  exit_program(1);
270  }
271  ist = input_streams[input_files[file_idx]->ist_index + st->index];
272  if (ist->user_set_discard == AVDISCARD_ALL) {
273  av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
274  "matches a disabled input stream.\n", p, fg->graph_desc);
275  exit_program(1);
276  }
277  } else {
278  /* find the first unused stream of corresponding type */
279  for (i = 0; i < nb_input_streams; i++) {
280  ist = input_streams[i];
281  if (ist->user_set_discard == AVDISCARD_ALL)
282  continue;
283  if (ist->dec_ctx->codec_type == type && ist->discard)
284  break;
285  }
286  if (i == nb_input_streams) {
287  av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
288  "unlabeled input pad %d on filter %s\n", in->pad_idx,
289  in->filter_ctx->name);
290  exit_program(1);
291  }
292  }
293  av_assert0(ist);
294 
295  ist->discard = 0;
297  ist->processing_needed = 1;
298  ist->st->discard = AVDISCARD_NONE;
299 
300  ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
301  ifilter->ist = ist;
302  ifilter->graph = fg;
303  ifilter->format = -1;
304  ifilter->type = ist->st->codecpar->codec_type;
305  ifilter->name = describe_filter_link(fg, in, 1);
306 
307  ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
308  if (!ifilter->frame_queue)
309  exit_program(1);
310 
311  GROW_ARRAY(ist->filters, ist->nb_filters);
312  ist->filters[ist->nb_filters - 1] = ifilter;
313 }
314 
316 {
317  AVFilterInOut *inputs, *outputs, *cur;
318  AVFilterGraph *graph;
319  int ret = 0;
320 
321  /* this graph is only used for determining the kinds of inputs
322  * and outputs we have, and is discarded on exit from this function */
323  graph = avfilter_graph_alloc();
324  if (!graph)
325  return AVERROR(ENOMEM);
326  graph->nb_threads = 1;
327 
329  if (ret < 0)
330  goto fail;
331 
332  for (cur = inputs; cur; cur = cur->next)
333  init_input_filter(fg, cur);
334 
335  for (cur = outputs; cur;) {
336  OutputFilter *const ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
337 
338  ofilter->graph = fg;
339  ofilter->out_tmp = cur;
341  cur->pad_idx);
342  ofilter->name = describe_filter_link(fg, cur, 0);
343  cur = cur->next;
344  ofilter->out_tmp->next = NULL;
345  }
346 
347 fail:
349  avfilter_graph_free(&graph);
350  return ret;
351 }
352 
353 static int insert_trim(int64_t start_time, int64_t duration,
354  AVFilterContext **last_filter, int *pad_idx,
355  const char *filter_name)
356 {
357  AVFilterGraph *graph = (*last_filter)->graph;
359  const AVFilter *trim;
360  enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
361  const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
362  int ret = 0;
363 
364  if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
365  return 0;
366 
367  trim = avfilter_get_by_name(name);
368  if (!trim) {
369  av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
370  "recording time.\n", name);
372  }
373 
374  ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
375  if (!ctx)
376  return AVERROR(ENOMEM);
377 
378  if (duration != INT64_MAX) {
379  ret = av_opt_set_int(ctx, "durationi", duration,
381  }
382  if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
383  ret = av_opt_set_int(ctx, "starti", start_time,
385  }
386  if (ret < 0) {
387  av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
388  return ret;
389  }
390 
392  if (ret < 0)
393  return ret;
394 
395  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
396  if (ret < 0)
397  return ret;
398 
399  *last_filter = ctx;
400  *pad_idx = 0;
401  return 0;
402 }
403 
404 static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
405  const char *filter_name, const char *args)
406 {
407  AVFilterGraph *graph = (*last_filter)->graph;
409  int ret;
410 
412  avfilter_get_by_name(filter_name),
413  filter_name, args, NULL, graph);
414  if (ret < 0)
415  return ret;
416 
417  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
418  if (ret < 0)
419  return ret;
420 
421  *last_filter = ctx;
422  *pad_idx = 0;
423  return 0;
424 }
425 
427 {
428  OutputStream *ost = ofilter->ost;
429  OutputFile *of = output_files[ost->file_index];
430  AVFilterContext *last_filter = out->filter_ctx;
431  AVBPrint bprint;
432  int pad_idx = out->pad_idx;
433  int ret;
434  const char *pix_fmts;
435  char name[255];
436 
437  snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
439  avfilter_get_by_name("buffersink"),
440  name, NULL, NULL, fg->graph);
441 
442  if (ret < 0)
443  return ret;
444 
445  if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) {
446  char args[255];
448  const AVDictionaryEntry *e = NULL;
449 
450  snprintf(args, sizeof(args), "%d:%d",
451  ofilter->width, ofilter->height);
452 
453  while ((e = av_dict_get(ost->sws_dict, "", e,
455  av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
456  }
457 
458  snprintf(name, sizeof(name), "scaler_out_%d_%d",
459  ost->file_index, ost->index);
461  name, args, NULL, fg->graph)) < 0)
462  return ret;
463  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
464  return ret;
465 
466  last_filter = filter;
467  pad_idx = 0;
468  }
469 
471  if ((pix_fmts = choose_pix_fmts(ofilter, &bprint))) {
473 
475  avfilter_get_by_name("format"),
476  "format", pix_fmts, NULL, fg->graph);
477  av_bprint_finalize(&bprint, NULL);
478  if (ret < 0)
479  return ret;
480  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
481  return ret;
482 
483  last_filter = filter;
484  pad_idx = 0;
485  }
486 
487  if (ost->frame_rate.num && 0) {
488  AVFilterContext *fps;
489  char args[255];
490 
491  snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
492  ost->frame_rate.den);
493  snprintf(name, sizeof(name), "fps_out_%d_%d",
494  ost->file_index, ost->index);
496  name, args, NULL, fg->graph);
497  if (ret < 0)
498  return ret;
499 
500  ret = avfilter_link(last_filter, pad_idx, fps, 0);
501  if (ret < 0)
502  return ret;
503  last_filter = fps;
504  pad_idx = 0;
505  }
506 
507  snprintf(name, sizeof(name), "trim_out_%d_%d",
508  ost->file_index, ost->index);
510  &last_filter, &pad_idx, name);
511  if (ret < 0)
512  return ret;
513 
514 
515  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
516  return ret;
517 
518  return 0;
519 }
520 
522 {
523  OutputStream *ost = ofilter->ost;
524  OutputFile *of = output_files[ost->file_index];
525  AVCodecContext *codec = ost->enc_ctx;
526  AVFilterContext *last_filter = out->filter_ctx;
527  int pad_idx = out->pad_idx;
528  AVBPrint args;
529  char name[255];
530  int ret;
531 
532  snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
534  avfilter_get_by_name("abuffersink"),
535  name, NULL, NULL, fg->graph);
536  if (ret < 0)
537  return ret;
538  if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
539  return ret;
540 
541 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
542  AVFilterContext *filt_ctx; \
543  \
544  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
545  "similarly to -af " filter_name "=%s.\n", arg); \
546  \
547  ret = avfilter_graph_create_filter(&filt_ctx, \
548  avfilter_get_by_name(filter_name), \
549  filter_name, arg, NULL, fg->graph); \
550  if (ret < 0) \
551  goto fail; \
552  \
553  ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
554  if (ret < 0) \
555  goto fail; \
556  \
557  last_filter = filt_ctx; \
558  pad_idx = 0; \
559 } while (0)
561  if (ost->audio_channels_mapped) {
562  AVChannelLayout mapped_layout = { 0 };
563  int i;
564  av_channel_layout_default(&mapped_layout, ost->audio_channels_mapped);
565  av_channel_layout_describe_bprint(&mapped_layout, &args);
566  for (i = 0; i < ost->audio_channels_mapped; i++)
567  if (ost->audio_channels_map[i] != -1)
568  av_bprintf(&args, "|c%d=c%d", i, ost->audio_channels_map[i]);
569 
570  AUTO_INSERT_FILTER("-map_channel", "pan", args.str);
571  av_bprint_clear(&args);
572  }
573 
576 
577  choose_sample_fmts(ofilter, &args);
578  choose_sample_rates(ofilter, &args);
579  choose_channel_layouts(ofilter, &args);
580  if (!av_bprint_is_complete(&args)) {
581  ret = AVERROR(ENOMEM);
582  goto fail;
583  }
584  if (args.len) {
586 
587  snprintf(name, sizeof(name), "format_out_%d_%d",
588  ost->file_index, ost->index);
590  avfilter_get_by_name("aformat"),
591  name, args.str, NULL, fg->graph);
592  if (ret < 0)
593  goto fail;
594 
595  ret = avfilter_link(last_filter, pad_idx, format, 0);
596  if (ret < 0)
597  goto fail;
598 
599  last_filter = format;
600  pad_idx = 0;
601  }
602 
603  if (ost->apad && of->shortest) {
604  int i;
605 
606  for (i=0; i<of->ctx->nb_streams; i++)
608  break;
609 
610  if (i<of->ctx->nb_streams) {
611  AUTO_INSERT_FILTER("-apad", "apad", ost->apad);
612  }
613  }
614 
615  snprintf(name, sizeof(name), "trim for output stream %d:%d",
616  ost->file_index, ost->index);
618  &last_filter, &pad_idx, name);
619  if (ret < 0)
620  goto fail;
621 
622  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
623  goto fail;
624 fail:
625  av_bprint_finalize(&args, NULL);
626 
627  return ret;
628 }
629 
632 {
633  if (!ofilter->ost) {
634  av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
635  exit_program(1);
636  }
637 
638  switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
639  case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
640  case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
641  default: av_assert0(0); return 0;
642  }
643 }
644 
646 {
647  int i;
648  for (i = 0; i < nb_filtergraphs; i++) {
649  int n;
650  for (n = 0; n < filtergraphs[i]->nb_outputs; n++) {
652  if (!output->ost) {
653  av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", output->name);
654  exit_program(1);
655  }
656  }
657  }
658 }
659 
660 static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
661 {
663  int i, w, h;
664 
665  /* Compute the size of the canvas for the subtitles stream.
666  If the subtitles codecpar has set a size, use it. Otherwise use the
667  maximum dimensions of the video streams in the same file. */
668  w = ifilter->width;
669  h = ifilter->height;
670  if (!(w && h)) {
671  for (i = 0; i < avf->nb_streams; i++) {
673  w = FFMAX(w, avf->streams[i]->codecpar->width);
674  h = FFMAX(h, avf->streams[i]->codecpar->height);
675  }
676  }
677  if (!(w && h)) {
678  w = FFMAX(w, 720);
679  h = FFMAX(h, 576);
680  }
681  av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
682  }
683  ist->sub2video.w = ifilter->width = w;
684  ist->sub2video.h = ifilter->height = h;
685 
686  ifilter->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w;
687  ifilter->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h;
688 
689  /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
690  palettes for all rectangles are identical or compatible */
691  ifilter->format = AV_PIX_FMT_RGB32;
692 
693  ist->sub2video.frame = av_frame_alloc();
694  if (!ist->sub2video.frame)
695  return AVERROR(ENOMEM);
696  ist->sub2video.last_pts = INT64_MIN;
697  ist->sub2video.end_pts = INT64_MIN;
698 
699  /* sub2video structure has been (re-)initialized.
700  Mark it as such so that the system will be
701  initialized with the first received heartbeat. */
702  ist->sub2video.initialize = 1;
703 
704  return 0;
705 }
706 
708  AVFilterInOut *in)
709 {
710  AVFilterContext *last_filter;
711  const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
712  const AVPixFmtDescriptor *desc;
713  InputStream *ist = ifilter->ist;
715  AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
716  ist->st->time_base;
717  AVRational fr = ist->framerate;
718  AVRational sar;
719  AVBPrint args;
720  char name[255];
721  int ret, pad_idx = 0;
722  int64_t tsoffset = 0;
724 
725  if (!par)
726  return AVERROR(ENOMEM);
727  memset(par, 0, sizeof(*par));
728  par->format = AV_PIX_FMT_NONE;
729 
730  if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
731  av_log(NULL, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
732  ret = AVERROR(EINVAL);
733  goto fail;
734  }
735 
736  if (!fr.num)
737  fr = av_guess_frame_rate(input_files[ist->file_index]->ctx, ist->st, NULL);
738 
740  ret = sub2video_prepare(ist, ifilter);
741  if (ret < 0)
742  goto fail;
743  }
744 
745  sar = ifilter->sample_aspect_ratio;
746  if(!sar.den)
747  sar = (AVRational){0,1};
749  av_bprintf(&args,
750  "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
751  "pixel_aspect=%d/%d",
752  ifilter->width, ifilter->height, ifilter->format,
753  tb.num, tb.den, sar.num, sar.den);
754  if (fr.num && fr.den)
755  av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
756  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
757  ist->file_index, ist->st->index);
758 
759 
760  if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
761  args.str, NULL, fg->graph)) < 0)
762  goto fail;
763  par->hw_frames_ctx = ifilter->hw_frames_ctx;
764  ret = av_buffersrc_parameters_set(ifilter->filter, par);
765  if (ret < 0)
766  goto fail;
767  av_freep(&par);
768  last_filter = ifilter->filter;
769 
770  desc = av_pix_fmt_desc_get(ifilter->format);
771  av_assert0(desc);
772 
773  // TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
774  if (ist->autorotate && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
775  int32_t *displaymatrix = ifilter->displaymatrix;
776  double theta;
777 
778  if (!displaymatrix)
780  theta = get_rotation(displaymatrix);
781 
782  if (fabs(theta - 90) < 1.0) {
783  ret = insert_filter(&last_filter, &pad_idx, "transpose",
784  displaymatrix[3] > 0 ? "cclock_flip" : "clock");
785  } else if (fabs(theta - 180) < 1.0) {
786  if (displaymatrix[0] < 0) {
787  ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
788  if (ret < 0)
789  return ret;
790  }
791  if (displaymatrix[4] < 0) {
792  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
793  }
794  } else if (fabs(theta - 270) < 1.0) {
795  ret = insert_filter(&last_filter, &pad_idx, "transpose",
796  displaymatrix[3] < 0 ? "clock_flip" : "cclock");
797  } else if (fabs(theta) > 1.0) {
798  char rotate_buf[64];
799  snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
800  ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf);
801  } else if (fabs(theta) < 1.0) {
802  if (displaymatrix && displaymatrix[4] < 0) {
803  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
804  }
805  }
806  if (ret < 0)
807  return ret;
808  }
809 
810  snprintf(name, sizeof(name), "trim_in_%d_%d",
811  ist->file_index, ist->st->index);
812  if (copy_ts) {
813  tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
814  if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
815  tsoffset += f->ctx->start_time;
816  }
817  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
818  AV_NOPTS_VALUE : tsoffset, f->recording_time,
819  &last_filter, &pad_idx, name);
820  if (ret < 0)
821  return ret;
822 
823  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
824  return ret;
825  return 0;
826 fail:
827  av_freep(&par);
828 
829  return ret;
830 }
831 
833  AVFilterInOut *in)
834 {
835  AVFilterContext *last_filter;
836  const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
837  InputStream *ist = ifilter->ist;
839  AVBPrint args;
840  char name[255];
841  int ret, pad_idx = 0;
842  int64_t tsoffset = 0;
843 
844  if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
845  av_log(NULL, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
846  return AVERROR(EINVAL);
847  }
848 
850  av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
851  1, ifilter->sample_rate,
852  ifilter->sample_rate,
853  av_get_sample_fmt_name(ifilter->format));
854  if (av_channel_layout_check(&ifilter->ch_layout) &&
856  av_bprintf(&args, ":channel_layout=");
858  } else
859  av_bprintf(&args, ":channels=%d", ifilter->ch_layout.nb_channels);
860  snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index,
861  ist->file_index, ist->st->index);
862 
863  if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
864  name, args.str, NULL,
865  fg->graph)) < 0)
866  return ret;
867  last_filter = ifilter->filter;
868 
869 #define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
870  AVFilterContext *filt_ctx; \
871  \
872  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
873  "similarly to -af " filter_name "=%s.\n", arg); \
874  \
875  snprintf(name, sizeof(name), "graph_%d_%s_in_%d_%d", \
876  fg->index, filter_name, ist->file_index, ist->st->index); \
877  ret = avfilter_graph_create_filter(&filt_ctx, \
878  avfilter_get_by_name(filter_name), \
879  name, arg, NULL, fg->graph); \
880  if (ret < 0) \
881  return ret; \
882  \
883  ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
884  if (ret < 0) \
885  return ret; \
886  \
887  last_filter = filt_ctx; \
888 } while (0)
889 
890  if (audio_sync_method > 0) {
891  char args[256] = {0};
892 
893  av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method);
894  if (audio_drift_threshold != 0.1)
895  av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", audio_drift_threshold);
896  if (!fg->reconfiguration)
897  av_strlcatf(args, sizeof(args), ":first_pts=0");
898  AUTO_INSERT_FILTER_INPUT("-async", "aresample", args);
899  }
900 
901 // if (ost->audio_channels_mapped) {
902 // int i;
903 // AVBPrint pan_buf;
904 // av_bprint_init(&pan_buf, 256, 8192);
905 // av_bprintf(&pan_buf, "0x%"PRIx64,
906 // av_get_default_channel_layout(ost->audio_channels_mapped));
907 // for (i = 0; i < ost->audio_channels_mapped; i++)
908 // if (ost->audio_channels_map[i] != -1)
909 // av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
910 // AUTO_INSERT_FILTER_INPUT("-map_channel", "pan", pan_buf.str);
911 // av_bprint_finalize(&pan_buf, NULL);
912 // }
913 
914  if (audio_volume != 256) {
915  char args[256];
916 
917  av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
918  "audio filter instead.\n");
919 
920  snprintf(args, sizeof(args), "%f", audio_volume / 256.);
921  AUTO_INSERT_FILTER_INPUT("-vol", "volume", args);
922  }
923 
924  snprintf(name, sizeof(name), "trim for input stream %d:%d",
925  ist->file_index, ist->st->index);
926  if (copy_ts) {
927  tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
928  if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
929  tsoffset += f->ctx->start_time;
930  }
931  ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
932  AV_NOPTS_VALUE : tsoffset, f->recording_time,
933  &last_filter, &pad_idx, name);
934  if (ret < 0)
935  return ret;
936 
937  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
938  return ret;
939 
940  return 0;
941 }
942 
944  AVFilterInOut *in)
945 {
946  if (!ifilter->ist->dec) {
948  "No decoder for stream #%d:%d, filtering impossible\n",
949  ifilter->ist->file_index, ifilter->ist->st->index);
951  }
952  switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
953  case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
954  case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
955  default: av_assert0(0); return 0;
956  }
957 }
958 
960 {
961  int i;
962  for (i = 0; i < fg->nb_outputs; i++)
963  fg->outputs[i]->filter = (AVFilterContext *)NULL;
964  for (i = 0; i < fg->nb_inputs; i++)
965  fg->inputs[i]->filter = (AVFilterContext *)NULL;
967 }
968 
970 {
971  return f->nb_inputs == 0 &&
972  (!strcmp(f->filter->name, "buffer") ||
973  !strcmp(f->filter->name, "abuffer"));
974 }
975 
976 static int graph_is_meta(AVFilterGraph *graph)
977 {
978  for (unsigned i = 0; i < graph->nb_filters; i++) {
979  const AVFilterContext *f = graph->filters[i];
980 
981  /* in addition to filters flagged as meta, also
982  * disregard sinks and buffersources (but not other sources,
983  * since they introduce data we are not aware of)
984  */
985  if (!((f->filter->flags & AVFILTER_FLAG_METADATA_ONLY) ||
986  f->nb_outputs == 0 ||
988  return 0;
989  }
990  return 1;
991 }
992 
994 {
995  AVFilterInOut *inputs, *outputs, *cur;
996  int ret, i, simple = filtergraph_is_simple(fg);
997  const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
998  fg->graph_desc;
999 
1000  cleanup_filtergraph(fg);
1001  if (!(fg->graph = avfilter_graph_alloc()))
1002  return AVERROR(ENOMEM);
1003 
1004  if (simple) {
1005  OutputStream *ost = fg->outputs[0]->ost;
1006  char args[512];
1007  const AVDictionaryEntry *e = NULL;
1008 
1009  if (filter_nbthreads) {
1010  ret = av_opt_set(fg->graph, "threads", filter_nbthreads, 0);
1011  if (ret < 0)
1012  goto fail;
1013  } else {
1014  e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
1015  if (e)
1016  av_opt_set(fg->graph, "threads", e->value, 0);
1017  }
1018 
1019  args[0] = 0;
1020  e = NULL;
1021  while ((e = av_dict_get(ost->sws_dict, "", e,
1023  av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
1024  }
1025  if (strlen(args)) {
1026  args[strlen(args)-1] = 0;
1027  fg->graph->scale_sws_opts = av_strdup(args);
1028  }
1029 
1030  args[0] = 0;
1031  e = NULL;
1032  while ((e = av_dict_get(ost->swr_opts, "", e,
1034  av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
1035  }
1036  if (strlen(args))
1037  args[strlen(args)-1] = 0;
1038  av_opt_set(fg->graph, "aresample_swr_opts", args, 0);
1039  } else {
1041  }
1042 
1043  if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
1044  goto fail;
1045 
1047  if (ret < 0)
1048  goto fail;
1049 
1050  if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
1051  const char *num_inputs;
1052  const char *num_outputs;
1053  if (!outputs) {
1054  num_outputs = "0";
1055  } else if (outputs->next) {
1056  num_outputs = ">1";
1057  } else {
1058  num_outputs = "1";
1059  }
1060  if (!inputs) {
1061  num_inputs = "0";
1062  } else if (inputs->next) {
1063  num_inputs = ">1";
1064  } else {
1065  num_inputs = "1";
1066  }
1067  av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
1068  "to have exactly 1 input and 1 output."
1069  " However, it had %s input(s) and %s output(s)."
1070  " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
1071  graph_desc, num_inputs, num_outputs);
1072  ret = AVERROR(EINVAL);
1073  goto fail;
1074  }
1075 
1076  for (cur = inputs, i = 0; cur; cur = cur->next, i++)
1077  if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0) {
1080  goto fail;
1081  }
1083 
1084  for (cur = outputs, i = 0; cur; cur = cur->next, i++)
1085  configure_output_filter(fg, fg->outputs[i], cur);
1087 
1090  if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
1091  goto fail;
1092 
1093  fg->is_meta = graph_is_meta(fg->graph);
1094 
1095  /* limit the lists of allowed formats to the ones selected, to
1096  * make sure they stay the same if the filtergraph is reconfigured later */
1097  for (i = 0; i < fg->nb_outputs; i++) {
1098  OutputFilter *ofilter = fg->outputs[i];
1099  AVFilterContext *sink = ofilter->filter;
1100 
1101  ofilter->format = av_buffersink_get_format(sink);
1102 
1103  ofilter->width = av_buffersink_get_w(sink);
1104  ofilter->height = av_buffersink_get_h(sink);
1105 
1106  ofilter->sample_rate = av_buffersink_get_sample_rate(sink);
1108  ret = av_buffersink_get_ch_layout(sink, &ofilter->ch_layout);
1109  if (ret < 0)
1110  goto fail;
1111  }
1112 
1113  fg->reconfiguration = 1;
1114 
1115  for (i = 0; i < fg->nb_outputs; i++) {
1116  OutputStream *ost = fg->outputs[i]->ost;
1117  if (!ost->enc) {
1118  /* identical to the same check in ffmpeg.c, needed because
1119  complex filter graphs are initialized earlier */
1120  av_log(NULL, AV_LOG_ERROR, "Encoder (codec %s) not found for output stream #%d:%d\n",
1121  avcodec_get_name(ost->st->codecpar->codec_id), ost->file_index, ost->index);
1122  ret = AVERROR(EINVAL);
1123  goto fail;
1124  }
1125  if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
1126  !(ost->enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
1127  av_buffersink_set_frame_size(ost->filter->filter,
1128  ost->enc_ctx->frame_size);
1129  }
1130 
1131  for (i = 0; i < fg->nb_inputs; i++) {
1132  AVFrame *tmp;
1133  while (av_fifo_read(fg->inputs[i]->frame_queue, &tmp, 1) >= 0) {
1135  av_frame_free(&tmp);
1136  if (ret < 0)
1137  goto fail;
1138  }
1139  }
1140 
1141  /* send the EOFs for the finished inputs */
1142  for (i = 0; i < fg->nb_inputs; i++) {
1143  if (fg->inputs[i]->eof) {
1145  if (ret < 0)
1146  goto fail;
1147  }
1148  }
1149 
1150  /* process queued up subtitle packets */
1151  for (i = 0; i < fg->nb_inputs; i++) {
1152  InputStream *ist = fg->inputs[i]->ist;
1153  if (ist->sub2video.sub_queue && ist->sub2video.frame) {
1154  AVSubtitle tmp;
1155  while (av_fifo_read(ist->sub2video.sub_queue, &tmp, 1) >= 0) {
1156  sub2video_update(ist, INT64_MIN, &tmp);
1157  avsubtitle_free(&tmp);
1158  }
1159  }
1160  }
1161 
1162  return 0;
1163 
1164 fail:
1165  cleanup_filtergraph(fg);
1166  return ret;
1167 }
1168 
1170 {
1171  AVFrameSideData *sd;
1172  int ret;
1173 
1174  av_buffer_unref(&ifilter->hw_frames_ctx);
1175 
1176  ifilter->format = frame->format;
1177 
1178  ifilter->width = frame->width;
1179  ifilter->height = frame->height;
1180  ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
1181 
1182  ifilter->sample_rate = frame->sample_rate;
1183  ret = av_channel_layout_copy(&ifilter->ch_layout, &frame->ch_layout);
1184  if (ret < 0)
1185  return ret;
1186 
1187  av_freep(&ifilter->displaymatrix);
1189  if (sd)
1190  ifilter->displaymatrix = av_memdup(sd->data, sizeof(int32_t) * 9);
1191 
1192  if (frame->hw_frames_ctx) {
1193  ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
1194  if (!ifilter->hw_frames_ctx)
1195  return AVERROR(ENOMEM);
1196  }
1197 
1198  return 0;
1199 }
1200 
1202 {
1203  return !fg->graph_desc;
1204 }
AVSubtitle
Definition: avcodec.h:2305
formats
formats
Definition: signature.h:48
init_complex_filtergraph
int init_complex_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:315
InputFilter::sample_aspect_ratio
AVRational sample_aspect_ratio
Definition: ffmpeg.h:255
AVCodec
AVCodec.
Definition: codec.h:196
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:241
audio_sync_method
int audio_sync_method
Definition: ffmpeg_opt.c:160
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:269
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:150
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:57
AVFilterGraph::nb_threads
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:897
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:953
InputFilter::width
int width
Definition: ffmpeg.h:254
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
InputFilter::displaymatrix
int32_t * displaymatrix
Definition: ffmpeg.h:261
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:684
FilterGraph::graph_desc
const char * graph_desc
Definition: ffmpeg.h:292
ALLOC_ARRAY_ELEM
#define ALLOC_ARRAY_ELEM(array, nb_elems)
Definition: cmdutils.h:434
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:2662
FilterGraph::inputs
InputFilter ** inputs
Definition: ffmpeg.h:300
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:1010
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg.h:316
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:310
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
AVCodec::pix_fmts
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:218
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:111
OutputFile::start_time
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:595
InputFilter::ch_layout
AVChannelLayout ch_layout
Definition: ffmpeg.h:258
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
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:1042
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1281
init_simple_filtergraph
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
Definition: ffmpeg_filter.c:176
w
uint8_t w
Definition: llviddspenc.c:38
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:58
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:159
FilterGraph::index
int index
Definition: ffmpeg.h:291
check_filter_outputs
void check_filter_outputs(void)
Definition: ffmpeg_filter.c:645
InputStream::nb_filters
int nb_filters
Definition: ffmpeg.h:372
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:68
ffmpeg.h
FilterGraph::nb_inputs
int nb_inputs
Definition: ffmpeg.h:301
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
av_fifo_read
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition: fifo.c:240
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:295
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilterContext::output_pads
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:419
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:311
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:300
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:45
sample_rate
sample_rate
Definition: ffmpeg_filter.c:153
FF_COMPLIANCE_UNOFFICIAL
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: avcodec.h:1304
avfilter_graph_free
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:119
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:637
InputFilter::ist
struct InputStream * ist
Definition: ffmpeg.h:244
configure_filtergraph
int configure_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:993
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:312
exit_program
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:93
InputStream
Definition: ffmpeg.h:306
filter_nbthreads
char * filter_nbthreads
Definition: ffmpeg_opt.c:177
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:204
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
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2056
InputStream::sub2video
struct InputStream::sub2video sub2video
fail
#define fail()
Definition: checkasm.h:131
InputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:247
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
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:48
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
OutputFilter::sample_rate
int sample_rate
Definition: ffmpeg.h:280
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
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:976
InputStream::sub2video::last_pts
int64_t last_pts
Definition: ffmpeg.h:361
AVRational::num
int num
Numerator.
Definition: rational.h:59
InputFile
Definition: ffmpeg.h:404
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:418
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:730
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:99
AVFilterContext::input_pads
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:415
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:886
OutputFile::shortest
int shortest
Definition: ffmpeg.h:598
avfilter_inout_free
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:212
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVFILTER_AUTO_CONVERT_NONE
@ AVFILTER_AUTO_CONVERT_NONE
all automatic conversions disabled
Definition: avfilter.h:1004
duration
int64_t duration
Definition: movenc.c:64
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:40
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:277
input_streams
InputStream ** input_streams
Definition: ffmpeg.c:147
s
#define s(width, name)
Definition: cbs_vp9.c:256
FilterGraph::outputs
OutputFilter ** outputs
Definition: ffmpeg.h:302
InputStream::framerate
AVRational framerate
Definition: ffmpeg.h:347
configure_input_audio_filter
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:832
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
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:106
AVDictionaryEntry::key
char * key
Definition: dict.h:80
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:127
InputFilter
Definition: ffmpeg.h:242
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:268
OutputStream::avfilter
char * avfilter
Definition: ffmpeg.h:524
ctx
AVFormatContext * ctx
Definition: movenc.c:48
audio_drift_threshold
float audio_drift_threshold
Definition: ffmpeg_opt.c:155
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:371
InputFilter::graph
struct FilterGraph * graph
Definition: ffmpeg.h:245
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
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
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:54
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
avfilter_get_by_name
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: allfilters.c:595
OutputFilter::height
int height
Definition: ffmpeg.h:277
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
OutputFilter::name
uint8_t * name
Definition: ffmpeg.h:270
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:1166
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:978
NULL
#define NULL
Definition: coverity.c:32
InputStream::sub2video::w
int w
Definition: ffmpeg.h:365
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:308
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
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
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:873
AVFilterContext::name
char * name
name of this filter instance
Definition: avfilter.h:413
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:960
InputFilter::eof
int eof
Definition: ffmpeg.h:263
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:134
AVFilterGraph
Definition: avfilter.h:871
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
nb_input_streams
int nb_input_streams
Definition: ffmpeg.c:148
avfilter_graph_parse2
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
Definition: graphparser.c:418
InputStream::sub2video::sub_queue
AVFifo * sub_queue
queue of AVSubtitle* before filter init
Definition: ffmpeg.h:363
FilterGraph::nb_outputs
int nb_outputs
Definition: ffmpeg.h:303
InputStream::sub2video::initialize
unsigned int initialize
marks if sub2video_update should force an initialization
Definition: ffmpeg.h:366
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:149
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:185
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:630
FilterGraph
Definition: ffmpeg.h:290
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1269
InputFilter::filter
AVFilterContext * filter
Definition: ffmpeg.h:243
AVFilterInOut::pad_idx
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:1039
AVFilterGraph::scale_sws_opts
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:876
f
f
Definition: af_crystalizer.c:122
AVMediaType
AVMediaType
Definition: avutil.h:199
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:290
av_buffersrc_parameters_alloc
AVBufferSrcParameters * av_buffersrc_parameters_alloc(void)
Allocate a new AVBufferSrcParameters instance.
Definition: buffersrc.c:86
InputStream::file_index
int file_index
Definition: ffmpeg.h:307
AVFilterInOut::filter_ctx
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1036
output_files
OutputFile ** output_files
Definition: ffmpeg.c:154
avfilter_link
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:140
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:294
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:353
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:167
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
av_guess_frame_rate
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
Definition: avformat.c:612
AVFrameSideData::data
uint8_t * data
Definition: frame.h:233
sub2video_update
void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
Definition: ffmpeg.c:240
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:267
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:379
filter_is_buffersrc
static int filter_is_buffersrc(const AVFilterContext *f)
Definition: ffmpeg_filter.c:969
OutputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:274
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
sample_rates
sample_rates
Definition: ffmpeg_filter.c:153
avfilter_init_str
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:919
buffersink.h
choose_pixel_fmt
static enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *enc_ctx, const AVCodec *codec, enum AVPixelFormat target)
Definition: ffmpeg_filter.c:55
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:447
ifilter_parameters_from_frame
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
Definition: ffmpeg_filter.c:1169
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:97
DECODING_FOR_FILTER
#define DECODING_FOR_FILTER
Definition: ffmpeg.h:313
configure_input_filter
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:943
choose_channel_layouts
static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
Definition: ffmpeg_filter.c:156
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:630
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:904
AVCodecParameters::height
int height
Definition: codec_par.h:128
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
display.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
InputStream::processing_needed
int processing_needed
Definition: ffmpeg.h:314
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:405
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:264
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:203
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
init_input_filter
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
Definition: ffmpeg_filter.c:228
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:157
AVCodecContext::height
int height
Definition: avcodec.h:562
av_buffersink_get_h
int av_buffersink_get_h(const AVFilterContext *ctx)
AVFilter
Filter definition.
Definition: avfilter.h:171
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:948
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:246
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1300
OutputFilter::ch_layout
AVChannelLayout ch_layout
Definition: ffmpeg.h:281
insert_filter
static int insert_filter(AVFilterContext **last_filter, int *pad_idx, const char *filter_name, const char *args)
Definition: ffmpeg_filter.c:404
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:140
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
InputFile::ist_index
int ist_index
Definition: ffmpeg.h:408
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:257
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:958
OutputFilter::format
int format
Definition: ffmpeg.h:279
configure_input_video_filter
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:707
AVCodecContext
main external API structure.
Definition: avcodec.h:389
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:956
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:227
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:2953
DEF_CHOOSE_FORMAT
#define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name)
Definition: ffmpeg_filter.c:127
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:252
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:211
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
avfilter.h
FilterGraph::is_meta
int is_meta
Definition: ffmpeg.h:298
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:143
InputFilter::height
int height
Definition: ffmpeg.h:254
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:431
AVERROR_FILTER_NOT_FOUND
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
Definition: error.h:60
InputStream::discard
int discard
Definition: ffmpeg.h:309
AVFilterContext
An instance of a filter.
Definition: avfilter.h:408
OutputFilter
Definition: ffmpeg.h:266
cleanup_filtergraph
static void cleanup_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:959
InputStream::sub2video::frame
AVFrame * frame
Definition: ffmpeg.h:364
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:397
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:280
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:168
audio_volume
int audio_volume
Definition: ffmpeg_opt.c:159
OutputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:591
OutputFilter::out_tmp
AVFilterInOut * out_tmp
Definition: ffmpeg.h:273
auto_conversion_filters
int auto_conversion_filters
Definition: ffmpeg_opt.c:180
InputStream::sub2video::h
int h
Definition: ffmpeg.h:365
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:231
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:500
InputFilter::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Definition: ffmpeg.h:260
AVDictionaryEntry
Definition: dict.h:79
InputStream::sub2video::end_pts
int64_t end_pts
Definition: ffmpeg.h:362
choose_pix_fmts
static const char * choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
Definition: ffmpeg_filter.c:89
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:61
FilterGraph::reconfiguration
int reconfiguration
Definition: ffmpeg.h:295
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
filtergraph_is_simple
int filtergraph_is_simple(FilterGraph *fg)
Definition: ffmpeg_filter.c:1201
InputFilter::frame_queue
AVFifo * frame_queue
Definition: ffmpeg.h:249
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:158
AVFilterInOut::name
char * name
unique name for this input/output in the list
Definition: avfilter.h:1033
d
d
Definition: ffmpeg_filter.c:153
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:562
int32_t
int32_t
Definition: audioconvert.c:56
imgutils.h
OutputStream
Definition: muxing.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:426
h
h
Definition: vp9dsp_template.c:2038
AVDictionaryEntry::value
char * value
Definition: dict.h:81
AVFilterGraph::nb_filters
unsigned nb_filters
Definition: avfilter.h:874
get_rotation
double get_rotation(int32_t *displaymatrix)
Definition: cmdutils.c:1003
avstring.h
OutputFile::recording_time
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:594
AVFilterInOut
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1031
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:317
snprintf
#define snprintf
Definition: snprintf.h:34
buffersrc.h
AUTO_INSERT_FILTER_INPUT
#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg)
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
configure_output_audio_filter
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
Definition: ffmpeg_filter.c:521
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:2582
filter_complex_nbthreads
int filter_complex_nbthreads
Definition: ffmpeg_opt.c:178
OutputFile
Definition: ffmpeg.h:586
sub2video_prepare
static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
Definition: ffmpeg_filter.c:660
InputStream::autorotate
int autorotate
Definition: ffmpeg.h:351