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