ffmpeg_filter.c
Go to the documentation of this file.
1 /*
2  * ffmpeg filter configuration
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "ffmpeg.h"
22 
23 #include "libavfilter/avfilter.h"
24 #include "libavfilter/buffersink.h"
25 
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/bprint.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/pixfmt.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/samplefmt.h"
37 
39 {
40  if (codec && codec->pix_fmts) {
41  const enum AVPixelFormat *p = codec->pix_fmts;
42  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
43  int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
44  enum AVPixelFormat best= AV_PIX_FMT_NONE;
46  if (st->codec->codec_id == AV_CODEC_ID_MJPEG) {
48  } else if (st->codec->codec_id == AV_CODEC_ID_LJPEG) {
51  }
52  }
53  for (; *p != AV_PIX_FMT_NONE; p++) {
54  best= avcodec_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
55  if (*p == target)
56  break;
57  }
58  if (*p == AV_PIX_FMT_NONE) {
59  if (target != AV_PIX_FMT_NONE)
61  "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
62  av_get_pix_fmt_name(target),
63  codec->name,
64  av_get_pix_fmt_name(best));
65  return best;
66  }
67  }
68  return target;
69 }
70 
72 {
73  if (codec && codec->sample_fmts) {
74  const enum AVSampleFormat *p = codec->sample_fmts;
75  for (; *p != -1; p++) {
76  if (*p == st->codec->sample_fmt)
77  break;
78  }
79  if (*p == -1) {
81  av_log(NULL, AV_LOG_ERROR, "Conversion will not be lossless.\n");
84  "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
86  codec->name,
88  st->codec->sample_fmt = codec->sample_fmts[0];
89  }
90  }
91 }
92 
93 static char *choose_pix_fmts(OutputStream *ost)
94 {
95  if (ost->keep_pix_fmt) {
96  if (ost->filter)
99  if (ost->st->codec->pix_fmt == AV_PIX_FMT_NONE)
100  return NULL;
101  return av_strdup(av_get_pix_fmt_name(ost->st->codec->pix_fmt));
102  }
103  if (ost->st->codec->pix_fmt != AV_PIX_FMT_NONE) {
104  return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc, ost->st->codec->pix_fmt)));
105  } else if (ost->enc && ost->enc->pix_fmts) {
106  const enum AVPixelFormat *p;
107  AVIOContext *s = NULL;
108  uint8_t *ret;
109  int len;
110 
111  if (avio_open_dyn_buf(&s) < 0)
112  exit(1);
113 
114  p = ost->enc->pix_fmts;
116  if (ost->st->codec->codec_id == AV_CODEC_ID_MJPEG) {
118  } else if (ost->st->codec->codec_id == AV_CODEC_ID_LJPEG) {
121  }
122  }
123 
124  for (; *p != AV_PIX_FMT_NONE; p++) {
125  const char *name = av_get_pix_fmt_name(*p);
126  avio_printf(s, "%s|", name);
127  }
128  len = avio_close_dyn_buf(s, &ret);
129  ret[len - 1] = 0;
130  return ret;
131  } else
132  return NULL;
133 }
134 
135 /* Define a function for building a string containing a list of
136  * allowed formats. */
137 #define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name) \
138 static char *choose_ ## var ## s(OutputStream *ost) \
139 { \
140  if (ost->st->codec->var != none) { \
141  get_name(ost->st->codec->var); \
142  return av_strdup(name); \
143  } else if (ost->enc && ost->enc->supported_list) { \
144  const type *p; \
145  AVIOContext *s = NULL; \
146  uint8_t *ret; \
147  int len; \
148  \
149  if (avio_open_dyn_buf(&s) < 0) \
150  exit(1); \
151  \
152  for (p = ost->enc->supported_list; *p != none; p++) { \
153  get_name(*p); \
154  avio_printf(s, "%s|", name); \
155  } \
156  len = avio_close_dyn_buf(s, &ret); \
157  ret[len - 1] = 0; \
158  return ret; \
159  } else \
160  return NULL; \
161 }
162 
163 // DEF_CHOOSE_FORMAT(enum AVPixelFormat, pix_fmt, pix_fmts, AV_PIX_FMT_NONE,
164 // GET_PIX_FMT_NAME)
165 
168 
171 
172 DEF_CHOOSE_FORMAT(uint64_t, channel_layout, channel_layouts, 0,
174 
176 {
177  FilterGraph *fg = av_mallocz(sizeof(*fg));
178 
179  if (!fg)
180  exit(1);
181  fg->index = nb_filtergraphs;
182 
183  GROW_ARRAY(fg->outputs, fg->nb_outputs);
184  if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
185  exit(1);
186  fg->outputs[0]->ost = ost;
187  fg->outputs[0]->graph = fg;
188 
189  ost->filter = fg->outputs[0];
190 
191  GROW_ARRAY(fg->inputs, fg->nb_inputs);
192  if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
193  exit(1);
194  fg->inputs[0]->ist = ist;
195  fg->inputs[0]->graph = fg;
196 
197  GROW_ARRAY(ist->filters, ist->nb_filters);
198  ist->filters[ist->nb_filters - 1] = fg->inputs[0];
199 
201  filtergraphs[nb_filtergraphs - 1] = fg;
202 
203  return fg;
204 }
205 
207 {
208  InputStream *ist = NULL;
210  int i;
211 
212  // TODO: support other filter types
213  if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
214  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
215  "currently.\n");
216  exit(1);
217  }
218 
219  if (in->name) {
221  AVStream *st = NULL;
222  char *p;
223  int file_idx = strtol(in->name, &p, 0);
224 
225  if (file_idx < 0 || file_idx >= nb_input_files) {
226  av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
227  file_idx, fg->graph_desc);
228  exit(1);
229  }
230  s = input_files[file_idx]->ctx;
231 
232  for (i = 0; i < s->nb_streams; i++) {
233  enum AVMediaType stream_type = s->streams[i]->codec->codec_type;
234  if (stream_type != type &&
235  !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
236  type == AVMEDIA_TYPE_VIDEO /* sub2video hack */))
237  continue;
238  if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
239  st = s->streams[i];
240  break;
241  }
242  }
243  if (!st) {
244  av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
245  "matches no streams.\n", p, fg->graph_desc);
246  exit(1);
247  }
248  ist = input_streams[input_files[file_idx]->ist_index + st->index];
249  } else {
250  /* find the first unused stream of corresponding type */
251  for (i = 0; i < nb_input_streams; i++) {
252  ist = input_streams[i];
253  if (ist->st->codec->codec_type == type && ist->discard)
254  break;
255  }
256  if (i == nb_input_streams) {
257  av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
258  "unlabeled input pad %d on filter %s\n", in->pad_idx,
259  in->filter_ctx->name);
260  exit(1);
261  }
262  }
263  av_assert0(ist);
264 
265  ist->discard = 0;
266  ist->decoding_needed++;
267  ist->st->discard = AVDISCARD_NONE;
268 
269  GROW_ARRAY(fg->inputs, fg->nb_inputs);
270  if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
271  exit(1);
272  fg->inputs[fg->nb_inputs - 1]->ist = ist;
273  fg->inputs[fg->nb_inputs - 1]->graph = fg;
274 
275  GROW_ARRAY(ist->filters, ist->nb_filters);
276  ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
277 }
278 
280 {
281  char *pix_fmts;
282  OutputStream *ost = ofilter->ost;
283  AVCodecContext *codec = ost->st->codec;
284  AVFilterContext *last_filter = out->filter_ctx;
285  int pad_idx = out->pad_idx;
286  int ret;
287  char name[255];
288 
289  snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
290  ret = avfilter_graph_create_filter(&ofilter->filter,
291  avfilter_get_by_name("buffersink"),
292  name, NULL, NULL, fg->graph);
293 
294  if (ret < 0)
295  return ret;
296 
297  if (codec->width || codec->height) {
298  char args[255];
300 
301  snprintf(args, sizeof(args), "%d:%d:flags=0x%X",
302  codec->width,
303  codec->height,
304  (unsigned)ost->sws_flags);
305  snprintf(name, sizeof(name), "scaler for output stream %d:%d",
306  ost->file_index, ost->index);
307  if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
308  name, args, NULL, fg->graph)) < 0)
309  return ret;
310  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
311  return ret;
312 
313  last_filter = filter;
314  pad_idx = 0;
315  }
316 
317  if ((pix_fmts = choose_pix_fmts(ost))) {
319  snprintf(name, sizeof(name), "pixel format for output stream %d:%d",
320  ost->file_index, ost->index);
321  if ((ret = avfilter_graph_create_filter(&filter,
322  avfilter_get_by_name("format"),
323  "format", pix_fmts, NULL,
324  fg->graph)) < 0)
325  return ret;
326  if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
327  return ret;
328 
329  last_filter = filter;
330  pad_idx = 0;
331  av_freep(&pix_fmts);
332  }
333 
334  if (ost->frame_rate.num && 0) {
335  AVFilterContext *fps;
336  char args[255];
337 
338  snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
339  ost->frame_rate.den);
340  snprintf(name, sizeof(name), "fps for output stream %d:%d",
341  ost->file_index, ost->index);
343  name, args, NULL, fg->graph);
344  if (ret < 0)
345  return ret;
346 
347  ret = avfilter_link(last_filter, pad_idx, fps, 0);
348  if (ret < 0)
349  return ret;
350  last_filter = fps;
351  pad_idx = 0;
352  }
353 
354  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
355  return ret;
356 
357  return 0;
358 }
359 
361 {
362  OutputStream *ost = ofilter->ost;
363  AVCodecContext *codec = ost->st->codec;
364  AVFilterContext *last_filter = out->filter_ctx;
365  int pad_idx = out->pad_idx;
366  char *sample_fmts, *sample_rates, *channel_layouts;
367  char name[255];
368  int ret;
369 
370  snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
371  ret = avfilter_graph_create_filter(&ofilter->filter,
372  avfilter_get_by_name("abuffersink"),
373  name, NULL, NULL, fg->graph);
374  if (ret < 0)
375  return ret;
376  if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
377  return ret;
378 
379 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
380  AVFilterContext *filt_ctx; \
381  \
382  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
383  "similarly to -af " filter_name "=%s.\n", arg); \
384  \
385  ret = avfilter_graph_create_filter(&filt_ctx, \
386  avfilter_get_by_name(filter_name), \
387  filter_name, arg, NULL, fg->graph); \
388  if (ret < 0) \
389  return ret; \
390  \
391  ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
392  if (ret < 0) \
393  return ret; \
394  \
395  last_filter = filt_ctx; \
396  pad_idx = 0; \
397 } while (0)
398  if (ost->audio_channels_mapped) {
399  int i;
400  AVBPrint pan_buf;
401  av_bprint_init(&pan_buf, 256, 8192);
402  av_bprintf(&pan_buf, "0x%"PRIx64,
404  for (i = 0; i < ost->audio_channels_mapped; i++)
405  if (ost->audio_channels_map[i] != -1)
406  av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
407 
408  AUTO_INSERT_FILTER("-map_channel", "pan", pan_buf.str);
409  av_bprint_finalize(&pan_buf, NULL);
410  }
411 
412  if (codec->channels && !codec->channel_layout)
414 
415  sample_fmts = choose_sample_fmts(ost);
416  sample_rates = choose_sample_rates(ost);
417  channel_layouts = choose_channel_layouts(ost);
418  if (sample_fmts || sample_rates || channel_layouts) {
420  char args[256];
421  args[0] = 0;
422 
423  if (sample_fmts)
424  av_strlcatf(args, sizeof(args), "sample_fmts=%s:",
425  sample_fmts);
426  if (sample_rates)
427  av_strlcatf(args, sizeof(args), "sample_rates=%s:",
428  sample_rates);
429  if (channel_layouts)
430  av_strlcatf(args, sizeof(args), "channel_layouts=%s:",
431  channel_layouts);
432 
433  av_freep(&sample_fmts);
434  av_freep(&sample_rates);
435  av_freep(&channel_layouts);
436 
437  snprintf(name, sizeof(name), "audio format for output stream %d:%d",
438  ost->file_index, ost->index);
439  ret = avfilter_graph_create_filter(&format,
440  avfilter_get_by_name("aformat"),
441  name, args, NULL, fg->graph);
442  if (ret < 0)
443  return ret;
444 
445  ret = avfilter_link(last_filter, pad_idx, format, 0);
446  if (ret < 0)
447  return ret;
448 
449  last_filter = format;
450  pad_idx = 0;
451  }
452 
453  if (audio_volume != 256 && 0) {
454  char args[256];
455 
456  snprintf(args, sizeof(args), "%f", audio_volume / 256.);
457  AUTO_INSERT_FILTER("-vol", "volume", args);
458  }
459 
460  if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
461  return ret;
462 
463  return 0;
464 }
465 
466 #define DESCRIBE_FILTER_LINK(f, inout, in) \
467 { \
468  AVFilterContext *ctx = inout->filter_ctx; \
469  AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \
470  int nb_pads = in ? ctx->input_count : ctx->output_count; \
471  AVIOContext *pb; \
472  \
473  if (avio_open_dyn_buf(&pb) < 0) \
474  exit(1); \
475  \
476  avio_printf(pb, "%s", ctx->filter->name); \
477  if (nb_pads > 1) \
478  avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
479  avio_w8(pb, 0); \
480  avio_close_dyn_buf(pb, &f->name); \
481 }
482 
484 {
485  av_freep(&ofilter->name);
486  DESCRIBE_FILTER_LINK(ofilter, out, 0);
487 
488  switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
489  case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
490  case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
491  default: av_assert0(0);
492  }
493 }
494 
496 {
498  int i, w, h;
499 
500  /* Compute the size of the canvas for the subtitles stream.
501  If the subtitles codec has set a size, use it. Otherwise use the
502  maximum dimensions of the video streams in the same file. */
503  w = ist->st->codec->width;
504  h = ist->st->codec->height;
505  if (!(w && h)) {
506  for (i = 0; i < avf->nb_streams; i++) {
507  if (avf->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
508  w = FFMAX(w, avf->streams[i]->codec->width);
509  h = FFMAX(h, avf->streams[i]->codec->height);
510  }
511  }
512  if (!(w && h)) {
513  w = FFMAX(w, 720);
514  h = FFMAX(h, 576);
515  }
516  av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
517  }
518  ist->sub2video.w = ist->st->codec->width = ist->resample_width = w;
519  ist->sub2video.h = ist->st->codec->height = ist->resample_height = h;
520 
521  /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
522  palettes for all rectangles are identical or compatible */
524 
525  ist->sub2video.frame = av_frame_alloc();
526  if (!ist->sub2video.frame)
527  return AVERROR(ENOMEM);
528  return 0;
529 }
530 
532  AVFilterInOut *in)
533 {
535  AVFilter *filter = avfilter_get_by_name("buffer");
536  InputStream *ist = ifilter->ist;
537  AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
538  ist->st->time_base;
539  AVRational fr = ist->framerate;
540  AVRational sar;
541  AVBPrint args;
542  char name[255];
543  int pad_idx = in->pad_idx;
544  int ret;
545 
546  if (!fr.num)
547  fr = av_guess_frame_rate(input_files[ist->file_index]->ctx, ist->st, NULL);
548 
549  if (ist->st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
550  ret = sub2video_prepare(ist);
551  if (ret < 0)
552  return ret;
553  }
554 
555  sar = ist->st->sample_aspect_ratio.num ?
556  ist->st->sample_aspect_ratio :
558  if(!sar.den)
559  sar = (AVRational){0,1};
560  av_bprint_init(&args, 0, 1);
561  av_bprintf(&args,
562  "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
563  "pixel_aspect=%d/%d:sws_param=flags=%d", ist->resample_width,
565  tb.num, tb.den, sar.num, sar.den,
567  if (fr.num && fr.den)
568  av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
569  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
570  ist->file_index, ist->st->index);
571 
572  if ((ret = avfilter_graph_create_filter(&ifilter->filter, filter, name,
573  args.str, NULL, fg->graph)) < 0)
574  return ret;
575 
576  if (ist->framerate.num) {
577  AVFilterContext *setpts;
578 
579  snprintf(name, sizeof(name), "force CFR for input from stream %d:%d",
580  ist->file_index, ist->st->index);
581  if ((ret = avfilter_graph_create_filter(&setpts,
582  avfilter_get_by_name("setpts"),
583  name, "N", NULL,
584  fg->graph)) < 0)
585  return ret;
586 
587  if ((ret = avfilter_link(setpts, 0, first_filter, pad_idx)) < 0)
588  return ret;
589 
590  first_filter = setpts;
591  pad_idx = 0;
592  }
593 
594  if (do_deinterlace) {
595  AVFilterContext *yadif;
596 
597  snprintf(name, sizeof(name), "deinterlace input from stream %d:%d",
598  ist->file_index, ist->st->index);
599  if ((ret = avfilter_graph_create_filter(&yadif,
600  avfilter_get_by_name("yadif"),
601  name, "", NULL,
602  fg->graph)) < 0)
603  return ret;
604 
605  if ((ret = avfilter_link(yadif, 0, first_filter, pad_idx)) < 0)
606  return ret;
607 
608  first_filter = yadif;
609  pad_idx = 0;
610  }
611 
612  if ((ret = avfilter_link(ifilter->filter, 0, first_filter, pad_idx)) < 0)
613  return ret;
614  return 0;
615 }
616 
618  AVFilterInOut *in)
619 {
621  AVFilter *filter = avfilter_get_by_name("abuffer");
622  InputStream *ist = ifilter->ist;
623  int pad_idx = in->pad_idx;
624  AVBPrint args;
625  char name[255];
626  int ret;
627 
629  av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
630  1, ist->st->codec->sample_rate,
631  ist->st->codec->sample_rate,
633  if (ist->st->codec->channel_layout)
634  av_bprintf(&args, ":channel_layout=0x%"PRIx64,
635  ist->st->codec->channel_layout);
636  else
637  av_bprintf(&args, ":channels=%d", ist->st->codec->channels);
638  snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
639  ist->file_index, ist->st->index);
640 
641  if ((ret = avfilter_graph_create_filter(&ifilter->filter, filter,
642  name, args.str, NULL,
643  fg->graph)) < 0)
644  return ret;
645 
646 #define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
647  AVFilterContext *filt_ctx; \
648  \
649  av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
650  "similarly to -af " filter_name "=%s.\n", arg); \
651  \
652  snprintf(name, sizeof(name), "graph %d %s for input stream %d:%d", \
653  fg->index, filter_name, ist->file_index, ist->st->index); \
654  ret = avfilter_graph_create_filter(&filt_ctx, \
655  avfilter_get_by_name(filter_name), \
656  name, arg, NULL, fg->graph); \
657  if (ret < 0) \
658  return ret; \
659  \
660  ret = avfilter_link(filt_ctx, 0, first_filter, pad_idx); \
661  if (ret < 0) \
662  return ret; \
663  \
664  first_filter = filt_ctx; \
665 } while (0)
666 
667  if (audio_sync_method > 0) {
668  char args[256] = {0};
669 
670  av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method);
671  if (audio_drift_threshold != 0.1)
672  av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", audio_drift_threshold);
673  if (!fg->reconfiguration)
674  av_strlcatf(args, sizeof(args), ":first_pts=0");
675  AUTO_INSERT_FILTER_INPUT("-async", "aresample", args);
676  }
677 
678 // if (ost->audio_channels_mapped) {
679 // int i;
680 // AVBPrint pan_buf;
681 // av_bprint_init(&pan_buf, 256, 8192);
682 // av_bprintf(&pan_buf, "0x%"PRIx64,
683 // av_get_default_channel_layout(ost->audio_channels_mapped));
684 // for (i = 0; i < ost->audio_channels_mapped; i++)
685 // if (ost->audio_channels_map[i] != -1)
686 // av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
687 // AUTO_INSERT_FILTER_INPUT("-map_channel", "pan", pan_buf.str);
688 // av_bprint_finalize(&pan_buf, NULL);
689 // }
690 
691  if (audio_volume != 256) {
692  char args[256];
693 
694  av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
695  "audio filter instead.\n");
696 
697  snprintf(args, sizeof(args), "%f", audio_volume / 256.);
698  AUTO_INSERT_FILTER_INPUT("-vol", "volume", args);
699  }
700  if ((ret = avfilter_link(ifilter->filter, 0, first_filter, pad_idx)) < 0)
701  return ret;
702 
703  return 0;
704 }
705 
707  AVFilterInOut *in)
708 {
709  av_freep(&ifilter->name);
710  DESCRIBE_FILTER_LINK(ifilter, in, 1);
711 
712  switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
713  case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
714  case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
715  default: av_assert0(0);
716  }
717 }
718 
720 {
721  AVFilterInOut *inputs, *outputs, *cur;
722  int ret, i, init = !fg->graph, simple = !fg->graph_desc;
723  const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
724  fg->graph_desc;
725 
727  if (!(fg->graph = avfilter_graph_alloc()))
728  return AVERROR(ENOMEM);
729 
730  if (simple) {
731  OutputStream *ost = fg->outputs[0]->ost;
732  char args[512];
733  AVDictionaryEntry *e = NULL;
734 
735  snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
736  fg->graph->scale_sws_opts = av_strdup(args);
737 
738  args[0] = 0;
739  while ((e = av_dict_get(ost->swr_opts, "", e,
741  av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
742  }
743  if (strlen(args))
744  args[strlen(args)-1] = 0;
745  av_opt_set(fg->graph, "aresample_swr_opts", args, 0);
746 
747  args[0] = '\0';
748  while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
750  av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
751  }
752  if (strlen(args))
753  args[strlen(args) - 1] = '\0';
754  fg->graph->resample_lavr_opts = av_strdup(args);
755  }
756 
757  if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
758  return ret;
759 
760  if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
761  av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' does not have "
762  "exactly one input and output.\n", graph_desc);
763  return AVERROR(EINVAL);
764  }
765 
766  for (cur = inputs; !simple && init && cur; cur = cur->next)
767  init_input_filter(fg, cur);
768 
769  for (cur = inputs, i = 0; cur; cur = cur->next, i++)
770  if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0)
771  return ret;
772  avfilter_inout_free(&inputs);
773 
774  if (!init || simple) {
775  /* we already know the mappings between lavfi outputs and output streams,
776  * so we can finish the setup */
777  for (cur = outputs, i = 0; cur; cur = cur->next, i++)
778  configure_output_filter(fg, fg->outputs[i], cur);
779  avfilter_inout_free(&outputs);
780 
781  if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
782  return ret;
783  } else {
784  /* wait until output mappings are processed */
785  for (cur = outputs; cur;) {
786  GROW_ARRAY(fg->outputs, fg->nb_outputs);
787  if (!(fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]))))
788  exit(1);
789  fg->outputs[fg->nb_outputs - 1]->graph = fg;
790  fg->outputs[fg->nb_outputs - 1]->out_tmp = cur;
791  cur = cur->next;
792  fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL;
793  }
794  }
795 
796  fg->reconfiguration = 1;
797  return 0;
798 }
799 
801 {
802  int i;
803  for (i = 0; i < fg->nb_inputs; i++)
804  if (fg->inputs[i]->ist == ist)
805  return 1;
806  return 0;
807 }
808 
const char * name
Definition: avisynth_c.h:675
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
Enable or disable automatic format conversion inside the graph.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
int keep_pix_fmt
Definition: ffmpeg.h:364
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:93
uint8_t * name
Definition: ffmpeg.h:194
int nb_outputs
Definition: ffmpeg.h:210
AVDictionary * swr_opts
Definition: ffmpeg.h:355
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:988
AVRational frame_rate
Definition: ffmpeg.h:329
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:73
misc image utilities
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:53
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
AVStream * st
Definition: ffmpeg.h:313
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVRational framerate
Definition: ffmpeg.h:239
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:175
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
Definition: avfilter.h:1134
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:1828
AVFilterInOut * out_tmp
Definition: ffmpeg.h:197
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:842
#define CODEC_CAP_LOSSLESS
Codec is lossless.
int decoding_needed
Definition: ffmpeg.h:217
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:709
int num
numerator
Definition: rational.h:44
FilterGraph * init_simple_filtergraph(InputStream *ist, OutputStream *ost)
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
int index
stream index in AVFormatContext
Definition: avformat.h:644
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:75
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name)
int nb_input_streams
Definition: ffmpeg.c:146
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:976
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:193
int index
Definition: ffmpeg.h:201
output residual component w
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:1002
struct FilterGraph * graph
Definition: ffmpeg.h:186
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
Format I/O context.
Definition: avformat.h:944
AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
int configure_filtergraph(FilterGraph *fg)
memory buffer sink API for audio and video
struct InputStream * ist
Definition: ffmpeg.h:185
char * name
name of this filter instance
Definition: avfilter.h:529
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVFilterGraph * graph
Definition: ffmpeg.h:204
supported_samplerates
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:114
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:538
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
enum AVSampleFormat sample_fmt
audio sample format
uint8_t
AVOptions.
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
int audio_sync_method
Definition: ffmpeg_opt.c:72
AVStream ** streams
Definition: avformat.h:992
the mask is usually to keep the same permissions Filters should remove permissions on reference they give to output whenever necessary It can be automatically done by setting the rej_perms field on the output pad Here are a few guidelines corresponding to common then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:142
char * resample_lavr_opts
libavresample options to use for the auto-inserted resample filters
Definition: avfilter.h:1003
#define SWS_BITEXACT
Definition: swscale.h:84
AVDictionary * resample_opts
Definition: ffmpeg.h:356
AVFilterContext * filter
Definition: ffmpeg.h:191
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:81
int nb_input_files
Definition: ffmpeg.c:148
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
Definition: graphparser.c:379
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
int file_index
Definition: ffmpeg.h:214
struct InputStream::sub2video sub2video
int resample_pix_fmt
Definition: ffmpeg.h:245
int resample_height
Definition: ffmpeg.h:243
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:531
#define GET_CH_LAYOUT_NAME(ch_layout)
Definition: cmdutils.h:544
FilterGraph ** filtergraphs
Definition: ffmpeg.c:155
AVFilterContext * filter
Definition: ffmpeg.h:184
enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum AVPixelFormat target)
Definition: ffmpeg_filter.c:38
int64_t sws_flags
Definition: ffmpeg.h:353
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
Definition: bprint.c:68
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:99
int capabilities
Codec capabilities.
int flags
CODEC_FLAG_*.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:394
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
#define FFMAX(a, b)
Definition: common.h:56
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
uint64_t channel_layout
Audio channel layout.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:72
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
OutputFilter * filter
Definition: ffmpeg.h:350
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
struct AVRational AVRational
rational number numerator/denominator
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
Buffer to print data progressively.
Definition: bprint.h:75
audio channel layout utility functions
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
external API header
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:80
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:538
static AVFilter * first_filter
Definition: avfilter.c:389
struct OutputStream * ost
Definition: ffmpeg.h:192
ret
Definition: avfilter.c:821
int width
picture width / height.
AVS_Value args
Definition: avisynth_c.h:603
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
int nb_filtergraphs
Definition: ffmpeg.c:156
all automatic conversions disabled
Definition: avfilter.h:1096
int audio_channels_mapped
Definition: ffmpeg.h:345
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
#define GET_SAMPLE_FMT_NAME(sample_fmt)
Definition: cmdutils.h:537
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1128
int audio_volume
Definition: ffmpeg_opt.c:71
Stream structure.
Definition: avformat.h:643
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1123
InputFilter ** filters
Definition: ffmpeg.h:270
enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
Find the best pixel format to convert to given a certain source pixel format and a selection of two d...
Definition: imgconvert.c:218
#define GET_SAMPLE_RATE_NAME(rate)
Definition: cmdutils.h:540
NULL
Definition: eval.c:55
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
sample_rate
#define AV_BPRINT_SIZE_AUTOMATIC
Definition: bprint.h:90
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
enum AVMediaType codec_type
enum AVCodecID codec_id
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
int sample_rate
samples per second
static char * choose_pix_fmts(OutputStream *ost)
Definition: ffmpeg_filter.c:93
int ist_index
Definition: ffmpeg.h:280
const char * graph_desc
Definition: ffmpeg.h:202
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
main external API structure.
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:259
static int sub2video_prepare(InputStream *ist)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
#define AUTO_INSERT_FILTER(opt_name, filter_name, arg)
int audio_channels_map[SWR_CH_MAX]
Definition: ffmpeg.h:344
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
AVStream * st
Definition: ffmpeg.h:215
Filter definition.
Definition: avfilter.h:436
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:1131
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
int file_index
Definition: ffmpeg.h:310
AVMediaType
Definition: avutil.h:141
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:100
#define snprintf
Definition: snprintf.h:34
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
#define type
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:95
float audio_drift_threshold
Definition: ffmpeg_opt.c:67
char * name
unique name for this input/output in the list
Definition: avfilter.h:1125
int nb_filters
Definition: ffmpeg.h:271
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:122
int resample_width
Definition: ffmpeg.h:244
int reconfiguration
Definition: ffmpeg.h:205
struct FilterGraph * graph
Definition: ffmpeg.h:193
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
#define DESCRIBE_FILTER_LINK(f, inout, in)
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
#define SWS_BILINEAR
Definition: swscale.h:59
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:82
char * key
Definition: dict.h:81
int den
denominator
Definition: rational.h:45
AVFormatContext * ctx
Definition: ffmpeg.h:277
AVCodec * enc
Definition: ffmpeg.h:324
int do_deinterlace
Definition: ffmpeg_opt.c:74
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:531
pixel format definitions
char * avfilter
Definition: ffmpeg.h:351
uint8_t * name
Definition: ffmpeg.h:187
char * value
Definition: dict.h:82
int len
int channels
number of audio channels
OutputFilter ** outputs
Definition: ffmpeg.h:209
InputFile ** input_files
Definition: ffmpeg.c:147
An instance of a filter.
Definition: avfilter.h:524
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:700
#define AV_LOG_INFO
Definition: log.h:156
InputFilter ** inputs
Definition: ffmpeg.h:207
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
int discard
Definition: ffmpeg.h:216
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:1700
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
void choose_sample_fmt(AVStream *st, AVCodec *codec)
Definition: ffmpeg_filter.c:71
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:391
int nb_inputs
Definition: ffmpeg.h:208
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:702
int index
Definition: ffmpeg.h:311
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
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
#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg)
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:252
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
#define tb
Definition: regdef.h:68
InputStream ** input_streams
Definition: ffmpeg.c:145
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
discard nothing
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.