FFmpeg
ffmpeg_mux_init.c
Go to the documentation of this file.
1 /*
2  * Muxer/output file setup.
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 <string.h>
22 
23 #include "cmdutils.h"
24 #include "ffmpeg.h"
25 #include "ffmpeg_mux.h"
26 #include "fopen_utf8.h"
27 
28 #include "libavformat/avformat.h"
29 #include "libavformat/avio.h"
30 
31 #include "libavcodec/avcodec.h"
32 
33 #include "libavfilter/avfilter.h"
34 
35 #include "libavutil/avassert.h"
36 #include "libavutil/avstring.h"
37 #include "libavutil/avutil.h"
38 #include "libavutil/bprint.h"
39 #include "libavutil/dict.h"
40 #include "libavutil/getenv_utf8.h"
41 #include "libavutil/intreadwrite.h"
42 #include "libavutil/log.h"
43 #include "libavutil/mem.h"
44 #include "libavutil/opt.h"
45 #include "libavutil/parseutils.h"
46 #include "libavutil/pixdesc.h"
47 
48 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
49 
50 static const char *const opt_name_apad[] = {"apad", NULL};
51 static const char *const opt_name_autoscale[] = {"autoscale", NULL};
52 static const char *const opt_name_bits_per_raw_sample[] = {"bits_per_raw_sample", NULL};
53 static const char *const opt_name_bitstream_filters[] = {"bsf", "absf", "vbsf", NULL};
54 static const char *const opt_name_copy_initial_nonkeyframes[] = {"copyinkf", NULL};
55 static const char *const opt_name_copy_prior_start[] = {"copypriorss", NULL};
56 static const char *const opt_name_disposition[] = {"disposition", NULL};
57 static const char *const opt_name_enc_time_bases[] = {"enc_time_base", NULL};
58 static const char *const opt_name_enc_stats_pre[] = {"enc_stats_pre", NULL};
59 static const char *const opt_name_enc_stats_post[] = {"enc_stats_post", NULL};
60 static const char *const opt_name_enc_stats_pre_fmt[] = {"enc_stats_pre_fmt", NULL};
61 static const char *const opt_name_enc_stats_post_fmt[] = {"enc_stats_post_fmt", NULL};
62 static const char *const opt_name_filters[] = {"filter", "af", "vf", NULL};
63 static const char *const opt_name_filter_scripts[] = {"filter_script", NULL};
64 static const char *const opt_name_fix_sub_duration_heartbeat[] = {"fix_sub_duration_heartbeat", NULL};
65 static const char *const opt_name_fps_mode[] = {"fps_mode", NULL};
66 static const char *const opt_name_force_fps[] = {"force_fps", NULL};
67 static const char *const opt_name_forced_key_frames[] = {"forced_key_frames", NULL};
68 static const char *const opt_name_frame_aspect_ratios[] = {"aspect", NULL};
69 static const char *const opt_name_intra_matrices[] = {"intra_matrix", NULL};
70 static const char *const opt_name_inter_matrices[] = {"inter_matrix", NULL};
71 static const char *const opt_name_chroma_intra_matrices[] = {"chroma_intra_matrix", NULL};
72 static const char *const opt_name_max_frame_rates[] = {"fpsmax", NULL};
73 static const char *const opt_name_max_frames[] = {"frames", "aframes", "vframes", "dframes", NULL};
74 static const char *const opt_name_max_muxing_queue_size[] = {"max_muxing_queue_size", NULL};
75 static const char *const opt_name_muxing_queue_data_threshold[] = {"muxing_queue_data_threshold", NULL};
76 static const char *const opt_name_pass[] = {"pass", NULL};
77 static const char *const opt_name_passlogfiles[] = {"passlogfile", NULL};
78 static const char *const opt_name_presets[] = {"pre", "apre", "vpre", "spre", NULL};
79 static const char *const opt_name_qscale[] = {"q", "qscale", NULL};
80 static const char *const opt_name_rc_overrides[] = {"rc_override", NULL};
81 static const char *const opt_name_time_bases[] = {"time_base", NULL};
82 static const char *const opt_name_audio_channels[] = {"ac", NULL};
83 static const char *const opt_name_audio_ch_layouts[] = {"channel_layout", "ch_layout", NULL};
84 static const char *const opt_name_audio_sample_rate[] = {"ar", NULL};
85 static const char *const opt_name_frame_sizes[] = {"s", NULL};
86 static const char *const opt_name_frame_pix_fmts[] = {"pix_fmt", NULL};
87 static const char *const opt_name_sample_fmts[] = {"sample_fmt", NULL};
88 
89 static int check_opt_bitexact(void *ctx, const AVDictionary *opts,
90  const char *opt_name, int flag)
91 {
92  const AVDictionaryEntry *e = av_dict_get(opts, opt_name, NULL, 0);
93 
94  if (e) {
95  const AVOption *o = av_opt_find(ctx, opt_name, NULL, 0, 0);
96  int val = 0;
97  if (!o)
98  return 0;
99  av_opt_eval_flags(ctx, o, e->value, &val);
100  return !!(val & flag);
101  }
102  return 0;
103 }
104 
106  OutputStream *ost, const AVCodec **enc)
107 {
108  enum AVMediaType type = ost->st->codecpar->codec_type;
109  char *codec_name = NULL;
110 
111  *enc = NULL;
112 
114  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
115  if (!codec_name) {
116  ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
117  NULL, ost->st->codecpar->codec_type);
119  if (!*enc) {
120  av_log(ost, AV_LOG_FATAL, "Automatic encoder selection failed "
121  "Default encoder for format %s (codec %s) is "
122  "probably disabled. Please choose an encoder manually.\n",
123  s->oformat->name, avcodec_get_name(ost->st->codecpar->codec_id));
125  }
126  } else if (strcmp(codec_name, "copy")) {
127  *enc = find_codec_or_die(ost, codec_name, ost->st->codecpar->codec_type, 1);
128  ost->st->codecpar->codec_id = (*enc)->id;
129  }
130  }
131 
132  return 0;
133 }
134 
135 static char *get_line(AVIOContext *s, AVBPrint *bprint)
136 {
137  char c;
138 
139  while ((c = avio_r8(s)) && c != '\n')
140  av_bprint_chars(bprint, c, 1);
141 
142  if (!av_bprint_is_complete(bprint))
143  report_and_exit(AVERROR(ENOMEM));
144  return bprint->str;
145 }
146 
147 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
148 {
149  int i, ret = -1;
150  char filename[1000];
151  char *env_avconv_datadir = getenv_utf8("AVCONV_DATADIR");
152  char *env_home = getenv_utf8("HOME");
153  const char *base[3] = { env_avconv_datadir,
154  env_home,
155  AVCONV_DATADIR,
156  };
157 
158  for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
159  if (!base[i])
160  continue;
161  if (codec_name) {
162  snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
163  i != 1 ? "" : "/.avconv", codec_name, preset_name);
164  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
165  }
166  if (ret < 0) {
167  snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
168  i != 1 ? "" : "/.avconv", preset_name);
169  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
170  }
171  }
172  freeenv_utf8(env_home);
173  freeenv_utf8(env_avconv_datadir);
174  return ret;
175 }
176 
177 typedef struct EncStatsFile {
178  char *path;
180 } EncStatsFile;
181 
184 
185 static int enc_stats_get_file(AVIOContext **io, const char *path)
186 {
187  EncStatsFile *esf;
188  int ret;
189 
190  for (int i = 0; i < nb_enc_stats_files; i++)
191  if (!strcmp(path, enc_stats_files[i].path)) {
192  *io = enc_stats_files[i].io;
193  return 0;
194  }
195 
197 
199 
200  ret = avio_open2(&esf->io, path, AVIO_FLAG_WRITE, &int_cb, NULL);
201  if (ret < 0) {
202  av_log(NULL, AV_LOG_ERROR, "Error opening stats file '%s': %s\n",
203  path, av_err2str(ret));
204  return ret;
205  }
206 
207  esf->path = av_strdup(path);
208  if (!esf->path)
209  return AVERROR(ENOMEM);
210 
211  *io = esf->io;
212 
213  return 0;
214 }
215 
217 {
218  for (int i = 0; i < nb_enc_stats_files; i++) {
219  av_freep(&enc_stats_files[i].path);
221  }
223  nb_enc_stats_files = 0;
224 }
225 
226 static int unescape(char **pdst, size_t *dst_len,
227  const char **pstr, char delim)
228 {
229  const char *str = *pstr;
230  char *dst;
231  size_t len, idx;
232 
233  *pdst = NULL;
234 
235  len = strlen(str);
236  if (!len)
237  return 0;
238 
239  dst = av_malloc(len + 1);
240  if (!dst)
241  return AVERROR(ENOMEM);
242 
243  for (idx = 0; *str; idx++, str++) {
244  if (str[0] == '\\' && str[1])
245  str++;
246  else if (*str == delim)
247  break;
248 
249  dst[idx] = *str;
250  }
251  if (!idx) {
252  av_freep(&dst);
253  return 0;
254  }
255 
256  dst[idx] = 0;
257 
258  *pdst = dst;
259  *dst_len = idx;
260  *pstr = str;
261 
262  return 0;
263 }
264 
265 static int enc_stats_init(OutputStream *ost, int pre,
266  const char *path, const char *fmt_spec)
267 {
268  static const struct {
269  enum EncStatsType type;
270  const char *str;
271  int pre_only:1;
272  int post_only:1;
273  int need_input_data:1;
274  } fmt_specs[] = {
275  { ENC_STATS_FILE_IDX, "fidx" },
276  { ENC_STATS_STREAM_IDX, "sidx" },
277  { ENC_STATS_FRAME_NUM, "n" },
278  { ENC_STATS_FRAME_NUM_IN, "ni", 0, 0, 1 },
279  { ENC_STATS_TIMEBASE, "tb" },
280  { ENC_STATS_TIMEBASE_IN, "tbi", 0, 0, 1 },
281  { ENC_STATS_PTS, "pts" },
282  { ENC_STATS_PTS_TIME, "t" },
283  { ENC_STATS_PTS_IN, "ptsi", 0, 0, 1 },
284  { ENC_STATS_PTS_TIME_IN, "ti", 0, 0, 1 },
285  { ENC_STATS_DTS, "dts", 0, 1 },
286  { ENC_STATS_DTS_TIME, "dt", 0, 1 },
287  { ENC_STATS_SAMPLE_NUM, "sn", 1 },
288  { ENC_STATS_NB_SAMPLES, "samp", 1 },
289  { ENC_STATS_PKT_SIZE, "size", 0, 1 },
290  { ENC_STATS_BITRATE, "br", 0, 1 },
291  { ENC_STATS_AVG_BITRATE, "abr", 0, 1 },
292  };
293  EncStats *es = pre ? &ost->enc_stats_pre : &ost->enc_stats_post;
294  const char *next = fmt_spec;
295 
296  int ret;
297 
298  while (*next) {
300  char *val;
301  size_t val_len;
302 
303  // get the sequence up until next opening brace
304  ret = unescape(&val, &val_len, &next, '{');
305  if (ret < 0)
306  return ret;
307 
308  if (val) {
310 
311  c = &es->components[es->nb_components - 1];
312  c->type = ENC_STATS_LITERAL;
313  c->str = val;
314  c->str_len = val_len;
315  }
316 
317  if (!*next)
318  break;
319  next++;
320 
321  // get the part inside braces
322  ret = unescape(&val, &val_len, &next, '}');
323  if (ret < 0)
324  return ret;
325 
326  if (!val) {
328  "Empty formatting directive in: %s\n", fmt_spec);
329  return AVERROR(EINVAL);
330  }
331 
332  if (!*next) {
334  "Missing closing brace in: %s\n", fmt_spec);
335  ret = AVERROR(EINVAL);
336  goto fail;
337  }
338  next++;
339 
341  c = &es->components[es->nb_components - 1];
342 
343  for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) {
344  if (!strcmp(val, fmt_specs[i].str)) {
345  if ((pre && fmt_specs[i].post_only) || (!pre && fmt_specs[i].pre_only)) {
347  "Format directive '%s' may only be used %s-encoding\n",
348  val, pre ? "post" : "pre");
349  ret = AVERROR(EINVAL);
350  goto fail;
351  }
352 
353  c->type = fmt_specs[i].type;
354 
355  if (fmt_specs[i].need_input_data) {
356  if (ost->ist)
357  ost->ist->want_frame_data = 1;
358  else {
360  "Format directive '%s' is unavailable, because "
361  "this output stream has no associated input stream\n",
362  val);
363  }
364  }
365 
366  break;
367  }
368  }
369 
370  if (!c->type) {
371  av_log(NULL, AV_LOG_ERROR, "Invalid format directive: %s\n", val);
372  ret = AVERROR(EINVAL);
373  goto fail;
374  }
375 
376 fail:
377  av_freep(&val);
378  if (ret < 0)
379  return ret;
380  }
381 
382  ret = enc_stats_get_file(&es->io, path);
383  if (ret < 0)
384  return ret;
385 
386  return 0;
387 }
388 
389 static const char *output_stream_item_name(void *obj)
390 {
391  const MuxStream *ms = obj;
392 
393  return ms->log_name;
394 }
395 
396 static const AVClass output_stream_class = {
397  .class_name = "OutputStream",
398  .version = LIBAVUTIL_VERSION_INT,
399  .item_name = output_stream_item_name,
400  .category = AV_CLASS_CATEGORY_MUXER,
401 };
402 
404 {
405  const char *type_str = av_get_media_type_string(type);
406  MuxStream *ms = allocate_array_elem(&mux->of.streams, sizeof(*ms),
407  &mux->of.nb_streams);
408 
409  ms->ost.file_index = mux->of.index;
410  ms->ost.index = mux->of.nb_streams - 1;
411 
413 
414  snprintf(ms->log_name, sizeof(ms->log_name), "%cost#%d:%d",
415  type_str ? *type_str : '?', mux->of.index, ms->ost.index);
416 
417  return ms;
418 }
419 
421  enum AVMediaType type, InputStream *ist)
422 {
423  AVFormatContext *oc = mux->fc;
424  MuxStream *ms;
425  OutputStream *ost;
426  const AVCodec *enc;
427  AVStream *st = avformat_new_stream(oc, NULL);
428  int ret = 0;
429  const char *bsfs = NULL, *time_base = NULL;
430  char *next, *codec_tag = NULL;
431  double qscale = -1;
432  int i;
433 
434  if (!st)
435  report_and_exit(AVERROR(ENOMEM));
436 
437  if (oc->nb_streams - 1 < o->nb_streamid_map)
438  st->id = o->streamid_map[oc->nb_streams - 1];
439 
440  ms = mux_stream_alloc(mux, type);
441  ost = &ms->ost;
442 
443  ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
444  if (!ms->muxing_queue)
445  report_and_exit(AVERROR(ENOMEM));
447 
448  ost->st = st;
449  ost->ist = ist;
450  ost->kf.ref_pts = AV_NOPTS_VALUE;
451  st->codecpar->codec_type = type;
452 
453  ret = choose_encoder(o, oc, ost, &enc);
454  if (ret < 0) {
455  av_log(ost, AV_LOG_FATAL, "Error selecting an encoder\n");
456  exit_program(1);
457  }
458 
459  if (enc) {
460  ost->enc_ctx = avcodec_alloc_context3(enc);
461  if (!ost->enc_ctx)
462  report_and_exit(AVERROR(ENOMEM));
463 
464  av_strlcat(ms->log_name, "/", sizeof(ms->log_name));
465  av_strlcat(ms->log_name, enc->name, sizeof(ms->log_name));
466  } else {
467  av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name));
468  }
469 
470  ost->filtered_frame = av_frame_alloc();
471  if (!ost->filtered_frame)
472  report_and_exit(AVERROR(ENOMEM));
473 
474  ost->pkt = av_packet_alloc();
475  if (!ost->pkt)
476  report_and_exit(AVERROR(ENOMEM));
477 
478  if (ost->enc_ctx) {
479  AVCodecContext *enc = ost->enc_ctx;
480  AVIOContext *s = NULL;
481  char *buf = NULL, *arg = NULL, *preset = NULL;
482  const char *enc_stats_pre = NULL, *enc_stats_post = NULL;
483 
484  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id,
485  oc, st, enc->codec);
486 
488  ost->autoscale = 1;
489  MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
490  if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {
491  AVBPrint bprint;
493  do {
494  av_bprint_clear(&bprint);
495  buf = get_line(s, &bprint);
496  if (!buf[0] || buf[0] == '#')
497  continue;
498  if (!(arg = strchr(buf, '='))) {
499  av_log(ost, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
500  exit_program(1);
501  }
502  *arg++ = 0;
503  av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
504  } while (!s->eof_reached);
505  av_bprint_finalize(&bprint, NULL);
506  avio_closep(&s);
507  }
508  if (ret) {
510  "Preset %s specified, but could not be opened.\n", preset);
511  exit_program(1);
512  }
513 
514  MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st);
515  if (enc_stats_pre &&
517  const char *format = "{fidx} {sidx} {n} {t}";
518 
519  MATCH_PER_STREAM_OPT(enc_stats_pre_fmt, str, format, oc, st);
520 
521  ret = enc_stats_init(ost, 1, enc_stats_pre, format);
522  if (ret < 0)
523  exit_program(1);
524  }
525 
526  MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st);
527  if (enc_stats_post &&
529  const char *format = "{fidx} {sidx} {n} {t}";
530 
531  MATCH_PER_STREAM_OPT(enc_stats_post_fmt, str, format, oc, st);
532 
533  ret = enc_stats_init(ost, 0, enc_stats_post, format);
534  if (ret < 0)
535  exit_program(1);
536  }
537  } else {
538  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
539  }
540 
541 
542  if (o->bitexact) {
543  ost->bitexact = 1;
544  } else if (ost->enc_ctx) {
545  ost->bitexact = check_opt_bitexact(ost->enc_ctx, ost->encoder_opts, "flags",
547  }
548 
549  MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
550  if (time_base) {
551  AVRational q;
552  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
553  q.num <= 0 || q.den <= 0) {
554  av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
555  exit_program(1);
556  }
557  st->time_base = q;
558  }
559 
560  MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
561  if (time_base) {
562  AVRational q;
563  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
564  q.den <= 0) {
565  av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
566  exit_program(1);
567  }
568  ost->enc_timebase = q;
569  }
570 
571  ms->max_frames = INT64_MAX;
572  MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st);
573  for (i = 0; i<o->nb_max_frames; i++) {
574  char *p = o->max_frames[i].specifier;
575  if (!*p && type != AVMEDIA_TYPE_VIDEO) {
576  av_log(ost, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
577  break;
578  }
579  }
580 
581  ost->copy_prior_start = -1;
582  MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
583 
584  MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
585  if (bsfs && *bsfs) {
586  ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);
587  if (ret < 0) {
588  av_log(ost, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
589  exit_program(1);
590  }
591  }
592 
593  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
594  if (codec_tag) {
595  uint32_t tag = strtol(codec_tag, &next, 0);
596  if (*next)
597  tag = AV_RL32(codec_tag);
598  ost->st->codecpar->codec_tag = tag;
599  if (ost->enc_ctx)
600  ost->enc_ctx->codec_tag = tag;
601  }
602 
603  MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
604  if (ost->enc_ctx && qscale >= 0) {
605  ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
606  ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
607  }
608 
609  ms->max_muxing_queue_size = 128;
610  MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ms->max_muxing_queue_size, oc, st);
611 
612  ms->muxing_queue_data_threshold = 50*1024*1024;
613  MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ms->muxing_queue_data_threshold, oc, st);
614 
615  MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample,
616  oc, st);
617 
618  MATCH_PER_STREAM_OPT(fix_sub_duration_heartbeat, i, ost->fix_sub_duration_heartbeat,
619  oc, st);
620 
621  if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)
622  ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
623 
624  av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
625 
626  av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
627  if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24)
628  av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
629 
630  if (ost->ist) {
631  ost->ist->discard = 0;
632  ost->ist->st->discard = ost->ist->user_set_discard;
633  }
634  ost->last_mux_dts = AV_NOPTS_VALUE;
635  ost->last_filter_pts = AV_NOPTS_VALUE;
636 
637  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i,
638  ost->copy_initial_nonkeyframes, oc, st);
639 
640  return ost;
641 }
642 
643 static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc,
644  OutputStream *ost)
645 {
646  AVStream *st = ost->st;
647 
648  if (ost->filters_script && ost->filters) {
649  av_log(ost, AV_LOG_ERROR, "Both -filter and -filter_script set\n");
650  exit_program(1);
651  }
652 
653  if (ost->filters_script)
654  return file_read(ost->filters_script);
655  else if (ost->filters)
656  return av_strdup(ost->filters);
657 
659  "null" : "anull");
660 }
661 
664 {
665  if (ost->filters_script || ost->filters) {
667  "%s '%s' was defined, but codec copy was selected.\n"
668  "Filtering and streamcopy cannot be used together.\n",
669  ost->filters ? "Filtergraph" : "Filtergraph script",
670  ost->filters ? ost->filters : ost->filters_script);
671  exit_program(1);
672  }
673 }
674 
675 static void parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str)
676 {
677  int i;
678  const char *p = str;
679  for (i = 0;; i++) {
680  dest[i] = atoi(p);
681  if (i == 63)
682  break;
683  p = strchr(p, ',');
684  if (!p) {
685  av_log(logctx, AV_LOG_FATAL,
686  "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
687  exit_program(1);
688  }
689  p++;
690  }
691 }
692 
694 {
695  AVFormatContext *oc = mux->fc;
696  AVStream *st;
697  OutputStream *ost;
698  char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL;
699 
700  ost = new_output_stream(mux, o, AVMEDIA_TYPE_VIDEO, ist);
701  st = ost->st;
702 
703  MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
704  if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
705  av_log(ost, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
706  exit_program(1);
707  }
708 
709  MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
710  if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
711  av_log(ost, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
712  exit_program(1);
713  }
714 
715  if (frame_rate && max_frame_rate) {
716  av_log(ost, AV_LOG_ERROR, "Only one of -fpsmax and -r can be set for a stream.\n");
717  exit_program(1);
718  }
719 
720  MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
721  if (frame_aspect_ratio) {
722  AVRational q;
723  if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
724  q.num <= 0 || q.den <= 0) {
725  av_log(ost, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
726  exit_program(1);
727  }
728  ost->frame_aspect_ratio = q;
729  }
730 
731  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
732  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
733 
734  if (ost->enc_ctx) {
735  AVCodecContext *video_enc = ost->enc_ctx;
736  const char *p = NULL, *fps_mode = NULL;
737  char *frame_size = NULL;
738  char *frame_pix_fmt = NULL;
739  char *intra_matrix = NULL, *inter_matrix = NULL;
740  char *chroma_intra_matrix = NULL;
741  int do_pass = 0;
742  int i;
743 
745  if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
746  av_log(ost, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
747  exit_program(1);
748  }
749 
750  MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
751  if (frame_pix_fmt && *frame_pix_fmt == '+') {
752  ost->keep_pix_fmt = 1;
753  if (!*++frame_pix_fmt)
754  frame_pix_fmt = NULL;
755  }
756  if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
757  av_log(ost, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
758  exit_program(1);
759  }
760  st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
761 
762  MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
763  if (intra_matrix) {
764  if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64)))
765  report_and_exit(AVERROR(ENOMEM));
766  parse_matrix_coeffs(ost, video_enc->intra_matrix, intra_matrix);
767  }
768  MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
769  if (chroma_intra_matrix) {
770  uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
771  if (!p)
772  report_and_exit(AVERROR(ENOMEM));
773  video_enc->chroma_intra_matrix = p;
774  parse_matrix_coeffs(ost, p, chroma_intra_matrix);
775  }
776  MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
777  if (inter_matrix) {
778  if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64)))
779  report_and_exit(AVERROR(ENOMEM));
780  parse_matrix_coeffs(ost, video_enc->inter_matrix, inter_matrix);
781  }
782 
783  MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
784  for (i = 0; p; i++) {
785  int start, end, q;
786  int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
787  if (e != 3) {
788  av_log(ost, AV_LOG_FATAL, "error parsing rc_override\n");
789  exit_program(1);
790  }
791  video_enc->rc_override =
792  av_realloc_array(video_enc->rc_override,
793  i + 1, sizeof(RcOverride));
794  if (!video_enc->rc_override) {
795  av_log(ost, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
796  exit_program(1);
797  }
798  video_enc->rc_override[i].start_frame = start;
799  video_enc->rc_override[i].end_frame = end;
800  if (q > 0) {
801  video_enc->rc_override[i].qscale = q;
802  video_enc->rc_override[i].quality_factor = 1.0;
803  }
804  else {
805  video_enc->rc_override[i].qscale = 0;
806  video_enc->rc_override[i].quality_factor = -q/100.0;
807  }
808  p = strchr(p, '/');
809  if (p) p++;
810  }
811  video_enc->rc_override_count = i;
812 
813 #if FFMPEG_OPT_PSNR
814  if (do_psnr) {
815  av_log(ost, AV_LOG_WARNING, "The -psnr option is deprecated, use -flags +psnr\n");
816  video_enc->flags|= AV_CODEC_FLAG_PSNR;
817  }
818 #endif
819 
820  /* two pass mode */
821  MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
822  if (do_pass) {
823  if (do_pass & 1) {
824  video_enc->flags |= AV_CODEC_FLAG_PASS1;
825  av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
826  }
827  if (do_pass & 2) {
828  video_enc->flags |= AV_CODEC_FLAG_PASS2;
829  av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
830  }
831  }
832 
833  MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
834  if (ost->logfile_prefix &&
835  !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
836  report_and_exit(AVERROR(ENOMEM));
837 
838  if (do_pass) {
839  int ost_idx = -1;
840  char logfilename[1024];
841  FILE *f;
842 
843  /* compute this stream's global index */
844  for (int i = 0; i <= ost->file_index; i++)
845  ost_idx += output_files[i]->nb_streams;
846 
847  snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
848  ost->logfile_prefix ? ost->logfile_prefix :
850  ost_idx);
851  if (!strcmp(ost->enc_ctx->codec->name, "libx264")) {
852  av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
853  } else {
854  if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
855  char *logbuffer = file_read(logfilename);
856 
857  if (!logbuffer) {
858  av_log(ost, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
859  logfilename);
860  exit_program(1);
861  }
862  video_enc->stats_in = logbuffer;
863  }
864  if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
865  f = fopen_utf8(logfilename, "wb");
866  if (!f) {
868  "Cannot write log file '%s' for pass-1 encoding: %s\n",
869  logfilename, strerror(errno));
870  exit_program(1);
871  }
872  ost->logfile = f;
873  }
874  }
875  }
876 
877  MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
878 
879  ost->top_field_first = -1;
880  MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
881 
882  ost->vsync_method = video_sync_method;
883  MATCH_PER_STREAM_OPT(fps_mode, str, fps_mode, oc, st);
884  if (fps_mode)
885  parse_and_set_vsync(fps_mode, &ost->vsync_method, ost->file_index, ost->index, 0);
886 
887  if ((ost->frame_rate.num || ost->max_frame_rate.num) &&
888  !(ost->vsync_method == VSYNC_AUTO ||
889  ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR)) {
890  av_log(ost, AV_LOG_FATAL, "One of -r/-fpsmax was specified "
891  "together a non-CFR -vsync/-fps_mode. This is contradictory.\n");
892  exit_program(1);
893  }
894 
895  if (ost->vsync_method == VSYNC_AUTO) {
896  if (ost->frame_rate.num || ost->max_frame_rate.num) {
897  ost->vsync_method = VSYNC_CFR;
898  } else if (!strcmp(oc->oformat->name, "avi")) {
899  ost->vsync_method = VSYNC_VFR;
900  } else {
901  ost->vsync_method = (oc->oformat->flags & AVFMT_VARIABLE_FPS) ?
902  ((oc->oformat->flags & AVFMT_NOTIMESTAMPS) ?
904  VSYNC_CFR;
905  }
906 
907  if (ost->ist && ost->vsync_method == VSYNC_CFR) {
908  const InputFile *ifile = input_files[ost->ist->file_index];
909 
910  if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0)
911  ost->vsync_method = VSYNC_VSCFR;
912  }
913 
914  if (ost->vsync_method == VSYNC_CFR && copy_ts) {
915  ost->vsync_method = VSYNC_VSCFR;
916  }
917  }
918  ost->is_cfr = (ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR);
919 
920  ost->avfilter = get_ost_filters(o, oc, ost);
921  if (!ost->avfilter)
922  exit_program(1);
923 
924  ost->last_frame = av_frame_alloc();
925  if (!ost->last_frame)
926  report_and_exit(AVERROR(ENOMEM));
927  } else
929 
930  return ost;
931 }
932 
934 {
935  AVFormatContext *oc = mux->fc;
936  AVStream *st;
937  OutputStream *ost;
938 
939  ost = new_output_stream(mux, o, AVMEDIA_TYPE_AUDIO, ist);
940  st = ost->st;
941 
942 
943  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
944  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
945 
946  if (ost->enc_ctx) {
947  AVCodecContext *audio_enc = ost->enc_ctx;
948  int channels = 0;
949  char *layout = NULL;
950  char *sample_fmt = NULL;
951 
953  if (channels) {
955  audio_enc->ch_layout.nb_channels = channels;
956  }
957 
958  MATCH_PER_STREAM_OPT(audio_ch_layouts, str, layout, oc, st);
959  if (layout) {
960  if (av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) {
961 #if FF_API_OLD_CHANNEL_LAYOUT
962  uint64_t mask;
965  })
966  if (!mask) {
967 #endif
968  av_log(ost, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout);
969  exit_program(1);
970 #if FF_API_OLD_CHANNEL_LAYOUT
971  }
972  av_log(ost, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
973  layout);
975 #endif
976  }
977  }
978 
979  MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
980  if (sample_fmt &&
981  (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
982  av_log(ost, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
983  exit_program(1);
984  }
985 
986  MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
987 
988  MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
989  ost->apad = av_strdup(ost->apad);
990 
991  ost->avfilter = get_ost_filters(o, oc, ost);
992  if (!ost->avfilter)
993  exit_program(1);
994 
995 #if FFMPEG_OPT_MAP_CHANNEL
996  /* check for channel mapping for this audio stream */
997  for (int n = 0; n < o->nb_audio_channel_maps; n++) {
999  if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
1000  (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
1001  InputStream *ist;
1002 
1003  if (map->channel_idx == -1) {
1004  ist = NULL;
1005  } else if (!ost->ist) {
1006  av_log(ost, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
1007  ost->file_index, ost->st->index);
1008  continue;
1009  } else {
1010  ist = ost->ist;
1011  }
1012 
1013  if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
1014  if (av_reallocp_array(&ost->audio_channels_map,
1015  ost->audio_channels_mapped + 1,
1016  sizeof(*ost->audio_channels_map)
1017  ) < 0 )
1018  report_and_exit(AVERROR(ENOMEM));
1019 
1020  ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
1021  }
1022  }
1023  }
1024 #endif
1025  } else
1027 
1028  return ost;
1029 }
1030 
1032 {
1033  OutputStream *ost;
1034 
1035  ost = new_output_stream(mux, o, AVMEDIA_TYPE_DATA, ist);
1036  if (ost->enc_ctx) {
1037  av_log(ost, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
1038  exit_program(1);
1039  }
1040 
1041  return ost;
1042 }
1043 
1045 {
1046  OutputStream *ost;
1047 
1048  ost = new_output_stream(mux, o, AVMEDIA_TYPE_UNKNOWN, ist);
1049  if (ost->enc_ctx) {
1050  av_log(ost, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
1051  exit_program(1);
1052  }
1053 
1054  return ost;
1055 }
1056 
1058 {
1060  ost->finished = 1;
1061  return ost;
1062 }
1063 
1065 {
1066  AVStream *st;
1067  OutputStream *ost;
1068 
1070  st = ost->st;
1071 
1072  if (ost->enc_ctx) {
1073  AVCodecContext *subtitle_enc = ost->enc_ctx;
1074  char *frame_size = NULL;
1075 
1077  if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
1078  av_log(ost, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1079  exit_program(1);
1080  }
1081  }
1082 
1083  return ost;
1084 }
1085 
1086 static void init_output_filter(OutputFilter *ofilter, const OptionsContext *o,
1087  Muxer *mux)
1088 {
1089  OutputStream *ost;
1090 
1091  switch (ofilter->type) {
1092  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(mux, o, NULL); break;
1093  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(mux, o, NULL); break;
1094  default:
1095  av_log(mux, AV_LOG_FATAL, "Only video and audio filters are supported "
1096  "currently.\n");
1097  exit_program(1);
1098  }
1099 
1100  ost->filter = ofilter;
1101 
1102  ofilter->ost = ost;
1103  ofilter->format = -1;
1104 
1105  if (!ost->enc_ctx) {
1106  av_log(ost, AV_LOG_ERROR, "Streamcopy requested for output stream fed "
1107  "from a complex filtergraph. Filtering and streamcopy "
1108  "cannot be used together.\n");
1109  exit_program(1);
1110  }
1111 
1112  if (ost->avfilter && (ost->filters || ost->filters_script)) {
1113  const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
1115  "%s '%s' was specified through the %s option "
1116  "for output stream %d:%d, which is fed from a complex filtergraph.\n"
1117  "%s and -filter_complex cannot be used together for the same stream.\n",
1118  ost->filters ? "Filtergraph" : "Filtergraph script",
1119  ost->filters ? ost->filters : ost->filters_script,
1120  opt, ost->file_index, ost->index, opt);
1121  exit_program(1);
1122  }
1123 
1124  avfilter_inout_free(&ofilter->out_tmp);
1125 }
1126 
1127 static void map_auto_video(Muxer *mux, const OptionsContext *o)
1128 {
1129  AVFormatContext *oc = mux->fc;
1130  InputStream *best_ist = NULL;
1131  int best_score = 0;
1132  int qcr;
1133 
1134  /* video: highest resolution */
1136  return;
1137 
1138  qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
1139  for (int j = 0; j < nb_input_files; j++) {
1140  InputFile *ifile = input_files[j];
1141  InputStream *file_best_ist = NULL;
1142  int file_best_score = 0;
1143  for (int i = 0; i < ifile->nb_streams; i++) {
1144  InputStream *ist = ifile->streams[i];
1145  int score;
1146 
1147  if (ist->user_set_discard == AVDISCARD_ALL ||
1149  continue;
1150 
1151  score = ist->st->codecpar->width * ist->st->codecpar->height
1152  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
1153  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
1154  if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1155  score = 1;
1156 
1157  if (score > file_best_score) {
1158  if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1159  continue;
1160  file_best_score = score;
1161  file_best_ist = ist;
1162  }
1163  }
1164  if (file_best_ist) {
1165  if((qcr == MKTAG('A', 'P', 'I', 'C')) ||
1166  !(file_best_ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1167  file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT);
1168  if (file_best_score > best_score) {
1169  best_score = file_best_score;
1170  best_ist = file_best_ist;
1171  }
1172  }
1173  }
1174  if (best_ist)
1175  new_video_stream(mux, o, best_ist);
1176 }
1177 
1178 static void map_auto_audio(Muxer *mux, const OptionsContext *o)
1179 {
1180  AVFormatContext *oc = mux->fc;
1181  InputStream *best_ist = NULL;
1182  int best_score = 0;
1183 
1184  /* audio: most channels */
1186  return;
1187 
1188  for (int j = 0; j < nb_input_files; j++) {
1189  InputFile *ifile = input_files[j];
1190  InputStream *file_best_ist = NULL;
1191  int file_best_score = 0;
1192  for (int i = 0; i < ifile->nb_streams; i++) {
1193  InputStream *ist = ifile->streams[i];
1194  int score;
1195 
1196  if (ist->user_set_discard == AVDISCARD_ALL ||
1198  continue;
1199 
1200  score = ist->st->codecpar->ch_layout.nb_channels
1201  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
1202  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
1203  if (score > file_best_score) {
1204  file_best_score = score;
1205  file_best_ist = ist;
1206  }
1207  }
1208  if (file_best_ist) {
1209  file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT);
1210  if (file_best_score > best_score) {
1211  best_score = file_best_score;
1212  best_ist = file_best_ist;
1213  }
1214  }
1215  }
1216  if (best_ist)
1217  new_audio_stream(mux, o, best_ist);
1218 }
1219 
1220 static void map_auto_subtitle(Muxer *mux, const OptionsContext *o)
1221 {
1222  AVFormatContext *oc = mux->fc;
1223  char *subtitle_codec_name = NULL;
1224 
1225  /* subtitles: pick first */
1226  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
1228  return;
1229 
1230  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist))
1231  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1232  AVCodecDescriptor const *input_descriptor =
1233  avcodec_descriptor_get(ist->st->codecpar->codec_id);
1234  AVCodecDescriptor const *output_descriptor = NULL;
1235  AVCodec const *output_codec =
1237  int input_props = 0, output_props = 0;
1238  if (ist->user_set_discard == AVDISCARD_ALL)
1239  continue;
1240  if (output_codec)
1241  output_descriptor = avcodec_descriptor_get(output_codec->id);
1242  if (input_descriptor)
1243  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
1244  if (output_descriptor)
1245  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
1246  if (subtitle_codec_name ||
1247  input_props & output_props ||
1248  // Map dvb teletext which has neither property to any output subtitle encoder
1249  input_descriptor && output_descriptor &&
1250  (!input_descriptor->props ||
1251  !output_descriptor->props)) {
1252  new_subtitle_stream(mux, o, ist);
1253  break;
1254  }
1255  }
1256 }
1257 
1258 static void map_auto_data(Muxer *mux, const OptionsContext *o)
1259 {
1260  AVFormatContext *oc = mux->fc;
1261  /* Data only if codec id match */
1263 
1264  if (codec_id == AV_CODEC_ID_NONE)
1265  return;
1266 
1267  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
1268  if (ist->user_set_discard == AVDISCARD_ALL)
1269  continue;
1270  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA &&
1271  ist->st->codecpar->codec_id == codec_id )
1272  new_data_stream(mux, o, ist);
1273  }
1274 }
1275 
1276 static void map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map)
1277 {
1278  InputStream *ist;
1279 
1280  if (map->disabled)
1281  return;
1282 
1283  if (map->linklabel) {
1284  FilterGraph *fg;
1285  OutputFilter *ofilter = NULL;
1286  int j, k;
1287 
1288  for (j = 0; j < nb_filtergraphs; j++) {
1289  fg = filtergraphs[j];
1290  for (k = 0; k < fg->nb_outputs; k++) {
1291  AVFilterInOut *out = fg->outputs[k]->out_tmp;
1292  if (out && !strcmp(out->name, map->linklabel)) {
1293  ofilter = fg->outputs[k];
1294  goto loop_end;
1295  }
1296  }
1297  }
1298 loop_end:
1299  if (!ofilter) {
1300  av_log(mux, AV_LOG_FATAL, "Output with label '%s' does not exist "
1301  "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
1302  exit_program(1);
1303  }
1304  init_output_filter(ofilter, o, mux);
1305  } else {
1306  ist = input_files[map->file_index]->streams[map->stream_index];
1307  if (ist->user_set_discard == AVDISCARD_ALL) {
1308  av_log(mux, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
1309  map->file_index, map->stream_index);
1310  exit_program(1);
1311  }
1313  return;
1315  return;
1317  return;
1318  if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
1319  return;
1320 
1321  switch (ist->st->codecpar->codec_type) {
1322  case AVMEDIA_TYPE_VIDEO: new_video_stream (mux, o, ist); break;
1323  case AVMEDIA_TYPE_AUDIO: new_audio_stream (mux, o, ist); break;
1324  case AVMEDIA_TYPE_SUBTITLE: new_subtitle_stream (mux, o, ist); break;
1325  case AVMEDIA_TYPE_DATA: new_data_stream (mux, o, ist); break;
1326  case AVMEDIA_TYPE_ATTACHMENT: new_attachment_stream(mux, o, ist); break;
1327  case AVMEDIA_TYPE_UNKNOWN:
1328  if (copy_unknown_streams) {
1329  new_unknown_stream (mux, o, ist);
1330  break;
1331  }
1332  default:
1334  "Cannot map stream #%d:%d - unsupported type.\n",
1335  map->file_index, map->stream_index);
1336  if (!ignore_unknown_streams) {
1337  av_log(mux, AV_LOG_FATAL,
1338  "If you want unsupported types ignored instead "
1339  "of failing, please use the -ignore_unknown option\n"
1340  "If you want them copied, please use -copy_unknown\n");
1341  exit_program(1);
1342  }
1343  }
1344  }
1345 }
1346 
1347 static void of_add_attachments(Muxer *mux, const OptionsContext *o)
1348 {
1349  OutputStream *ost;
1350  int err;
1351 
1352  for (int i = 0; i < o->nb_attachments; i++) {
1353  AVIOContext *pb;
1354  uint8_t *attachment;
1355  const char *p;
1356  int64_t len;
1357 
1358  if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
1359  av_log(mux, AV_LOG_FATAL, "Could not open attachment file %s.\n",
1360  o->attachments[i]);
1361  exit_program(1);
1362  }
1363  if ((len = avio_size(pb)) <= 0) {
1364  av_log(mux, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
1365  o->attachments[i]);
1366  exit_program(1);
1367  }
1368  if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
1369  !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
1370  av_log(mux, AV_LOG_FATAL, "Attachment %s too large.\n",
1371  o->attachments[i]);
1372  exit_program(1);
1373  }
1374  avio_read(pb, attachment, len);
1375  memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1376 
1377  ost = new_attachment_stream(mux, o, NULL);
1378  ost->attachment_filename = o->attachments[i];
1379  ost->st->codecpar->extradata = attachment;
1380  ost->st->codecpar->extradata_size = len;
1381 
1382  p = strrchr(o->attachments[i], '/');
1383  av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
1384  avio_closep(&pb);
1385  }
1386 }
1387 
1388 static void create_streams(Muxer *mux, const OptionsContext *o)
1389 {
1390  AVFormatContext *oc = mux->fc;
1391  int auto_disable_v = o->video_disable;
1392  int auto_disable_a = o->audio_disable;
1393  int auto_disable_s = o->subtitle_disable;
1394  int auto_disable_d = o->data_disable;
1395 
1396  /* create streams for all unlabeled output pads */
1397  for (int i = 0; i < nb_filtergraphs; i++) {
1398  FilterGraph *fg = filtergraphs[i];
1399  for (int j = 0; j < fg->nb_outputs; j++) {
1400  OutputFilter *ofilter = fg->outputs[j];
1401 
1402  if (!ofilter->out_tmp || ofilter->out_tmp->name)
1403  continue;
1404 
1405  switch (ofilter->type) {
1406  case AVMEDIA_TYPE_VIDEO: auto_disable_v = 1; break;
1407  case AVMEDIA_TYPE_AUDIO: auto_disable_a = 1; break;
1408  case AVMEDIA_TYPE_SUBTITLE: auto_disable_s = 1; break;
1409  }
1410  init_output_filter(ofilter, o, mux);
1411  }
1412  }
1413 
1414  if (!o->nb_stream_maps) {
1415  /* pick the "best" stream of each type */
1416  if (!auto_disable_v)
1417  map_auto_video(mux, o);
1418  if (!auto_disable_a)
1419  map_auto_audio(mux, o);
1420  if (!auto_disable_s)
1421  map_auto_subtitle(mux, o);
1422  if (!auto_disable_d)
1423  map_auto_data(mux, o);
1424  } else {
1425  for (int i = 0; i < o->nb_stream_maps; i++)
1426  map_manual(mux, o, &o->stream_maps[i]);
1427  }
1428 
1429  of_add_attachments(mux, o);
1430 
1431  if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
1432  av_dump_format(oc, nb_output_files - 1, oc->url, 1);
1433  av_log(mux, AV_LOG_ERROR, "Output file does not contain any stream\n");
1434  exit_program(1);
1435  }
1436 }
1437 
1438 static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_us)
1439 {
1440  OutputFile *of = &mux->of;
1441  int nb_av_enc = 0, nb_interleaved = 0;
1442  int limit_frames = 0, limit_frames_av_enc = 0;
1443 
1444 #define IS_AV_ENC(ost, type) \
1445  (ost->enc_ctx && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))
1446 #define IS_INTERLEAVED(type) (type != AVMEDIA_TYPE_ATTACHMENT)
1447 
1448  for (int i = 0; i < oc->nb_streams; i++) {
1449  OutputStream *ost = of->streams[i];
1450  MuxStream *ms = ms_from_ost(ost);
1451  enum AVMediaType type = ost->st->codecpar->codec_type;
1452 
1453  ost->sq_idx_encode = -1;
1454  ost->sq_idx_mux = -1;
1455 
1456  nb_interleaved += IS_INTERLEAVED(type);
1457  nb_av_enc += IS_AV_ENC(ost, type);
1458 
1459  limit_frames |= ms->max_frames < INT64_MAX;
1460  limit_frames_av_enc |= (ms->max_frames < INT64_MAX) && IS_AV_ENC(ost, type);
1461  }
1462 
1463  if (!((nb_interleaved > 1 && of->shortest) ||
1464  (nb_interleaved > 0 && limit_frames)))
1465  return 0;
1466 
1467  /* if we have more than one encoded audio/video streams, or at least
1468  * one encoded audio/video stream is frame-limited, then we
1469  * synchronize them before encoding */
1470  if ((of->shortest && nb_av_enc > 1) || limit_frames_av_enc) {
1471  of->sq_encode = sq_alloc(SYNC_QUEUE_FRAMES, buf_size_us);
1472  if (!of->sq_encode)
1473  return AVERROR(ENOMEM);
1474 
1475  for (int i = 0; i < oc->nb_streams; i++) {
1476  OutputStream *ost = of->streams[i];
1477  MuxStream *ms = ms_from_ost(ost);
1478  enum AVMediaType type = ost->st->codecpar->codec_type;
1479 
1480  if (!IS_AV_ENC(ost, type))
1481  continue;
1482 
1483  ost->sq_idx_encode = sq_add_stream(of->sq_encode,
1484  of->shortest || ms->max_frames < INT64_MAX);
1485  if (ost->sq_idx_encode < 0)
1486  return ost->sq_idx_encode;
1487 
1488  ost->sq_frame = av_frame_alloc();
1489  if (!ost->sq_frame)
1490  return AVERROR(ENOMEM);
1491 
1492  if (ms->max_frames != INT64_MAX)
1493  sq_limit_frames(of->sq_encode, ost->sq_idx_encode, ms->max_frames);
1494  }
1495  }
1496 
1497  /* if there are any additional interleaved streams, then ALL the streams
1498  * are also synchronized before sending them to the muxer */
1499  if (nb_interleaved > nb_av_enc) {
1500  mux->sq_mux = sq_alloc(SYNC_QUEUE_PACKETS, buf_size_us);
1501  if (!mux->sq_mux)
1502  return AVERROR(ENOMEM);
1503 
1504  mux->sq_pkt = av_packet_alloc();
1505  if (!mux->sq_pkt)
1506  return AVERROR(ENOMEM);
1507 
1508  for (int i = 0; i < oc->nb_streams; i++) {
1509  OutputStream *ost = of->streams[i];
1510  MuxStream *ms = ms_from_ost(ost);
1511  enum AVMediaType type = ost->st->codecpar->codec_type;
1512 
1513  if (!IS_INTERLEAVED(type))
1514  continue;
1515 
1516  ost->sq_idx_mux = sq_add_stream(mux->sq_mux,
1517  of->shortest || ms->max_frames < INT64_MAX);
1518  if (ost->sq_idx_mux < 0)
1519  return ost->sq_idx_mux;
1520 
1521  if (ms->max_frames != INT64_MAX)
1522  sq_limit_frames(mux->sq_mux, ost->sq_idx_mux, ms->max_frames);
1523  }
1524  }
1525 
1526 #undef IS_AV_ENC
1527 #undef IS_INTERLEAVED
1528 
1529  return 0;
1530 }
1531 
1532 static void of_add_programs(Muxer *mux, const OptionsContext *o)
1533 {
1534  AVFormatContext *oc = mux->fc;
1535  /* process manually set programs */
1536  for (int i = 0; i < o->nb_program; i++) {
1537  const char *p = o->program[i].u.str;
1538  int progid = i+1;
1539  AVProgram *program;
1540 
1541  while(*p) {
1542  const char *p2 = av_get_token(&p, ":");
1543  const char *to_dealloc = p2;
1544  char *key;
1545  if (!p2)
1546  break;
1547 
1548  if(*p) p++;
1549 
1550  key = av_get_token(&p2, "=");
1551  if (!key || !*p2) {
1552  av_freep(&to_dealloc);
1553  av_freep(&key);
1554  break;
1555  }
1556  p2++;
1557 
1558  if (!strcmp(key, "program_num"))
1559  progid = strtol(p2, NULL, 0);
1560  av_freep(&to_dealloc);
1561  av_freep(&key);
1562  }
1563 
1564  program = av_new_program(oc, progid);
1565  if (!program)
1566  report_and_exit(AVERROR(ENOMEM));
1567 
1568  p = o->program[i].u.str;
1569  while(*p) {
1570  const char *p2 = av_get_token(&p, ":");
1571  const char *to_dealloc = p2;
1572  char *key;
1573  if (!p2)
1574  break;
1575  if(*p) p++;
1576 
1577  key = av_get_token(&p2, "=");
1578  if (!key) {
1579  av_log(mux, AV_LOG_FATAL,
1580  "No '=' character in program string %s.\n",
1581  p2);
1582  exit_program(1);
1583  }
1584  if (!*p2)
1585  exit_program(1);
1586  p2++;
1587 
1588  if (!strcmp(key, "title")) {
1589  av_dict_set(&program->metadata, "title", p2, 0);
1590  } else if (!strcmp(key, "program_num")) {
1591  } else if (!strcmp(key, "st")) {
1592  int st_num = strtol(p2, NULL, 0);
1593  av_program_add_stream_index(oc, progid, st_num);
1594  } else {
1595  av_log(mux, AV_LOG_FATAL, "Unknown program key %s.\n", key);
1596  exit_program(1);
1597  }
1598  av_freep(&to_dealloc);
1599  av_freep(&key);
1600  }
1601  }
1602 }
1603 
1604 /**
1605  * Parse a metadata specifier passed as 'arg' parameter.
1606  * @param arg metadata string to parse
1607  * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
1608  * @param index for type c/p, chapter/program index is written here
1609  * @param stream_spec for type s, the stream specifier is written here
1610  */
1611 static void parse_meta_type(void *logctx, const char *arg,
1612  char *type, int *index, const char **stream_spec)
1613 {
1614  if (*arg) {
1615  *type = *arg;
1616  switch (*arg) {
1617  case 'g':
1618  break;
1619  case 's':
1620  if (*(++arg) && *arg != ':') {
1621  av_log(logctx, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
1622  exit_program(1);
1623  }
1624  *stream_spec = *arg == ':' ? arg + 1 : "";
1625  break;
1626  case 'c':
1627  case 'p':
1628  if (*(++arg) == ':')
1629  *index = strtol(++arg, NULL, 0);
1630  break;
1631  default:
1632  av_log(logctx, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
1633  exit_program(1);
1634  }
1635  } else
1636  *type = 'g';
1637 }
1638 
1640  const OptionsContext *o)
1641 {
1642  for (int i = 0; i < o->nb_metadata; i++) {
1643  AVDictionary **m;
1644  char type, *val;
1645  const char *stream_spec;
1646  int index = 0, ret = 0;
1647 
1648  val = strchr(o->metadata[i].u.str, '=');
1649  if (!val) {
1650  av_log(of, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
1651  o->metadata[i].u.str);
1652  exit_program(1);
1653  }
1654  *val++ = 0;
1655 
1656  parse_meta_type(of, o->metadata[i].specifier, &type, &index, &stream_spec);
1657  if (type == 's') {
1658  for (int j = 0; j < oc->nb_streams; j++) {
1659  OutputStream *ost = of->streams[j];
1660  if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
1661 #if FFMPEG_ROTATION_METADATA
1662  if (!strcmp(o->metadata[i].u.str, "rotate")) {
1663  char *tail;
1664  double theta = av_strtod(val, &tail);
1665  if (!*tail) {
1666  ost->rotate_overridden = 1;
1667  ost->rotate_override_value = theta;
1668  }
1669 
1671  "Conversion of a 'rotate' metadata key to a "
1672  "proper display matrix rotation is deprecated. "
1673  "See -display_rotation for setting rotation "
1674  "instead.");
1675  } else {
1676 #endif
1677  av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
1678 #if FFMPEG_ROTATION_METADATA
1679  }
1680 #endif
1681  } else if (ret < 0)
1682  exit_program(1);
1683  }
1684  } else {
1685  switch (type) {
1686  case 'g':
1687  m = &oc->metadata;
1688  break;
1689  case 'c':
1690  if (index < 0 || index >= oc->nb_chapters) {
1691  av_log(of, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
1692  exit_program(1);
1693  }
1694  m = &oc->chapters[index]->metadata;
1695  break;
1696  case 'p':
1697  if (index < 0 || index >= oc->nb_programs) {
1698  av_log(of, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
1699  exit_program(1);
1700  }
1701  m = &oc->programs[index]->metadata;
1702  break;
1703  default:
1704  av_log(of, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
1705  exit_program(1);
1706  }
1707  av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
1708  }
1709  }
1710 }
1711 
1713 {
1714  const AVCodec *c = ost->enc_ctx->codec;
1715  int i, err;
1716 
1717  if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
1718  /* Pass the layout through for all orders but UNSPEC */
1719  err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout);
1720  if (err < 0)
1721  report_and_exit(AVERROR(ENOMEM));
1722  return;
1723  }
1724 
1725  /* Requested layout is of order UNSPEC */
1726  if (!c->ch_layouts) {
1727  /* Use the default native layout for the requested amount of channels when the
1728  encoder doesn't have a list of supported layouts */
1729  av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
1730  return;
1731  }
1732  /* Encoder has a list of supported layouts. Pick the first layout in it with the
1733  same amount of channels as the requested layout */
1734  for (i = 0; c->ch_layouts[i].nb_channels; i++) {
1735  if (c->ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels)
1736  break;
1737  }
1738  if (c->ch_layouts[i].nb_channels) {
1739  /* Use it if one is found */
1740  err = av_channel_layout_copy(&f->ch_layout, &c->ch_layouts[i]);
1741  if (err < 0)
1742  report_and_exit(AVERROR(ENOMEM));
1743  return;
1744  }
1745  /* If no layout for the amount of channels requested was found, use the default
1746  native layout for it. */
1747  av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
1748 }
1749 
1751  int copy_metadata)
1752 {
1753  AVFormatContext *is = ifile->ctx;
1754  AVChapter **tmp;
1755  int i;
1756 
1757  tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
1758  if (!tmp)
1759  return AVERROR(ENOMEM);
1760  os->chapters = tmp;
1761 
1762  for (i = 0; i < is->nb_chapters; i++) {
1763  AVChapter *in_ch = is->chapters[i], *out_ch;
1764  int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
1765  int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
1766  AV_TIME_BASE_Q, in_ch->time_base);
1767  int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
1768  av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
1769 
1770 
1771  if (in_ch->end < ts_off)
1772  continue;
1773  if (rt != INT64_MAX && in_ch->start > rt + ts_off)
1774  break;
1775 
1776  out_ch = av_mallocz(sizeof(AVChapter));
1777  if (!out_ch)
1778  return AVERROR(ENOMEM);
1779 
1780  out_ch->id = in_ch->id;
1781  out_ch->time_base = in_ch->time_base;
1782  out_ch->start = FFMAX(0, in_ch->start - ts_off);
1783  out_ch->end = FFMIN(rt, in_ch->end - ts_off);
1784 
1785  if (copy_metadata)
1786  av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
1787 
1788  os->chapters[os->nb_chapters++] = out_ch;
1789  }
1790  return 0;
1791 }
1792 
1793 static int copy_metadata(Muxer *mux, AVFormatContext *ic,
1794  const char *outspec, const char *inspec,
1795  int *metadata_global_manual, int *metadata_streams_manual,
1796  int *metadata_chapters_manual, const OptionsContext *o)
1797 {
1798  AVFormatContext *oc = mux->fc;
1799  AVDictionary **meta_in = NULL;
1800  AVDictionary **meta_out = NULL;
1801  int i, ret = 0;
1802  char type_in, type_out;
1803  const char *istream_spec = NULL, *ostream_spec = NULL;
1804  int idx_in = 0, idx_out = 0;
1805 
1806  parse_meta_type(mux, inspec, &type_in, &idx_in, &istream_spec);
1807  parse_meta_type(mux, outspec, &type_out, &idx_out, &ostream_spec);
1808 
1809  if (type_in == 'g' || type_out == 'g')
1810  *metadata_global_manual = 1;
1811  if (type_in == 's' || type_out == 's')
1812  *metadata_streams_manual = 1;
1813  if (type_in == 'c' || type_out == 'c')
1814  *metadata_chapters_manual = 1;
1815 
1816  /* ic is NULL when just disabling automatic mappings */
1817  if (!ic)
1818  return 0;
1819 
1820 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
1821  if ((index) < 0 || (index) >= (nb_elems)) {\
1822  av_log(mux, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
1823  (desc), (index));\
1824  exit_program(1);\
1825  }
1826 
1827 #define SET_DICT(type, meta, context, index)\
1828  switch (type) {\
1829  case 'g':\
1830  meta = &context->metadata;\
1831  break;\
1832  case 'c':\
1833  METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
1834  meta = &context->chapters[index]->metadata;\
1835  break;\
1836  case 'p':\
1837  METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
1838  meta = &context->programs[index]->metadata;\
1839  break;\
1840  case 's':\
1841  break; /* handled separately below */ \
1842  default: av_assert0(0);\
1843  }\
1844 
1845  SET_DICT(type_in, meta_in, ic, idx_in);
1846  SET_DICT(type_out, meta_out, oc, idx_out);
1847 
1848  /* for input streams choose first matching stream */
1849  if (type_in == 's') {
1850  for (i = 0; i < ic->nb_streams; i++) {
1851  if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
1852  meta_in = &ic->streams[i]->metadata;
1853  break;
1854  } else if (ret < 0)
1855  exit_program(1);
1856  }
1857  if (!meta_in) {
1858  av_log(mux, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
1859  exit_program(1);
1860  }
1861  }
1862 
1863  if (type_out == 's') {
1864  for (i = 0; i < oc->nb_streams; i++) {
1865  if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
1866  meta_out = &oc->streams[i]->metadata;
1867  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
1868  } else if (ret < 0)
1869  exit_program(1);
1870  }
1871  } else
1872  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
1873 
1874  return 0;
1875 }
1876 
1877 static void copy_meta(Muxer *mux, const OptionsContext *o)
1878 {
1879  OutputFile *of = &mux->of;
1880  AVFormatContext *oc = mux->fc;
1881  int chapters_input_file = o->chapters_input_file;
1882  int metadata_global_manual = 0;
1883  int metadata_streams_manual = 0;
1884  int metadata_chapters_manual = 0;
1885 
1886  /* copy metadata */
1887  for (int i = 0; i < o->nb_metadata_map; i++) {
1888  char *p;
1889  int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
1890 
1891  if (in_file_index >= nb_input_files) {
1892  av_log(mux, AV_LOG_FATAL, "Invalid input file index %d while "
1893  "processing metadata maps\n", in_file_index);
1894  exit_program(1);
1895  }
1896  copy_metadata(mux,
1897  in_file_index >= 0 ? input_files[in_file_index]->ctx : NULL,
1898  o->metadata_map[i].specifier, *p ? p + 1 : p,
1899  &metadata_global_manual, &metadata_streams_manual,
1900  &metadata_chapters_manual, o);
1901  }
1902 
1903  /* copy chapters */
1904  if (chapters_input_file >= nb_input_files) {
1905  if (chapters_input_file == INT_MAX) {
1906  /* copy chapters from the first input file that has them*/
1907  chapters_input_file = -1;
1908  for (int i = 0; i < nb_input_files; i++)
1909  if (input_files[i]->ctx->nb_chapters) {
1910  chapters_input_file = i;
1911  break;
1912  }
1913  } else {
1914  av_log(mux, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
1915  chapters_input_file);
1916  exit_program(1);
1917  }
1918  }
1919  if (chapters_input_file >= 0)
1920  copy_chapters(input_files[chapters_input_file], of, oc,
1921  !metadata_chapters_manual);
1922 
1923  /* copy global metadata by default */
1924  if (!metadata_global_manual && nb_input_files){
1927  if (of->recording_time != INT64_MAX)
1928  av_dict_set(&oc->metadata, "duration", NULL, 0);
1929  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
1930  av_dict_set(&oc->metadata, "company_name", NULL, 0);
1931  av_dict_set(&oc->metadata, "product_name", NULL, 0);
1932  av_dict_set(&oc->metadata, "product_version", NULL, 0);
1933  }
1934  if (!metadata_streams_manual)
1935  for (int i = 0; i < of->nb_streams; i++) {
1936  OutputStream *ost = of->streams[i];
1937 
1938  if (!ost->ist) /* this is true e.g. for attached files */
1939  continue;
1941  if (ost->enc_ctx) {
1942  av_dict_set(&ost->st->metadata, "encoder", NULL, 0);
1943  }
1944  }
1945 }
1946 
1947 static int set_dispositions(Muxer *mux, const OptionsContext *o)
1948 {
1949  OutputFile *of = &mux->of;
1950  AVFormatContext *ctx = mux->fc;
1951 
1952  int nb_streams[AVMEDIA_TYPE_NB] = { 0 };
1953  int have_default[AVMEDIA_TYPE_NB] = { 0 };
1954  int have_manual = 0;
1955  int ret = 0;
1956 
1957  const char **dispositions;
1958 
1959  dispositions = av_calloc(ctx->nb_streams, sizeof(*dispositions));
1960  if (!dispositions)
1961  return AVERROR(ENOMEM);
1962 
1963  // first, copy the input dispositions
1964  for (int i = 0; i < ctx->nb_streams; i++) {
1965  OutputStream *ost = of->streams[i];
1966 
1967  nb_streams[ost->st->codecpar->codec_type]++;
1968 
1969  MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st);
1970 
1971  have_manual |= !!dispositions[i];
1972 
1973  if (ost->ist) {
1974  ost->st->disposition = ost->ist->st->disposition;
1975 
1977  have_default[ost->st->codecpar->codec_type] = 1;
1978  }
1979  }
1980 
1981  if (have_manual) {
1982  // process manually set dispositions - they override the above copy
1983  for (int i = 0; i < ctx->nb_streams; i++) {
1984  OutputStream *ost = of->streams[i];
1985  const char *disp = dispositions[i];
1986 
1987  if (!disp)
1988  continue;
1989 
1990 #if LIBAVFORMAT_VERSION_MAJOR >= 60
1991  ret = av_opt_set(ost->st, "disposition", disp, 0);
1992 #else
1993  {
1994  const AVClass *class = av_stream_get_class();
1995  const AVOption *o = av_opt_find(&class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ);
1996 
1997  av_assert0(o);
1998  ret = av_opt_eval_flags(&class, o, disp, &ost->st->disposition);
1999  }
2000 #endif
2001 
2002  if (ret < 0)
2003  goto finish;
2004  }
2005  } else {
2006  // For each media type with more than one stream, find a suitable stream to
2007  // mark as default, unless one is already marked default.
2008  // "Suitable" means the first of that type, skipping attached pictures.
2009  for (int i = 0; i < ctx->nb_streams; i++) {
2010  OutputStream *ost = of->streams[i];
2011  enum AVMediaType type = ost->st->codecpar->codec_type;
2012 
2013  if (nb_streams[type] < 2 || have_default[type] ||
2015  continue;
2016 
2018  have_default[type] = 1;
2019  }
2020  }
2021 
2022 finish:
2023  av_freep(&dispositions);
2024 
2025  return ret;
2026 }
2027 
2028 const char *const forced_keyframes_const_names[] = {
2029  "n",
2030  "n_forced",
2031  "prev_forced_n",
2032  "prev_forced_t",
2033  "t",
2034  NULL
2035 };
2036 
2037 static int compare_int64(const void *a, const void *b)
2038 {
2039  return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
2040 }
2041 
2042 static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux,
2043  const char *spec)
2044 {
2045  const char *p;
2046  int n = 1, i, size, index = 0;
2047  int64_t t, *pts;
2048 
2049  for (p = spec; *p; p++)
2050  if (*p == ',')
2051  n++;
2052  size = n;
2053  pts = av_malloc_array(size, sizeof(*pts));
2054  if (!pts)
2055  report_and_exit(AVERROR(ENOMEM));
2056 
2057  p = spec;
2058  for (i = 0; i < n; i++) {
2059  char *next = strchr(p, ',');
2060 
2061  if (next)
2062  *next++ = 0;
2063 
2064  if (!memcmp(p, "chapters", 8)) {
2065  AVChapter * const *ch = mux->fc->chapters;
2066  unsigned int nb_ch = mux->fc->nb_chapters;
2067  int j;
2068 
2069  if (nb_ch > INT_MAX - size ||
2070  !(pts = av_realloc_f(pts, size += nb_ch - 1,
2071  sizeof(*pts))))
2072  report_and_exit(AVERROR(ENOMEM));
2073  t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0;
2074 
2075  for (j = 0; j < nb_ch; j++) {
2076  const AVChapter *c = ch[j];
2077  av_assert1(index < size);
2078  pts[index++] = av_rescale_q(c->start, c->time_base,
2079  AV_TIME_BASE_Q) + t;
2080  }
2081 
2082  } else {
2083  av_assert1(index < size);
2084  pts[index++] = parse_time_or_die("force_key_frames", p, 1);
2085  }
2086 
2087  p = next;
2088  }
2089 
2090  av_assert0(index == size);
2091  qsort(pts, size, sizeof(*pts), compare_int64);
2092  kf->nb_pts = size;
2093  kf->pts = pts;
2094 }
2095 
2097 {
2098  for (int i = 0; i < mux->of.nb_streams; i++) {
2099  OutputStream *ost = mux->of.streams[i];
2100  const char *forced_keyframes = NULL;
2101 
2102  MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_keyframes, mux->fc, ost->st);
2103 
2104  if (!(ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2105  ost->enc_ctx && forced_keyframes))
2106  continue;
2107 
2108  if (!strncmp(forced_keyframes, "expr:", 5)) {
2109  int ret = av_expr_parse(&ost->kf.pexpr, forced_keyframes + 5,
2111  if (ret < 0) {
2113  "Invalid force_key_frames expression '%s'\n", forced_keyframes + 5);
2114  return ret;
2115  }
2116  ost->kf.expr_const_values[FKF_N] = 0;
2117  ost->kf.expr_const_values[FKF_N_FORCED] = 0;
2118  ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN;
2119  ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN;
2120 
2121  // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
2122  // parse it only for static kf timings
2123  } else if (!strcmp(forced_keyframes, "source")) {
2124  ost->kf.type = KF_FORCE_SOURCE;
2125  } else if (!strcmp(forced_keyframes, "source_no_drop")) {
2126  ost->kf.type = KF_FORCE_SOURCE_NO_DROP;
2127  } else {
2128  parse_forced_key_frames(&ost->kf, mux, forced_keyframes);
2129  }
2130  }
2131 
2132  return 0;
2133 }
2134 
2135 static void validate_enc_avopt(Muxer *mux, const AVDictionary *codec_avopt)
2136 {
2137  const AVClass *class = avcodec_get_class();
2138  const AVClass *fclass = avformat_get_class();
2139  const OutputFile *of = &mux->of;
2140 
2141  AVDictionary *unused_opts;
2142  const AVDictionaryEntry *e;
2143 
2144  unused_opts = strip_specifiers(codec_avopt);
2145  for (int i = 0; i < of->nb_streams; i++) {
2146  e = NULL;
2147  while ((e = av_dict_iterate(of->streams[i]->encoder_opts, e)))
2148  av_dict_set(&unused_opts, e->key, NULL, 0);
2149  }
2150 
2151  e = NULL;
2152  while ((e = av_dict_iterate(unused_opts, e))) {
2153  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2155  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2157  if (!option || foption)
2158  continue;
2159 
2160  if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2161  av_log(mux, AV_LOG_ERROR, "Codec AVOption %s (%s) is not an "
2162  "encoding option.\n", e->key, option->help ? option->help : "");
2163  exit_program(1);
2164  }
2165 
2166  // gop_timecode is injected by generic code but not always used
2167  if (!strcmp(e->key, "gop_timecode"))
2168  continue;
2169 
2170  av_log(mux, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
2171  "for any stream. The most likely reason is either wrong type "
2172  "(e.g. a video option with no video streams) or that it is a "
2173  "private option of some encoder which was not actually used for "
2174  "any stream.\n", e->key, option->help ? option->help : "");
2175  }
2176  av_dict_free(&unused_opts);
2177 }
2178 
2179 static const char *output_file_item_name(void *obj)
2180 {
2181  const Muxer *mux = obj;
2182 
2183  return mux->log_name;
2184 }
2185 
2186 static const AVClass output_file_class = {
2187  .class_name = "OutputFile",
2188  .version = LIBAVUTIL_VERSION_INT,
2189  .item_name = output_file_item_name,
2190  .category = AV_CLASS_CATEGORY_MUXER,
2191 };
2192 
2193 static Muxer *mux_alloc(void)
2194 {
2195  Muxer *mux = allocate_array_elem(&output_files, sizeof(*mux), &nb_output_files);
2196 
2197  mux->of.class = &output_file_class;
2198  mux->of.index = nb_output_files - 1;
2199 
2200  snprintf(mux->log_name, sizeof(mux->log_name), "out#%d", mux->of.index);
2201 
2202  return mux;
2203 }
2204 
2205 int of_open(const OptionsContext *o, const char *filename)
2206 {
2207  Muxer *mux;
2208  AVFormatContext *oc;
2209  int err;
2210  OutputFile *of;
2211 
2212  int64_t recording_time = o->recording_time;
2213  int64_t stop_time = o->stop_time;
2214 
2215  mux = mux_alloc();
2216  of = &mux->of;
2217 
2218  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
2219  stop_time = INT64_MAX;
2220  av_log(mux, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2221  }
2222 
2223  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
2224  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2225  if (stop_time <= start_time) {
2226  av_log(mux, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2227  exit_program(1);
2228  } else {
2229  recording_time = stop_time - start_time;
2230  }
2231  }
2232 
2233  of->recording_time = recording_time;
2234  of->start_time = o->start_time;
2235  of->shortest = o->shortest;
2236 
2237  mux->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
2238  mux->limit_filesize = o->limit_filesize;
2239  av_dict_copy(&mux->opts, o->g->format_opts, 0);
2240 
2241  if (!strcmp(filename, "-"))
2242  filename = "pipe:";
2243 
2244  err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2245  if (!oc) {
2246  print_error(filename, err);
2247  exit_program(1);
2248  }
2249  mux->fc = oc;
2250 
2251  av_strlcat(mux->log_name, "/", sizeof(mux->log_name));
2252  av_strlcat(mux->log_name, oc->oformat->name, sizeof(mux->log_name));
2253 
2254  if (strcmp(oc->oformat->name, "rtp"))
2255  want_sdp = 0;
2256 
2257  of->format = oc->oformat;
2258  if (recording_time != INT64_MAX)
2259  oc->duration = recording_time;
2260 
2261  oc->interrupt_callback = int_cb;
2262 
2263  if (o->bitexact) {
2264  oc->flags |= AVFMT_FLAG_BITEXACT;
2265  of->bitexact = 1;
2266  } else {
2267  of->bitexact = check_opt_bitexact(oc, mux->opts, "fflags",
2269  }
2270 
2271  /* create all output streams for this file */
2272  create_streams(mux, o);
2273 
2274  /* check if all codec options have been used */
2275  validate_enc_avopt(mux, o->g->codec_opts);
2276 
2277  /* set the decoding_needed flags and create simple filtergraphs */
2278  for (int i = 0; i < of->nb_streams; i++) {
2279  OutputStream *ost = of->streams[i];
2280 
2281  if (ost->enc_ctx && ost->ist) {
2282  InputStream *ist = ost->ist;
2284  ist->processing_needed = 1;
2285 
2286  if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2288  err = init_simple_filtergraph(ist, ost);
2289  if (err < 0) {
2291  "Error initializing a simple filtergraph\n");
2292  exit_program(1);
2293  }
2294  }
2295  } else if (ost->ist) {
2296  ost->ist->processing_needed = 1;
2297  }
2298 
2299  /* set the filter output constraints */
2300  if (ost->filter) {
2301  const AVCodec *c = ost->enc_ctx->codec;
2302  OutputFilter *f = ost->filter;
2303  switch (ost->enc_ctx->codec_type) {
2304  case AVMEDIA_TYPE_VIDEO:
2305  f->frame_rate = ost->frame_rate;
2306  f->width = ost->enc_ctx->width;
2307  f->height = ost->enc_ctx->height;
2308  if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2309  f->format = ost->enc_ctx->pix_fmt;
2310  } else {
2311  f->formats = c->pix_fmts;
2312  }
2313  break;
2314  case AVMEDIA_TYPE_AUDIO:
2315  if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2316  f->format = ost->enc_ctx->sample_fmt;
2317  } else {
2318  f->formats = c->sample_fmts;
2319  }
2320  if (ost->enc_ctx->sample_rate) {
2321  f->sample_rate = ost->enc_ctx->sample_rate;
2322  } else {
2323  f->sample_rates = c->supported_samplerates;
2324  }
2325  if (ost->enc_ctx->ch_layout.nb_channels) {
2327  } else if (c->ch_layouts) {
2328  f->ch_layouts = c->ch_layouts;
2329  }
2330  break;
2331  }
2332  }
2333  }
2334 
2335  /* check filename in case of an image number is expected */
2336  if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2337  if (!av_filename_number_test(oc->url)) {
2338  print_error(oc->url, AVERROR(EINVAL));
2339  exit_program(1);
2340  }
2341  }
2342 
2343  if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2344  /* test if it already exists to avoid losing precious files */
2345  assert_file_overwrite(filename);
2346 
2347  /* open the file */
2348  if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2349  &oc->interrupt_callback,
2350  &mux->opts)) < 0) {
2351  print_error(filename, err);
2352  exit_program(1);
2353  }
2354  } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
2355  assert_file_overwrite(filename);
2356 
2357  if (o->mux_preload) {
2358  av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2359  }
2360  oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2361 
2362  /* copy metadata and chapters from input files */
2363  copy_meta(mux, o);
2364 
2365  of_add_programs(mux, o);
2366  of_add_metadata(of, oc, o);
2367 
2368  err = set_dispositions(mux, o);
2369  if (err < 0) {
2370  av_log(mux, AV_LOG_FATAL, "Error setting output stream dispositions\n");
2371  exit_program(1);
2372  }
2373 
2374  // parse forced keyframe specifications;
2375  // must be done after chapters are created
2376  err = process_forced_keyframes(mux, o);
2377  if (err < 0) {
2378  av_log(mux, AV_LOG_FATAL, "Error processing forced keyframes\n");
2379  exit_program(1);
2380  }
2381 
2383  if (err < 0) {
2384  av_log(mux, AV_LOG_FATAL, "Error setting up output sync queues\n");
2385  exit_program(1);
2386  }
2387 
2388  of->url = filename;
2389 
2390  /* write the header for files with no streams */
2391  if (of->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) {
2392  int ret = mux_check_init(mux);
2393  if (ret < 0)
2394  return ret;
2395  }
2396 
2397  return 0;
2398 }
choose_encoder
static int choose_encoder(const OptionsContext *o, AVFormatContext *s, OutputStream *ost, const AVCodec **enc)
Definition: ffmpeg_mux_init.c:105
KeyframeForceCtx::pts
int64_t * pts
Definition: ffmpeg.h:548
MuxStream::ost
OutputStream ost
Definition: ffmpeg_mux.h:38
parse_forced_key_frames
static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux, const char *spec)
Definition: ffmpeg_mux_init.c:2042
fopen_utf8
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: fopen_utf8.h:65
SYNC_QUEUE_PACKETS
@ SYNC_QUEUE_PACKETS
Definition: sync_queue.h:29
opt_name_filters
static const char *const opt_name_filters[]
Definition: ffmpeg_mux_init.c:62
AVCodec
AVCodec.
Definition: codec.h:204
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:76
Muxer::fc
AVFormatContext * fc
Definition: ffmpeg_mux.h:72
OptionsContext::stop_time
int64_t stop_time
Definition: ffmpeg.h:158
opt_name_max_muxing_queue_size
static const char *const opt_name_max_muxing_queue_size[]
Definition: ffmpeg_mux_init.c:74
program
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
Definition: undefined.txt:6
FKF_PREV_FORCED_T
@ FKF_PREV_FORCED_T
Definition: ffmpeg.h:487
VSYNC_VFR
@ VSYNC_VFR
Definition: ffmpeg.h:62
ms_from_ost
static MuxStream * ms_from_ost(OutputStream *ost)
Definition: ffmpeg_mux.h:95
AVOutputFormat::name
const char * name
Definition: avformat.h:510
AVChapter::metadata
AVDictionary * metadata
Definition: avformat.h:1179
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:215
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
nb_input_files
int nb_input_files
Definition: ffmpeg.c:144
opt.h
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:237
MATCH_PER_STREAM_OPT
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
Definition: ffmpeg.h:865
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:58
opt_name_muxing_queue_data_threshold
static const char *const opt_name_muxing_queue_data_threshold[]
Definition: ffmpeg_mux_init.c:75
new_subtitle_stream
static OutputStream * new_subtitle_stream(Muxer *mux, const OptionsContext *o, InputStream *ist)
Definition: ffmpeg_mux_init.c:1064
AVSTREAM_EVENT_FLAG_NEW_PACKETS
#define AVSTREAM_EVENT_FLAG_NEW_PACKETS
Definition: avformat.h:1087
ENC_STATS_PTS
@ ENC_STATS_PTS
Definition: ffmpeg.h:503
out
FILE * out
Definition: movenc.c:54
ENC_STATS_FRAME_NUM_IN
@ ENC_STATS_FRAME_NUM_IN
Definition: ffmpeg.h:500
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1049
KF_FORCE_SOURCE_NO_DROP
@ KF_FORCE_SOURCE_NO_DROP
Definition: ffmpeg.h:539
FKF_PREV_FORCED_N
@ FKF_PREV_FORCED_N
Definition: ffmpeg.h:486
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
av_get_token
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:154
is
The official guide to swscale for confused that is
Definition: swscale.txt:28
AVFormatContext::nb_chapters
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1434
opt_name_enc_stats_pre
static const char *const opt_name_enc_stats_pre[]
Definition: ffmpeg_mux_init.c:58
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:947
parse_matrix_coeffs
static void parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str)
Definition: ffmpeg_mux_init.c:675
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:484
AV_DISPOSITION_ATTACHED_PIC
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition: avformat.h:879
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:1010
ENC_STATS_DTS
@ ENC_STATS_DTS
Definition: ffmpeg.h:507
MATCH_PER_TYPE_OPT
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
Definition: ffmpeg.h:882
sq_limit_frames
void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t frames)
Limit the number of output frames for stream with index stream_idx to max_frames.
Definition: sync_queue.c:393
MuxStream::muxing_queue
AVFifo * muxing_queue
Definition: ffmpeg_mux.h:44
KeyframeForceCtx::nb_pts
int nb_pts
Definition: ffmpeg.h:549
IS_INTERLEAVED
#define IS_INTERLEAVED(type)
AV_CODEC_FLAG_QSCALE
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:216
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:481
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:335
OptionsContext::nb_metadata
int nb_metadata
Definition: ffmpeg.h:176
ENC_STATS_AVG_BITRATE
@ ENC_STATS_AVG_BITRATE
Definition: ffmpeg.h:513
AVCodecContext::intra_matrix
uint16_t * intra_matrix
custom intra quantization matrix Must be allocated with the av_malloc() family of functions,...
Definition: avcodec.h:925
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:197
ist_iter
InputStream * ist_iter(InputStream *prev)
Definition: ffmpeg.c:604
parse_and_set_vsync
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
Definition: ffmpeg_opt.c:184
AV_DISPOSITION_DEFAULT
#define AV_DISPOSITION_DEFAULT
The stream should be chosen by default among other streams of the same type, unless the user has expl...
Definition: avformat.h:826
OptionsContext::nb_attachments
int nb_attachments
Definition: ffmpeg.h:153
MuxStream::max_muxing_queue_size
int max_muxing_queue_size
Definition: ffmpeg_mux.h:56
OutputFile::start_time
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:702
avcodec_find_encoder
const AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: allcodecs.c:958
Muxer::thread_queue_size
int thread_queue_size
Definition: ffmpeg_mux.h:79
audio_channels
int audio_channels
Definition: rtp.c:40
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1284
OptionsContext::mux_max_delay
float mux_max_delay
Definition: ffmpeg.h:161
map_auto_video
static void map_auto_video(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1127
MuxStream::muxing_queue_data_threshold
size_t muxing_queue_data_threshold
Definition: ffmpeg_mux.h:59
subtitle_codec_name
static const char * subtitle_codec_name
Definition: ffplay.c:345
ENC_STATS_LITERAL
@ ENC_STATS_LITERAL
Definition: ffmpeg.h:496
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:168
opt_name_disposition
static const char *const opt_name_disposition[]
Definition: ffmpeg_mux_init.c:56
AVOption
AVOption.
Definition: opt.h:251
OutputStream::index
int index
Definition: ffmpeg.h:562
opt_name_sample_fmts
static const char *const opt_name_sample_fmts[]
Definition: ffmpeg_mux_init.c:87
b
#define b
Definition: input.c:41
fix_sub_duration_heartbeat
static int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts)
Definition: ffmpeg.c:2456
opt_name_max_frames
static const char *const opt_name_max_frames[]
Definition: ffmpeg_mux_init.c:73
AVChapter::start
int64_t start
Definition: avformat.h:1178
Muxer::of
OutputFile of
Definition: ffmpeg_mux.h:67
AV_DICT_APPEND
#define AV_DICT_APPEND
If the entry already exists, append to it.
Definition: dict.h:82
RcOverride::qscale
int qscale
Definition: avcodec.h:199
ffmpeg.h
opt_name_fix_sub_duration_heartbeat
static const char *const opt_name_fix_sub_duration_heartbeat[]
Definition: ffmpeg_mux_init.c:64
base
uint8_t base
Definition: vp3data.h:128
freeenv_utf8
static void freeenv_utf8(char *var)
Definition: getenv_utf8.h:72
AV_NOWARN_DEPRECATED
#define AV_NOWARN_DEPRECATED(code)
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
Definition: attributes.h:126
OptionGroup::swr_opts
AVDictionary * swr_opts
Definition: cmdutils.h:260
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1385
IS_AV_ENC
#define IS_AV_ENC(ost, type)
OptionsContext::bitexact
int bitexact
Definition: ffmpeg.h:164
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:66
opt_name_qscale
static const char *const opt_name_qscale[]
Definition: ffmpeg_mux_init.c:79
video_disable
static int video_disable
Definition: ffplay.c:320
enc_stats_init
static int enc_stats_init(OutputStream *ost, int pre, const char *path, const char *fmt_spec)
Definition: ffmpeg_mux_init.c:265
AVDictionary
Definition: dict.c:32
set_channel_layout
static void set_channel_layout(OutputFilter *f, OutputStream *ost)
Definition: ffmpeg_mux_init.c:1712
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:306
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AV_CODEC_FLAG_PSNR
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
Definition: avcodec.h:305
InputStream::decoding_needed
int decoding_needed
Definition: ffmpeg.h:336
OptionsContext::format
const char * format
Definition: ffmpeg.h:103
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:354
ost
static AVStream * ost
Definition: vaapi_transcode.c:45
opt_name_apad
static const char *const opt_name_apad[]
Definition: ffmpeg_mux_init.c:50
set_dispositions
static int set_dispositions(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1947
AVOutputFormat::subtitle_codec
enum AVCodecID subtitle_codec
default subtitle codec
Definition: avformat.h:522
new_audio_stream
static OutputStream * new_audio_stream(Muxer *mux, const OptionsContext *o, InputStream *ist)
Definition: ffmpeg_mux_init.c:933
ENC_STATS_TIMEBASE_IN
@ ENC_STATS_TIMEBASE_IN
Definition: ffmpeg.h:502
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AV_CODEC_FLAG_GLOBAL_HEADER
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:326
get_preset_file_2
static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
Definition: ffmpeg_mux_init.c:147
init_simple_filtergraph
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
Definition: ffmpeg_filter.c:179
of_add_programs
static void of_add_programs(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1532
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:697
av_filename_number_test
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition: utils.c:125
av_expr_parse
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:685
exit_program
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:99
Muxer
Definition: ffmpeg_mux.h:66
InputStream
Definition: ffmpeg.h:331
OptionsContext::chapters_input_file
int chapters_input_file
Definition: ffmpeg.h:155
SET_DICT
#define SET_DICT(type, meta, context, index)
EncStatsFile
Definition: ffmpeg_mux_init.c:177
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1483
of_add_metadata
static void of_add_metadata(OutputFile *of, AVFormatContext *oc, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1639
print_error
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
Definition: cmdutils.c:799
avio_open2
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1251
finish
static void finish(void)
Definition: movenc.c:342
fopen_utf8.h
assert_file_overwrite
void assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:656
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:449
presets
static const Preset presets[]
Definition: vf_pseudocolor.c:186
opt_name_audio_channels
static const char *const opt_name_audio_channels[]
Definition: ffmpeg_mux_init.c:82
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:97
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2106
report_and_exit
void report_and_exit(int ret)
Reports an error corresponding to the provided AVERROR code and calls exit_program() with the corresp...
Definition: cmdutils.c:93
mux_alloc
static Muxer * mux_alloc(void)
Definition: ffmpeg_mux_init.c:2193
fail
#define fail()
Definition: checkasm.h:134
opt_name_audio_ch_layouts
static const char *const opt_name_audio_ch_layouts[]
Definition: ffmpeg_mux_init.c:83
opt_name_audio_sample_rate
static const char *const opt_name_audio_sample_rate[]
Definition: ffmpeg_mux_init.c:84
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:520
AVChapter
Definition: avformat.h:1175
val
static double val(void *priv, double ch)
Definition: aeval.c:77
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:654
want_sdp
int want_sdp
Definition: ffmpeg_mux.c:41
setup_sync_queues
static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_us)
Definition: ffmpeg_mux_init.c:1438
OptionsContext
Definition: ffmpeg.h:96
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:487
av_new_program
AVProgram * av_new_program(AVFormatContext *ac, int id)
Definition: avformat.c:304
Muxer::sq_pkt
AVPacket * sq_pkt
Definition: ffmpeg_mux.h:87
enc_stats_files
static EncStatsFile * enc_stats_files
Definition: ffmpeg_mux_init.c:182
AVRational::num
int num
Numerator.
Definition: rational.h:59
OptionsContext::nb_audio_channel_maps
int nb_audio_channel_maps
Definition: ffmpeg.h:150
InputFile
Definition: ffmpeg.h:446
FFDIFFSIGN
#define FFDIFFSIGN(x, y)
Comparator.
Definition: macros.h:45
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:157
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:104
OptionsContext::nb_stream_maps
int nb_stream_maps
Definition: ffmpeg.h:147
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:167
check_stream_specifier
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:887
preset
preset
Definition: vf_curves.c:46
OutputFile::shortest
int shortest
Definition: ffmpeg.h:704
avfilter_inout_free
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:206
avassert.h
RcOverride::quality_factor
float quality_factor
Definition: avcodec.h:200
MuxStream::log_name
char log_name[32]
Definition: ffmpeg_mux.h:41
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AudioChannelMap
Definition: ffmpeg.h:90
AVFormatContext::metadata
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1445
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:257
av_dump_format
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
Definition: dump.c:629
ENC_STATS_PTS_IN
@ ENC_STATS_PTS_IN
Definition: ffmpeg.h:505
mask
static const uint16_t mask[17]
Definition: lzw.c:38
OptionsContext::nb_program
int nb_program
Definition: ffmpeg.h:248
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:60
avformat_query_codec
int avformat_query_codec(const AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance)
Test if the given container can store a codec.
Definition: mux_utils.c:43
output_stream_class
static const AVClass output_stream_class
Definition: ffmpeg_mux_init.c:396
VSYNC_VSCFR
@ VSYNC_VSCFR
Definition: ffmpeg.h:63
EncStats::components
EncStatsComponent * components
Definition: ffmpeg.h:524
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:153
AVChapter::end
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:1178
SpecifierOpt::specifier
char * specifier
stream/chapter/program/...
Definition: cmdutils.h:135
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
mux_stream_alloc
static MuxStream * mux_stream_alloc(Muxer *mux, enum AVMediaType type)
Definition: ffmpeg_mux_init.c:403
intreadwrite.h
opt_name_enc_stats_post_fmt
static const char *const opt_name_enc_stats_post_fmt[]
Definition: ffmpeg_mux_init.c:61
s
#define s(width, name)
Definition: cbs_vp9.c:256
AVCodecContext::stats_in
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:1315
init_output_filter
static void init_output_filter(OutputFilter *ofilter, const OptionsContext *o, Muxer *mux)
Definition: ffmpeg_mux_init.c:1086
mux_check_init
int mux_check_init(Muxer *mux)
Definition: ffmpeg_mux.c:497
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:281
FilterGraph::outputs
OutputFilter ** outputs
Definition: ffmpeg.h:327
enc_stats_get_file
static int enc_stats_get_file(AVIOContext **io, const char *path)
Definition: ffmpeg_mux_init.c:185
do_psnr
int do_psnr
Definition: ffmpeg_opt.c:96
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:225
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1334
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
output_file_class
static const AVClass output_file_class
Definition: ffmpeg_mux_init.c:2186
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1384
RcOverride
Definition: avcodec.h:196
AVFormatContext::chapters
AVChapter ** chapters
Definition: avformat.h:1435
ENC_STATS_FILE_IDX
@ ENC_STATS_FILE_IDX
Definition: ffmpeg.h:497
AVDictionaryEntry::key
char * key
Definition: dict.h:90
frame_size
int frame_size
Definition: mxfenc.c:2202
OptionsContext::limit_filesize
int64_t limit_filesize
Definition: ffmpeg.h:159
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:128
of_add_attachments
static void of_add_attachments(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1347
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
av_channel_layout_from_mask
FF_ENABLE_DEPRECATION_WARNINGS int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:391
get_line
static char * get_line(AVIOContext *s, AVBPrint *bprint)
Definition: ffmpeg_mux_init.c:135
filters
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
Definition: af_crystalizer.c:55
ENC_STATS_BITRATE
@ ENC_STATS_BITRATE
Definition: ffmpeg.h:512
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVMEDIA_TYPE_NB
@ AVMEDIA_TYPE_NB
Definition: avutil.h:206
output_stream_item_name
static const char * output_stream_item_name(void *obj)
Definition: ffmpeg_mux_init.c:389
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:634
OutputFilter::ost
struct OutputStream * ost
Definition: ffmpeg.h:293
ignore_unknown_streams
int ignore_unknown_streams
Definition: ffmpeg_opt.c:98
ctx
AVFormatContext * ctx
Definition: movenc.c:48
RcOverride::start_frame
int start_frame
Definition: avcodec.h:197
channels
channels
Definition: aptx.h:31
nb_streams
static int nb_streams
Definition: ffprobe.c:309
opt_name_enc_stats_pre_fmt
static const char *const opt_name_enc_stats_pre_fmt[]
Definition: ffmpeg_mux_init.c:60
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
opt_name_intra_matrices
static const char *const opt_name_intra_matrices[]
Definition: ffmpeg_mux_init.c:69
OptionsContext::shortest
int shortest
Definition: ffmpeg.h:163
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:388
key
const char * key
Definition: hwcontext_opencl.c:174
create_streams
static void create_streams(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1388
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
NAN
#define NAN
Definition: mathematics.h:64
MuxStream::max_frames
int64_t max_frames
Definition: ffmpeg_mux.h:48
pass
#define pass
Definition: fft_template.c:608
AVFMT_NEEDNUMBER
#define AVFMT_NEEDNUMBER
Needs 'd' in filename.
Definition: avformat.h:471
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:450
Muxer::limit_filesize
int64_t limit_filesize
Definition: ffmpeg_mux.h:82
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1772
arg
const char * arg
Definition: jacosubdec.c:67
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
sq_add_stream
int sq_add_stream(SyncQueue *sq, int limiting)
Add a new stream to the sync queue.
Definition: sync_queue.c:351
option
option
Definition: libkvazaar.c:312
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:100
OutputStream::encoder_opts
AVDictionary * encoder_opts
Definition: ffmpeg.h:632
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:76
AVFormatContext
Format I/O context.
Definition: avformat.h:1216
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:32
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:258
opts
AVDictionary * opts
Definition: movenc.c:50
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
get_ost_filters
static char * get_ost_filters(const OptionsContext *o, AVFormatContext *oc, OutputStream *ost)
Definition: ffmpeg_mux_init.c:643
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
avcodec_get_class
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:187
opt_name_inter_matrices
static const char *const opt_name_inter_matrices[]
Definition: ffmpeg_mux_init.c:70
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:978
DEFAULT_PASS_LOGFILENAME_PREFIX
#define DEFAULT_PASS_LOGFILENAME_PREFIX
Definition: ffmpeg_mux_init.c:48
NULL
#define NULL
Definition: coverity.c:32
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: avformat.c:335
InputStream::st
AVStream * st
Definition: ffmpeg.h:333
map_manual
static void map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map)
Definition: ffmpeg_mux_init.c:1276
nb_enc_stats_files
static int nb_enc_stats_files
Definition: ffmpeg_mux_init.c:183
ENC_STATS_PTS_TIME
@ ENC_STATS_PTS_TIME
Definition: ffmpeg.h:504
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
opt_name_forced_key_frames
static const char *const opt_name_forced_key_frames[]
Definition: ffmpeg_mux_init.c:67
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1258
AV_CODEC_PROP_BITMAP_SUB
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect->pict fiel...
Definition: codec_desc.h:97
parseutils.h
EncStats
Definition: ffmpeg.h:523
EncStatsFile::io
AVIOContext * io
Definition: ffmpeg_mux_init.c:179
getenv_utf8
static char * getenv_utf8(const char *varname)
Definition: getenv_utf8.h:67
copy_unknown_streams
int copy_unknown_streams
Definition: ffmpeg_opt.c:99
opt_name_time_bases
static const char *const opt_name_time_bases[]
Definition: ffmpeg_mux_init.c:81
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:1019
MuxStream::bsf_ctx
AVBSFContext * bsf_ctx
Definition: ffmpeg_mux.h:46
check_streamcopy_filters
static void check_streamcopy_filters(const OptionsContext *o, AVFormatContext *oc, OutputStream *ost, enum AVMediaType type)
Definition: ffmpeg_mux_init.c:662
validate_enc_avopt
static void validate_enc_avopt(Muxer *mux, const AVDictionary *codec_avopt)
Definition: ffmpeg_mux_init.c:2135
AV_DICT_DONT_OVERWRITE
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition: dict.h:81
av_parse_ratio
int av_parse_ratio(AVRational *q, const char *str, int max, int log_offset, void *log_ctx)
Parse str and store the parsed ratio in q.
Definition: parseutils.c:45
OptionsContext::max_frames
SpecifierOpt * max_frames
Definition: ffmpeg.h:177
av_get_channel_layout
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
Definition: channel_layout.c:239
Muxer::log_name
char log_name[32]
Definition: ffmpeg_mux.h:70
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:213
OutputFile::index
int index
Definition: ffmpeg.h:691
OptionsContext::program
SpecifierOpt * program
Definition: ffmpeg.h:247
OutputFile::class
const AVClass * class
Definition: ffmpeg.h:689
ENC_STATS_PTS_TIME_IN
@ ENC_STATS_PTS_TIME_IN
Definition: ffmpeg.h:506
FilterGraph::nb_outputs
int nb_outputs
Definition: ffmpeg.h:328
of_open
int of_open(const OptionsContext *o, const char *filename)
Definition: ffmpeg_mux_init.c:2205
index
int index
Definition: gxfenc.c:89
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
OptionsContext::nb_metadata_map
int nb_metadata_map
Definition: ffmpeg.h:212
opt_name_chroma_intra_matrices
static const char *const opt_name_chroma_intra_matrices[]
Definition: ffmpeg_mux_init.c:71
input_files
InputFile ** input_files
Definition: ffmpeg.c:143
OutputFile::streams
OutputStream ** streams
Definition: ffmpeg.h:696
AV_OPT_SEARCH_FAKE_OBJ
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
Definition: opt.h:571
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
opt_name_frame_pix_fmts
static const char *const opt_name_frame_pix_fmts[]
Definition: ffmpeg_mux_init.c:86
FilterGraph
Definition: ffmpeg.h:315
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:80
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1272
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:529
opt_name_filter_scripts
static const char *const opt_name_filter_scripts[]
Definition: ffmpeg_mux_init.c:63
av_get_exact_bits_per_sample
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:486
frame_sizes
static const uint8_t frame_sizes[]
Definition: rtpdec_qcelp.c:24
f
f
Definition: af_crystalizer.c:122
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
AVCodecContext::rc_override
RcOverride * rc_override
Definition: avcodec.h:1258
OptionsContext::thread_queue_size
int thread_queue_size
Definition: ffmpeg.h:128
AVMediaType
AVMediaType
Definition: avutil.h:199
Muxer::sq_mux
SyncQueue * sq_mux
Definition: ffmpeg_mux.h:86
opt_name_bits_per_raw_sample
static const char *const opt_name_bits_per_raw_sample[]
Definition: ffmpeg_mux_init.c:52
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
InputStream::file_index
int file_index
Definition: ffmpeg.h:332
output_files
OutputFile ** output_files
Definition: ffmpeg.c:146
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
opt_name_frame_sizes
static const char *const opt_name_frame_sizes[]
Definition: ffmpeg_mux_init.c:85
start_time
static int64_t start_time
Definition: ffplay.c:331
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1299
EncStatsType
EncStatsType
Definition: ffmpeg.h:495
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1065
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
StreamMap
Definition: ffmpeg.h:82
ENC_STATS_NB_SAMPLES
@ ENC_STATS_NB_SAMPLES
Definition: ffmpeg.h:510
size
int size
Definition: twinvq_data.h:10344
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:76
avio.h
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVStream::event_flags
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
Definition: avformat.h:1074
opt_name_pass
static const char *const opt_name_pass[]
Definition: ffmpeg_mux_init.c:76
OutputFile::url
const char * url
Definition: ffmpeg.h:694
DECODING_FOR_OST
#define DECODING_FOR_OST
Definition: ffmpeg.h:337
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:470
AVCodecContext::chroma_intra_matrix
uint16_t * chroma_intra_matrix
custom intra quantization matrix
Definition: avcodec.h:1871
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
Muxer::opts
AVDictionary * opts
Definition: ffmpeg_mux.h:77
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:1017
AVFMT_NOSTREAMS
#define AVFMT_NOSTREAMS
Format does not require any streams.
Definition: avformat.h:486
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:987
of_enc_stats_close
void of_enc_stats_close(void)
Definition: ffmpeg_mux_init.c:216
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:563
MuxStream
Definition: ffmpeg_mux.h:37
AV_CODEC_FLAG_PASS2
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:293
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:634
getenv_utf8.h
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
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition: mem.c:233
strip_specifiers
AVDictionary * strip_specifiers(const AVDictionary *dict)
Definition: ffmpeg_opt.c:167
OptionsContext::metadata
SpecifierOpt * metadata
Definition: ffmpeg.h:175
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:62
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
opt_name_enc_stats_post
static const char *const opt_name_enc_stats_post[]
Definition: ffmpeg_mux_init.c:59
OutputFile::sq_encode
SyncQueue * sq_encode
Definition: ffmpeg.h:699
KF_FORCE_SOURCE
@ KF_FORCE_SOURCE
Definition: ffmpeg.h:538
av_parse_video_size
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:150
ENC_STATS_FRAME_NUM
@ ENC_STATS_FRAME_NUM
Definition: ffmpeg.h:499
KeyframeForceCtx
Definition: ffmpeg.h:542
OutputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:299
opt_name_autoscale
static const char *const opt_name_autoscale[]
Definition: ffmpeg_mux_init.c:51
AVCodec::id
enum AVCodecID id
Definition: codec.h:218
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:962
layout
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 layout
Definition: filter_design.txt:18
flag
#define flag(name)
Definition: cbs_av1.c:553
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:438
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
avio_closep
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: aviobuf.c:1290
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:404
bprint.h
log.h
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:480
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
RcOverride::end_frame
int end_frame
Definition: avcodec.h:198
OptionsContext::metadata_map
SpecifierOpt * metadata_map
Definition: ffmpeg.h:211
AVChapter::id
int64_t id
unique ID to identify the chapter
Definition: avformat.h:1176
OptionsContext::stream_maps
StreamMap * stream_maps
Definition: ffmpeg.h:146
AVCodecParameters::height
int height
Definition: codec_par.h:129
av_get_sample_fmt
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
Definition: samplefmt.c:58
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
find_codec_or_die
const AVCodec * find_codec_or_die(void *logctx, const char *name, enum AVMediaType type, int encoder)
Definition: ffmpeg_opt.c:626
VSYNC_CFR
@ VSYNC_CFR
Definition: ffmpeg.h:61
OptionsContext::shortest_buf_duration
float shortest_buf_duration
Definition: ffmpeg.h:162
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AVProgram::metadata
AVDictionary * metadata
Definition: avformat.h:1146
map_auto_audio
static void map_auto_audio(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1178
OutputFile::bitexact
int bitexact
Definition: ffmpeg.h:705
opt_name_frame_aspect_ratios
static const char *const opt_name_frame_aspect_ratios[]
Definition: ffmpeg_mux_init.c:68
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
opt_name_enc_time_bases
static const char *const opt_name_enc_time_bases[]
Definition: ffmpeg_mux_init.c:57
filter_codec_opts
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec)
Filter out options for given codec.
Definition: cmdutils.c:895
InputStream::processing_needed
int processing_needed
Definition: ffmpeg.h:339
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:449
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVFormatContext::max_delay
int max_delay
Definition: avformat.h:1328
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:264
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1140
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:211
len
int len
Definition: vorbis_enc_data.h:426
ENC_STATS_STREAM_IDX
@ ENC_STATS_STREAM_IDX
Definition: ffmpeg.h:498
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:149
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:500
AVCodecContext::height
int height
Definition: avcodec.h:613
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:650
ENC_STATS_SAMPLE_NUM
@ ENC_STATS_SAMPLE_NUM
Definition: ffmpeg.h:509
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
nb_output_files
int nb_output_files
Definition: ffmpeg.c:147
OptionsContext::streamid_map
int * streamid_map
Definition: ffmpeg.h:172
avcodec.h
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition: cmdutils.h:259
av_opt_eval_flags
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:1008
new_unknown_stream
static OutputStream * new_unknown_stream(Muxer *mux, const OptionsContext *o, InputStream *ist)
Definition: ffmpeg_mux_init.c:1044
tag
uint32_t tag
Definition: movenc.c:1647
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:962
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1351
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:948
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
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:71
av_strtod
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:106
AVFormatContext::oformat
const struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1235
av_strlcat
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
Definition: avstring.c:96
OptionsContext::nb_streamid_map
int nb_streamid_map
Definition: ffmpeg.h:173
output_file_item_name
static const char * output_file_item_name(void *obj)
Definition: ffmpeg_mux_init.c:2179
normalize.ifile
ifile
Definition: normalize.py:6
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:102
OptionsContext::audio_channel_maps
AudioChannelMap * audio_channel_maps
Definition: ffmpeg.h:149
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:470
avformat.h
dict.h
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
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
av_guess_codec
enum AVCodecID av_guess_codec(const AVOutputFormat *fmt, const char *short_name, const char *filename, const char *mime_type, enum AVMediaType type)
Guess the codec ID based upon muxer and filename.
Definition: format.c:89
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2820
OptionsContext::nb_max_frames
int nb_max_frames
Definition: ffmpeg.h:178
OutputFilter::format
int format
Definition: ffmpeg.h:304
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
AVCodecContext
main external API structure.
Definition: avcodec.h:440
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:956
AV_CLASS_CATEGORY_MUXER
@ AV_CLASS_CATEGORY_MUXER
Definition: log.h:32
new_attachment_stream
static OutputStream * new_attachment_stream(Muxer *mux, const OptionsContext *o, InputStream *ist)
Definition: ffmpeg_mux_init.c:1057
OptionsContext::mux_preload
float mux_preload
Definition: ffmpeg.h:160
map_auto_subtitle
static void map_auto_subtitle(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1220
map_auto_data
static void map_auto_data(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1258
copy_metadata
static int copy_metadata(Muxer *mux, AVFormatContext *ic, const char *outspec, const char *inspec, int *metadata_global_manual, int *metadata_streams_manual, int *metadata_chapters_manual, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1793
AVRational::den
int den
Denominator.
Definition: rational.h:60
new_output_stream
static OutputStream * new_output_stream(Muxer *mux, const OptionsContext *o, enum AVMediaType type, InputStream *ist)
Definition: ffmpeg_mux_init.c:420
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:137
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
avfilter.h
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:227
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:643
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:166
AVOutputFormat::video_codec
enum AVCodecID video_codec
default video codec
Definition: avformat.h:521
opt_name_passlogfiles
static const char *const opt_name_passlogfiles[]
Definition: ffmpeg_mux_init.c:77
opt_name_rc_overrides
static const char *const opt_name_rc_overrides[]
Definition: ffmpeg_mux_init.c:80
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1318
video_sync_method
enum VideoSyncMethod video_sync_method
Definition: ffmpeg_opt.c:70
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:442
VSYNC_AUTO
@ VSYNC_AUTO
Definition: ffmpeg.h:59
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:639
OutputFilter
Definition: ffmpeg.h:291
av_dict_set_int
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition: dict.c:167
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:633
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVERROR_ENCODER_NOT_FOUND
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
Definition: error.h:56
av_bsf_list_parse_str
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition: bsf.c:527
unescape
static int unescape(char **pdst, size_t *dst_len, const char **pstr, char delim)
Definition: ffmpeg_mux_init.c:226
avutil.h
mem.h
SpecifierOpt::u
union SpecifierOpt::@0 u
OutputStream::file_index
int file_index
Definition: ffmpeg.h:561
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:330
OutputFilter::out_tmp
AVFilterInOut * out_tmp
Definition: ffmpeg.h:298
ffmpeg_mux.h
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
EncStatsFile::path
char * path
Definition: ffmpeg_mux_init.c:178
compare_int64
static int compare_int64(const void *a, const void *b)
Definition: ffmpeg_mux_init.c:2037
copy_meta
static void copy_meta(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1877
FKF_N_FORCED
@ FKF_N_FORCED
Definition: ffmpeg.h:485
AVDictionaryEntry
Definition: dict.h:89
OptionsContext::attachments
const char ** attachments
Definition: ffmpeg.h:152
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:62
AVPacket
This structure stores compressed data.
Definition: packet.h:351
audio_disable
static int audio_disable
Definition: ffplay.c:319
EncStatsComponent
Definition: ffmpeg.h:516
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
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_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:237
AVCodecContext::inter_matrix
uint16_t * inter_matrix
custom inter quantization matrix Must be allocated with the av_malloc() family of functions,...
Definition: avcodec.h:934
cmdutils.h
AVCodecContext::rc_override_count
int rc_override_count
ratecontrol override, see RcOverride
Definition: avcodec.h:1257
file_read
char * file_read(const char *filename)
Definition: ffmpeg_opt.c:700
EncStats::nb_components
int nb_components
Definition: ffmpeg.h:525
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:169
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:150
AVFilterInOut::name
char * name
unique name for this input/output in the list
Definition: avfilter.h:1027
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:613
convert_header.str
string str
Definition: convert_header.py:20
parse_time_or_die
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Parse a string specifying a time and return its corresponding value as a number of microseconds.
Definition: cmdutils.c:128
ENC_STATS_PKT_SIZE
@ ENC_STATS_PKT_SIZE
Definition: ffmpeg.h:511
OutputStream
Definition: muxing.c:54
check_opt_bitexact
static int check_opt_bitexact(void *ctx, const AVDictionary *opts, const char *opt_name, int flag)
Definition: ffmpeg_mux_init.c:89
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
forced_keyframes_const_names
const char *const forced_keyframes_const_names[]
Definition: ffmpeg_mux_init.c:2028
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
process_forced_keyframes
static int process_forced_keyframes(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:2096
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:140
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3657
SYNC_QUEUE_FRAMES
@ SYNC_QUEUE_FRAMES
Definition: sync_queue.h:30
OutputFile::format
const AVOutputFormat * format
Definition: ffmpeg.h:693
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
av_stream_get_class
const AVClass * av_stream_get_class(void)
Get the AVClass for AVStream.
Definition: options.c:232
FF_QP2LAMBDA
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
opt_name_copy_initial_nonkeyframes
static const char *const opt_name_copy_initial_nonkeyframes[]
Definition: ffmpeg_mux_init.c:54
FKF_N
@ FKF_N
Definition: ffmpeg.h:484
avformat_alloc_output_context2
int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:91
ENC_STATS_DTS_TIME
@ ENC_STATS_DTS_TIME
Definition: ffmpeg.h:508
AVChapter::time_base
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1177
OutputFile::recording_time
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:701
int
int
Definition: ffmpeg_filter.c:156
AVFilterInOut
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1025
VSYNC_PASSTHROUGH
@ VSYNC_PASSTHROUGH
Definition: ffmpeg.h:60
opt_name_fps_mode
static const char *const opt_name_fps_mode[]
Definition: ffmpeg_mux_init.c:65
snprintf
#define snprintf
Definition: snprintf.h:34
EncStats::io
AVIOContext * io
Definition: ffmpeg.h:527
normalize.ofile
ofile
Definition: normalize.py:8
opt_name_bitstream_filters
static const char *const opt_name_bitstream_filters[]
Definition: ffmpeg_mux_init.c:53
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:810
new_video_stream
static OutputStream * new_video_stream(Muxer *mux, const OptionsContext *o, InputStream *ist)
Definition: ffmpeg_mux_init.c:693
parse_meta_type
static void parse_meta_type(void *logctx, const char *arg, char *type, int *index, const char **stream_spec)
Parse a metadata specifier passed as 'arg' parameter.
Definition: ffmpeg_mux_init.c:1611
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42
sq_alloc
SyncQueue * sq_alloc(enum SyncQueueType type, int64_t buf_size_us)
Allocate a sync queue of the given type.
Definition: sync_queue.c:405
opt_name_presets
static const char *const opt_name_presets[]
Definition: ffmpeg_mux_init.c:78
copy_chapters
static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *os, int copy_metadata)
Definition: ffmpeg_mux_init.c:1750
MuxStream::last_mux_dts
int64_t last_mux_dts
Definition: ffmpeg_mux.h:63
opt_name_max_frame_rates
static const char *const opt_name_max_frame_rates[]
Definition: ffmpeg_mux_init.c:72
ENC_STATS_TIMEBASE
@ ENC_STATS_TIMEBASE
Definition: ffmpeg.h:501
new_data_stream
static OutputStream * new_data_stream(Muxer *mux, const OptionsContext *o, InputStream *ist)
Definition: ffmpeg_mux_init.c:1031
OutputStream::class
const AVClass * class
Definition: ffmpeg.h:559
opt_name_copy_prior_start
static const char *const opt_name_copy_prior_start[]
Definition: ffmpeg_mux_init.c:55
opt_name_force_fps
static const char *const opt_name_force_fps[]
Definition: ffmpeg_mux_init.c:66
OutputFile
Definition: ffmpeg.h:688
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:289