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 #include "graph/graphprint.h"
25 
26 #include "libavfilter/avfilter.h"
27 #include "libavfilter/buffersink.h"
28 #include "libavfilter/buffersrc.h"
29 
30 #include "libavutil/attributes.h"
31 #include "libavutil/avassert.h"
32 #include "libavutil/avstring.h"
33 #include "libavutil/bprint.h"
35 #include "libavutil/downmix_info.h"
36 #include "libavutil/mem.h"
37 #include "libavutil/opt.h"
38 #include "libavutil/pixdesc.h"
39 #include "libavutil/pixfmt.h"
40 #include "libavutil/samplefmt.h"
41 #include "libavutil/time.h"
42 #include "libavutil/timestamp.h"
43 
44 typedef struct FilterGraphPriv {
46 
47  // name used for logging
48  char log_name[32];
49 
50  int is_simple;
51  // true when the filtergraph contains only meta filters
52  // that do not modify the frame data
53  int is_meta;
55 
56  unsigned nb_outputs_done;
57 
59 
60  // frame for temporarily holding output from the filtergraph
62  // frame for sending output to the encoder
64 
66  unsigned sch_idx;
68 
70 {
71  return (FilterGraphPriv*)fg;
72 }
73 
74 static const FilterGraphPriv *cfgp_from_cfg(const FilterGraph *fg)
75 {
76  return (const FilterGraphPriv*)fg;
77 }
78 
79 // data that is local to the filter thread and not visible outside of it
80 typedef struct FilterGraphThread {
82 
84 
85  // Temporary buffer for output frames, since on filtergraph reset
86  // we cannot send them to encoders immediately.
87  // The output index is stored in frame opaque.
89 
90  // index of the next input to request from the scheduler
91  unsigned next_in;
92  // set to 1 after at least one frame passed through this output
93  int got_frame;
94 
95  // EOF status of each input/output, as received by the thread
96  uint8_t *eof_in;
97  uint8_t *eof_out;
99 
100 typedef struct InputFilterPriv {
102 
104 
105  // used to hold submitted input
107 
108  // For inputs bound to a filtergraph output
110 
111  // source data type: AVMEDIA_TYPE_SUBTITLE for sub2video,
112  // same as type otherwise
114 
115  int eof;
116  int bound;
118  uint64_t nb_dropped;
119 
120  // parameters configured for this input
121  int format;
122 
123  int width, height;
128 
131 
133 
136 
138 
140 
144 
147 
151 
152  struct {
153  AVFrame *frame;
154 
157 
158  /// marks if sub2video_update should force an initialization
159  unsigned int initialize;
160  } sub2video;
162 
164 {
165  return (InputFilterPriv*)ifilter;
166 }
167 
168 typedef struct FPSConvContext {
170  /* number of frames emitted by the video-encoding sync code */
172  /* history of nb_frames_prev, i.e. the number of times the
173  * previous frame was duplicated by vsync code in recent
174  * do_video_out() calls */
176 
177  uint64_t dup_warning;
178 
181 
183 
189 
190 typedef struct OutputFilterPriv {
192 
193  void *log_parent;
194  char log_name[32];
195 
196  int needed;
197 
198  /* desired output stream properties */
199  int format;
200  int width, height;
206 
207  unsigned crop_top;
208  unsigned crop_bottom;
209  unsigned crop_left;
210  unsigned crop_right;
211 
214 
215  // time base in which the output is sent to our downstream
216  // does not need to match the filtersink's timebase
218  // at least one frame with the above timebase was sent
219  // to our downstream, so it cannot change anymore
221 
223 
226 
227  // those are only set if no format is specified and the encoder gives us multiple options
228  // They point directly to the relevant lists of the encoder.
229  union {
230  const enum AVPixelFormat *pix_fmts;
232  };
234  const int *sample_rates;
238 
240 
244  // offset for output timestamps, in AV_TIME_BASE_Q
248 
249  unsigned flags;
251 
253 {
254  return (OutputFilterPriv*)ofilter;
255 }
256 
257 typedef struct FilterCommand {
258  char *target;
259  char *command;
260  char *arg;
261 
262  double time;
264 } FilterCommand;
265 
266 static void filter_command_free(void *opaque, uint8_t *data)
267 {
269 
270  av_freep(&fc->target);
271  av_freep(&fc->command);
272  av_freep(&fc->arg);
273 
274  av_free(data);
275 }
276 
278 {
279  AVFrame *frame = ifp->sub2video.frame;
280  int ret;
281 
283 
284  frame->width = ifp->width;
285  frame->height = ifp->height;
286  frame->format = ifp->format;
287  frame->colorspace = ifp->color_space;
288  frame->color_range = ifp->color_range;
289  frame->alpha_mode = ifp->alpha_mode;
290 
292  if (ret < 0)
293  return ret;
294 
295  memset(frame->data[0], 0, frame->height * frame->linesize[0]);
296 
297  return 0;
298 }
299 
300 static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h,
301  AVSubtitleRect *r)
302 {
303  uint32_t *pal, *dst2;
304  uint8_t *src, *src2;
305  int x, y;
306 
307  if (r->type != SUBTITLE_BITMAP) {
308  av_log(NULL, AV_LOG_WARNING, "sub2video: non-bitmap subtitle\n");
309  return;
310  }
311  if (r->x < 0 || r->x + r->w > w || r->y < 0 || r->y + r->h > h) {
312  av_log(NULL, AV_LOG_WARNING, "sub2video: rectangle (%d %d %d %d) overflowing %d %d\n",
313  r->x, r->y, r->w, r->h, w, h
314  );
315  return;
316  }
317 
318  dst += r->y * dst_linesize + r->x * 4;
319  src = r->data[0];
320  pal = (uint32_t *)r->data[1];
321  for (y = 0; y < r->h; y++) {
322  dst2 = (uint32_t *)dst;
323  src2 = src;
324  for (x = 0; x < r->w; x++)
325  *(dst2++) = pal[*(src2++)];
326  dst += dst_linesize;
327  src += r->linesize[0];
328  }
329 }
330 
332 {
333  AVFrame *frame = ifp->sub2video.frame;
334  int ret;
335 
336  av_assert1(frame->data[0]);
337  ifp->sub2video.last_pts = frame->pts = pts;
341  if (ret != AVERROR_EOF && ret < 0)
343  "Error while add the frame to buffer source(%s).\n",
344  av_err2str(ret));
345 }
346 
347 static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts,
348  const AVSubtitle *sub)
349 {
350  AVFrame *frame = ifp->sub2video.frame;
351  int8_t *dst;
352  int dst_linesize;
353  int num_rects;
354  int64_t pts, end_pts;
355 
356  if (sub) {
357  pts = av_rescale_q(sub->pts + sub->start_display_time * 1000LL,
358  AV_TIME_BASE_Q, ifp->time_base);
359  end_pts = av_rescale_q(sub->pts + sub->end_display_time * 1000LL,
360  AV_TIME_BASE_Q, ifp->time_base);
361  num_rects = sub->num_rects;
362  } else {
363  /* If we are initializing the system, utilize current heartbeat
364  PTS as the start time, and show until the following subpicture
365  is received. Otherwise, utilize the previous subpicture's end time
366  as the fall-back value. */
367  pts = ifp->sub2video.initialize ?
368  heartbeat_pts : ifp->sub2video.end_pts;
369  end_pts = INT64_MAX;
370  num_rects = 0;
371  }
372  if (sub2video_get_blank_frame(ifp) < 0) {
374  "Impossible to get a blank canvas.\n");
375  return;
376  }
377  dst = frame->data [0];
378  dst_linesize = frame->linesize[0];
379  for (int i = 0; i < num_rects; i++)
380  sub2video_copy_rect(dst, dst_linesize, frame->width, frame->height, sub->rects[i]);
381  sub2video_push_ref(ifp, pts);
382  ifp->sub2video.end_pts = end_pts;
383  ifp->sub2video.initialize = 0;
384 }
385 
386 /* Define a function for appending a list of allowed formats
387  * to an AVBPrint. If nonempty, the list will have a header. */
388 #define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \
389 static void choose_ ## name (OutputFilterPriv *ofp, AVBPrint *bprint) \
390 { \
391  if (ofp->var == none && !ofp->supported_list) \
392  return; \
393  av_bprintf(bprint, #name "="); \
394  if (ofp->var != none) { \
395  av_bprintf(bprint, printf_format, get_name(ofp->var)); \
396  } else { \
397  const type *p; \
398  \
399  for (p = ofp->supported_list; *p != none; p++) { \
400  av_bprintf(bprint, printf_format "|", get_name(*p)); \
401  } \
402  if (bprint->len > 0) \
403  bprint->str[--bprint->len] = '\0'; \
404  } \
405  av_bprint_chars(bprint, ':', 1); \
406 }
407 
410 
413 
415  "%d", )
416 
417 DEF_CHOOSE_FORMAT(color_spaces, enum AVColorSpace, color_space, color_spaces,
419 
420 DEF_CHOOSE_FORMAT(color_ranges, enum AVColorRange, color_range, color_ranges,
422 
423 DEF_CHOOSE_FORMAT(alpha_modes, enum AVAlphaMode, alpha_mode, alpha_modes,
425 
426 static void choose_channel_layouts(OutputFilterPriv *ofp, AVBPrint *bprint)
427 {
428  if (av_channel_layout_check(&ofp->ch_layout)) {
429  av_bprintf(bprint, "channel_layouts=");
430  av_channel_layout_describe_bprint(&ofp->ch_layout, bprint);
431  } else if (ofp->ch_layouts) {
432  const AVChannelLayout *p;
433 
434  av_bprintf(bprint, "channel_layouts=");
435  for (p = ofp->ch_layouts; p->nb_channels; p++) {
437  av_bprintf(bprint, "|");
438  }
439  if (bprint->len > 0)
440  bprint->str[--bprint->len] = '\0';
441  } else
442  return;
443  av_bprint_chars(bprint, ':', 1);
444 }
445 
446 static int read_binary(void *logctx, const char *path,
447  uint8_t **data, int *len)
448 {
449  AVIOContext *io = NULL;
450  int64_t fsize;
451  int ret;
452 
453  *data = NULL;
454  *len = 0;
455 
456  ret = avio_open2(&io, path, AVIO_FLAG_READ, &int_cb, NULL);
457  if (ret < 0) {
458  av_log(logctx, AV_LOG_ERROR, "Cannot open file '%s': %s\n",
459  path, av_err2str(ret));
460  return ret;
461  }
462 
463  fsize = avio_size(io);
464  if (fsize < 0 || fsize > INT_MAX) {
465  av_log(logctx, AV_LOG_ERROR, "Cannot obtain size of file %s\n", path);
466  ret = AVERROR(EIO);
467  goto fail;
468  }
469 
470  *data = av_malloc(fsize);
471  if (!*data) {
472  ret = AVERROR(ENOMEM);
473  goto fail;
474  }
475 
476  ret = avio_read(io, *data, fsize);
477  if (ret != fsize) {
478  av_log(logctx, AV_LOG_ERROR, "Error reading file %s\n", path);
479  ret = ret < 0 ? ret : AVERROR(EIO);
480  goto fail;
481  }
482 
483  *len = fsize;
484 
485  ret = 0;
486 fail:
487  avio_close(io);
488  if (ret < 0) {
489  av_freep(data);
490  *len = 0;
491  }
492  return ret;
493 }
494 
495 static int filter_opt_apply(void *logctx, AVFilterContext *f,
496  const char *key, const char *val)
497 {
498  const AVOption *o = NULL;
499  int ret;
500 
502  if (ret >= 0)
503  return 0;
504 
505  if (ret == AVERROR_OPTION_NOT_FOUND && key[0] == '/')
507  if (!o)
508  goto err_apply;
509 
510  // key is a valid option name prefixed with '/'
511  // interpret value as a path from which to load the actual option value
512  key++;
513 
514  if (o->type == AV_OPT_TYPE_BINARY) {
515  uint8_t *data;
516  int len;
517 
518  ret = read_binary(logctx, val, &data, &len);
519  if (ret < 0)
520  goto err_load;
521 
523  av_freep(&data);
524  } else {
525  char *data = read_file_to_string(val);
526  if (!data) {
527  ret = AVERROR(EIO);
528  goto err_load;
529  }
530 
532  av_freep(&data);
533  }
534  if (ret < 0)
535  goto err_apply;
536 
537  return 0;
538 
539 err_apply:
540  av_log(logctx, AV_LOG_ERROR,
541  "Error applying option '%s' to filter '%s': %s\n",
542  key, f->filter->name, av_err2str(ret));
543  return ret;
544 err_load:
545  av_log(logctx, AV_LOG_ERROR,
546  "Error loading value for option '%s' from file '%s'\n",
547  key, val);
548  return ret;
549 }
550 
551 static int graph_opts_apply(void *logctx, AVFilterGraphSegment *seg)
552 {
553  for (size_t i = 0; i < seg->nb_chains; i++) {
554  AVFilterChain *ch = seg->chains[i];
555 
556  for (size_t j = 0; j < ch->nb_filters; j++) {
557  AVFilterParams *p = ch->filters[j];
558  const AVDictionaryEntry *e = NULL;
559 
560  av_assert0(p->filter);
561 
562  while ((e = av_dict_iterate(p->opts, e))) {
563  int ret = filter_opt_apply(logctx, p->filter, e->key, e->value);
564  if (ret < 0)
565  return ret;
566  }
567 
568  av_dict_free(&p->opts);
569  }
570  }
571 
572  return 0;
573 }
574 
575 static int graph_parse(void *logctx,
576  AVFilterGraph *graph, const char *desc,
578  AVBufferRef *hw_device)
579 {
581  int ret;
582 
583  *inputs = NULL;
584  *outputs = NULL;
585 
586  ret = avfilter_graph_segment_parse(graph, desc, 0, &seg);
587  if (ret < 0)
588  return ret;
589 
591  if (ret < 0)
592  goto fail;
593 
594  if (hw_device) {
595  for (int i = 0; i < graph->nb_filters; i++) {
596  AVFilterContext *f = graph->filters[i];
597 
598  if (!(f->filter->flags & AVFILTER_FLAG_HWDEVICE))
599  continue;
600  f->hw_device_ctx = av_buffer_ref(hw_device);
601  if (!f->hw_device_ctx) {
602  ret = AVERROR(ENOMEM);
603  goto fail;
604  }
605  }
606  }
607 
608  ret = graph_opts_apply(logctx, seg);
609  if (ret < 0)
610  goto fail;
611 
613 
614 fail:
616  return ret;
617 }
618 
619 // Filters can be configured only if the formats of all inputs are known.
621 {
622  for (int i = 0; i < fg->nb_inputs; i++) {
624  if (ifp->format < 0)
625  return 0;
626  }
627  return 1;
628 }
629 
630 static int filter_thread(void *arg);
631 
632 static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
633 {
634  AVFilterContext *ctx = inout->filter_ctx;
635  AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads;
636  int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs;
637 
638  if (nb_pads > 1)
639  return av_strdup(ctx->filter->name);
640  return av_asprintf("%s:%s", ctx->filter->name,
641  avfilter_pad_get_name(pads, inout->pad_idx));
642 }
643 
644 static const char *ofilter_item_name(void *obj)
645 {
646  OutputFilterPriv *ofp = obj;
647  return ofp->log_name;
648 }
649 
650 static const AVClass ofilter_class = {
651  .class_name = "OutputFilter",
652  .version = LIBAVUTIL_VERSION_INT,
653  .item_name = ofilter_item_name,
654  .parent_log_context_offset = offsetof(OutputFilterPriv, log_parent),
655  .category = AV_CLASS_CATEGORY_FILTER,
656 };
657 
659 {
660  OutputFilterPriv *ofp;
661  OutputFilter *ofilter;
662 
663  ofp = allocate_array_elem(&fg->outputs, sizeof(*ofp), &fg->nb_outputs);
664  if (!ofp)
665  return NULL;
666 
667  ofilter = &ofp->ofilter;
668  ofilter->class = &ofilter_class;
669  ofp->log_parent = fg;
670  ofilter->graph = fg;
671  ofilter->type = type;
672  ofp->format = -1;
676  ofilter->index = fg->nb_outputs - 1;
677 
678  snprintf(ofp->log_name, sizeof(ofp->log_name), "%co%d",
679  av_get_media_type_string(type)[0], ofilter->index);
680 
681  return ofilter;
682 }
683 
684 static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist,
685  const ViewSpecifier *vs)
686 {
687  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
688  FilterGraphPriv *fgp = fgp_from_fg(ifilter->graph);
690  int ret;
691 
692  av_assert0(!ifp->bound);
693  ifp->bound = 1;
694 
695  if (ifilter->type != ist->par->codec_type &&
696  !(ifilter->type == AVMEDIA_TYPE_VIDEO && ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE)) {
697  av_log(fgp, AV_LOG_ERROR, "Tried to connect %s stream to %s filtergraph input\n",
699  return AVERROR(EINVAL);
700  }
701 
702  ifp->type_src = ist->st->codecpar->codec_type;
703 
704  ifp->opts.fallback = av_frame_alloc();
705  if (!ifp->opts.fallback)
706  return AVERROR(ENOMEM);
707 
708  ret = ist_filter_add(ist, ifilter, filtergraph_is_simple(ifilter->graph),
709  vs, &ifp->opts, &src);
710  if (ret < 0)
711  return ret;
712 
713  ifilter->input_name = av_strdup(ifp->opts.name);
714  if (!ifilter->input_name)
715  return AVERROR(EINVAL);
716 
717  ret = sch_connect(fgp->sch,
718  src, SCH_FILTER_IN(fgp->sch_idx, ifilter->index));
719  if (ret < 0)
720  return ret;
721 
722  if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) {
723  ifp->sub2video.frame = av_frame_alloc();
724  if (!ifp->sub2video.frame)
725  return AVERROR(ENOMEM);
726 
727  ifp->width = ifp->opts.sub2video_width;
728  ifp->height = ifp->opts.sub2video_height;
729 
730  /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
731  palettes for all rectangles are identical or compatible */
732  ifp->format = AV_PIX_FMT_RGB32;
733 
734  ifp->time_base = AV_TIME_BASE_Q;
735 
736  av_log(fgp, AV_LOG_VERBOSE, "sub2video: using %dx%d canvas\n",
737  ifp->width, ifp->height);
738  }
739 
740  return 0;
741 }
742 
744  const ViewSpecifier *vs)
745 {
748  int ret;
749 
750  av_assert0(!ifp->bound);
751  ifp->bound = 1;
752 
753  if (ifp->ifilter.type != dec->type) {
754  av_log(fgp, AV_LOG_ERROR, "Tried to connect %s decoder to %s filtergraph input\n",
756  return AVERROR(EINVAL);
757  }
758 
759  ifp->type_src = ifp->ifilter.type;
760 
761  ret = dec_filter_add(dec, &ifp->ifilter, &ifp->opts, vs, &src);
762  if (ret < 0)
763  return ret;
764 
765  ifp->ifilter.input_name = av_strdup(ifp->opts.name);
766  if (!ifp->ifilter.input_name)
767  return AVERROR(EINVAL);
768 
769  ret = sch_connect(fgp->sch, src, SCH_FILTER_IN(fgp->sch_idx, ifp->ifilter.index));
770  if (ret < 0)
771  return ret;
772 
773  return 0;
774 }
775 
776 static int set_channel_layout(OutputFilterPriv *f, const AVChannelLayout *layouts_allowed,
777  const AVChannelLayout *layout_requested)
778 {
779  int i, err;
780 
781  if (layout_requested->order != AV_CHANNEL_ORDER_UNSPEC) {
782  /* Pass the layout through for all orders but UNSPEC */
783  err = av_channel_layout_copy(&f->ch_layout, layout_requested);
784  if (err < 0)
785  return err;
786  return 0;
787  }
788 
789  /* Requested layout is of order UNSPEC */
790  if (!layouts_allowed) {
791  /* Use the default native layout for the requested amount of channels when the
792  encoder doesn't have a list of supported layouts */
793  av_channel_layout_default(&f->ch_layout, layout_requested->nb_channels);
794  return 0;
795  }
796  /* Encoder has a list of supported layouts. Pick the first layout in it with the
797  same amount of channels as the requested layout */
798  for (i = 0; layouts_allowed[i].nb_channels; i++) {
799  if (layouts_allowed[i].nb_channels == layout_requested->nb_channels)
800  break;
801  }
802  if (layouts_allowed[i].nb_channels) {
803  /* Use it if one is found */
804  err = av_channel_layout_copy(&f->ch_layout, &layouts_allowed[i]);
805  if (err < 0)
806  return err;
807  return 0;
808  }
809  /* If no layout for the amount of channels requested was found, use the default
810  native layout for it. */
811  av_channel_layout_default(&f->ch_layout, layout_requested->nb_channels);
812 
813  return 0;
814 }
815 
816 int ofilter_bind_enc(OutputFilter *ofilter, unsigned sched_idx_enc,
817  const OutputFilterOptions *opts)
818 {
819  OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
820  FilterGraph *fg = ofilter->graph;
821  FilterGraphPriv *fgp = fgp_from_fg(fg);
822  int ret;
823 
824  av_assert0(!ofilter->bound);
825  av_assert0(!opts->enc ||
826  ofilter->type == opts->enc->type);
827 
828  ofp->needed = ofilter->bound = 1;
829  av_freep(&ofilter->linklabel);
830 
831  ofp->flags |= opts->flags;
832  ofp->ts_offset = opts->ts_offset;
833  ofp->enc_timebase = opts->output_tb;
834 
835  ofp->trim_start_us = opts->trim_start_us;
836  ofp->trim_duration_us = opts->trim_duration_us;
837 
838  ofilter->output_name = av_strdup(opts->name);
839  if (!ofilter->output_name)
840  return AVERROR(EINVAL);
841 
842  ret = av_dict_copy(&ofp->sws_opts, opts->sws_opts, 0);
843  if (ret < 0)
844  return ret;
845 
846  ret = av_dict_copy(&ofp->swr_opts, opts->swr_opts, 0);
847  if (ret < 0)
848  return ret;
849 
850  if (opts->flags & OFILTER_FLAG_AUDIO_24BIT)
851  av_dict_set(&ofp->swr_opts, "output_sample_bits", "24", 0);
852 
853  if (fgp->is_simple) {
854  // for simple filtergraph there is just one output,
855  // so use only graph-level information for logging
856  ofp->log_parent = NULL;
857  av_strlcpy(ofp->log_name, fgp->log_name, sizeof(ofp->log_name));
858  } else
859  av_strlcatf(ofp->log_name, sizeof(ofp->log_name), "->%s", ofilter->output_name);
860 
861  switch (ofilter->type) {
862  case AVMEDIA_TYPE_VIDEO:
863  ofp->width = opts->width;
864  ofp->height = opts->height;
865  if (opts->format != AV_PIX_FMT_NONE) {
866  ofp->format = opts->format;
867  } else
868  ofp->pix_fmts = opts->pix_fmts;
869 
870  if (opts->color_space != AVCOL_SPC_UNSPECIFIED)
871  ofp->color_space = opts->color_space;
872  else
873  ofp->color_spaces = opts->color_spaces;
874 
875  if (opts->color_range != AVCOL_RANGE_UNSPECIFIED)
876  ofp->color_range = opts->color_range;
877  else
878  ofp->color_ranges = opts->color_ranges;
879 
880  if (opts->alpha_mode != AVALPHA_MODE_UNSPECIFIED)
881  ofp->alpha_mode = opts->alpha_mode;
882  else
883  ofp->alpha_modes = opts->alpha_modes;
884 
886 
887  ofp->fps.last_frame = av_frame_alloc();
888  if (!ofp->fps.last_frame)
889  return AVERROR(ENOMEM);
890 
891  ofp->fps.vsync_method = opts->vsync_method;
892  ofp->fps.framerate = opts->frame_rate;
893  ofp->fps.framerate_max = opts->max_frame_rate;
894  ofp->fps.framerate_supported = opts->frame_rates;
895 
896  // reduce frame rate for mpeg4 to be within the spec limits
897  if (opts->enc && opts->enc->id == AV_CODEC_ID_MPEG4)
898  ofp->fps.framerate_clip = 65535;
899 
900  ofp->fps.dup_warning = 1000;
901 
902  break;
903  case AVMEDIA_TYPE_AUDIO:
904  if (opts->format != AV_SAMPLE_FMT_NONE) {
905  ofp->format = opts->format;
906  } else {
907  ofp->sample_fmts = opts->sample_fmts;
908  }
909  if (opts->sample_rate) {
910  ofp->sample_rate = opts->sample_rate;
911  } else
912  ofp->sample_rates = opts->sample_rates;
913  if (opts->ch_layout.nb_channels) {
914  int ret = set_channel_layout(ofp, opts->ch_layouts, &opts->ch_layout);
915  if (ret < 0)
916  return ret;
917  } else {
918  ofp->ch_layouts = opts->ch_layouts;
919  }
920  break;
921  }
922 
923  ret = sch_connect(fgp->sch, SCH_FILTER_OUT(fgp->sch_idx, ofilter->index),
924  SCH_ENC(sched_idx_enc));
925  if (ret < 0)
926  return ret;
927 
928  return 0;
929 }
930 
932  const OutputFilterOptions *opts)
933 {
934  OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
935 
936  av_assert0(!ofilter->bound);
937  av_assert0(ofilter->type == ifp->ifilter.type);
938 
939  ofp->needed = ofilter->bound = 1;
940  av_freep(&ofilter->linklabel);
941 
942  ofilter->output_name = av_strdup(opts->name);
943  if (!ofilter->output_name)
944  return AVERROR(EINVAL);
945 
946  ifp->ofilter_src = ofilter;
947 
948  av_strlcatf(ofp->log_name, sizeof(ofp->log_name), "->%s", ofilter->output_name);
949 
950  return 0;
951 }
952 
953 static int ifilter_bind_fg(InputFilterPriv *ifp, FilterGraph *fg_src, int out_idx)
954 {
956  OutputFilter *ofilter_src = fg_src->outputs[out_idx];
958  char name[32];
959  int ret;
960 
961  av_assert0(!ifp->bound);
962  ifp->bound = 1;
963 
964  if (ifp->ifilter.type != ofilter_src->type) {
965  av_log(fgp, AV_LOG_ERROR, "Tried to connect %s output to %s input\n",
966  av_get_media_type_string(ofilter_src->type),
968  return AVERROR(EINVAL);
969  }
970 
971  ifp->type_src = ifp->ifilter.type;
972 
973  memset(&opts, 0, sizeof(opts));
974 
975  snprintf(name, sizeof(name), "fg:%d:%d", fgp->fg.index, ifp->ifilter.index);
976  opts.name = name;
977 
978  ret = ofilter_bind_ifilter(ofilter_src, ifp, &opts);
979  if (ret < 0)
980  return ret;
981 
982  ret = sch_connect(fgp->sch, SCH_FILTER_OUT(fg_src->index, out_idx),
983  SCH_FILTER_IN(fgp->sch_idx, ifp->ifilter.index));
984  if (ret < 0)
985  return ret;
986 
987  return 0;
988 }
989 
991 {
992  InputFilterPriv *ifp;
993  InputFilter *ifilter;
994 
995  ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp), &fg->nb_inputs);
996  if (!ifp)
997  return NULL;
998 
999  ifilter = &ifp->ifilter;
1000  ifilter->graph = fg;
1001 
1002  ifp->frame = av_frame_alloc();
1003  if (!ifp->frame)
1004  return NULL;
1005 
1006  ifilter->index = fg->nb_inputs - 1;
1007  ifp->format = -1;
1011 
1013  if (!ifp->frame_queue)
1014  return NULL;
1015 
1016  return ifilter;
1017 }
1018 
1020 {
1021  FilterGraph *fg = *pfg;
1022  FilterGraphPriv *fgp;
1023 
1024  if (!fg)
1025  return;
1026  fgp = fgp_from_fg(fg);
1027 
1028  for (int j = 0; j < fg->nb_inputs; j++) {
1029  InputFilter *ifilter = fg->inputs[j];
1030  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
1031 
1032  if (ifp->frame_queue) {
1033  AVFrame *frame;
1034  while (av_fifo_read(ifp->frame_queue, &frame, 1) >= 0)
1035  av_frame_free(&frame);
1036  av_fifo_freep2(&ifp->frame_queue);
1037  }
1038  av_frame_free(&ifp->sub2video.frame);
1039 
1040  av_frame_free(&ifp->frame);
1041  av_frame_free(&ifp->opts.fallback);
1042 
1045  av_freep(&ifilter->linklabel);
1046  av_freep(&ifp->opts.name);
1049  av_freep(&ifilter->name);
1050  av_freep(&ifilter->input_name);
1051  av_freep(&fg->inputs[j]);
1052  }
1053  av_freep(&fg->inputs);
1054  for (int j = 0; j < fg->nb_outputs; j++) {
1055  OutputFilter *ofilter = fg->outputs[j];
1056  OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
1057 
1058  av_frame_free(&ofp->fps.last_frame);
1059  av_dict_free(&ofp->sws_opts);
1060  av_dict_free(&ofp->swr_opts);
1061 
1062  av_freep(&ofilter->linklabel);
1063  av_freep(&ofilter->name);
1064  av_freep(&ofilter->output_name);
1065  av_freep(&ofilter->apad);
1068  av_freep(&fg->outputs[j]);
1069  }
1070  av_freep(&fg->outputs);
1071  av_freep(&fg->graph_desc);
1072 
1073  av_frame_free(&fgp->frame);
1074  av_frame_free(&fgp->frame_enc);
1075 
1076  av_freep(pfg);
1077 }
1078 
1079 static const char *fg_item_name(void *obj)
1080 {
1081  const FilterGraphPriv *fgp = obj;
1082 
1083  return fgp->log_name;
1084 }
1085 
1086 static const AVClass fg_class = {
1087  .class_name = "FilterGraph",
1088  .version = LIBAVUTIL_VERSION_INT,
1089  .item_name = fg_item_name,
1090  .category = AV_CLASS_CATEGORY_FILTER,
1091 };
1092 
1093 int fg_create(FilterGraph **pfg, char **graph_desc, Scheduler *sch,
1094  const OutputFilterOptions *opts)
1095 {
1096  FilterGraphPriv *fgp;
1097  FilterGraph *fg;
1098 
1100  AVFilterGraph *graph;
1101  int ret = 0;
1102 
1103  fgp = av_mallocz(sizeof(*fgp));
1104  if (!fgp) {
1105  av_freep(graph_desc);
1106  return AVERROR(ENOMEM);
1107  }
1108  fg = &fgp->fg;
1109 
1110  if (pfg) {
1111  *pfg = fg;
1112  fg->index = -1;
1113  } else {
1115  if (ret < 0) {
1116  av_freep(graph_desc);
1117  av_freep(&fgp);
1118  return ret;
1119  }
1120 
1121  fg->index = nb_filtergraphs - 1;
1122  }
1123 
1124  fg->class = &fg_class;
1125  fg->graph_desc = *graph_desc;
1127  fgp->nb_threads = -1;
1128  fgp->sch = sch;
1129 
1130  *graph_desc = NULL;
1131 
1132  snprintf(fgp->log_name, sizeof(fgp->log_name), "fc#%d", fg->index);
1133 
1134  fgp->frame = av_frame_alloc();
1135  fgp->frame_enc = av_frame_alloc();
1136  if (!fgp->frame || !fgp->frame_enc)
1137  return AVERROR(ENOMEM);
1138 
1139  /* this graph is only used for determining the kinds of inputs
1140  * and outputs we have, and is discarded on exit from this function */
1141  graph = avfilter_graph_alloc();
1142  if (!graph)
1143  return AVERROR(ENOMEM);;
1144  graph->nb_threads = 1;
1145 
1146  ret = graph_parse(fg, graph, fg->graph_desc, &inputs, &outputs,
1148  if (ret < 0)
1149  goto fail;
1150 
1151  for (AVFilterInOut *cur = inputs; cur; cur = cur->next) {
1152  InputFilter *const ifilter = ifilter_alloc(fg);
1153 
1154  if (!ifilter) {
1155  ret = AVERROR(ENOMEM);
1156  goto fail;
1157  }
1158 
1159  ifilter->linklabel = cur->name;
1160  cur->name = NULL;
1161 
1162  ifilter->type = avfilter_pad_get_type(cur->filter_ctx->input_pads,
1163  cur->pad_idx);
1164 
1165  if (ifilter->type != AVMEDIA_TYPE_VIDEO && ifilter->type != AVMEDIA_TYPE_AUDIO) {
1166  av_log(fg, AV_LOG_FATAL, "Only video and audio filters supported "
1167  "currently.\n");
1168  ret = AVERROR(ENOSYS);
1169  goto fail;
1170  }
1171 
1172  ifilter->name = describe_filter_link(fg, cur, 1);
1173  if (!ifilter->name) {
1174  ret = AVERROR(ENOMEM);
1175  goto fail;
1176  }
1177  }
1178 
1179  for (AVFilterInOut *cur = outputs; cur; cur = cur->next) {
1180  const enum AVMediaType type = avfilter_pad_get_type(cur->filter_ctx->output_pads,
1181  cur->pad_idx);
1182  OutputFilter *const ofilter = ofilter_alloc(fg, type);
1183  OutputFilterPriv *ofp;
1184 
1185  if (!ofilter) {
1186  ret = AVERROR(ENOMEM);
1187  goto fail;
1188  }
1189  ofp = ofp_from_ofilter(ofilter);
1190 
1191  ofilter->linklabel = cur->name;
1192  cur->name = NULL;
1193 
1194  ofilter->name = describe_filter_link(fg, cur, 0);
1195  if (!ofilter->name) {
1196  ret = AVERROR(ENOMEM);
1197  goto fail;
1198  }
1199 
1200  // opts should only be needed in this function to fill fields from filtergraphs
1201  // whose output is meant to be treated as if it was stream, e.g. merged HEIF
1202  // tile groups.
1203  if (opts) {
1204  ofp->flags = opts->flags;
1205  ofp->side_data = opts->side_data;
1206  ofp->nb_side_data = opts->nb_side_data;
1207 
1208  ofp->crop_top = opts->crop_top;
1209  ofp->crop_bottom = opts->crop_bottom;
1210  ofp->crop_left = opts->crop_left;
1211  ofp->crop_right = opts->crop_right;
1212 
1215  if (sd)
1216  memcpy(ofp->displaymatrix, sd->data, sizeof(ofp->displaymatrix));
1217  }
1218  }
1219 
1220  if (!fg->nb_outputs) {
1221  av_log(fg, AV_LOG_FATAL, "A filtergraph has zero outputs, this is not supported\n");
1222  ret = AVERROR(ENOSYS);
1223  goto fail;
1224  }
1225 
1226  ret = sch_add_filtergraph(sch, fg->nb_inputs, fg->nb_outputs,
1227  filter_thread, fgp);
1228  if (ret < 0)
1229  goto fail;
1230  fgp->sch_idx = ret;
1231 
1232 fail:
1235  avfilter_graph_free(&graph);
1236 
1237  if (ret < 0)
1238  return ret;
1239 
1240  return 0;
1241 }
1242 
1244  InputStream *ist,
1245  char **graph_desc,
1246  Scheduler *sch, unsigned sched_idx_enc,
1247  const OutputFilterOptions *opts)
1248 {
1249  const enum AVMediaType type = ist->par->codec_type;
1250  FilterGraph *fg;
1251  FilterGraphPriv *fgp;
1252  int ret;
1253 
1254  ret = fg_create(pfg, graph_desc, sch, NULL);
1255  if (ret < 0)
1256  return ret;
1257  fg = *pfg;
1258  fgp = fgp_from_fg(fg);
1259 
1260  fgp->is_simple = 1;
1261 
1262  snprintf(fgp->log_name, sizeof(fgp->log_name), "%cf%s",
1263  av_get_media_type_string(type)[0], opts->name);
1264 
1265  if (fg->nb_inputs != 1 || fg->nb_outputs != 1) {
1266  av_log(fg, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
1267  "to have exactly 1 input and 1 output. "
1268  "However, it had %d input(s) and %d output(s). Please adjust, "
1269  "or use a complex filtergraph (-filter_complex) instead.\n",
1270  *graph_desc, fg->nb_inputs, fg->nb_outputs);
1271  return AVERROR(EINVAL);
1272  }
1273  if (fg->outputs[0]->type != type) {
1274  av_log(fg, AV_LOG_ERROR, "Filtergraph has a %s output, cannot connect "
1275  "it to %s output stream\n",
1278  return AVERROR(EINVAL);
1279  }
1280 
1281  ret = ifilter_bind_ist(fg->inputs[0], ist, opts->vs);
1282  if (ret < 0)
1283  return ret;
1284 
1285  ret = ofilter_bind_enc(fg->outputs[0], sched_idx_enc, opts);
1286  if (ret < 0)
1287  return ret;
1288 
1289  if (opts->nb_threads >= 0)
1290  fgp->nb_threads = opts->nb_threads;
1291 
1292  return 0;
1293 }
1294 
1295 static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter, int commit)
1296 {
1297  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
1298  InputStream *ist = NULL;
1299  enum AVMediaType type = ifilter->type;
1301  const char *spec;
1302  char *p;
1303  int i, ret;
1304 
1305  if (ifilter->linklabel && !strncmp(ifilter->linklabel, "dec:", 4)) {
1306  // bind to a standalone decoder
1307  int dec_idx;
1308 
1309  dec_idx = strtol(ifilter->linklabel + 4, &p, 0);
1310  if (dec_idx < 0 || dec_idx >= nb_decoders) {
1311  av_log(fg, AV_LOG_ERROR, "Invalid decoder index %d in filtergraph description %s\n",
1312  dec_idx, fg->graph_desc);
1313  return AVERROR(EINVAL);
1314  }
1315 
1316  if (type == AVMEDIA_TYPE_VIDEO) {
1317  spec = *p == ':' ? p + 1 : p;
1318  ret = view_specifier_parse(&spec, &vs);
1319  if (ret < 0)
1320  return ret;
1321  }
1322 
1323  ret = ifilter_bind_dec(ifp, decoders[dec_idx], &vs);
1324  if (ret < 0)
1325  av_log(fg, AV_LOG_ERROR, "Error binding a decoder to filtergraph input %s\n",
1326  ifilter->name);
1327  return ret;
1328  } else if (ifilter->linklabel) {
1330  AVFormatContext *s;
1331  AVStream *st = NULL;
1332  int file_idx;
1333 
1334  // try finding an unbound filtergraph output with this label
1335  for (int i = 0; i < nb_filtergraphs; i++) {
1336  FilterGraph *fg_src = filtergraphs[i];
1337 
1338  if (fg == fg_src)
1339  continue;
1340 
1341  for (int j = 0; j < fg_src->nb_outputs; j++) {
1342  OutputFilter *ofilter = fg_src->outputs[j];
1343 
1344  if (!ofilter->bound && ofilter->linklabel &&
1345  !strcmp(ofilter->linklabel, ifilter->linklabel)) {
1346  if (commit) {
1347  av_log(fg, AV_LOG_VERBOSE,
1348  "Binding input with label '%s' to filtergraph output %d:%d\n",
1349  ifilter->linklabel, i, j);
1350 
1351  ret = ifilter_bind_fg(ifp, fg_src, j);
1352  if (ret < 0) {
1353  av_log(fg, AV_LOG_ERROR, "Error binding filtergraph input %s\n",
1354  ifilter->linklabel);
1355  return ret;
1356  }
1357  } else
1358  ofp_from_ofilter(ofilter)->needed = 1;
1359  return 0;
1360  }
1361  }
1362  }
1363 
1364  // bind to an explicitly specified demuxer stream
1365  file_idx = strtol(ifilter->linklabel, &p, 0);
1366  if (file_idx < 0 || file_idx >= nb_input_files) {
1367  av_log(fg, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
1368  file_idx, fg->graph_desc);
1369  return AVERROR(EINVAL);
1370  }
1371  s = input_files[file_idx]->ctx;
1372 
1373  ret = stream_specifier_parse(&ss, *p == ':' ? p + 1 : p, 1, fg);
1374  if (ret < 0) {
1375  av_log(fg, AV_LOG_ERROR, "Invalid stream specifier: %s\n", p);
1376  return ret;
1377  }
1378 
1379  if (type == AVMEDIA_TYPE_VIDEO) {
1380  spec = ss.remainder ? ss.remainder : "";
1381  ret = view_specifier_parse(&spec, &vs);
1382  if (ret < 0) {
1384  return ret;
1385  }
1386  }
1387 
1388  for (i = 0; i < s->nb_streams; i++) {
1389  enum AVMediaType stream_type = s->streams[i]->codecpar->codec_type;
1390  if (stream_type != type &&
1391  !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
1392  type == AVMEDIA_TYPE_VIDEO /* sub2video hack */))
1393  continue;
1394  if (stream_specifier_match(&ss, s, s->streams[i], fg)) {
1395  st = s->streams[i];
1396  break;
1397  }
1398  }
1400  if (!st) {
1401  av_log(fg, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
1402  "matches no streams.\n", p, fg->graph_desc);
1403  return AVERROR(EINVAL);
1404  }
1405  ist = input_files[file_idx]->streams[st->index];
1406 
1407  if (commit)
1408  av_log(fg, AV_LOG_VERBOSE,
1409  "Binding input with label '%s' to input stream %d:%d\n",
1410  ifilter->linklabel, ist->file->index, ist->index);
1411  } else {
1412  // try finding an unbound filtergraph output
1413  for (int i = 0; i < nb_filtergraphs; i++) {
1414  FilterGraph *fg_src = filtergraphs[i];
1415 
1416  if (fg == fg_src)
1417  continue;
1418 
1419  for (int j = 0; j < fg_src->nb_outputs; j++) {
1420  OutputFilter *ofilter = fg_src->outputs[j];
1421 
1422  if (!ofilter->bound) {
1423  if (commit) {
1424  av_log(fg, AV_LOG_VERBOSE,
1425  "Binding unlabeled filtergraph input to filtergraph output %d:%d\n", i, j);
1426 
1427  ret = ifilter_bind_fg(ifp, fg_src, j);
1428  if (ret < 0) {
1429  av_log(fg, AV_LOG_ERROR, "Error binding filtergraph input %d:%d\n", i, j);
1430  return ret;
1431  }
1432  } else
1433  ofp_from_ofilter(ofilter)->needed = 1;
1434  return 0;
1435  }
1436  }
1437  }
1438 
1439  ist = ist_find_unused(type);
1440  if (!ist) {
1441  av_log(fg, AV_LOG_FATAL,
1442  "Cannot find an unused %s input stream to feed the "
1443  "unlabeled input pad %s.\n",
1444  av_get_media_type_string(type), ifilter->name);
1445  return AVERROR(EINVAL);
1446  }
1447 
1448  if (commit)
1449  av_log(fg, AV_LOG_VERBOSE,
1450  "Binding unlabeled input %d to input stream %d:%d\n",
1451  ifilter->index, ist->file->index, ist->index);
1452  }
1453  av_assert0(ist);
1454 
1455  if (commit) {
1456  ret = ifilter_bind_ist(ifilter, ist, &vs);
1457  if (ret < 0) {
1458  av_log(fg, AV_LOG_ERROR,
1459  "Error binding an input stream to complex filtergraph input %s.\n",
1460  ifilter->name);
1461  return ret;
1462  }
1463  }
1464 
1465  return 0;
1466 }
1467 
1468 static int bind_inputs(FilterGraph *fg, int commit)
1469 {
1470  // bind filtergraph inputs to input streams or other filtergraphs
1471  for (int i = 0; i < fg->nb_inputs; i++) {
1473  int ret;
1474 
1475  if (ifp->bound)
1476  continue;
1477 
1478  ret = fg_complex_bind_input(fg, &ifp->ifilter, commit);
1479  if (ret < 0)
1480  return ret;
1481  }
1482 
1483  return 0;
1484 }
1485 
1487 {
1488  int ret;
1489 
1490  for (int i = 0; i < nb_filtergraphs; i++) {
1491  ret = bind_inputs(filtergraphs[i], 0);
1492  if (ret < 0)
1493  return ret;
1494  }
1495 
1496  // check that all outputs were bound
1497  for (int i = nb_filtergraphs - 1; i >= 0; i--) {
1498  FilterGraph *fg = filtergraphs[i];
1500 
1501  for (int j = 0; j < fg->nb_outputs; j++) {
1502  OutputFilter *output = fg->outputs[j];
1503  if (!ofp_from_ofilter(output)->needed) {
1504  if (!fg->is_internal) {
1505  av_log(fg, AV_LOG_FATAL,
1506  "Filter '%s' has output %d (%s) unconnected\n",
1507  output->name, j,
1508  output->linklabel ? (const char *)output->linklabel : "unlabeled");
1509  return AVERROR(EINVAL);
1510  }
1511 
1512  av_log(fg, AV_LOG_DEBUG,
1513  "Internal filter '%s' has output %d (%s) unconnected. Removing graph\n",
1514  output->name, j,
1515  output->linklabel ? (const char *)output->linklabel : "unlabeled");
1516  sch_remove_filtergraph(fgp->sch, fgp->sch_idx);
1517  fg_free(&filtergraphs[i]);
1518  nb_filtergraphs--;
1519  if (nb_filtergraphs > 0)
1520  memmove(&filtergraphs[i],
1521  &filtergraphs[i + 1],
1522  (nb_filtergraphs - i) * sizeof(*filtergraphs));
1523  break;
1524  }
1525  }
1526  }
1527 
1528  for (int i = 0; i < nb_filtergraphs; i++) {
1529  ret = bind_inputs(filtergraphs[i], 1);
1530  if (ret < 0)
1531  return ret;
1532  }
1533 
1534  return 0;
1535 }
1536 
1537 static int insert_trim(void *logctx, int64_t start_time, int64_t duration,
1538  AVFilterContext **last_filter, int *pad_idx,
1539  const char *filter_name)
1540 {
1541  AVFilterGraph *graph = (*last_filter)->graph;
1543  const AVFilter *trim;
1544  enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
1545  const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
1546  int ret = 0;
1547 
1548  if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
1549  return 0;
1550 
1551  trim = avfilter_get_by_name(name);
1552  if (!trim) {
1553  av_log(logctx, AV_LOG_ERROR, "%s filter not present, cannot limit "
1554  "recording time.\n", name);
1555  return AVERROR_FILTER_NOT_FOUND;
1556  }
1557 
1558  ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
1559  if (!ctx)
1560  return AVERROR(ENOMEM);
1561 
1562  if (duration != INT64_MAX) {
1563  ret = av_opt_set_int(ctx, "durationi", duration,
1565  }
1566  if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
1567  ret = av_opt_set_int(ctx, "starti", start_time,
1569  }
1570  if (ret < 0) {
1571  av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
1572  return ret;
1573  }
1574 
1576  if (ret < 0)
1577  return ret;
1578 
1579  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
1580  if (ret < 0)
1581  return ret;
1582 
1583  *last_filter = ctx;
1584  *pad_idx = 0;
1585  return 0;
1586 }
1587 
1588 static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
1589  const char *filter_name, const char *args)
1590 {
1591  AVFilterGraph *graph = (*last_filter)->graph;
1592  const AVFilter *filter = avfilter_get_by_name(filter_name);
1594  int ret;
1595 
1596  if (!filter)
1597  return AVERROR_BUG;
1598 
1600  filter,
1601  filter_name, args, NULL, graph);
1602  if (ret < 0)
1603  return ret;
1604 
1605  ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
1606  if (ret < 0)
1607  return ret;
1608 
1609  *last_filter = ctx;
1610  *pad_idx = 0;
1611  return 0;
1612 }
1613 
1615  OutputFilter *ofilter, AVFilterInOut *out)
1616 {
1617  OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
1618  AVFilterContext *last_filter = out->filter_ctx;
1619  AVBPrint bprint;
1620  int pad_idx = out->pad_idx;
1621  int ret;
1622  char name[255];
1623 
1624  snprintf(name, sizeof(name), "out_%s", ofilter->output_name);
1626  avfilter_get_by_name("buffersink"),
1627  name, NULL, NULL, graph);
1628 
1629  if (ret < 0)
1630  return ret;
1631 
1632  if (ofp->flags & OFILTER_FLAG_CROP) {
1633  char crop_buf[64];
1634  snprintf(crop_buf, sizeof(crop_buf), "w=iw-%u-%u:h=ih-%u-%u:x=%u:y=%u",
1635  ofp->crop_left, ofp->crop_right,
1636  ofp->crop_top, ofp->crop_bottom,
1637  ofp->crop_left, ofp->crop_top);
1638  ret = insert_filter(&last_filter, &pad_idx, "crop", crop_buf);
1639  if (ret < 0)
1640  return ret;
1641  }
1642 
1643  if (ofp->flags & OFILTER_FLAG_AUTOROTATE) {
1644  int32_t *displaymatrix = ofp->displaymatrix;
1645  double theta;
1646 
1647  theta = get_rotation(displaymatrix);
1648 
1649  if (fabs(theta - 90) < 1.0) {
1650  ret = insert_filter(&last_filter, &pad_idx, "transpose",
1651  displaymatrix[3] > 0 ? "cclock_flip" : "clock");
1652  } else if (fabs(theta - 180) < 1.0) {
1653  if (displaymatrix[0] < 0) {
1654  ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
1655  if (ret < 0)
1656  return ret;
1657  }
1658  if (displaymatrix[4] < 0) {
1659  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
1660  }
1661  } else if (fabs(theta - 270) < 1.0) {
1662  ret = insert_filter(&last_filter, &pad_idx, "transpose",
1663  displaymatrix[3] < 0 ? "clock_flip" : "cclock");
1664  } else if (fabs(theta) > 1.0) {
1665  char rotate_buf[64];
1666  snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
1667  ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf);
1668  } else if (fabs(theta) < 1.0) {
1669  if (displaymatrix && displaymatrix[4] < 0) {
1670  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
1671  }
1672  }
1673  if (ret < 0)
1674  return ret;
1675 
1677  }
1678 
1679  if ((ofp->width || ofp->height) && (ofp->flags & OFILTER_FLAG_AUTOSCALE) &&
1680  // skip add scale for hardware format
1681  !(ofp->format != AV_PIX_FMT_NONE &&
1683  char args[255];
1685  const AVDictionaryEntry *e = NULL;
1686 
1687  snprintf(args, sizeof(args), "%d:%d",
1688  ofp->width, ofp->height);
1689 
1690  while ((e = av_dict_iterate(ofp->sws_opts, e))) {
1691  av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
1692  }
1693 
1694  snprintf(name, sizeof(name), "scaler_out_%s", ofilter->output_name);
1696  name, args, NULL, graph)) < 0)
1697  return ret;
1698  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
1699  return ret;
1700 
1701  last_filter = filter;
1702  pad_idx = 0;
1703  }
1704 
1706  ofp->format != AV_PIX_FMT_NONE || !ofp->pix_fmts);
1708  choose_pix_fmts(ofp, &bprint);
1709  choose_color_spaces(ofp, &bprint);
1710  choose_color_ranges(ofp, &bprint);
1711  choose_alpha_modes(ofp, &bprint);
1712  if (!av_bprint_is_complete(&bprint))
1713  return AVERROR(ENOMEM);
1714 
1715  if (bprint.len) {
1717 
1719  avfilter_get_by_name("format"),
1720  "format", bprint.str, NULL, graph);
1721  av_bprint_finalize(&bprint, NULL);
1722  if (ret < 0)
1723  return ret;
1724  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
1725  return ret;
1726 
1727  last_filter = filter;
1728  pad_idx = 0;
1729  }
1730 
1731  snprintf(name, sizeof(name), "trim_out_%s", ofilter->output_name);
1732  ret = insert_trim(fgp, ofp->trim_start_us, ofp->trim_duration_us,
1733  &last_filter, &pad_idx, name);
1734  if (ret < 0)
1735  return ret;
1736 
1737 
1738  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
1739  return ret;
1740 
1741  return 0;
1742 }
1743 
1745  OutputFilter *ofilter, AVFilterInOut *out)
1746 {
1747  OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
1748  AVFilterContext *last_filter = out->filter_ctx;
1749  int pad_idx = out->pad_idx;
1750  AVBPrint args;
1751  char name[255];
1752  int ret;
1753 
1754  snprintf(name, sizeof(name), "out_%s", ofilter->output_name);
1756  avfilter_get_by_name("abuffersink"),
1757  name, NULL, NULL, graph);
1758  if (ret < 0)
1759  return ret;
1760 
1761 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
1762  AVFilterContext *filt_ctx; \
1763  \
1764  av_log(ofilter, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
1765  "similarly to -af " filter_name "=%s.\n", arg); \
1766  \
1767  ret = avfilter_graph_create_filter(&filt_ctx, \
1768  avfilter_get_by_name(filter_name), \
1769  filter_name, arg, NULL, graph); \
1770  if (ret < 0) \
1771  goto fail; \
1772  \
1773  ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
1774  if (ret < 0) \
1775  goto fail; \
1776  \
1777  last_filter = filt_ctx; \
1778  pad_idx = 0; \
1779 } while (0)
1781 
1782  choose_sample_fmts(ofp, &args);
1783  choose_sample_rates(ofp, &args);
1784  choose_channel_layouts(ofp, &args);
1785  if (!av_bprint_is_complete(&args)) {
1786  ret = AVERROR(ENOMEM);
1787  goto fail;
1788  }
1789  if (args.len) {
1791 
1792  snprintf(name, sizeof(name), "format_out_%s", ofilter->output_name);
1794  avfilter_get_by_name("aformat"),
1795  name, args.str, NULL, graph);
1796  if (ret < 0)
1797  goto fail;
1798 
1799  ret = avfilter_link(last_filter, pad_idx, format, 0);
1800  if (ret < 0)
1801  goto fail;
1802 
1803  last_filter = format;
1804  pad_idx = 0;
1805  }
1806 
1807  if (ofilter->apad)
1808  AUTO_INSERT_FILTER("-apad", "apad", ofilter->apad);
1809 
1810  snprintf(name, sizeof(name), "trim for output %s", ofilter->output_name);
1811  ret = insert_trim(fgp, ofp->trim_start_us, ofp->trim_duration_us,
1812  &last_filter, &pad_idx, name);
1813  if (ret < 0)
1814  goto fail;
1815 
1816  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
1817  goto fail;
1818 fail:
1819  av_bprint_finalize(&args, NULL);
1820 
1821  return ret;
1822 }
1823 
1825  OutputFilter *ofilter, AVFilterInOut *out)
1826 {
1827  switch (ofilter->type) {
1828  case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fgp, graph, ofilter, out);
1829  case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fgp, graph, ofilter, out);
1830  default: av_assert0(0); return 0;
1831  }
1832 }
1833 
1835 {
1836  ifp->sub2video.last_pts = INT64_MIN;
1837  ifp->sub2video.end_pts = INT64_MIN;
1838 
1839  /* sub2video structure has been (re-)initialized.
1840  Mark it as such so that the system will be
1841  initialized with the first received heartbeat. */
1842  ifp->sub2video.initialize = 1;
1843 }
1844 
1846  InputFilter *ifilter, AVFilterInOut *in)
1847 {
1848  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
1849 
1850  AVFilterContext *last_filter;
1851  const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
1852  const AVPixFmtDescriptor *desc;
1853  char name[255];
1854  int ret, pad_idx = 0;
1856  if (!par)
1857  return AVERROR(ENOMEM);
1858 
1859  if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE)
1860  sub2video_prepare(ifp);
1861 
1862  snprintf(name, sizeof(name), "graph %d input from stream %s", fg->index,
1863  ifp->opts.name);
1864 
1865  ifilter->filter = avfilter_graph_alloc_filter(graph, buffer_filt, name);
1866  if (!ifilter->filter) {
1867  ret = AVERROR(ENOMEM);
1868  goto fail;
1869  }
1870 
1871  par->format = ifp->format;
1872  par->time_base = ifp->time_base;
1873  par->frame_rate = ifp->opts.framerate;
1874  par->width = ifp->width;
1875  par->height = ifp->height;
1876  par->sample_aspect_ratio = ifp->sample_aspect_ratio.den > 0 ?
1877  ifp->sample_aspect_ratio : (AVRational){ 0, 1 };
1878  par->color_space = ifp->color_space;
1879  par->color_range = ifp->color_range;
1880  par->alpha_mode = ifp->alpha_mode;
1881  par->hw_frames_ctx = ifp->hw_frames_ctx;
1882  par->side_data = ifp->side_data;
1883  par->nb_side_data = ifp->nb_side_data;
1884 
1885  ret = av_buffersrc_parameters_set(ifilter->filter, par);
1886  if (ret < 0)
1887  goto fail;
1888  av_freep(&par);
1889 
1890  ret = avfilter_init_dict(ifilter->filter, NULL);
1891  if (ret < 0)
1892  goto fail;
1893 
1894  last_filter = ifilter->filter;
1895 
1897  av_assert0(desc);
1898 
1899  if ((ifp->opts.flags & IFILTER_FLAG_CROP)) {
1900  char crop_buf[64];
1901  snprintf(crop_buf, sizeof(crop_buf), "w=iw-%u-%u:h=ih-%u-%u:x=%u:y=%u",
1902  ifp->opts.crop_left, ifp->opts.crop_right,
1903  ifp->opts.crop_top, ifp->opts.crop_bottom,
1904  ifp->opts.crop_left, ifp->opts.crop_top);
1905  ret = insert_filter(&last_filter, &pad_idx, "crop", crop_buf);
1906  if (ret < 0)
1907  return ret;
1908  }
1909 
1910  // TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
1911  ifp->displaymatrix_applied = 0;
1912  if ((ifp->opts.flags & IFILTER_FLAG_AUTOROTATE) &&
1913  !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
1914  int32_t *displaymatrix = ifp->displaymatrix;
1915  double theta;
1916 
1917  theta = get_rotation(displaymatrix);
1918 
1919  if (fabs(theta - 90) < 1.0) {
1920  ret = insert_filter(&last_filter, &pad_idx, "transpose",
1921  displaymatrix[3] > 0 ? "cclock_flip" : "clock");
1922  } else if (fabs(theta - 180) < 1.0) {
1923  if (displaymatrix[0] < 0) {
1924  ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
1925  if (ret < 0)
1926  return ret;
1927  }
1928  if (displaymatrix[4] < 0) {
1929  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
1930  }
1931  } else if (fabs(theta - 270) < 1.0) {
1932  ret = insert_filter(&last_filter, &pad_idx, "transpose",
1933  displaymatrix[3] < 0 ? "clock_flip" : "cclock");
1934  } else if (fabs(theta) > 1.0) {
1935  char rotate_buf[64];
1936  snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
1937  ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf);
1938  } else if (fabs(theta) < 1.0) {
1939  if (displaymatrix && displaymatrix[4] < 0) {
1940  ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
1941  }
1942  }
1943  if (ret < 0)
1944  return ret;
1945 
1946  ifp->displaymatrix_applied = 1;
1947  }
1948 
1949  snprintf(name, sizeof(name), "trim_in_%s", ifp->opts.name);
1950  ret = insert_trim(fg, ifp->opts.trim_start_us, ifp->opts.trim_end_us,
1951  &last_filter, &pad_idx, name);
1952  if (ret < 0)
1953  return ret;
1954 
1955  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
1956  return ret;
1957  return 0;
1958 fail:
1959  av_freep(&par);
1960 
1961  return ret;
1962 }
1963 
1965  InputFilter *ifilter, AVFilterInOut *in)
1966 {
1967  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
1968  AVFilterContext *last_filter;
1969  AVBufferSrcParameters *par;
1970  const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
1971  AVBPrint args;
1972  char name[255];
1973  int ret, pad_idx = 0;
1974 
1976  av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
1977  ifp->time_base.num, ifp->time_base.den,
1978  ifp->sample_rate,
1980  if (av_channel_layout_check(&ifp->ch_layout) &&
1982  av_bprintf(&args, ":channel_layout=");
1984  } else
1985  av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels);
1986  snprintf(name, sizeof(name), "graph_%d_in_%s", fg->index, ifp->opts.name);
1987 
1988  if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
1989  name, args.str, NULL,
1990  graph)) < 0)
1991  return ret;
1993  if (!par)
1994  return AVERROR(ENOMEM);
1995  par->side_data = ifp->side_data;
1996  par->nb_side_data = ifp->nb_side_data;
1997  ret = av_buffersrc_parameters_set(ifilter->filter, par);
1998  av_free(par);
1999  if (ret < 0)
2000  return ret;
2001  last_filter = ifilter->filter;
2002 
2003  snprintf(name, sizeof(name), "trim for input stream %s", ifp->opts.name);
2004  ret = insert_trim(fg, ifp->opts.trim_start_us, ifp->opts.trim_end_us,
2005  &last_filter, &pad_idx, name);
2006  if (ret < 0)
2007  return ret;
2008 
2009  if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
2010  return ret;
2011 
2012  return 0;
2013 }
2014 
2016  InputFilter *ifilter, AVFilterInOut *in)
2017 {
2018  switch (ifilter->type) {
2019  case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, graph, ifilter, in);
2020  case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, graph, ifilter, in);
2021  default: av_assert0(0); return 0;
2022  }
2023 }
2024 
2026 {
2027  for (int i = 0; i < fg->nb_outputs; i++)
2028  fg->outputs[i]->filter = NULL;
2029  for (int i = 0; i < fg->nb_inputs; i++)
2030  fg->inputs[i]->filter = NULL;
2031  avfilter_graph_free(&fgt->graph);
2032 }
2033 
2035 {
2036  return f->nb_inputs == 0 &&
2037  (!strcmp(f->filter->name, "buffer") ||
2038  !strcmp(f->filter->name, "abuffer"));
2039 }
2040 
2041 static int graph_is_meta(AVFilterGraph *graph)
2042 {
2043  for (unsigned i = 0; i < graph->nb_filters; i++) {
2044  const AVFilterContext *f = graph->filters[i];
2045 
2046  /* in addition to filters flagged as meta, also
2047  * disregard sinks and buffersources (but not other sources,
2048  * since they introduce data we are not aware of)
2049  */
2050  if (!((f->filter->flags & AVFILTER_FLAG_METADATA_ONLY) ||
2051  f->nb_outputs == 0 ||
2053  return 0;
2054  }
2055  return 1;
2056 }
2057 
2058 static int sub2video_frame(InputFilter *ifilter, AVFrame *frame, int buffer);
2059 
2061 {
2062  FilterGraphPriv *fgp = fgp_from_fg(fg);
2063  AVBufferRef *hw_device;
2064  AVFilterInOut *inputs, *outputs, *cur;
2065  int ret = AVERROR_BUG, i, simple = filtergraph_is_simple(fg);
2066  int have_input_eof = 0;
2067  const char *graph_desc = fg->graph_desc;
2068 
2069  cleanup_filtergraph(fg, fgt);
2070  fgt->graph = avfilter_graph_alloc();
2071  if (!fgt->graph)
2072  return AVERROR(ENOMEM);
2073 
2074  if (simple) {
2075  OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[0]);
2076 
2077  if (filter_nbthreads) {
2078  ret = av_opt_set(fgt->graph, "threads", filter_nbthreads, 0);
2079  if (ret < 0)
2080  goto fail;
2081  } else if (fgp->nb_threads >= 0) {
2082  ret = av_opt_set_int(fgt->graph, "threads", fgp->nb_threads, 0);
2083  if (ret < 0)
2084  return ret;
2085  }
2086 
2087  if (av_dict_count(ofp->sws_opts)) {
2089  &fgt->graph->scale_sws_opts,
2090  '=', ':');
2091  if (ret < 0)
2092  goto fail;
2093  }
2094 
2095  if (av_dict_count(ofp->swr_opts)) {
2096  char *args;
2097  ret = av_dict_get_string(ofp->swr_opts, &args, '=', ':');
2098  if (ret < 0)
2099  goto fail;
2100  av_opt_set(fgt->graph, "aresample_swr_opts", args, 0);
2101  av_free(args);
2102  }
2103  } else {
2105  }
2106 
2107  if (filter_buffered_frames) {
2108  ret = av_opt_set_int(fgt->graph, "max_buffered_frames", filter_buffered_frames, 0);
2109  if (ret < 0)
2110  return ret;
2111  }
2112 
2113  hw_device = hw_device_for_filter();
2114 
2115  ret = graph_parse(fg, fgt->graph, graph_desc, &inputs, &outputs, hw_device);
2116  if (ret < 0)
2117  goto fail;
2118 
2119  for (cur = inputs, i = 0; cur; cur = cur->next, i++)
2120  if ((ret = configure_input_filter(fg, fgt->graph, fg->inputs[i], cur)) < 0) {
2123  goto fail;
2124  }
2126 
2127  for (cur = outputs, i = 0; cur; cur = cur->next, i++) {
2128  ret = configure_output_filter(fgp, fgt->graph, fg->outputs[i], cur);
2129  if (ret < 0) {
2131  goto fail;
2132  }
2133  }
2135 
2136  if (fgp->disable_conversions)
2138  if ((ret = avfilter_graph_config(fgt->graph, NULL)) < 0)
2139  goto fail;
2140 
2141  fgp->is_meta = graph_is_meta(fgt->graph);
2142 
2143  /* limit the lists of allowed formats to the ones selected, to
2144  * make sure they stay the same if the filtergraph is reconfigured later */
2145  for (int i = 0; i < fg->nb_outputs; i++) {
2146  const AVFrameSideData *const *sd;
2147  int nb_sd;
2148  OutputFilter *ofilter = fg->outputs[i];
2149  OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
2150  AVFilterContext *sink = ofilter->filter;
2151 
2152  ofp->format = av_buffersink_get_format(sink);
2153 
2154  ofp->width = av_buffersink_get_w(sink);
2155  ofp->height = av_buffersink_get_h(sink);
2159 
2160  // If the timing parameters are not locked yet, get the tentative values
2161  // here but don't lock them. They will only be used if no output frames
2162  // are ever produced.
2163  if (!ofp->tb_out_locked) {
2165  if (ofp->fps.framerate.num <= 0 && ofp->fps.framerate.den <= 0 &&
2166  fr.num > 0 && fr.den > 0)
2167  ofp->fps.framerate = fr;
2168  ofp->tb_out = av_buffersink_get_time_base(sink);
2169  }
2171 
2174  ret = av_buffersink_get_ch_layout(sink, &ofp->ch_layout);
2175  if (ret < 0)
2176  goto fail;
2177  sd = av_buffersink_get_side_data(sink, &nb_sd);
2178  if (nb_sd)
2179  for (int j = 0; j < nb_sd; j++) {
2182  if (ret < 0) {
2184  goto fail;
2185  }
2186  }
2187  }
2188 
2189  for (int i = 0; i < fg->nb_inputs; i++) {
2190  InputFilter *ifilter = fg->inputs[i];
2192  AVFrame *tmp;
2193  while (av_fifo_read(ifp->frame_queue, &tmp, 1) >= 0) {
2194  if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) {
2195  sub2video_frame(&ifp->ifilter, tmp, !fgt->graph);
2196  } else {
2197  if (ifp->type_src == AVMEDIA_TYPE_VIDEO) {
2198  if (ifp->displaymatrix_applied)
2200  }
2201  ret = av_buffersrc_add_frame(ifilter->filter, tmp);
2202  }
2203  av_frame_free(&tmp);
2204  if (ret < 0)
2205  goto fail;
2206  }
2207  }
2208 
2209  /* send the EOFs for the finished inputs */
2210  for (int i = 0; i < fg->nb_inputs; i++) {
2211  InputFilter *ifilter = fg->inputs[i];
2212  if (fgt->eof_in[i]) {
2213  ret = av_buffersrc_add_frame(ifilter->filter, NULL);
2214  if (ret < 0)
2215  goto fail;
2216  have_input_eof = 1;
2217  }
2218  }
2219 
2220  if (have_input_eof) {
2221  // make sure the EOF propagates to the end of the graph
2223  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
2224  goto fail;
2225  }
2226 
2227  return 0;
2228 fail:
2229  cleanup_filtergraph(fg, fgt);
2230  return ret;
2231 }
2232 
2234 {
2235  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
2236  AVFrameSideData *sd;
2237  int ret;
2238 
2239  ret = av_buffer_replace(&ifp->hw_frames_ctx, frame->hw_frames_ctx);
2240  if (ret < 0)
2241  return ret;
2242 
2243  ifp->time_base = (ifilter->type == AVMEDIA_TYPE_AUDIO) ? (AVRational){ 1, frame->sample_rate } :
2244  (ifp->opts.flags & IFILTER_FLAG_CFR) ? av_inv_q(ifp->opts.framerate) :
2245  frame->time_base;
2246 
2247  ifp->format = frame->format;
2248 
2249  ifp->width = frame->width;
2250  ifp->height = frame->height;
2251  ifp->sample_aspect_ratio = frame->sample_aspect_ratio;
2252  ifp->color_space = frame->colorspace;
2253  ifp->color_range = frame->color_range;
2254  ifp->alpha_mode = frame->alpha_mode;
2255 
2256  ifp->sample_rate = frame->sample_rate;
2257  ret = av_channel_layout_copy(&ifp->ch_layout, &frame->ch_layout);
2258  if (ret < 0)
2259  return ret;
2260 
2262  for (int i = 0; i < frame->nb_side_data; i++) {
2263  const AVSideDataDescriptor *desc = av_frame_side_data_desc(frame->side_data[i]->type);
2264 
2265  if (!(desc->props & AV_SIDE_DATA_PROP_GLOBAL))
2266  continue;
2267 
2269  &ifp->nb_side_data,
2270  frame->side_data[i], 0);
2271  if (ret < 0)
2272  return ret;
2273  }
2274 
2276  if (sd) {
2277  memcpy(ifp->displaymatrix, sd->data, sizeof(ifp->displaymatrix));
2278  if (ifp->opts.flags & IFILTER_FLAG_AUTOROTATE)
2280  }
2281  ifp->displaymatrix_present = !!sd;
2282 
2283  /* Copy downmix related side data to InputFilterPriv so it may be propagated
2284  * to the filter chain even though it's not "global", as filters like aresample
2285  * require this information during init and not when remixing a frame */
2287  if (sd) {
2289  &ifp->nb_side_data, sd, 0);
2290  if (ret < 0)
2291  return ret;
2292  memcpy(&ifp->downmixinfo, sd->data, sizeof(ifp->downmixinfo));
2293  }
2294  ifp->downmixinfo_present = !!sd;
2296  if (sd) {
2298  &ifp->nb_side_data, sd, 0);
2299  if (ret < 0)
2300  return ret;
2301  ret = av_buffer_replace(&ifp->downmixmatrix, sd->buf);
2302  if (ret < 0)
2303  return ret;
2304  ifp->downmixmatrix_size = sd->size;
2305  }
2306  ifp->downmixmatrix_present = !!sd;
2307 
2308  return 0;
2309 }
2310 
2312 {
2313  const OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
2314  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
2315 
2316  if (!ifp->opts.framerate.num) {
2317  ifp->opts.framerate = ofp->fps.framerate;
2318  if (ifp->opts.framerate.num > 0 && ifp->opts.framerate.den > 0)
2319  ifp->opts.flags |= IFILTER_FLAG_CFR;
2320  }
2321 
2322  for (int i = 0; i < ofp->nb_side_data; i++) {
2325  if (ret < 0)
2326  return ret;
2327  }
2328 
2329  return 0;
2330 }
2331 
2333 {
2334  const FilterGraphPriv *fgp = cfgp_from_cfg(fg);
2335  return fgp->is_simple;
2336 }
2337 
2338 static void send_command(FilterGraph *fg, AVFilterGraph *graph,
2339  double time, const char *target,
2340  const char *command, const char *arg, int all_filters)
2341 {
2342  int ret;
2343 
2344  if (!graph)
2345  return;
2346 
2347  if (time < 0) {
2348  char response[4096];
2349  ret = avfilter_graph_send_command(graph, target, command, arg,
2350  response, sizeof(response),
2351  all_filters ? 0 : AVFILTER_CMD_FLAG_ONE);
2352  fprintf(stderr, "Command reply for stream %d: ret:%d res:\n%s",
2353  fg->index, ret, response);
2354  } else if (!all_filters) {
2355  fprintf(stderr, "Queuing commands only on filters supporting the specific command is unsupported\n");
2356  } else {
2357  ret = avfilter_graph_queue_command(graph, target, command, arg, 0, time);
2358  if (ret < 0)
2359  fprintf(stderr, "Queuing command failed with error %s\n", av_err2str(ret));
2360  }
2361 }
2362 
2363 static int choose_input(const FilterGraph *fg, const FilterGraphThread *fgt)
2364 {
2365  int nb_requests, nb_requests_max = -1;
2366  int best_input = -1;
2367 
2368  for (int i = 0; i < fg->nb_inputs; i++) {
2369  InputFilter *ifilter = fg->inputs[i];
2370 
2371  if (fgt->eof_in[i])
2372  continue;
2373 
2374  nb_requests = av_buffersrc_get_nb_failed_requests(ifilter->filter);
2375  if (nb_requests > nb_requests_max) {
2376  nb_requests_max = nb_requests;
2377  best_input = i;
2378  }
2379  }
2380 
2381  av_assert0(best_input >= 0);
2382 
2383  return best_input;
2384 }
2385 
2387 {
2388  OutputFilter *ofilter = &ofp->ofilter;
2389  FPSConvContext *fps = &ofp->fps;
2390  AVRational tb = (AVRational){ 0, 0 };
2391  AVRational fr;
2392  const FrameData *fd;
2393 
2394  fd = frame_data_c(frame);
2395 
2396  // apply -enc_time_base
2397  if (ofp->enc_timebase.num == ENC_TIME_BASE_DEMUX &&
2398  (fd->dec.tb.num <= 0 || fd->dec.tb.den <= 0)) {
2399  av_log(ofp, AV_LOG_ERROR,
2400  "Demuxing timebase not available - cannot use it for encoding\n");
2401  return AVERROR(EINVAL);
2402  }
2403 
2404  switch (ofp->enc_timebase.num) {
2405  case 0: break;
2406  case ENC_TIME_BASE_DEMUX: tb = fd->dec.tb; break;
2407  case ENC_TIME_BASE_FILTER: tb = frame->time_base; break;
2408  default: tb = ofp->enc_timebase; break;
2409  }
2410 
2411  if (ofilter->type == AVMEDIA_TYPE_AUDIO) {
2412  tb = tb.num ? tb : (AVRational){ 1, frame->sample_rate };
2413  goto finish;
2414  }
2415 
2416  fr = fps->framerate;
2417  if (!fr.num) {
2418  AVRational fr_sink = av_buffersink_get_frame_rate(ofilter->filter);
2419  if (fr_sink.num > 0 && fr_sink.den > 0)
2420  fr = fr_sink;
2421  }
2422 
2423  if (fps->vsync_method == VSYNC_CFR || fps->vsync_method == VSYNC_VSCFR) {
2424  if (!fr.num && !fps->framerate_max.num) {
2425  fr = (AVRational){25, 1};
2426  av_log(ofp, AV_LOG_WARNING,
2427  "No information "
2428  "about the input framerate is available. Falling "
2429  "back to a default value of 25fps. Use the -r option "
2430  "if you want a different framerate.\n");
2431  }
2432 
2433  if (fps->framerate_max.num &&
2434  (av_q2d(fr) > av_q2d(fps->framerate_max) ||
2435  !fr.den))
2436  fr = fps->framerate_max;
2437  }
2438 
2439  if (fr.num > 0) {
2440  if (fps->framerate_supported) {
2441  int idx = av_find_nearest_q_idx(fr, fps->framerate_supported);
2442  fr = fps->framerate_supported[idx];
2443  }
2444  if (fps->framerate_clip) {
2445  av_reduce(&fr.num, &fr.den,
2446  fr.num, fr.den, fps->framerate_clip);
2447  }
2448  }
2449 
2450  if (!(tb.num > 0 && tb.den > 0))
2451  tb = av_inv_q(fr);
2452  if (!(tb.num > 0 && tb.den > 0))
2453  tb = frame->time_base;
2454 
2455  fps->framerate = fr;
2456 finish:
2457  ofp->tb_out = tb;
2458  ofp->tb_out_locked = 1;
2459 
2460  return 0;
2461 }
2462 
2463 static double adjust_frame_pts_to_encoder_tb(void *logctx, AVFrame *frame,
2464  AVRational tb_dst, int64_t start_time)
2465 {
2466  double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision
2467 
2468  AVRational tb = tb_dst;
2469  AVRational filter_tb = frame->time_base;
2470  const int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
2471 
2472  if (frame->pts == AV_NOPTS_VALUE)
2473  goto early_exit;
2474 
2475  tb.den <<= extra_bits;
2476  float_pts = av_rescale_q(frame->pts, filter_tb, tb) -
2478  float_pts /= 1 << extra_bits;
2479  // when float_pts is not exactly an integer,
2480  // avoid exact midpoints to reduce the chance of rounding differences, this
2481  // can be removed in case the fps code is changed to work with integers
2482  if (float_pts != llrint(float_pts))
2483  float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
2484 
2485  frame->pts = av_rescale_q(frame->pts, filter_tb, tb_dst) -
2487  frame->time_base = tb_dst;
2488 
2489 early_exit:
2490 
2491  if (debug_ts) {
2492  av_log(logctx, AV_LOG_INFO,
2493  "filter -> pts:%s pts_time:%s exact:%f time_base:%d/%d\n",
2494  frame ? av_ts2str(frame->pts) : "NULL",
2495  av_ts2timestr(frame->pts, &tb_dst),
2496  float_pts, tb_dst.num, tb_dst.den);
2497  }
2498 
2499  return float_pts;
2500 }
2501 
2503 {
2504  int64_t max2, min2, m;
2505 
2506  if (a >= b) {
2507  max2 = a;
2508  min2 = b;
2509  } else {
2510  max2 = b;
2511  min2 = a;
2512  }
2513  m = (c >= max2) ? max2 : c;
2514 
2515  return (m >= min2) ? m : min2;
2516 }
2517 
2518 
2519 /* Convert frame timestamps to the encoder timebase and decide how many times
2520  * should this (and possibly previous) frame be repeated in order to conform to
2521  * desired target framerate (if any).
2522  */
2524  int64_t *nb_frames, int64_t *nb_frames_prev)
2525 {
2526  OutputFilter *ofilter = &ofp->ofilter;
2527  FPSConvContext *fps = &ofp->fps;
2528  double delta0, delta, sync_ipts, duration;
2529 
2530  if (!frame) {
2531  *nb_frames_prev = *nb_frames = median3(fps->frames_prev_hist[0],
2532  fps->frames_prev_hist[1],
2533  fps->frames_prev_hist[2]);
2534 
2535  if (!*nb_frames && fps->last_dropped) {
2536  atomic_fetch_add(&ofilter->nb_frames_drop, 1);
2537  fps->last_dropped++;
2538  }
2539 
2540  goto finish;
2541  }
2542 
2543  duration = frame->duration * av_q2d(frame->time_base) / av_q2d(ofp->tb_out);
2544 
2545  sync_ipts = adjust_frame_pts_to_encoder_tb(ofilter->graph, frame,
2546  ofp->tb_out, ofp->ts_offset);
2547  /* delta0 is the "drift" between the input frame and
2548  * where it would fall in the output. */
2549  delta0 = sync_ipts - ofp->next_pts;
2550  delta = delta0 + duration;
2551 
2552  // tracks the number of times the PREVIOUS frame should be duplicated,
2553  // mostly for variable framerate (VFR)
2554  *nb_frames_prev = 0;
2555  /* by default, we output a single frame */
2556  *nb_frames = 1;
2557 
2558  if (delta0 < 0 &&
2559  delta > 0 &&
2560  fps->vsync_method != VSYNC_PASSTHROUGH) {
2561  if (delta0 < -0.6) {
2562  av_log(ofp, AV_LOG_VERBOSE, "Past duration %f too large\n", -delta0);
2563  } else
2564  av_log(ofp, AV_LOG_DEBUG, "Clipping frame in rate conversion by %f\n", -delta0);
2565  sync_ipts = ofp->next_pts;
2566  duration += delta0;
2567  delta0 = 0;
2568  }
2569 
2570  switch (fps->vsync_method) {
2571  case VSYNC_VSCFR:
2572  if (fps->frame_number == 0 && delta0 >= 0.5) {
2573  av_log(ofp, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0));
2574  delta = duration;
2575  delta0 = 0;
2576  ofp->next_pts = llrint(sync_ipts);
2577  }
2579  case VSYNC_CFR:
2580  // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
2581  if (frame_drop_threshold && delta < frame_drop_threshold && fps->frame_number) {
2582  *nb_frames = 0;
2583  } else if (delta < -1.1)
2584  *nb_frames = 0;
2585  else if (delta > 1.1) {
2586  *nb_frames = llrintf(delta);
2587  if (delta0 > 1.1)
2588  *nb_frames_prev = llrintf(delta0 - 0.6);
2589  }
2590  frame->duration = 1;
2591  break;
2592  case VSYNC_VFR:
2593  if (delta <= -0.6)
2594  *nb_frames = 0;
2595  else if (delta > 0.6)
2596  ofp->next_pts = llrint(sync_ipts);
2597  frame->duration = llrint(duration);
2598  break;
2599  case VSYNC_PASSTHROUGH:
2600  ofp->next_pts = llrint(sync_ipts);
2601  frame->duration = llrint(duration);
2602  break;
2603  default:
2604  av_assert0(0);
2605  }
2606 
2607 finish:
2608  memmove(fps->frames_prev_hist + 1,
2609  fps->frames_prev_hist,
2610  sizeof(fps->frames_prev_hist[0]) * (FF_ARRAY_ELEMS(fps->frames_prev_hist) - 1));
2611  fps->frames_prev_hist[0] = *nb_frames_prev;
2612 
2613  if (*nb_frames_prev == 0 && fps->last_dropped) {
2614  atomic_fetch_add(&ofilter->nb_frames_drop, 1);
2615  av_log(ofp, AV_LOG_VERBOSE,
2616  "*** dropping frame %"PRId64" at ts %"PRId64"\n",
2617  fps->frame_number, fps->last_frame->pts);
2618  }
2619  if (*nb_frames > (*nb_frames_prev && fps->last_dropped) + (*nb_frames > *nb_frames_prev)) {
2620  uint64_t nb_frames_dup;
2621  if (*nb_frames > dts_error_threshold * 30) {
2622  av_log(ofp, AV_LOG_ERROR, "%"PRId64" frame duplication too large, skipping\n", *nb_frames - 1);
2623  atomic_fetch_add(&ofilter->nb_frames_drop, 1);
2624  *nb_frames = 0;
2625  return;
2626  }
2627  nb_frames_dup = atomic_fetch_add(&ofilter->nb_frames_dup,
2628  *nb_frames - (*nb_frames_prev && fps->last_dropped) - (*nb_frames > *nb_frames_prev));
2629  av_log(ofp, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", *nb_frames - 1);
2630  if (nb_frames_dup > fps->dup_warning) {
2631  av_log(ofp, AV_LOG_WARNING, "More than %"PRIu64" frames duplicated\n", fps->dup_warning);
2632  fps->dup_warning *= 10;
2633  }
2634  }
2635 
2636  fps->last_dropped = *nb_frames == *nb_frames_prev && frame;
2637  fps->dropped_keyframe |= fps->last_dropped && (frame->flags & AV_FRAME_FLAG_KEY);
2638 }
2639 
2640 static void close_input(InputFilterPriv *ifp)
2641 {
2643 
2644  if (!ifp->eof) {
2646  ifp->eof = 1;
2647  }
2648 }
2649 
2651 {
2653  int ret;
2654 
2655  // we are finished and no frames were ever seen at this output,
2656  // at least initialize the encoder with a dummy frame
2657  if (!fgt->got_frame) {
2658  AVFrame *frame = fgt->frame;
2659  FrameData *fd;
2660 
2661  frame->time_base = ofp->tb_out;
2662  frame->format = ofp->format;
2663 
2664  frame->width = ofp->width;
2665  frame->height = ofp->height;
2666  frame->sample_aspect_ratio = ofp->sample_aspect_ratio;
2667 
2668  frame->sample_rate = ofp->sample_rate;
2669  if (ofp->ch_layout.nb_channels) {
2670  ret = av_channel_layout_copy(&frame->ch_layout, &ofp->ch_layout);
2671  if (ret < 0)
2672  return ret;
2673  }
2674 
2675  fd = frame_data(frame);
2676  if (!fd)
2677  return AVERROR(ENOMEM);
2678 
2681  ofp->side_data, ofp->nb_side_data, 0);
2682  if (ret < 0)
2683  return ret;
2684 
2685  fd->frame_rate_filter = ofp->fps.framerate;
2686 
2687  av_assert0(!frame->buf[0]);
2688 
2689  av_log(ofp, AV_LOG_WARNING,
2690  "No filtered frames for output stream, trying to "
2691  "initialize anyway.\n");
2692 
2693  ret = sch_filter_send(fgp->sch, fgp->sch_idx, ofp->ofilter.index, frame);
2694  if (ret < 0) {
2696  return ret;
2697  }
2698  }
2699 
2700  fgt->eof_out[ofp->ofilter.index] = 1;
2701 
2702  ret = sch_filter_send(fgp->sch, fgp->sch_idx, ofp->ofilter.index, NULL);
2703  return (ret == AVERROR_EOF) ? 0 : ret;
2704 }
2705 
2707  AVFrame *frame)
2708 {
2710  AVFrame *frame_prev = ofp->fps.last_frame;
2711  enum AVMediaType type = ofp->ofilter.type;
2712 
2713  int64_t nb_frames = !!frame, nb_frames_prev = 0;
2714 
2715  if (type == AVMEDIA_TYPE_VIDEO && (frame || fgt->got_frame))
2716  video_sync_process(ofp, frame, &nb_frames, &nb_frames_prev);
2717 
2718  for (int64_t i = 0; i < nb_frames; i++) {
2719  AVFrame *frame_out;
2720  int ret;
2721 
2722  if (type == AVMEDIA_TYPE_VIDEO) {
2723  AVFrame *frame_in = (i < nb_frames_prev && frame_prev->buf[0]) ?
2724  frame_prev : frame;
2725  if (!frame_in)
2726  break;
2727 
2728  frame_out = fgp->frame_enc;
2729  ret = av_frame_ref(frame_out, frame_in);
2730  if (ret < 0)
2731  return ret;
2732 
2733  frame_out->pts = ofp->next_pts;
2734 
2735  if (ofp->fps.dropped_keyframe) {
2736  frame_out->flags |= AV_FRAME_FLAG_KEY;
2737  ofp->fps.dropped_keyframe = 0;
2738  }
2739  } else {
2740  frame->pts = (frame->pts == AV_NOPTS_VALUE) ? ofp->next_pts :
2741  av_rescale_q(frame->pts, frame->time_base, ofp->tb_out) -
2743 
2744  frame->time_base = ofp->tb_out;
2745  frame->duration = av_rescale_q(frame->nb_samples,
2746  (AVRational){ 1, frame->sample_rate },
2747  ofp->tb_out);
2748 
2749  ofp->next_pts = frame->pts + frame->duration;
2750 
2751  frame_out = frame;
2752  }
2753 
2754  // send the frame to consumers
2755  ret = sch_filter_send(fgp->sch, fgp->sch_idx, ofp->ofilter.index, frame_out);
2756  if (ret < 0) {
2757  av_frame_unref(frame_out);
2758 
2759  if (!fgt->eof_out[ofp->ofilter.index]) {
2760  fgt->eof_out[ofp->ofilter.index] = 1;
2761  fgp->nb_outputs_done++;
2762  }
2763 
2764  return ret == AVERROR_EOF ? 0 : ret;
2765  }
2766 
2767  if (type == AVMEDIA_TYPE_VIDEO) {
2768  ofp->fps.frame_number++;
2769  ofp->next_pts++;
2770 
2771  if (i == nb_frames_prev && frame)
2772  frame->flags &= ~AV_FRAME_FLAG_KEY;
2773  }
2774 
2775  fgt->got_frame = 1;
2776  }
2777 
2778  if (frame && frame_prev) {
2779  av_frame_unref(frame_prev);
2780  av_frame_move_ref(frame_prev, frame);
2781  }
2782 
2783  if (!frame)
2784  return close_output(ofp, fgt);
2785 
2786  return 0;
2787 }
2788 
2790  AVFrame *frame)
2791 {
2794  FrameData *fd;
2795  int ret;
2796 
2799  if (ret == AVERROR_EOF && !fgt->eof_out[ofp->ofilter.index]) {
2800  ret = fg_output_frame(ofp, fgt, NULL);
2801  return (ret < 0) ? ret : 1;
2802  } else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
2803  return 1;
2804  } else if (ret < 0) {
2805  av_log(ofp, AV_LOG_WARNING,
2806  "Error in retrieving a frame from the filtergraph: %s\n",
2807  av_err2str(ret));
2808  return ret;
2809  }
2810 
2811  if (fgt->eof_out[ofp->ofilter.index]) {
2813  return 0;
2814  }
2815 
2817 
2818  if (debug_ts)
2819  av_log(ofp, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n",
2820  av_ts2str(frame->pts), av_ts2timestr(frame->pts, &frame->time_base),
2821  frame->time_base.num, frame->time_base.den);
2822 
2823  // Choose the output timebase the first time we get a frame.
2824  if (!ofp->tb_out_locked) {
2825  ret = choose_out_timebase(ofp, frame);
2826  if (ret < 0) {
2827  av_log(ofp, AV_LOG_ERROR, "Could not choose an output time base\n");
2829  return ret;
2830  }
2831  }
2832 
2833  fd = frame_data(frame);
2834  if (!fd) {
2836  return AVERROR(ENOMEM);
2837  }
2838 
2840  if (!fgt->got_frame) {
2842  ofp->side_data, ofp->nb_side_data, 0);
2843  if (ret < 0) {
2845  return ret;
2846  }
2847  }
2848 
2850 
2851  // only use bits_per_raw_sample passed through from the decoder
2852  // if the filtergraph did not touch the frame data
2853  if (!fgp->is_meta)
2854  fd->bits_per_raw_sample = 0;
2855 
2856  if (ofp->ofilter.type == AVMEDIA_TYPE_VIDEO) {
2857  if (!frame->duration) {
2859  if (fr.num > 0 && fr.den > 0)
2860  frame->duration = av_rescale_q(1, av_inv_q(fr), frame->time_base);
2861  }
2862 
2863  fd->frame_rate_filter = ofp->fps.framerate;
2864  }
2865 
2866  ret = fg_output_frame(ofp, fgt, frame);
2868  if (ret < 0)
2869  return ret;
2870 
2871  return 0;
2872 }
2873 
2874 /* retrieve all frames available at filtergraph outputs
2875  * and send them to consumers */
2877  AVFrame *frame)
2878 {
2879  FilterGraphPriv *fgp = fgp_from_fg(fg);
2880 
2881  // graph not configured, just select the input to request
2882  if (!fgt->graph) {
2883  for (int i = 0; i < fg->nb_inputs; i++) {
2885  if (ifp->format < 0 && !fgt->eof_in[i]) {
2886  fgt->next_in = i;
2887  return 0;
2888  }
2889  }
2890 
2891  // This state - graph is not configured, but all inputs are either
2892  // initialized or EOF - should be unreachable because sending EOF to a
2893  // filter without even a fallback format should fail
2894  av_assert0(0);
2895  return AVERROR_BUG;
2896  }
2897 
2898  if (fgp->nb_outputs_done < fg->nb_outputs) {
2899  int ret;
2900 
2901  /* Reap all buffers present in the buffer sinks */
2902  for (int i = 0; i < fg->nb_outputs; i++) {
2904 
2905  ret = 0;
2906  while (!ret) {
2907  ret = fg_output_step(ofp, fgt, frame);
2908  if (ret < 0)
2909  return ret;
2910  }
2911  }
2912 
2913 
2915  if (ret == AVERROR(EAGAIN)) {
2916  fgt->next_in = choose_input(fg, fgt);
2917  return 0;
2918  } else if (ret < 0) {
2919  if (ret == AVERROR_EOF)
2920  av_log(fg, AV_LOG_VERBOSE, "Filtergraph returned EOF, finishing\n");
2921  else
2922  av_log(fg, AV_LOG_ERROR,
2923  "Error requesting a frame from the filtergraph: %s\n",
2924  av_err2str(ret));
2925  return ret;
2926  }
2927  fgt->next_in = fg->nb_inputs;
2928 
2929  // return so that scheduler can rate-control us
2930  return 0;
2931  }
2932 
2933  return AVERROR_EOF;
2934 }
2935 
2937 {
2938  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
2939  int64_t pts2;
2940 
2941  /* subtitles seem to be usually muxed ahead of other streams;
2942  if not, subtracting a larger time here is necessary */
2943  pts2 = av_rescale_q(pts, tb, ifp->time_base) - 1;
2944 
2945  /* do not send the heartbeat frame if the subtitle is already ahead */
2946  if (pts2 <= ifp->sub2video.last_pts)
2947  return;
2948 
2949  if (pts2 >= ifp->sub2video.end_pts || ifp->sub2video.initialize)
2950  /* if we have hit the end of the current displayed subpicture,
2951  or if we need to initialize the system, update the
2952  overlaid subpicture and its start/end times */
2953  sub2video_update(ifp, pts2 + 1, NULL);
2954  else
2955  sub2video_push_ref(ifp, pts2);
2956 }
2957 
2958 static int sub2video_frame(InputFilter *ifilter, AVFrame *frame, int buffer)
2959 {
2960  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
2961  int ret;
2962 
2963  if (buffer) {
2964  AVFrame *tmp;
2965 
2966  if (!frame)
2967  return 0;
2968 
2969  tmp = av_frame_alloc();
2970  if (!tmp)
2971  return AVERROR(ENOMEM);
2972 
2974 
2975  ret = av_fifo_write(ifp->frame_queue, &tmp, 1);
2976  if (ret < 0) {
2977  av_frame_free(&tmp);
2978  return ret;
2979  }
2980 
2981  return 0;
2982  }
2983 
2984  // heartbeat frame
2985  if (frame && !frame->buf[0]) {
2986  sub2video_heartbeat(ifilter, frame->pts, frame->time_base);
2987  return 0;
2988  }
2989 
2990  if (!frame) {
2991  if (ifp->sub2video.end_pts < INT64_MAX)
2992  sub2video_update(ifp, INT64_MAX, NULL);
2993 
2994  return av_buffersrc_add_frame(ifilter->filter, NULL);
2995  }
2996 
2997  ifp->width = frame->width ? frame->width : ifp->width;
2998  ifp->height = frame->height ? frame->height : ifp->height;
2999 
3000  sub2video_update(ifp, INT64_MIN, (const AVSubtitle*)frame->buf[0]->data);
3001 
3002  return 0;
3003 }
3004 
3005 static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter,
3006  int64_t pts, AVRational tb)
3007 {
3008  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
3009  int ret;
3010 
3011  if (fgt->eof_in[ifilter->index])
3012  return 0;
3013 
3014  fgt->eof_in[ifilter->index] = 1;
3015 
3016  if (ifilter->filter) {
3017  pts = av_rescale_q_rnd(pts, tb, ifp->time_base,
3019 
3021  if (ret < 0)
3022  return ret;
3023  } else {
3024  if (ifp->format < 0) {
3025  // the filtergraph was never configured, use the fallback parameters
3026  ifp->format = ifp->opts.fallback->format;
3027  ifp->sample_rate = ifp->opts.fallback->sample_rate;
3028  ifp->width = ifp->opts.fallback->width;
3029  ifp->height = ifp->opts.fallback->height;
3031  ifp->color_space = ifp->opts.fallback->colorspace;
3032  ifp->color_range = ifp->opts.fallback->color_range;
3033  ifp->alpha_mode = ifp->opts.fallback->alpha_mode;
3034  ifp->time_base = ifp->opts.fallback->time_base;
3035 
3037  &ifp->opts.fallback->ch_layout);
3038  if (ret < 0)
3039  return ret;
3040 
3042  ret = clone_side_data(&ifp->side_data, &ifp->nb_side_data,
3043  ifp->opts.fallback->side_data,
3044  ifp->opts.fallback->nb_side_data, 0);
3045  if (ret < 0)
3046  return ret;
3047 
3048  if (ifilter_has_all_input_formats(ifilter->graph)) {
3049  ret = configure_filtergraph(ifilter->graph, fgt);
3050  if (ret < 0) {
3051  av_log(ifilter->graph, AV_LOG_ERROR, "Error initializing filters!\n");
3052  return ret;
3053  }
3054  }
3055  }
3056 
3057  if (ifp->format < 0) {
3058  av_log(ifilter->graph, AV_LOG_ERROR,
3059  "Cannot determine format of input %s after EOF\n",
3060  ifp->opts.name);
3061  return AVERROR_INVALIDDATA;
3062  }
3063  }
3064 
3065  return 0;
3066 }
3067 
3069  VIDEO_CHANGED = (1 << 0),
3070  AUDIO_CHANGED = (1 << 1),
3071  MATRIX_CHANGED = (1 << 2),
3072  DOWNMIX_CHANGED = (1 << 3),
3073  HWACCEL_CHANGED = (1 << 4)
3074 };
3075 
3076 static const char *unknown_if_null(const char *str)
3077 {
3078  return str ? str : "unknown";
3079 }
3080 
3082  InputFilter *ifilter, AVFrame *frame)
3083 {
3084  FilterGraphPriv *fgp = fgp_from_fg(fg);
3085  InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
3086  FrameData *fd;
3087  AVFrameSideData *sd;
3088  int need_reinit = 0, ret;
3089 
3090  /* determine if the parameters for this input changed */
3091  switch (ifilter->type) {
3092  case AVMEDIA_TYPE_AUDIO:
3093  if (ifp->format != frame->format ||
3094  ifp->sample_rate != frame->sample_rate ||
3095  av_channel_layout_compare(&ifp->ch_layout, &frame->ch_layout))
3096  need_reinit |= AUDIO_CHANGED;
3097  break;
3098  case AVMEDIA_TYPE_VIDEO:
3099  if (ifp->format != frame->format ||
3100  ifp->width != frame->width ||
3101  ifp->height != frame->height ||
3102  ifp->color_space != frame->colorspace ||
3103  ifp->color_range != frame->color_range ||
3104  ifp->alpha_mode != frame->alpha_mode)
3105  need_reinit |= VIDEO_CHANGED;
3106  break;
3107  }
3108 
3110  if (!ifp->displaymatrix_present ||
3111  memcmp(sd->data, ifp->displaymatrix, sizeof(ifp->displaymatrix)))
3112  need_reinit |= MATRIX_CHANGED;
3113  } else if (ifp->displaymatrix_present)
3114  need_reinit |= MATRIX_CHANGED;
3115 
3117  if (!ifp->downmixinfo_present ||
3118  memcmp(sd->data, &ifp->downmixinfo, sizeof(ifp->downmixinfo)))
3119  need_reinit |= DOWNMIX_CHANGED;
3120  } else if (ifp->downmixinfo_present)
3121  need_reinit |= DOWNMIX_CHANGED;
3122 
3124  if (!ifp->downmixmatrix_present ||
3125  sd->size != ifp->downmixmatrix_size || memcmp(sd->data, ifp->downmixmatrix->data, sd->size))
3126  need_reinit |= DOWNMIX_CHANGED;
3127  } else if (ifp->downmixmatrix_present)
3128  need_reinit |= DOWNMIX_CHANGED;
3129 
3130  if (need_reinit && fgt->graph && (ifp->opts.flags & IFILTER_FLAG_DROPCHANGED)) {
3131  ifp->nb_dropped++;
3132  av_log_once(fg, AV_LOG_WARNING, AV_LOG_DEBUG, &ifp->drop_warned, "Avoiding reinit; dropping frame pts: %s bound for %s\n", av_ts2str(frame->pts), ifilter->name);
3134  return 0;
3135  }
3136 
3137  if (!(ifp->opts.flags & IFILTER_FLAG_REINIT) && fgt->graph)
3138  need_reinit = 0;
3139 
3140  if (!!ifp->hw_frames_ctx != !!frame->hw_frames_ctx ||
3141  (ifp->hw_frames_ctx && ifp->hw_frames_ctx->data != frame->hw_frames_ctx->data))
3142  need_reinit |= HWACCEL_CHANGED;
3143 
3144  if (need_reinit) {
3146  if (ret < 0)
3147  return ret;
3148 
3149  /* Inputs bound to a filtergraph output will have some fields unset.
3150  * Handle them here */
3151  if (ifp->ofilter_src) {
3153  if (ret < 0)
3154  return ret;
3155  }
3156  }
3157 
3158  /* (re)init the graph if possible, otherwise buffer the frame and return */
3159  if (need_reinit || !fgt->graph) {
3160  AVFrame *tmp = av_frame_alloc();
3161 
3162  if (!tmp)
3163  return AVERROR(ENOMEM);
3164 
3165  if (!ifilter_has_all_input_formats(fg)) {
3167 
3168  ret = av_fifo_write(ifp->frame_queue, &tmp, 1);
3169  if (ret < 0)
3170  av_frame_free(&tmp);
3171 
3172  return ret;
3173  }
3174 
3175  ret = fgt->graph ? read_frames(fg, fgt, tmp) : 0;
3176  av_frame_free(&tmp);
3177  if (ret < 0)
3178  return ret;
3179 
3180  if (fgt->graph) {
3181  AVBPrint reason;
3183  if (need_reinit & AUDIO_CHANGED) {
3184  const char *sample_format_name = av_get_sample_fmt_name(frame->format);
3185  av_bprintf(&reason, "audio parameters changed to %d Hz, ", frame->sample_rate);
3186  av_channel_layout_describe_bprint(&frame->ch_layout, &reason);
3187  av_bprintf(&reason, ", %s, ", unknown_if_null(sample_format_name));
3188  }
3189  if (need_reinit & VIDEO_CHANGED) {
3190  const char *pixel_format_name = av_get_pix_fmt_name(frame->format);
3191  const char *color_space_name = av_color_space_name(frame->colorspace);
3192  const char *color_range_name = av_color_range_name(frame->color_range);
3193  const char *alpha_mode = av_alpha_mode_name(frame->alpha_mode);
3194  av_bprintf(&reason, "video parameters changed to %s(%s, %s), %dx%d, %s alpha, ",
3195  unknown_if_null(pixel_format_name), unknown_if_null(color_range_name),
3196  unknown_if_null(color_space_name), frame->width, frame->height,
3197  unknown_if_null(alpha_mode));
3198  }
3199  if (need_reinit & MATRIX_CHANGED)
3200  av_bprintf(&reason, "display matrix changed, ");
3201  if (need_reinit & DOWNMIX_CHANGED)
3202  av_bprintf(&reason, "downmix medatata changed, ");
3203  if (need_reinit & HWACCEL_CHANGED)
3204  av_bprintf(&reason, "hwaccel changed, ");
3205  if (reason.len > 1)
3206  reason.str[reason.len - 2] = '\0'; // remove last comma
3207  av_log(fg, AV_LOG_INFO, "Reconfiguring filter graph%s%s\n", reason.len ? " because " : "", reason.str);
3208  } else {
3209  /* Choke all input to avoid buffering excessive frames while the
3210  * initial filter graph is being configured, and before we have a
3211  * preferred input */
3212  sch_filter_choke_inputs(fgp->sch, fgp->sch_idx);
3213  }
3214 
3215  ret = configure_filtergraph(fg, fgt);
3216  if (ret < 0) {
3217  av_log(fg, AV_LOG_ERROR, "Error reinitializing filters!\n");
3218  return ret;
3219  }
3220  }
3221 
3222  frame->pts = av_rescale_q(frame->pts, frame->time_base, ifp->time_base);
3223  frame->duration = av_rescale_q(frame->duration, frame->time_base, ifp->time_base);
3224  frame->time_base = ifp->time_base;
3225 
3226  if (ifp->displaymatrix_applied)
3228 
3229  fd = frame_data(frame);
3230  if (!fd)
3231  return AVERROR(ENOMEM);
3233 
3236  if (ret < 0) {
3238  if (ret != AVERROR_EOF)
3239  av_log(fg, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
3240  return ret;
3241  }
3242 
3243  return 0;
3244 }
3245 
3246 static void fg_thread_set_name(const FilterGraph *fg)
3247 {
3248  char name[16];
3249  if (filtergraph_is_simple(fg)) {
3250  OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[0]);
3251  snprintf(name, sizeof(name), "%cf%s",
3253  ofp->ofilter.output_name);
3254  } else {
3255  snprintf(name, sizeof(name), "fc%d", fg->index);
3256  }
3257 
3259 }
3260 
3262 {
3263  if (fgt->frame_queue_out) {
3264  AVFrame *frame;
3265  while (av_fifo_read(fgt->frame_queue_out, &frame, 1) >= 0)
3266  av_frame_free(&frame);
3268  }
3269 
3270  av_frame_free(&fgt->frame);
3271  av_freep(&fgt->eof_in);
3272  av_freep(&fgt->eof_out);
3273 
3274  avfilter_graph_free(&fgt->graph);
3275 
3276  memset(fgt, 0, sizeof(*fgt));
3277 }
3278 
3279 static int fg_thread_init(FilterGraphThread *fgt, const FilterGraph *fg)
3280 {
3281  memset(fgt, 0, sizeof(*fgt));
3282 
3283  fgt->frame = av_frame_alloc();
3284  if (!fgt->frame)
3285  goto fail;
3286 
3287  fgt->eof_in = av_calloc(fg->nb_inputs, sizeof(*fgt->eof_in));
3288  if (!fgt->eof_in)
3289  goto fail;
3290 
3291  fgt->eof_out = av_calloc(fg->nb_outputs, sizeof(*fgt->eof_out));
3292  if (!fgt->eof_out)
3293  goto fail;
3294 
3296  if (!fgt->frame_queue_out)
3297  goto fail;
3298 
3299  return 0;
3300 
3301 fail:
3302  fg_thread_uninit(fgt);
3303  return AVERROR(ENOMEM);
3304 }
3305 
3306 static int filter_thread(void *arg)
3307 {
3308  FilterGraphPriv *fgp = arg;
3309  FilterGraph *fg = &fgp->fg;
3310 
3311  FilterGraphThread fgt;
3312  int ret = 0, input_status = 0;
3313 
3314  ret = fg_thread_init(&fgt, fg);
3315  if (ret < 0)
3316  goto finish;
3317 
3318  fg_thread_set_name(fg);
3319 
3320  // if we have all input parameters the graph can now be configured
3322  ret = configure_filtergraph(fg, &fgt);
3323  if (ret < 0) {
3324  av_log(fg, AV_LOG_ERROR, "Error configuring filter graph: %s\n",
3325  av_err2str(ret));
3326  goto finish;
3327  }
3328  }
3329 
3330  while (1) {
3331  InputFilter *ifilter;
3332  InputFilterPriv *ifp = NULL;
3333  enum FrameOpaque o;
3334  unsigned input_idx = fgt.next_in;
3335 
3336  input_status = sch_filter_receive(fgp->sch, fgp->sch_idx,
3337  &input_idx, fgt.frame);
3338  if (input_status == AVERROR_EOF) {
3339  av_log(fg, AV_LOG_VERBOSE, "Filtering thread received EOF\n");
3340  break;
3341  } else if (input_status == AVERROR(EAGAIN)) {
3342  // should only happen when we didn't request any input
3343  av_assert0(input_idx == fg->nb_inputs);
3344  goto read_frames;
3345  }
3346  av_assert0(input_status >= 0);
3347 
3348  o = (intptr_t)fgt.frame->opaque;
3349 
3350  // message on the control stream
3351  if (input_idx == fg->nb_inputs) {
3352  FilterCommand *fc;
3353 
3354  av_assert0(o == FRAME_OPAQUE_SEND_COMMAND && fgt.frame->buf[0]);
3355 
3356  fc = (FilterCommand*)fgt.frame->buf[0]->data;
3357  send_command(fg, fgt.graph, fc->time, fc->target, fc->command, fc->arg,
3358  fc->all_filters);
3359  av_frame_unref(fgt.frame);
3360  continue;
3361  }
3362 
3363  // we received an input frame or EOF
3364  ifilter = fg->inputs[input_idx];
3365  ifp = ifp_from_ifilter(ifilter);
3366 
3367  if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) {
3368  int hb_frame = input_status >= 0 && o == FRAME_OPAQUE_SUB_HEARTBEAT;
3369  ret = sub2video_frame(ifilter, (fgt.frame->buf[0] || hb_frame) ? fgt.frame : NULL,
3370  !fgt.graph);
3371  } else if (fgt.frame->buf[0]) {
3372  ret = send_frame(fg, &fgt, ifilter, fgt.frame);
3373  } else {
3375  ret = send_eof(&fgt, ifilter, fgt.frame->pts, fgt.frame->time_base);
3376  }
3377  av_frame_unref(fgt.frame);
3378  if (ret == AVERROR_EOF) {
3379  av_log(fg, AV_LOG_VERBOSE, "Input %u no longer accepts new data\n",
3380  input_idx);
3381  close_input(ifp);
3382  continue;
3383  }
3384  if (ret < 0)
3385  goto finish;
3386 
3387 read_frames:
3388  // retrieve all newly available frames
3389  ret = read_frames(fg, &fgt, fgt.frame);
3390  if (ret == AVERROR_EOF) {
3391  av_log(fg, AV_LOG_VERBOSE, "All consumers returned EOF\n");
3392  if (ifp && ifp->opts.flags & IFILTER_FLAG_DROPCHANGED)
3393  av_log(fg, AV_LOG_INFO, "Total changed input frames dropped : %"PRId64"\n", ifp->nb_dropped);
3394  break;
3395  } else if (ret < 0) {
3396  av_log(fg, AV_LOG_ERROR, "Error sending frames to consumers: %s\n",
3397  av_err2str(ret));
3398  goto finish;
3399  }
3400 
3401  // ensure all inputs no longer accepting data are closed
3402  for (int i = 0; fgt.graph && i < fg->nb_inputs; i++) {
3405  close_input(ifp);
3406  }
3407  }
3408 
3409  for (unsigned i = 0; i < fg->nb_outputs; i++) {
3411 
3412  if (fgt.eof_out[i] || !fgt.graph)
3413  continue;
3414 
3415  ret = fg_output_frame(ofp, &fgt, NULL);
3416  if (ret < 0)
3417  goto finish;
3418  }
3419 
3420 finish:
3421 
3423  print_filtergraph(fg, fgt.graph);
3424 
3425  // EOF is normal termination
3426  if (ret == AVERROR_EOF)
3427  ret = 0;
3428 
3429  fg_thread_uninit(&fgt);
3430 
3431  return ret;
3432 }
3433 
3434 void fg_send_command(FilterGraph *fg, double time, const char *target,
3435  const char *command, const char *arg, int all_filters)
3436 {
3437  FilterGraphPriv *fgp = fgp_from_fg(fg);
3438  AVBufferRef *buf;
3439  FilterCommand *fc;
3440 
3441  fc = av_mallocz(sizeof(*fc));
3442  if (!fc)
3443  return;
3444 
3445  buf = av_buffer_create((uint8_t*)fc, sizeof(*fc), filter_command_free, NULL, 0);
3446  if (!buf) {
3447  av_freep(&fc);
3448  return;
3449  }
3450 
3451  fc->target = av_strdup(target);
3452  fc->command = av_strdup(command);
3453  fc->arg = av_strdup(arg);
3454  if (!fc->target || !fc->command || !fc->arg) {
3455  av_buffer_unref(&buf);
3456  return;
3457  }
3458 
3459  fc->time = time;
3460  fc->all_filters = all_filters;
3461 
3462  fgp->frame->buf[0] = buf;
3463  fgp->frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_SEND_COMMAND;
3464 
3465  sch_filter_command(fgp->sch, fgp->sch_idx, fgp->frame);
3466 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:604
InputFilterPriv::nb_dropped
uint64_t nb_dropped
Definition: ffmpeg_filter.c:118
SCH_FILTER_OUT
#define SCH_FILTER_OUT(filter, output)
Definition: ffmpeg_sched.h:129
AVSubtitle
Definition: avcodec.h:2087
AVBufferSrcParameters::side_data
AVFrameSideData ** side_data
Definition: buffersrc.h:124
AVBufferSrcParameters::color_space
enum AVColorSpace color_space
Video only, the YUV colorspace and range.
Definition: buffersrc.h:121
configure_input_filter
static int configure_input_filter(FilterGraph *fg, AVFilterGraph *graph, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:2015
FilterGraphThread::next_in
unsigned next_in
Definition: ffmpeg_filter.c:91
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:57
AVFILTER_CMD_FLAG_ONE
#define AVFILTER_CMD_FLAG_ONE
Stop once a filter understood the command (for target=all for example), fast filters are favored auto...
Definition: avfilter.h:441
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:723
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:274
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
av_buffersink_get_sample_aspect_ratio
AVRational av_buffersink_get_sample_aspect_ratio(const AVFilterContext *ctx)
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
extra_bits
#define extra_bits(eb)
Definition: intrax8.c:120
OutputFilter::graph
struct FilterGraph * graph
Definition: ffmpeg.h:375
av_clip
#define av_clip
Definition: common.h:100
sch_filter_send
int sch_filter_send(Scheduler *sch, unsigned fg_idx, unsigned out_idx, AVFrame *frame)
Called by filtergraph tasks to send a filtered frame or EOF to consumers.
Definition: ffmpeg_sched.c:2682
OutputFilter::class
const AVClass * class
Definition: ffmpeg.h:373
view_specifier_parse
int view_specifier_parse(const char **pspec, ViewSpecifier *vs)
Definition: ffmpeg_opt.c:306
VSYNC_VFR
@ VSYNC_VFR
Definition: ffmpeg.h:60
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:218
r
const char * r
Definition: vf_curves.c:127
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:109
AVSubtitle::rects
AVSubtitleRect ** rects
Definition: avcodec.h:2092
opt.h
choose_input
static int choose_input(const FilterGraph *fg, const FilterGraphThread *fgt)
Definition: ffmpeg_filter.c:2363
get_rotation
double get_rotation(const int32_t *displaymatrix)
Definition: cmdutils.c:1553
FrameData::nb_side_data
int nb_side_data
Definition: ffmpeg.h:713
FilterGraphPriv::frame
AVFrame * frame
Definition: ffmpeg_filter.c:61
read_binary
static int read_binary(void *logctx, const char *path, uint8_t **data, int *len)
Definition: ffmpeg_filter.c:446
FilterGraphPriv::sch
Scheduler * sch
Definition: ffmpeg_filter.c:65
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:53
FilterGraphThread::got_frame
int got_frame
Definition: ffmpeg_filter.c:93
AVFilterGraph::nb_threads
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:587
InputFilterPriv::ch_layout
AVChannelLayout ch_layout
Definition: ffmpeg_filter.c:130
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:988
FrameData
Definition: ffmpeg.h:691
send_command
static void send_command(FilterGraph *fg, AVFilterGraph *graph, double time, const char *target, const char *command, const char *arg, int all_filters)
Definition: ffmpeg_filter.c:2338
InputFilterPriv::last_pts
int64_t last_pts
Definition: ffmpeg_filter.c:155
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:516
InputFilterOptions::crop_right
unsigned crop_right
Definition: ffmpeg.h:273
OutputFilter::apad
char * apad
Definition: ffmpeg.h:388
out
static FILE * out
Definition: movenc.c:55
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:206
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:659
clone_side_data
static int clone_side_data(AVFrameSideData ***dst, int *nb_dst, AVFrameSideData *const *src, int nb_src, unsigned int flags)
Wrapper calling av_frame_side_data_clone() in a loop for all source entries.
Definition: ffmpeg_utils.h:50
FilterGraph::graph_desc
const char * graph_desc
Definition: ffmpeg.h:410
OutputFilterPriv::sample_fmts
enum AVSampleFormat * sample_fmts
Definition: ffmpeg_filter.c:231
atomic_fetch_add
#define atomic_fetch_add(object, operand)
Definition: stdatomic.h:137
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:933
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3460
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
FilterGraph::inputs
InputFilter ** inputs
Definition: ffmpeg.h:400
av_buffersink_get_frame_flags
int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
Definition: buffersink.c:135
AVBufferSrcParameters::nb_side_data
int nb_side_data
Definition: buffersrc.h:125
InputFilterOptions::crop_bottom
unsigned crop_bottom
Definition: ffmpeg.h:271
av_dict_count
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:37
AVFrame::nb_side_data
int nb_side_data
Definition: frame.h:670
ifilter_parameters_from_frame
static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
Definition: ffmpeg_filter.c:2233
stream_specifier_parse
int stream_specifier_parse(StreamSpecifier *ss, const char *spec, int allow_remainder, void *logctx)
Parse a stream specifier string into a form suitable for matching.
Definition: cmdutils.c:1011
ofilter_class
static const AVClass ofilter_class
Definition: ffmpeg_filter.c:650
HWACCEL_CHANGED
@ HWACCEL_CHANGED
Definition: ffmpeg_filter.c:3073
frame_drop_threshold
float frame_drop_threshold
Definition: ffmpeg_opt.c:59
close_input
static void close_input(InputFilterPriv *ifp)
Definition: ffmpeg_filter.c:2640
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:263
ist_filter_add
int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, const ViewSpecifier *vs, InputFilterOptions *opts, SchedulerNode *src)
Definition: ffmpeg_demux.c:1210
InputFilterPriv::time_base
AVRational time_base
Definition: ffmpeg_filter.c:132
int64_t
long long int64_t
Definition: coverity.c:34
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:226
configure_output_filter
static int configure_output_filter(FilterGraphPriv *fgp, AVFilterGraph *graph, OutputFilter *ofilter, AVFilterInOut *out)
Definition: ffmpeg_filter.c:1824
av_alpha_mode_name
const char * av_alpha_mode_name(enum AVAlphaMode mode)
Definition: pixdesc.c:3925
FilterCommand::arg
char * arg
Definition: ffmpeg_filter.c:260
AVSubtitleRect
Definition: avcodec.h:2060
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:115
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2091
dec_filter_add
int dec_filter_add(Decoder *dec, InputFilter *ifilter, InputFilterOptions *opts, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_dec.c:1783
OutputFilterPriv::crop_left
unsigned crop_left
Definition: ffmpeg_filter.c:209
fg_free
void fg_free(FilterGraph **pfg)
Definition: ffmpeg_filter.c:1019
FPSConvContext::frames_prev_hist
int64_t frames_prev_hist[3]
Definition: ffmpeg_filter.c:175
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:62
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:610
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:734
InputFile::index
int index
Definition: ffmpeg.h:508
sample_rates
static const int sample_rates[]
Definition: dcaenc.h:34
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:472
AVFilterInOut::next
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
Definition: avfilter.h:729
pixdesc.h
AVFrameSideData::buf
AVBufferRef * buf
Definition: frame.h:332
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:574
AVFrame::width
int width
Definition: frame.h:544
FilterGraphPriv::log_name
char log_name[32]
Definition: ffmpeg_filter.c:48
StreamSpecifier
Definition: cmdutils.h:113
ofilter_bind_enc
int ofilter_bind_enc(OutputFilter *ofilter, unsigned sched_idx_enc, const OutputFilterOptions *opts)
Definition: ffmpeg_filter.c:816
AVOption
AVOption.
Definition: opt.h:428
InputFilterPriv::ofilter_src
OutputFilter * ofilter_src
Definition: ffmpeg_filter.c:109
fg_output_frame
static int fg_output_frame(OutputFilterPriv *ofp, FilterGraphThread *fgt, AVFrame *frame)
Definition: ffmpeg_filter.c:2706
b
#define b
Definition: input.c:43
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:191
FilterGraph::index
int index
Definition: ffmpeg.h:398
OutputFilter::index
int index
Definition: ffmpeg.h:377
InputFilterPriv::sample_rate
int sample_rate
Definition: ffmpeg_filter.c:129
data
const char data[16]
Definition: mxf.c:149
InputFilter::index
int index
Definition: ffmpeg.h:358
FPSConvContext::last_dropped
int last_dropped
Definition: ffmpeg_filter.c:179
OutputFilterPriv::ts_offset
int64_t ts_offset
Definition: ffmpeg_filter.c:245
cleanup_filtergraph
static void cleanup_filtergraph(FilterGraph *fg, FilterGraphThread *fgt)
Definition: ffmpeg_filter.c:2025
OutputFilterPriv::alpha_mode
enum AVAlphaMode alpha_mode
Definition: ffmpeg_filter.c:205
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
FilterGraph::nb_inputs
int nb_inputs
Definition: ffmpeg.h:401
VIDEO_CHANGED
@ VIDEO_CHANGED
Definition: ffmpeg_filter.c:3069
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
ViewSpecifier
Definition: ffmpeg.h:116
AVDictionary
Definition: dict.c:32
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:716
ofp_from_ofilter
static OutputFilterPriv * ofp_from_ofilter(OutputFilter *ofilter)
Definition: ffmpeg_filter.c:252
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:324
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVFILTER_AUTO_CONVERT_NONE
@ AVFILTER_AUTO_CONVERT_NONE
all automatic conversions disabled
Definition: avfilter.h:691
av_frame_side_data_clone
int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags)
Add a new side data entry to an array based on existing side data, taking a reference towards the con...
Definition: side_data.c:254
IFILTER_FLAG_AUTOROTATE
@ IFILTER_FLAG_AUTOROTATE
Definition: ffmpeg.h:250
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
configure_output_audio_filter
static int configure_output_audio_filter(FilterGraphPriv *fgp, AVFilterGraph *graph, OutputFilter *ofilter, AVFilterInOut *out)
Definition: ffmpeg_filter.c:1744
key
const char * key
Definition: ffmpeg_mux_init.c:2971
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:649
AVBufferSrcParameters::height
int height
Definition: buffersrc.h:87
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:326
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
fg_output_step
static int fg_output_step(OutputFilterPriv *ofp, FilterGraphThread *fgt, AVFrame *frame)
Definition: ffmpeg_filter.c:2789
FilterGraphPriv
Definition: ffmpeg_filter.c:44
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:600
FilterGraphThread::eof_in
uint8_t * eof_in
Definition: ffmpeg_filter.c:96
avfilter_graph_free
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:119
configure_filtergraph
static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt)
Definition: ffmpeg_filter.c:2060
OutputFilterPriv::log_name
char log_name[32]
Definition: ffmpeg_filter.c:194
stream_specifier_uninit
void stream_specifier_uninit(StreamSpecifier *ss)
Definition: cmdutils.c:1002
InputStream
Definition: ffmpeg.h:462
filter_nbthreads
char * filter_nbthreads
Definition: ffmpeg_opt.c:73
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:67
OutputFilterOptions
Definition: ffmpeg.h:293
InputFilterOptions::trim_start_us
int64_t trim_start_us
Definition: ffmpeg.h:258
InputFilterOptions::flags
unsigned flags
Definition: ffmpeg.h:279
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)
A convenience wrapper that allocates and initializes a filter in a single step.
Definition: avfiltergraph.c:140
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:167
finish
static void finish(void)
Definition: movenc.c:374
AV_OPT_TYPE_BINARY
@ AV_OPT_TYPE_BINARY
Underlying C type is a uint8_t* that is either NULL or points to an array allocated with the av_mallo...
Definition: opt.h:285
av_color_space_name
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:3860
FRAME_OPAQUE_SUB_HEARTBEAT
@ FRAME_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:76
OutputFilterPriv
Definition: ffmpeg_filter.c:190
FrameData::dec
struct FrameData::@6 dec
fg_thread_uninit
static void fg_thread_uninit(FilterGraphThread *fgt)
Definition: ffmpeg_filter.c:3261
filter_opt_apply
static int filter_opt_apply(void *logctx, AVFilterContext *f, const char *key, const char *val)
Definition: ffmpeg_filter.c:495
InputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:361
AVBufferSrcParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only, the sample (pixel) aspect ratio.
Definition: buffersrc.h:92
av_fifo_write
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition: fifo.c:188
sub2video_push_ref
static void sub2video_push_ref(InputFilterPriv *ifp, int64_t pts)
Definition: ffmpeg_filter.c:331
avfilter_graph_alloc
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:85
AV_FRAME_DATA_DOWNMIX_MATRIX
@ AV_FRAME_DATA_DOWNMIX_MATRIX
Metadata relevant to a downmix procedure in the form of a remixig matrix.
Definition: frame.h:307
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
FFSIGN
#define FFSIGN(a)
Definition: common.h:75
print_filtergraph
int print_filtergraph(FilterGraph *fg, AVFilterGraph *graph)
Definition: graphprint.c:948
samplefmt.h
OutputFilterPriv::side_data
AVFrameSideData ** side_data
Definition: ffmpeg_filter.c:212
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:276
sub2video_get_blank_frame
static int sub2video_get_blank_frame(InputFilterPriv *ifp)
Definition: ffmpeg_filter.c:277
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
ifilter_has_all_input_formats
static int ifilter_has_all_input_formats(FilterGraph *fg)
Definition: ffmpeg_filter.c:620
AVFrame::alpha_mode
enum AVAlphaMode alpha_mode
Indicates how the alpha channel of the video is to be handled.
Definition: frame.h:827
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:815
SCH_ENC
#define SCH_ENC(encoder)
Definition: ffmpeg_sched.h:123
configure_input_video_filter
static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:1845
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:460
AVDownmixInfo
This structure describes optional metadata relevant to a downmix procedure.
Definition: downmix_info.h:59
pts
static int64_t pts
Definition: transcode_aac.c:649
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:824
graph_is_meta
static int graph_is_meta(AVFilterGraph *graph)
Definition: ffmpeg_filter.c:2041
median3
static int64_t median3(int64_t a, int64_t b, int64_t c)
Definition: ffmpeg_filter.c:2502
FilterGraphThread::frame
AVFrame * frame
Definition: ffmpeg_filter.c:83
ss
#define ss(width, name, subs,...)
Definition: cbs_vp9.c:202
FrameData::tb
AVRational tb
Definition: ffmpeg.h:701
OutputFilterPriv::sws_opts
AVDictionary * sws_opts
Definition: ffmpeg_filter.c:224
fgp_from_fg
static FilterGraphPriv * fgp_from_fg(FilterGraph *fg)
Definition: ffmpeg_filter.c:69
OutputFilterPriv::sample_rate
int sample_rate
Definition: ffmpeg_filter.c:201
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
FPSConvContext::dropped_keyframe
int dropped_keyframe
Definition: ffmpeg_filter.c:180
AVRational::num
int num
Numerator.
Definition: rational.h:59
OutputFilter::bound
int bound
Definition: ffmpeg.h:385
LATENCY_PROBE_FILTER_PRE
@ LATENCY_PROBE_FILTER_PRE
Definition: ffmpeg.h:90
InputFilterOptions::trim_end_us
int64_t trim_end_us
Definition: ffmpeg.h:259
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:40
sch_add_filtergraph
int sch_add_filtergraph(Scheduler *sch, unsigned nb_inputs, unsigned nb_outputs, SchThreadFunc func, void *ctx)
Add a filtergraph to the scheduler.
Definition: ffmpeg_sched.c:875
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
sub2video_heartbeat
static void sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational tb)
Definition: ffmpeg_filter.c:2936
avfilter_inout_free
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:76
OutputFilterPriv::nb_side_data
int nb_side_data
Definition: ffmpeg_filter.c:213
avassert.h
OutputFilterPriv::trim_start_us
int64_t trim_start_us
Definition: ffmpeg_filter.c:242
FrameData::frame_rate_filter
AVRational frame_rate_filter
Definition: ffmpeg.h:704
InputFilterPriv::nb_side_data
int nb_side_data
Definition: ffmpeg_filter.c:135
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
send_eof
static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter, int64_t pts, AVRational tb)
Definition: ffmpeg_filter.c:3005
AVFrameSideData::size
size_t size
Definition: frame.h:330
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
InputFilterPriv
Definition: ffmpeg_filter.c:100
av_fifo_read
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition: fifo.c:240
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:687
av_buffersink_get_frame_rate
AVRational av_buffersink_get_frame_rate(const AVFilterContext *ctx)
Definition: buffersink.c:254
ifilter_alloc
static InputFilter * ifilter_alloc(FilterGraph *fg)
Definition: ffmpeg_filter.c:990
AVFilterChain::filters
AVFilterParams ** filters
Definition: avfilter.h:905
filter_command_free
static void filter_command_free(void *opaque, uint8_t *data)
Definition: ffmpeg_filter.c:266
VSYNC_VSCFR
@ VSYNC_VSCFR
Definition: ffmpeg.h:61
llrintf
#define llrintf(x)
Definition: libm.h:401
ifilter_bind_ist
static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist, const ViewSpecifier *vs)
Definition: ffmpeg_filter.c:684
FilterGraphPriv::frame_enc
AVFrame * frame_enc
Definition: ffmpeg_filter.c:63
DOWNMIX_CHANGED
@ DOWNMIX_CHANGED
Definition: ffmpeg_filter.c:3072
InputFilterPriv::frame
AVFrame * frame
Definition: ffmpeg_filter.c:106
FilterGraph::outputs
OutputFilter ** outputs
Definition: ffmpeg.h:402
ofilter_item_name
static const char * ofilter_item_name(void *obj)
Definition: ffmpeg_filter.c:644
AVDictionaryEntry::key
char * key
Definition: dict.h:91
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
VIEW_SPECIFIER_TYPE_NONE
@ VIEW_SPECIFIER_TYPE_NONE
Definition: ffmpeg.h:105
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:119
ifilter_bind_dec
static int ifilter_bind_dec(InputFilterPriv *ifp, Decoder *dec, const ViewSpecifier *vs)
Definition: ffmpeg_filter.c:743
DEF_CHOOSE_FORMAT
DEF_CHOOSE_FORMAT(pix_fmts, enum AVPixelFormat, format, pix_fmts, AV_PIX_FMT_NONE, "%s", av_get_pix_fmt_name) DEF_CHOOSE_FORMAT(sample_fmts
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
OutputFilter::linklabel
uint8_t * linklabel
Definition: ffmpeg.h:386
InputFilter
Definition: ffmpeg.h:355
FilterGraphPriv::nb_outputs_done
unsigned nb_outputs_done
Definition: ffmpeg_filter.c:56
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:494
av_buffersink_get_format
int av_buffersink_get_format(const AVFilterContext *ctx)
av_buffersink_get_time_base
AVRational av_buffersink_get_time_base(const AVFilterContext *ctx)
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
AV_BUFFERSRC_FLAG_KEEP_REF
@ AV_BUFFERSRC_FLAG_KEEP_REF
Keep a reference to the frame.
Definition: buffersrc.h:53
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
OFILTER_FLAG_AUTOSCALE
@ OFILTER_FLAG_AUTOSCALE
Definition: ffmpeg.h:288
print_graphs_file
char * print_graphs_file
Definition: ffmpeg_opt.c:78
InputFilter::linklabel
uint8_t * linklabel
Definition: ffmpeg.h:369
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2093
fg_thread_init
static int fg_thread_init(FilterGraphThread *fgt, const FilterGraph *fg)
Definition: ffmpeg_filter.c:3279
InputFilterOptions::name
uint8_t * name
Definition: ffmpeg.h:261
InputFilterOptions::crop_top
unsigned crop_top
Definition: ffmpeg.h:270
InputFilter::graph
struct FilterGraph * graph
Definition: ffmpeg.h:356
AV_SIDE_DATA_PROP_GLOBAL
@ AV_SIDE_DATA_PROP_GLOBAL
The side data type can be used in stream-global structures.
Definition: frame.h:341
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
color_range
color_range
Definition: vf_selectivecolor.c:43
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
InputFilterPriv::sub2video
struct InputFilterPriv::@10 sub2video
AV_ROUND_NEAR_INF
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
Definition: mathematics.h:135
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
OutputFilterPriv::fps
FPSConvContext fps
Definition: ffmpeg_filter.c:247
av_buffersink_get_alpha_mode
enum AVAlphaMode av_buffersink_get_alpha_mode(const AVFilterContext *ctx)
fg_item_name
static const char * fg_item_name(void *obj)
Definition: ffmpeg_filter.c:1079
AV_ROUND_PASS_MINMAX
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
Definition: mathematics.h:159
command
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:1196
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
arg
const char * arg
Definition: jacosubdec.c:65
OutputFilterPriv::ch_layouts
const AVChannelLayout * ch_layouts
Definition: ffmpeg_filter.c:233
if
if(ret)
Definition: filter_design.txt:179
OutputFilterPriv::width
int width
Definition: ffmpeg_filter.c:200
InputFilterOptions::crop_left
unsigned crop_left
Definition: ffmpeg.h:272
av_color_range_name
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:3776
AVBufferSrcParameters::alpha_mode
enum AVAlphaMode alpha_mode
Video only, the alpha mode.
Definition: buffersrc.h:130
AVFormatContext
Format I/O context.
Definition: avformat.h:1314
fail
#define fail
Definition: test.h:478
avfilter_get_by_name
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: allfilters.c:654
opts
static AVDictionary * opts
Definition: movenc.c:51
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:770
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
OutputFilter::name
uint8_t * name
Definition: ffmpeg.h:376
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:1434
OutputFilterPriv::crop_right
unsigned crop_right
Definition: ffmpeg_filter.c:210
OutputFilterPriv::enc_timebase
AVRational enc_timebase
Definition: ffmpeg_filter.c:241
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:882
InputFilterPriv::color_space
enum AVColorSpace color_space
Definition: ffmpeg_filter.c:125
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:884
set_channel_layout
static int set_channel_layout(OutputFilterPriv *f, const AVChannelLayout *layouts_allowed, const AVChannelLayout *layout_requested)
Definition: ffmpeg_filter.c:776
OutputFilterPriv::ch_layout
AVChannelLayout ch_layout
Definition: ffmpeg_filter.c:202
AVFilterParams
Parameters describing a filter to be created in a filtergraph.
Definition: avfilter.h:837
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
FPSConvContext::dup_warning
uint64_t dup_warning
Definition: ffmpeg_filter.c:177
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:470
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:162
InputFilterPriv::displaymatrix_present
int displaymatrix_present
Definition: ffmpeg_filter.c:141
Decoder
Definition: ffmpeg.h:448
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
OFILTER_FLAG_AUDIO_24BIT
@ OFILTER_FLAG_AUDIO_24BIT
Definition: ffmpeg.h:287
AVFilterChain::nb_filters
size_t nb_filters
Definition: avfilter.h:906
InputFilterPriv::downmixmatrix_size
size_t downmixmatrix_size
Definition: ffmpeg_filter.c:149
av_frame_side_data_remove
void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type from an array.
Definition: side_data.c:108
AVFilterGraph::filters
AVFilterContext ** filters
Definition: avfilter.h:563
ofilter_bind_ifilter
static int ofilter_bind_ifilter(OutputFilter *ofilter, InputFilterPriv *ifp, const OutputFilterOptions *opts)
Definition: ffmpeg_filter.c:931
av_fallthrough
#define av_fallthrough
Definition: attributes.h:67
OutputFilterPriv::sample_aspect_ratio
AVRational sample_aspect_ratio
Definition: ffmpeg_filter.c:222
ofilter_alloc
static OutputFilter * ofilter_alloc(FilterGraph *fg, enum AVMediaType type)
Definition: ffmpeg_filter.c:658
close_output
static int close_output(OutputFilterPriv *ofp, FilterGraphThread *fgt)
Definition: ffmpeg_filter.c:2650
FilterGraphThread::frame_queue_out
AVFifo * frame_queue_out
Definition: ffmpeg_filter.c:88
FilterGraphPriv::sch_idx
unsigned sch_idx
Definition: ffmpeg_filter.c:66
FrameData::wallclock
int64_t wallclock[LATENCY_PROBE_NB]
Definition: ffmpeg.h:708
avfilter_graph_request_oldest
int avfilter_graph_request_oldest(AVFilterGraph *graph)
Request a frame on the oldest sink link.
Definition: avfiltergraph.c:1567
time.h
AVFilterGraphSegment::chains
AVFilterChain ** chains
A list of filter chain contained in this segment.
Definition: avfilter.h:929
stream_specifier_match
unsigned stream_specifier_match(const StreamSpecifier *ss, const AVFormatContext *s, const AVStream *st, void *logctx)
Definition: cmdutils.c:1226
attributes.h
AVFilterGraph
Definition: avfilter.h:561
AV_FRAME_SIDE_DATA_FLAG_REPLACE
#define AV_FRAME_SIDE_DATA_FLAG_REPLACE
Don't add a new entry if another of the same type exists.
Definition: frame.h:1098
InputFilterPriv::downmixinfo_present
int downmixinfo_present
Definition: ffmpeg_filter.c:145
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:244
InputFilterOptions
Definition: ffmpeg.h:257
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
fg_create_simple
int fg_create_simple(FilterGraph **pfg, InputStream *ist, char **graph_desc, Scheduler *sch, unsigned sched_idx_enc, const OutputFilterOptions *opts)
Definition: ffmpeg_filter.c:1243
InputFilterPriv::sample_aspect_ratio
AVRational sample_aspect_ratio
Definition: ffmpeg_filter.c:124
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:749
FilterGraph::nb_outputs
int nb_outputs
Definition: ffmpeg.h:403
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
InputFilterPriv::downmixmatrix_present
int downmixmatrix_present
Definition: ffmpeg_filter.c:150
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:869
InputStream::par
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition: ffmpeg.h:478
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
input_files
InputFile ** input_files
Definition: ffmpeg.c:108
AV_CLASS_CATEGORY_FILTER
@ AV_CLASS_CATEGORY_FILTER
Definition: log.h:36
Scheduler
Definition: ffmpeg_sched.c:278
FilterGraphPriv::fg
FilterGraph fg
Definition: ffmpeg_filter.c:45
FilterGraphPriv::nb_threads
int nb_threads
Definition: ffmpeg_filter.c:58
OutputFilterPriv::ofilter
OutputFilter ofilter
Definition: ffmpeg_filter.c:191
FilterGraph
Definition: ffmpeg.h:396
AVFilterGraphSegment
A parsed representation of a filtergraph segment.
Definition: avfilter.h:918
OutputFilterPriv::crop_bottom
unsigned crop_bottom
Definition: ffmpeg_filter.c:208
ENC_TIME_BASE_DEMUX
@ ENC_TIME_BASE_DEMUX
Definition: ffmpeg.h:65
InputFilterOptions::sub2video_width
int sub2video_width
Definition: ffmpeg.h:275
InputFilter::filter
AVFilterContext * filter
Definition: ffmpeg.h:363
AVBufferSrcParameters::frame_rate
AVRational frame_rate
Video only, the frame rate of the input video.
Definition: buffersrc.h:100
AVFilterInOut::pad_idx
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:726
AVAlphaMode
AVAlphaMode
Correlation between the alpha channel and color values.
Definition: pixfmt.h:816
av_buffersrc_close
int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags)
Close the buffer source after EOF.
Definition: buffersrc.c:291
AVFilterGraph::scale_sws_opts
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:566
filtergraph_is_simple
int filtergraph_is_simple(const FilterGraph *fg)
Definition: ffmpeg_filter.c:2332
VideoSyncMethod
VideoSyncMethod
Definition: ffmpeg.h:56
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:1984
FrameData::side_data
AVFrameSideData ** side_data
Definition: ffmpeg.h:712
IFILTER_FLAG_REINIT
@ IFILTER_FLAG_REINIT
Definition: ffmpeg.h:251
f
f
Definition: af_crystalizer.c:122
OutputFilter::output_name
char * output_name
Definition: ffmpeg.h:381
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:83
filter_thread
static int filter_thread(void *arg)
Definition: ffmpeg_filter.c:3306
AVMediaType
AVMediaType
Definition: avutil.h:198
InputFilterPriv::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Definition: ffmpeg_filter.c:139
AVFifo
Definition: fifo.c:35
FRAME_OPAQUE_SEND_COMMAND
@ FRAME_OPAQUE_SEND_COMMAND
Definition: ffmpeg.h:78
FilterGraphThread
Definition: ffmpeg_filter.c:80
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:278
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
InputFilterPriv::displaymatrix
int32_t displaymatrix[9]
Definition: ffmpeg_filter.c:143
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
OutputFilterPriv::color_ranges
enum AVColorRange * color_ranges
Definition: ffmpeg_filter.c:236
FilterGraphThread::graph
AVFilterGraph * graph
Definition: ffmpeg_filter.c:81
av_buffersrc_parameters_alloc
AVBufferSrcParameters * av_buffersrc_parameters_alloc(void)
Allocate a new AVBufferSrcParameters instance.
Definition: buffersrc.c:108
AVFilterInOut::filter_ctx
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:723
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
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:122
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:635
av_buffersrc_get_status
int av_buffersrc_get_status(AVFilterContext *ctx)
Returns 0 or a negative AVERROR code.
Definition: buffersrc.c:300
OutputFilterPriv::tb_out_locked
int tb_out_locked
Definition: ffmpeg_filter.c:220
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
avfilter_link
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:149
sch_filter_choke_inputs
void sch_filter_choke_inputs(Scheduler *sch, unsigned fg_idx)
Called by filtergraph tasks to choke all filter inputs, preventing them from receiving more frames un...
Definition: ffmpeg_sched.c:2745
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:328
AV_BUFFERSRC_FLAG_PUSH
@ AV_BUFFERSRC_FLAG_PUSH
Immediately push the frame to the output.
Definition: buffersrc.h:46
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:187
InputFilterPriv::color_range
enum AVColorRange color_range
Definition: ffmpeg_filter.c:126
OutputFilterPriv::displaymatrix
int32_t displaymatrix[9]
Definition: ffmpeg_filter.c:239
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
MATRIX_CHANGED
@ MATRIX_CHANGED
Definition: ffmpeg_filter.c:3071
FilterCommand::time
double time
Definition: ffmpeg_filter.c:262
InputFilterPriv::initialize
unsigned int initialize
marks if sub2video_update should force an initialization
Definition: ffmpeg_filter.c:159
InputFilterPriv::displaymatrix_applied
int displaymatrix_applied
Definition: ffmpeg_filter.c:142
avfilter_graph_queue_command
int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts)
Queue a command for one or more filter instances.
Definition: avfiltergraph.c:1484
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:589
AVFrameSideData::data
uint8_t * data
Definition: frame.h:329
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:559
FilterGraphPriv::disable_conversions
int disable_conversions
Definition: ffmpeg_filter.c:54
frame_data
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition: ffmpeg.c:487
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2090
FilterGraphThread::eof_out
uint8_t * eof_out
Definition: ffmpeg_filter.c:97
allocate_array_elem
void * allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
Atomically add a new element to an array of pointers, i.e.
Definition: cmdutils.c:1540
FPSConvContext::vsync_method
enum VideoSyncMethod vsync_method
Definition: ffmpeg_filter.c:182
av_frame_remove_side_data
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition: frame.c:725
OutputFilter::filter
AVFilterContext * filter
Definition: ffmpeg.h:379
InputFilterPriv::width
int width
Definition: ffmpeg_filter.c:123
AVBufferSrcParameters::time_base
AVRational time_base
The timebase to be used for the timestamps on the input frames.
Definition: buffersrc.h:82
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:517
filter_is_buffersrc
static int filter_is_buffersrc(const AVFilterContext *f)
Definition: ffmpeg_filter.c:2034
fg_finalise_bindings
int fg_finalise_bindings(void)
Definition: ffmpeg_filter.c:1486
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AUDIO_CHANGED
@ AUDIO_CHANGED
Definition: ffmpeg_filter.c:3070
sch_filter_receive
int sch_filter_receive(Scheduler *sch, unsigned fg_idx, unsigned *in_idx, AVFrame *frame)
Called by filtergraph tasks to obtain frames for filtering.
Definition: ffmpeg_sched.c:2604
fg_complex_bind_input
static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter, int commit)
Definition: ffmpeg_filter.c:1295
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:233
unknown_if_null
static const char * unknown_if_null(const char *str)
Definition: ffmpeg_filter.c:3076
InputFilterOptions::sub2video_height
int sub2video_height
Definition: ffmpeg.h:276
decoders
Decoder ** decoders
Definition: ffmpeg.c:117
OutputFilterPriv::log_parent
void * log_parent
Definition: ffmpeg_filter.c:193
nb_decoders
int nb_decoders
Definition: ffmpeg.c:118
OutputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:390
read_frames
static int read_frames(FilterGraph *fg, FilterGraphThread *fgt, AVFrame *frame)
Definition: ffmpeg_filter.c:2876
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:811
SUBTITLE_BITMAP
@ SUBTITLE_BITMAP
A bitmap, pict will be set.
Definition: avcodec.h:2043
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
send_frame
static int send_frame(FilterGraph *fg, FilterGraphThread *fgt, InputFilter *ifilter, AVFrame *frame)
Definition: ffmpeg_filter.c:3081
avfilter_init_str
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:960
buffersink.h
av_buffersink_get_side_data
const AVFrameSideData *const * av_buffersink_get_side_data(const AVFilterContext *ctx, int *nb_side_data)
Definition: buffersink.c:287
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:841
av_find_nearest_q_idx
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
Find the value in a list of rationals nearest a given reference rational.
Definition: rational.c:144
OutputFilterPriv::color_range
enum AVColorRange color_range
Definition: ffmpeg_filter.c:204
av_buffersink_get_w
int av_buffersink_get_w(const AVFilterContext *ctx)
FilterCommand::all_filters
int all_filters
Definition: ffmpeg_filter.c:263
FPSConvContext::framerate_clip
int framerate_clip
Definition: ffmpeg_filter.c:187
bprint.h
FPSConvContext::frame_number
int64_t frame_number
Definition: ffmpeg_filter.c:171
filter_buffered_frames
int filter_buffered_frames
Definition: ffmpeg_opt.c:75
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:122
graph_opts_apply
static int graph_opts_apply(void *logctx, AVFilterGraphSegment *seg)
Definition: ffmpeg_filter.c:551
FPSConvContext
Definition: ffmpeg_filter.c:168
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
av_malloc
#define av_malloc(s)
Definition: ops_asmgen.c:44
AVBufferSrcParameters::width
int width
Video only, the display dimensions of the input frames.
Definition: buffersrc.h:87
FrameData::bits_per_raw_sample
int bits_per_raw_sample
Definition: ffmpeg.h:706
av_frame_side_data_free
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
Definition: side_data.c:139
fg_send_command
void fg_send_command(FilterGraph *fg, double time, const char *target, const char *command, const char *arg, int all_filters)
Definition: ffmpeg_filter.c:3434
downmix_info.h
sch_remove_filtergraph
void sch_remove_filtergraph(Scheduler *sch, int idx)
Definition: ffmpeg_sched.c:485
FilterGraphPriv::is_simple
int is_simple
Definition: ffmpeg_filter.c:50
InputFilterOptions::fallback
AVFrame * fallback
Definition: ffmpeg.h:281
av_buffersrc_add_frame_flags
int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Add a frame to the buffer source.
Definition: buffersrc.c:210
VSYNC_CFR
@ VSYNC_CFR
Definition: ffmpeg.h:59
src2
const pixel * src2
Definition: h264pred_template.c:421
configure_input_audio_filter
static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph, InputFilter *ifilter, AVFilterInOut *in)
Definition: ffmpeg_filter.c:1964
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:706
FPSConvContext::framerate_max
AVRational framerate_max
Definition: ffmpeg_filter.c:185
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:58
needed
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is needed
Definition: filter_design.txt:212
s
uint8_t s
Definition: llvidencdsp.c:39
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
OutputFilterPriv::crop_top
unsigned crop_top
Definition: ffmpeg_filter.c:207
delta
float delta
Definition: vorbis_enc_data.h:430
print_graphs
int print_graphs
Definition: ffmpeg_opt.c:77
FRAME_OPAQUE_EOF
@ FRAME_OPAQUE_EOF
Definition: ffmpeg.h:77
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:510
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:523
cfgp_from_cfg
static const FilterGraphPriv * cfgp_from_cfg(const FilterGraph *fg)
Definition: ffmpeg_filter.c:74
graph_parse
static int graph_parse(void *logctx, AVFilterGraph *graph, const char *desc, AVFilterInOut **inputs, AVFilterInOut **outputs, AVBufferRef *hw_device)
Definition: ffmpeg_filter.c:575
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
InputFilterPriv::eof
int eof
Definition: ffmpeg_filter.c:115
ifilter_parameters_from_ofilter
static int ifilter_parameters_from_ofilter(InputFilter *ifilter, OutputFilter *ofilter)
Definition: ffmpeg_filter.c:2311
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
IFILTER_FLAG_DROPCHANGED
@ IFILTER_FLAG_DROPCHANGED
Definition: ffmpeg.h:254
AVFrame::side_data
AVFrameSideData ** side_data
Definition: frame.h:669
len
int len
Definition: vorbis_enc_data.h:426
SchedulerNode
Definition: ffmpeg_sched.h:103
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:709
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:114
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:322
OutputFilterPriv::color_space
enum AVColorSpace color_space
Definition: ffmpeg_filter.c:203
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
OFILTER_FLAG_CROP
@ OFILTER_FLAG_CROP
Definition: ffmpeg.h:290
outputs
static const AVFilterPad outputs[]
Definition: af_aap.c:310
sch_connect
int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst)
Definition: ffmpeg_sched.c:973
av_buffersink_get_h
int av_buffersink_get_h(const AVFilterContext *ctx)
OutputFilterPriv::needed
int needed
Definition: ffmpeg_filter.c:196
sch_filter_command
int sch_filter_command(Scheduler *sch, unsigned fg_idx, AVFrame *frame)
Definition: ffmpeg_sched.c:2735
AVFilter
Filter definition.
Definition: avfilter.h:215
video_sync_process
static void video_sync_process(OutputFilterPriv *ofp, AVFrame *frame, int64_t *nb_frames, int64_t *nb_frames_prev)
Definition: ffmpeg_filter.c:2523
ifp_from_ifilter
static InputFilterPriv * ifp_from_ifilter(InputFilter *ifilter)
Definition: ffmpeg_filter.c:163
OFILTER_FLAG_AUTOROTATE
@ OFILTER_FLAG_AUTOROTATE
Definition: ffmpeg.h:289
AV_BUFFERSINK_FLAG_NO_REQUEST
#define AV_BUFFERSINK_FLAG_NO_REQUEST
Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
Definition: buffersink.h:92
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:747
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:204
pixfmt.h
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
AVALPHA_MODE_UNSPECIFIED
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition: pixfmt.h:817
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:265
InputFilter::name
uint8_t * name
Definition: ffmpeg.h:357
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:785
FPSConvContext::last_frame
AVFrame * last_frame
Definition: ffmpeg_filter.c:169
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:524
insert_filter
static int insert_filter(AVFilterContext **last_filter, int *pad_idx, const char *filter_name, const char *args)
Definition: ffmpeg_filter.c:1588
OutputFilterPriv::next_pts
int64_t next_pts
Definition: ffmpeg_filter.c:246
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:122
ReinitReason
ReinitReason
Definition: ffmpeg_filter.c:3068
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:444
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:569
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:993
av_dynarray_add_nofree
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:313
AVBufferSrcParameters::color_range
enum AVColorRange color_range
Definition: buffersrc.h:122
FrameOpaque
FrameOpaque
Definition: ffmpeg.h:75
OutputFilterPriv::swr_opts
AVDictionary * swr_opts
Definition: ffmpeg_filter.c:225
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
AVFrame::height
int height
Definition: frame.h:544
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:753
IFILTER_FLAG_CROP
@ IFILTER_FLAG_CROP
Definition: ffmpeg.h:253
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)
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:632
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
InputFilterPriv::bound
int bound
Definition: ffmpeg_filter.c:116
avfilter_init_dict
int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
Definition: avfilter.c:919
AVRational::den
int den
Denominator.
Definition: rational.h:60
InputStream::file
struct InputFile * file
Definition: ffmpeg.h:466
AVFilterChain
A filterchain is a list of filter specifications.
Definition: avfilter.h:904
InputFilterPriv::frame_queue
AVFifo * frame_queue
Definition: ffmpeg_filter.c:137
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
avfilter.h
InputFilterPriv::type_src
enum AVMediaType type_src
Definition: ffmpeg_filter.c:113
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:443
FilterGraphPriv::is_meta
int is_meta
Definition: ffmpeg_filter.c:53
insert_trim
static int insert_trim(void *logctx, int64_t start_time, int64_t duration, AVFilterContext **last_filter, int *pad_idx, const char *filter_name)
Definition: ffmpeg_filter.c:1537
IFILTER_FLAG_CFR
@ IFILTER_FLAG_CFR
Definition: ffmpeg.h:252
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:182
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:615
ifilter_bind_fg
static int ifilter_bind_fg(InputFilterPriv *ifp, FilterGraph *fg_src, int out_idx)
Definition: ffmpeg_filter.c:953
choose_out_timebase
static int choose_out_timebase(OutputFilterPriv *ofp, AVFrame *frame)
Definition: ffmpeg_filter.c:2386
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
OutputFilterPriv::flags
unsigned flags
Definition: ffmpeg_filter.c:249
OutputFilterPriv::sample_rates
const int * sample_rates
Definition: ffmpeg_filter.c:234
AVSideDataDescriptor
This struct describes the properties of a side data type.
Definition: frame.h:375
AVERROR_FILTER_NOT_FOUND
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
Definition: error.h:60
sub2video_copy_rect
static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h, AVSubtitleRect *r)
Definition: ffmpeg_filter.c:300
InputFilterPriv::side_data
AVFrameSideData ** side_data
Definition: ffmpeg_filter.c:134
AVFilterGraphSegment::nb_chains
size_t nb_chains
Definition: avfilter.h:930
OutputFilterPriv::alpha_modes
enum AVAlphaMode * alpha_modes
Definition: ffmpeg_filter.c:237
AVFilterContext
An instance of a filter.
Definition: avfilter.h:273
FilterGraph::class
const AVClass * class
Definition: ffmpeg.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:450
OutputFilter
Definition: ffmpeg.h:372
InputFilterPriv::drop_warned
int drop_warned
Definition: ffmpeg_filter.c:117
av_log_once
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
Definition: log.c:451
sub2video_frame
static int sub2video_frame(InputFilter *ifilter, AVFrame *frame, int buffer)
Definition: ffmpeg_filter.c:2958
InputFilterPriv::ifilter
InputFilter ifilter
Definition: ffmpeg_filter.c:101
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:617
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
configure_output_video_filter
static int configure_output_video_filter(FilterGraphPriv *fgp, AVFilterGraph *graph, OutputFilter *ofilter, AVFilterInOut *out)
Definition: ffmpeg_filter.c:1614
ViewSpecifier::type
enum ViewSpecifierType type
Definition: ffmpeg.h:117
av_buffersrc_get_nb_failed_requests
unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src)
Get the number of failed requests.
Definition: buffersrc.c:352
OutputFilterPriv::color_spaces
enum AVColorSpace * color_spaces
Definition: ffmpeg_filter.c:235
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
avio_open2
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: avio.c:497
av_buffersink_get_colorspace
enum AVColorSpace av_buffersink_get_colorspace(const AVFilterContext *ctx)
av_strdup
#define av_strdup(s)
Definition: ops_asmgen.c:47
adjust_frame_pts_to_encoder_tb
static double adjust_frame_pts_to_encoder_tb(void *logctx, AVFrame *frame, AVRational tb_dst, int64_t start_time)
Definition: ffmpeg_filter.c:2463
OutputFilter::nb_frames_drop
atomic_uint_least64_t nb_frames_drop
Definition: ffmpeg.h:393
auto_conversion_filters
int auto_conversion_filters
Definition: ffmpeg_opt.c:80
llrint
#define llrint(x)
Definition: libm.h:396
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:327
bind_inputs
static int bind_inputs(FilterGraph *fg, int commit)
Definition: ffmpeg_filter.c:1468
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
w
uint8_t w
Definition: llvidencdsp.c:39
InputStream::index
int index
Definition: ffmpeg.h:468
sch_filter_receive_finish
void sch_filter_receive_finish(Scheduler *sch, unsigned fg_idx, unsigned in_idx)
Called by filter tasks to signal that a filter input will no longer accept input.
Definition: ffmpeg_sched.c:2655
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
ENC_TIME_BASE_FILTER
@ ENC_TIME_BASE_FILTER
Definition: ffmpeg.h:66
FilterCommand::target
char * target
Definition: ffmpeg_filter.c:258
OutputFilterPriv::pix_fmts
enum AVPixelFormat * pix_fmts
Definition: ffmpeg_filter.c:230
av_frame_side_data_desc
const AVSideDataDescriptor * av_frame_side_data_desc(enum AVFrameSideDataType type)
Definition: side_data.c:68
fg_class
static const AVClass fg_class
Definition: ffmpeg_filter.c:1086
fg_create
int fg_create(FilterGraph **pfg, char **graph_desc, Scheduler *sch, const OutputFilterOptions *opts)
Create a new filtergraph in the global filtergraph list.
Definition: ffmpeg_filter.c:1093
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:86
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:260
OFILTER_FLAG_DISABLE_CONVERT
@ OFILTER_FLAG_DISABLE_CONVERT
Definition: ffmpeg.h:285
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:247
Decoder::type
enum AVMediaType type
Definition: ffmpeg.h:451
AVFormatContext::name
char * name
Name of this format context, only used for logging purposes.
Definition: avformat.h:1944
InputFilterPriv::format
int format
Definition: ffmpeg_filter.c:121
InputFilterPriv::end_pts
int64_t end_pts
Definition: ffmpeg_filter.c:156
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:115
av_frame_side_data_get
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
Definition: frame.h:1196
int32_t
int32_t
Definition: audioconvert.c:56
InputFilterPriv::alpha_mode
enum AVAlphaMode alpha_mode
Definition: ffmpeg_filter.c:127
sub2video_update
static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts, const AVSubtitle *sub)
Definition: ffmpeg_filter.c:347
timestamp.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: avio.c:622
OutputFilterPriv::format
int format
Definition: ffmpeg_filter.c:199
av_strlcpy
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:85
avfilter_graph_send_command
int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
Send a command to one or more filter instances.
Definition: avfiltergraph.c:1454
InputFilterPriv::downmixmatrix
AVBufferRef * downmixmatrix
Definition: ffmpeg_filter.c:148
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
graphprint.h
InputFilterPriv::opts
InputFilterOptions opts
Definition: ffmpeg_filter.c:103
dts_error_threshold
float dts_error_threshold
Definition: ffmpeg_opt.c:57
OutputFilterPriv::trim_duration_us
int64_t trim_duration_us
Definition: ffmpeg_filter.c:243
read_file_to_string
char * read_file_to_string(const char *filename)
Definition: cmdutils.c:1571
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
InputFilterPriv::downmixinfo
AVDownmixInfo downmixinfo
Definition: ffmpeg_filter.c:146
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
h
h
Definition: vp9dsp_template.c:2070
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:130
hw_device_for_filter
AVBufferRef * hw_device_for_filter(void)
Get a hardware device to be used with this filtergraph.
Definition: ffmpeg_hw.c:298
AVDictionaryEntry::value
char * value
Definition: dict.h:92
AVFilterGraph::nb_filters
unsigned nb_filters
Definition: avfilter.h:564
avstring.h
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:748
frame_data_c
const FrameData * frame_data_c(AVFrame *frame)
Definition: ffmpeg.c:493
OutputFilterPriv::tb_out
AVRational tb_out
Definition: ffmpeg_filter.c:217
AVFilterInOut
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:718
VSYNC_PASSTHROUGH
@ VSYNC_PASSTHROUGH
Definition: ffmpeg.h:58
OutputFilterPriv::height
int height
Definition: ffmpeg_filter.c:200
AV_FRAME_DATA_DOWNMIX_INFO
@ AV_FRAME_DATA_DOWNMIX_INFO
Metadata relevant to a downmix procedure.
Definition: frame.h:73
snprintf
#define snprintf
Definition: snprintf.h:34
SCH_FILTER_IN
#define SCH_FILTER_IN(filter, input)
Definition: ffmpeg_sched.h:126
FPSConvContext::framerate
AVRational framerate
Definition: ffmpeg_filter.c:184
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
buffersrc.h
fg_thread_set_name
static void fg_thread_set_name(const FilterGraph *fg)
Definition: ffmpeg_filter.c:3246
ist_find_unused
InputStream * ist_find_unused(enum AVMediaType type)
Find an unused input stream of given type.
Definition: ffmpeg_demux.c:191
sub2video_prepare
static void sub2video_prepare(InputFilterPriv *ifp)
Definition: ffmpeg_filter.c:1834
FilterGraph::is_internal
int is_internal
Definition: ffmpeg.h:408
av_rescale_q_rnd
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
Definition: mathematics.c:134
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42
AVSubtitle::start_display_time
uint32_t start_display_time
Definition: avcodec.h:2089
FilterCommand::command
char * command
Definition: ffmpeg_filter.c:259
src
#define src
Definition: vp8dsp.c:248
FilterCommand
Definition: ffmpeg_filter.c:257
duration
static int64_t duration
Definition: ffplay.c:329
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:63
InputFilterPriv::height
int height
Definition: ffmpeg_filter.c:123
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:3380
OutputFilter::nb_frames_dup
atomic_uint_least64_t nb_frames_dup
Definition: ffmpeg.h:392
filter_complex_nbthreads
int filter_complex_nbthreads
Definition: ffmpeg_opt.c:74
InputFilterOptions::framerate
AVRational framerate
Definition: ffmpeg.h:268
av_buffersink_get_color_range
enum AVColorRange av_buffersink_get_color_range(const AVFilterContext *ctx)
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:216
InputFilter::input_name
char * input_name
Definition: ffmpeg.h:365
LATENCY_PROBE_FILTER_POST
@ LATENCY_PROBE_FILTER_POST
Definition: ffmpeg.h:91
FPSConvContext::framerate_supported
const AVRational * framerate_supported
Definition: ffmpeg_filter.c:186