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