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/display.h"
41 #include "libavutil/getenv_utf8.h"
42 #include "libavutil/intreadwrite.h"
43 #include "libavutil/log.h"
44 #include "libavutil/mem.h"
45 #include "libavutil/opt.h"
46 #include "libavutil/parseutils.h"
47 #include "libavutil/pixdesc.h"
48 
49 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
50 
51 static const char *const opt_name_apad[] = {"apad", NULL};
52 static const char *const opt_name_autoscale[] = {"autoscale", NULL};
53 static const char *const opt_name_bits_per_raw_sample[] = {"bits_per_raw_sample", NULL};
54 static const char *const opt_name_bitstream_filters[] = {"bsf", "absf", "vbsf", NULL};
55 static const char *const opt_name_copy_initial_nonkeyframes[] = {"copyinkf", NULL};
56 static const char *const opt_name_copy_prior_start[] = {"copypriorss", NULL};
57 static const char *const opt_name_disposition[] = {"disposition", NULL};
58 static const char *const opt_name_enc_time_bases[] = {"enc_time_base", NULL};
59 static const char *const opt_name_enc_stats_pre[] = {"enc_stats_pre", NULL};
60 static const char *const opt_name_enc_stats_post[] = {"enc_stats_post", NULL};
61 static const char *const opt_name_mux_stats[] = {"mux_stats", NULL};
62 static const char *const opt_name_enc_stats_pre_fmt[] = {"enc_stats_pre_fmt", NULL};
63 static const char *const opt_name_enc_stats_post_fmt[] = {"enc_stats_post_fmt", NULL};
64 static const char *const opt_name_mux_stats_fmt[] = {"mux_stats_fmt", NULL};
65 static const char *const opt_name_filters[] = {"filter", "af", "vf", NULL};
66 static const char *const opt_name_filter_scripts[] = {"filter_script", NULL};
67 static const char *const opt_name_fix_sub_duration_heartbeat[] = {"fix_sub_duration_heartbeat", NULL};
68 static const char *const opt_name_fps_mode[] = {"fps_mode", NULL};
69 static const char *const opt_name_force_fps[] = {"force_fps", NULL};
70 static const char *const opt_name_forced_key_frames[] = {"forced_key_frames", NULL};
71 static const char *const opt_name_frame_aspect_ratios[] = {"aspect", NULL};
72 static const char *const opt_name_intra_matrices[] = {"intra_matrix", NULL};
73 static const char *const opt_name_inter_matrices[] = {"inter_matrix", NULL};
74 static const char *const opt_name_chroma_intra_matrices[] = {"chroma_intra_matrix", NULL};
75 static const char *const opt_name_max_frame_rates[] = {"fpsmax", NULL};
76 static const char *const opt_name_max_frames[] = {"frames", "aframes", "vframes", "dframes", NULL};
77 static const char *const opt_name_max_muxing_queue_size[] = {"max_muxing_queue_size", NULL};
78 static const char *const opt_name_muxing_queue_data_threshold[] = {"muxing_queue_data_threshold", NULL};
79 static const char *const opt_name_pass[] = {"pass", NULL};
80 static const char *const opt_name_passlogfiles[] = {"passlogfile", NULL};
81 static const char *const opt_name_presets[] = {"pre", "apre", "vpre", "spre", NULL};
82 static const char *const opt_name_qscale[] = {"q", "qscale", NULL};
83 static const char *const opt_name_rc_overrides[] = {"rc_override", NULL};
84 static const char *const opt_name_time_bases[] = {"time_base", NULL};
85 static const char *const opt_name_audio_channels[] = {"ac", NULL};
86 static const char *const opt_name_audio_ch_layouts[] = {"channel_layout", "ch_layout", NULL};
87 static const char *const opt_name_audio_sample_rate[] = {"ar", NULL};
88 static const char *const opt_name_frame_sizes[] = {"s", NULL};
89 static const char *const opt_name_frame_pix_fmts[] = {"pix_fmt", NULL};
90 static const char *const opt_name_sample_fmts[] = {"sample_fmt", NULL};
91 
92 static int check_opt_bitexact(void *ctx, const AVDictionary *opts,
93  const char *opt_name, int flag)
94 {
95  const AVDictionaryEntry *e = av_dict_get(opts, opt_name, NULL, 0);
96 
97  if (e) {
98  const AVOption *o = av_opt_find(ctx, opt_name, NULL, 0, 0);
99  int val = 0;
100  if (!o)
101  return 0;
102  av_opt_eval_flags(ctx, o, e->value, &val);
103  return !!(val & flag);
104  }
105  return 0;
106 }
107 
109  OutputStream *ost, const AVCodec **enc)
110 {
111  enum AVMediaType type = ost->type;
112  char *codec_name = NULL;
113 
114  *enc = NULL;
115 
116  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
117 
118  if (type != AVMEDIA_TYPE_VIDEO &&
121  if (codec_name && strcmp(codec_name, "copy")) {
122  const char *type_str = av_get_media_type_string(type);
124  "Encoder '%s' specified, but only '-codec copy' supported "
125  "for %s streams\n", codec_name, type_str);
126  return AVERROR(ENOSYS);
127  }
128  return 0;
129  }
130 
131  if (!codec_name) {
132  ost->par_in->codec_id = av_guess_codec(s->oformat, NULL, s->url, NULL, ost->type);
133  *enc = avcodec_find_encoder(ost->par_in->codec_id);
134  if (!*enc) {
135  av_log(ost, AV_LOG_FATAL, "Automatic encoder selection failed "
136  "Default encoder for format %s (codec %s) is "
137  "probably disabled. Please choose an encoder manually.\n",
138  s->oformat->name, avcodec_get_name(ost->par_in->codec_id));
140  }
141  } else if (strcmp(codec_name, "copy")) {
142  int ret = find_codec(ost, codec_name, ost->type, 1, enc);
143  if (ret < 0)
144  return ret;
145  ost->par_in->codec_id = (*enc)->id;
146  }
147 
148  return 0;
149 }
150 
151 static char *get_line(AVIOContext *s, AVBPrint *bprint)
152 {
153  char c;
154 
155  while ((c = avio_r8(s)) && c != '\n')
156  av_bprint_chars(bprint, c, 1);
157 
158  if (!av_bprint_is_complete(bprint))
159  return NULL;
160 
161  return bprint->str;
162 }
163 
164 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
165 {
166  int i, ret = -1;
167  char filename[1000];
168  char *env_avconv_datadir = getenv_utf8("AVCONV_DATADIR");
169  char *env_home = getenv_utf8("HOME");
170  const char *base[3] = { env_avconv_datadir,
171  env_home,
172  AVCONV_DATADIR,
173  };
174 
175  for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
176  if (!base[i])
177  continue;
178  if (codec_name) {
179  snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
180  i != 1 ? "" : "/.avconv", codec_name, preset_name);
181  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
182  }
183  if (ret < 0) {
184  snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
185  i != 1 ? "" : "/.avconv", preset_name);
186  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
187  }
188  }
189  freeenv_utf8(env_home);
190  freeenv_utf8(env_avconv_datadir);
191  return ret;
192 }
193 
194 typedef struct EncStatsFile {
195  char *path;
197 } EncStatsFile;
198 
201 
202 static int enc_stats_get_file(AVIOContext **io, const char *path)
203 {
204  EncStatsFile *esf;
205  int ret;
206 
207  for (int i = 0; i < nb_enc_stats_files; i++)
208  if (!strcmp(path, enc_stats_files[i].path)) {
209  *io = enc_stats_files[i].io;
210  return 0;
211  }
212 
214  if (ret < 0)
215  return ret;
216 
218 
219  ret = avio_open2(&esf->io, path, AVIO_FLAG_WRITE, &int_cb, NULL);
220  if (ret < 0) {
221  av_log(NULL, AV_LOG_ERROR, "Error opening stats file '%s': %s\n",
222  path, av_err2str(ret));
223  return ret;
224  }
225 
226  esf->path = av_strdup(path);
227  if (!esf->path)
228  return AVERROR(ENOMEM);
229 
230  *io = esf->io;
231 
232  return 0;
233 }
234 
236 {
237  for (int i = 0; i < nb_enc_stats_files; i++) {
238  av_freep(&enc_stats_files[i].path);
240  }
242  nb_enc_stats_files = 0;
243 }
244 
245 static int unescape(char **pdst, size_t *dst_len,
246  const char **pstr, char delim)
247 {
248  const char *str = *pstr;
249  char *dst;
250  size_t len, idx;
251 
252  *pdst = NULL;
253 
254  len = strlen(str);
255  if (!len)
256  return 0;
257 
258  dst = av_malloc(len + 1);
259  if (!dst)
260  return AVERROR(ENOMEM);
261 
262  for (idx = 0; *str; idx++, str++) {
263  if (str[0] == '\\' && str[1])
264  str++;
265  else if (*str == delim)
266  break;
267 
268  dst[idx] = *str;
269  }
270  if (!idx) {
271  av_freep(&dst);
272  return 0;
273  }
274 
275  dst[idx] = 0;
276 
277  *pdst = dst;
278  *dst_len = idx;
279  *pstr = str;
280 
281  return 0;
282 }
283 
284 static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
285  const char *path, const char *fmt_spec)
286 {
287  static const struct {
288  enum EncStatsType type;
289  const char *str;
290  int pre_only:1;
291  int post_only:1;
292  int need_input_data:1;
293  } fmt_specs[] = {
294  { ENC_STATS_FILE_IDX, "fidx" },
295  { ENC_STATS_STREAM_IDX, "sidx" },
296  { ENC_STATS_FRAME_NUM, "n" },
297  { ENC_STATS_FRAME_NUM_IN, "ni", 0, 0, 1 },
298  { ENC_STATS_TIMEBASE, "tb" },
299  { ENC_STATS_TIMEBASE_IN, "tbi", 0, 0, 1 },
300  { ENC_STATS_PTS, "pts" },
301  { ENC_STATS_PTS_TIME, "t" },
302  { ENC_STATS_PTS_IN, "ptsi", 0, 0, 1 },
303  { ENC_STATS_PTS_TIME_IN, "ti", 0, 0, 1 },
304  { ENC_STATS_DTS, "dts", 0, 1 },
305  { ENC_STATS_DTS_TIME, "dt", 0, 1 },
306  { ENC_STATS_SAMPLE_NUM, "sn", 1 },
307  { ENC_STATS_NB_SAMPLES, "samp", 1 },
308  { ENC_STATS_PKT_SIZE, "size", 0, 1 },
309  { ENC_STATS_BITRATE, "br", 0, 1 },
310  { ENC_STATS_AVG_BITRATE, "abr", 0, 1 },
311  };
312  const char *next = fmt_spec;
313 
314  int ret;
315 
316  while (*next) {
318  char *val;
319  size_t val_len;
320 
321  // get the sequence up until next opening brace
322  ret = unescape(&val, &val_len, &next, '{');
323  if (ret < 0)
324  return ret;
325 
326  if (val) {
328  if (ret < 0) {
329  av_freep(&val);
330  return ret;
331  }
332 
333  c = &es->components[es->nb_components - 1];
334  c->type = ENC_STATS_LITERAL;
335  c->str = val;
336  c->str_len = val_len;
337  }
338 
339  if (!*next)
340  break;
341  next++;
342 
343  // get the part inside braces
344  ret = unescape(&val, &val_len, &next, '}');
345  if (ret < 0)
346  return ret;
347 
348  if (!val) {
350  "Empty formatting directive in: %s\n", fmt_spec);
351  return AVERROR(EINVAL);
352  }
353 
354  if (!*next) {
356  "Missing closing brace in: %s\n", fmt_spec);
357  ret = AVERROR(EINVAL);
358  goto fail;
359  }
360  next++;
361 
363  if (ret < 0)
364  goto fail;
365 
366  c = &es->components[es->nb_components - 1];
367 
368  for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) {
369  if (!strcmp(val, fmt_specs[i].str)) {
370  if ((pre && fmt_specs[i].post_only) || (!pre && fmt_specs[i].pre_only)) {
372  "Format directive '%s' may only be used %s-encoding\n",
373  val, pre ? "post" : "pre");
374  ret = AVERROR(EINVAL);
375  goto fail;
376  }
377 
378  c->type = fmt_specs[i].type;
379 
380  if (fmt_specs[i].need_input_data && !ost->ist) {
382  "Format directive '%s' is unavailable, because "
383  "this output stream has no associated input stream\n",
384  val);
385  }
386 
387  break;
388  }
389  }
390 
391  if (!c->type) {
392  av_log(NULL, AV_LOG_ERROR, "Invalid format directive: %s\n", val);
393  ret = AVERROR(EINVAL);
394  goto fail;
395  }
396 
397 fail:
398  av_freep(&val);
399  if (ret < 0)
400  return ret;
401  }
402 
403  ret = enc_stats_get_file(&es->io, path);
404  if (ret < 0)
405  return ret;
406 
407  return 0;
408 }
409 
410 static const char *output_stream_item_name(void *obj)
411 {
412  const MuxStream *ms = obj;
413 
414  return ms->log_name;
415 }
416 
417 static const AVClass output_stream_class = {
418  .class_name = "OutputStream",
419  .version = LIBAVUTIL_VERSION_INT,
420  .item_name = output_stream_item_name,
421  .category = AV_CLASS_CATEGORY_MUXER,
422 };
423 
425 {
426  const char *type_str = av_get_media_type_string(type);
427  MuxStream *ms;
428 
429  ms = allocate_array_elem(&mux->of.streams, sizeof(*ms), &mux->of.nb_streams);
430  if (!ms)
431  return NULL;
432 
433  ms->ost.file_index = mux->of.index;
434  ms->ost.index = mux->of.nb_streams - 1;
435  ms->ost.type = type;
436 
438 
439  snprintf(ms->log_name, sizeof(ms->log_name), "%cost#%d:%d",
440  type_str ? *type_str : '?', mux->of.index, ms->ost.index);
441 
442  return ms;
443 }
444 
446  OutputStream *ost, char **dst)
447 {
448  const char *filters = NULL, *filters_script = NULL;
449 
450  MATCH_PER_STREAM_OPT(filter_scripts, str, filters_script, oc, ost->st);
451  MATCH_PER_STREAM_OPT(filters, str, filters, oc, ost->st);
452 
453  if (!ost->enc) {
454  if (filters_script || filters) {
456  "%s '%s' was specified, but codec copy was selected. "
457  "Filtering and streamcopy cannot be used together.\n",
458  filters ? "Filtergraph" : "Filtergraph script",
459  filters ? filters : filters_script);
460  return AVERROR(ENOSYS);
461  }
462  return 0;
463  }
464 
465  if (!ost->ist) {
466  if (filters_script || filters) {
468  "%s '%s' was specified for a stream fed from a complex "
469  "filtergraph. Simple and complex filtering cannot be used "
470  "together for the same stream.\n",
471  filters ? "Filtergraph" : "Filtergraph script",
472  filters ? filters : filters_script);
473  return AVERROR(EINVAL);
474  }
475  return 0;
476  }
477 
478  if (filters_script && filters) {
479  av_log(ost, AV_LOG_ERROR, "Both -filter and -filter_script set\n");
480  return AVERROR(EINVAL);
481  }
482 
483  if (filters_script)
484  *dst = file_read(filters_script);
485  else if (filters)
486  *dst = av_strdup(filters);
487  else
488  *dst = av_strdup(ost->type == AVMEDIA_TYPE_VIDEO ? "null" : "anull");
489  return *dst ? 0 : AVERROR(ENOMEM);
490 }
491 
492 static int parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str)
493 {
494  int i;
495  const char *p = str;
496  for (i = 0;; i++) {
497  dest[i] = atoi(p);
498  if (i == 63)
499  break;
500  p = strchr(p, ',');
501  if (!p) {
502  av_log(logctx, AV_LOG_FATAL,
503  "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
504  return AVERROR(EINVAL);
505  }
506  p++;
507  }
508 
509  return 0;
510 }
511 
512 static int fmt_in_list(const int *formats, int format)
513 {
514  for (; *formats != -1; formats++)
515  if (*formats == format)
516  return 1;
517  return 0;
518 }
519 
520 static enum AVPixelFormat
521 choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
522 {
523  const enum AVPixelFormat *p = codec->pix_fmts;
525  //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
526  int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
527  enum AVPixelFormat best= AV_PIX_FMT_NONE;
528 
529  for (; *p != AV_PIX_FMT_NONE; p++) {
530  best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
531  if (*p == target)
532  break;
533  }
534  if (*p == AV_PIX_FMT_NONE) {
535  if (target != AV_PIX_FMT_NONE)
537  "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
538  av_get_pix_fmt_name(target),
539  codec->name,
540  av_get_pix_fmt_name(best));
541  return best;
542  }
543  return target;
544 }
545 
546 static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
547 {
548  const enum AVPixelFormat *fmts = ost->enc_ctx->codec->pix_fmts;
549  enum AVPixelFormat fmt;
550 
551  fmt = av_get_pix_fmt(name);
552  if (fmt == AV_PIX_FMT_NONE) {
553  av_log(ost, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", name);
554  return AV_PIX_FMT_NONE;
555  }
556 
557  /* when the user specified-format is an alias for an endianness-specific
558  * one (e.g. rgb48 -> rgb48be/le), it gets translated into the native
559  * endianness by av_get_pix_fmt();
560  * the following code handles the case when the native endianness is not
561  * supported by the encoder, but the other one is */
562  if (fmts && !fmt_in_list(fmts, fmt)) {
563  const char *name_canonical = av_get_pix_fmt_name(fmt);
564  int len = strlen(name_canonical);
565 
566  if (strcmp(name, name_canonical) &&
567  (!strcmp(name_canonical + len - 2, "le") ||
568  !strcmp(name_canonical + len - 2, "be"))) {
569  char name_other[64];
570  enum AVPixelFormat fmt_other;
571 
572  snprintf(name_other, sizeof(name_other), "%s%ce",
573  name, name_canonical[len - 2] == 'l' ? 'b' : 'l');
574  fmt_other = av_get_pix_fmt(name_other);
575  if (fmt_other != AV_PIX_FMT_NONE && fmt_in_list(fmts, fmt_other)) {
576  av_log(ost, AV_LOG_VERBOSE, "Mapping pixel format %s->%s\n",
577  name, name_other);
578  fmt = fmt_other;
579  }
580  }
581  }
582 
583  if (fmts && !fmt_in_list(fmts, fmt))
584  fmt = choose_pixel_fmt(ost->enc_ctx->codec, fmt);
585 
586  return fmt;
587 }
588 
589 static int new_stream_video(Muxer *mux, const OptionsContext *o,
590  OutputStream *ost)
591 {
592  AVFormatContext *oc = mux->fc;
593  AVStream *st;
594  char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL;
595  int ret = 0;
596 
597  st = ost->st;
598 
599  MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
600  if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
601  av_log(ost, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
602  return AVERROR(EINVAL);
603  }
604 
605  MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
606  if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
607  av_log(ost, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
608  return AVERROR(EINVAL);
609  }
610 
611  if (frame_rate && max_frame_rate) {
612  av_log(ost, AV_LOG_ERROR, "Only one of -fpsmax and -r can be set for a stream.\n");
613  return AVERROR(EINVAL);
614  }
615 
616  MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
617  if (frame_aspect_ratio) {
618  AVRational q;
619  if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
620  q.num <= 0 || q.den <= 0) {
621  av_log(ost, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
622  return AVERROR(EINVAL);
623  }
624  ost->frame_aspect_ratio = q;
625  }
626 
627  if (ost->enc_ctx) {
628  AVCodecContext *video_enc = ost->enc_ctx;
629  const char *p = NULL, *fps_mode = NULL;
630  char *frame_size = NULL;
631  char *frame_pix_fmt = NULL;
632  char *intra_matrix = NULL, *inter_matrix = NULL;
633  char *chroma_intra_matrix = NULL;
634  int do_pass = 0;
635  int i;
636 
638  if (frame_size) {
639  ret = av_parse_video_size(&video_enc->width, &video_enc->height, frame_size);
640  if (ret < 0) {
641  av_log(ost, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
642  return AVERROR(EINVAL);
643  }
644  }
645 
646  MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
647  if (frame_pix_fmt && *frame_pix_fmt == '+') {
648  ost->keep_pix_fmt = 1;
649  if (!*++frame_pix_fmt)
650  frame_pix_fmt = NULL;
651  }
652  if (frame_pix_fmt) {
653  video_enc->pix_fmt = pix_fmt_parse(ost, frame_pix_fmt);
654  if (video_enc->pix_fmt == AV_PIX_FMT_NONE)
655  return AVERROR(EINVAL);
656  }
657 
658  MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
659  if (intra_matrix) {
660  if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64)))
661  return AVERROR(ENOMEM);
662 
663  ret = parse_matrix_coeffs(ost, video_enc->intra_matrix, intra_matrix);
664  if (ret < 0)
665  return ret;
666  }
667  MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
668  if (chroma_intra_matrix) {
669  uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
670  if (!p)
671  return AVERROR(ENOMEM);
672  video_enc->chroma_intra_matrix = p;
673  ret = parse_matrix_coeffs(ost, p, chroma_intra_matrix);
674  if (ret < 0)
675  return ret;
676  }
677  MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
678  if (inter_matrix) {
679  if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64)))
680  return AVERROR(ENOMEM);
681  ret = parse_matrix_coeffs(ost, video_enc->inter_matrix, inter_matrix);
682  if (ret < 0)
683  return ret;
684  }
685 
686  MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
687  for (i = 0; p; i++) {
688  int start, end, q;
689  int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
690  if (e != 3) {
691  av_log(ost, AV_LOG_FATAL, "error parsing rc_override\n");
692  return AVERROR(EINVAL);
693  }
694  video_enc->rc_override =
695  av_realloc_array(video_enc->rc_override,
696  i + 1, sizeof(RcOverride));
697  if (!video_enc->rc_override) {
698  av_log(ost, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
699  return AVERROR(ENOMEM);
700  }
701  video_enc->rc_override[i].start_frame = start;
702  video_enc->rc_override[i].end_frame = end;
703  if (q > 0) {
704  video_enc->rc_override[i].qscale = q;
705  video_enc->rc_override[i].quality_factor = 1.0;
706  }
707  else {
708  video_enc->rc_override[i].qscale = 0;
709  video_enc->rc_override[i].quality_factor = -q/100.0;
710  }
711  p = strchr(p, '/');
712  if (p) p++;
713  }
714  video_enc->rc_override_count = i;
715 
716 #if FFMPEG_OPT_PSNR
717  if (do_psnr) {
718  av_log(ost, AV_LOG_WARNING, "The -psnr option is deprecated, use -flags +psnr\n");
719  video_enc->flags|= AV_CODEC_FLAG_PSNR;
720  }
721 #endif
722 
723  /* two pass mode */
724  MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
725  if (do_pass) {
726  if (do_pass & 1) {
727  video_enc->flags |= AV_CODEC_FLAG_PASS1;
728  av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
729  }
730  if (do_pass & 2) {
731  video_enc->flags |= AV_CODEC_FLAG_PASS2;
732  av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
733  }
734  }
735 
736  MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
737  if (ost->logfile_prefix &&
738  !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
739  return AVERROR(ENOMEM);
740 
741  if (do_pass) {
742  int ost_idx = -1;
743  char logfilename[1024];
744  FILE *f;
745 
746  /* compute this stream's global index */
747  for (int i = 0; i <= ost->file_index; i++)
748  ost_idx += output_files[i]->nb_streams;
749 
750  snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
751  ost->logfile_prefix ? ost->logfile_prefix :
753  ost_idx);
754  if (!strcmp(ost->enc_ctx->codec->name, "libx264")) {
755  av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
756  } else {
757  if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
758  char *logbuffer = file_read(logfilename);
759 
760  if (!logbuffer) {
761  av_log(ost, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
762  logfilename);
763  return AVERROR(EIO);
764  }
765  video_enc->stats_in = logbuffer;
766  }
767  if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
768  f = fopen_utf8(logfilename, "wb");
769  if (!f) {
771  "Cannot write log file '%s' for pass-1 encoding: %s\n",
772  logfilename, strerror(errno));
773  return AVERROR(errno);
774  }
775  ost->logfile = f;
776  }
777  }
778  }
779 
780  MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
781 
782 #if FFMPEG_OPT_TOP
783  ost->top_field_first = -1;
784  MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
785  if (ost->top_field_first >= 0)
786  av_log(ost, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
787 #endif
788 
789  ost->vsync_method = video_sync_method;
790  MATCH_PER_STREAM_OPT(fps_mode, str, fps_mode, oc, st);
791  if (fps_mode) {
792  ret = parse_and_set_vsync(fps_mode, &ost->vsync_method, ost->file_index, ost->index, 0);
793  if (ret < 0)
794  return ret;
795  }
796 
797  if ((ost->frame_rate.num || ost->max_frame_rate.num) &&
798  !(ost->vsync_method == VSYNC_AUTO ||
799  ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR)) {
800  av_log(ost, AV_LOG_FATAL, "One of -r/-fpsmax was specified "
801  "together a non-CFR -vsync/-fps_mode. This is contradictory.\n");
802  return AVERROR(EINVAL);
803  }
804 
805  if (ost->vsync_method == VSYNC_AUTO) {
806  if (ost->frame_rate.num || ost->max_frame_rate.num) {
807  ost->vsync_method = VSYNC_CFR;
808  } else if (!strcmp(oc->oformat->name, "avi")) {
809  ost->vsync_method = VSYNC_VFR;
810  } else {
811  ost->vsync_method = (oc->oformat->flags & AVFMT_VARIABLE_FPS) ?
812  ((oc->oformat->flags & AVFMT_NOTIMESTAMPS) ?
814  VSYNC_CFR;
815  }
816 
817  if (ost->ist && ost->vsync_method == VSYNC_CFR) {
818  const InputFile *ifile = input_files[ost->ist->file_index];
819 
820  if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0)
821  ost->vsync_method = VSYNC_VSCFR;
822  }
823 
824  if (ost->vsync_method == VSYNC_CFR && copy_ts) {
825  ost->vsync_method = VSYNC_VSCFR;
826  }
827  }
828  ost->is_cfr = (ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR);
829  }
830 
831  return 0;
832 }
833 
834 static int new_stream_audio(Muxer *mux, const OptionsContext *o,
835  OutputStream *ost)
836 {
837  AVFormatContext *oc = mux->fc;
838  AVStream *st;
839  int ret = 0;
840 
841  st = ost->st;
842 
843  if (ost->enc_ctx) {
844  AVCodecContext *audio_enc = ost->enc_ctx;
845  int channels = 0;
846  char *layout = NULL;
847  char *sample_fmt = NULL;
848 
850  if (channels) {
852  audio_enc->ch_layout.nb_channels = channels;
853  }
854 
855  MATCH_PER_STREAM_OPT(audio_ch_layouts, str, layout, oc, st);
856  if (layout) {
857  if (av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) {
858 #if FF_API_OLD_CHANNEL_LAYOUT
859  uint64_t mask;
862  })
863  if (!mask) {
864 #endif
865  av_log(ost, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout);
866  return AVERROR(EINVAL);
867 #if FF_API_OLD_CHANNEL_LAYOUT
868  }
869  av_log(ost, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
870  layout);
872 #endif
873  }
874  }
875 
876  MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
877  if (sample_fmt &&
878  (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
879  av_log(ost, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
880  return AVERROR(EINVAL);
881  }
882 
883  MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
884 
885  MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
886  ost->apad = av_strdup(ost->apad);
887 
888 #if FFMPEG_OPT_MAP_CHANNEL
889  /* check for channel mapping for this audio stream */
890  for (int n = 0; n < o->nb_audio_channel_maps; n++) {
892  if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
893  (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
894  InputStream *ist;
895 
896  if (map->channel_idx == -1) {
897  ist = NULL;
898  } else if (!ost->ist) {
899  av_log(ost, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
900  ost->file_index, ost->st->index);
901  continue;
902  } else {
903  ist = ost->ist;
904  }
905 
906  if (!ist || (ist->file_index == map->file_idx && ist->index == map->stream_idx)) {
907  ret = av_reallocp_array(&ost->audio_channels_map,
908  ost->audio_channels_mapped + 1,
909  sizeof(*ost->audio_channels_map));
910  if (ret < 0)
911  return ret;
912 
913  ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
914  }
915  }
916  }
917 #endif
918  }
919 
920  return 0;
921 }
922 
923 static int new_stream_attachment(Muxer *mux, const OptionsContext *o,
924  OutputStream *ost)
925 {
926  ost->finished = 1;
927  return 0;
928 }
929 
930 static int new_stream_subtitle(Muxer *mux, const OptionsContext *o,
931  OutputStream *ost)
932 {
933  AVStream *st;
934 
935  st = ost->st;
936 
937  if (ost->enc_ctx) {
938  AVCodecContext *subtitle_enc = ost->enc_ctx;
939 
940  AVCodecDescriptor const *input_descriptor =
941  avcodec_descriptor_get(ost->ist->par->codec_id);
942  AVCodecDescriptor const *output_descriptor =
943  avcodec_descriptor_get(subtitle_enc->codec_id);
944  int input_props = 0, output_props = 0;
945 
946  char *frame_size = NULL;
947 
949  if (frame_size) {
950  int ret = av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size);
951  if (ret < 0) {
952  av_log(ost, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
953  return ret;
954  }
955  }
956  if (input_descriptor)
957  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
958  if (output_descriptor)
959  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
960  if (input_props && output_props && input_props != output_props) {
962  "Subtitle encoding currently only possible from text to text "
963  "or bitmap to bitmap\n");
964  return AVERROR(EINVAL);
965  }
966  }
967 
968  return 0;
969 }
970 
971 static int streamcopy_init(const Muxer *mux, OutputStream *ost)
972 {
973  MuxStream *ms = ms_from_ost(ost);
974 
975  const InputStream *ist = ost->ist;
976  const InputFile *ifile = input_files[ist->file_index];
977 
978  AVCodecParameters *par = ost->par_in;
979  uint32_t codec_tag = par->codec_tag;
980 
981  AVCodecContext *codec_ctx = NULL;
983 
984  AVRational fr = ost->frame_rate;
985 
986  int ret = 0;
987 
988  codec_ctx = avcodec_alloc_context3(NULL);
989  if (!codec_ctx)
990  return AVERROR(ENOMEM);
991 
992  ret = avcodec_parameters_to_context(codec_ctx, ist->par);
993  if (ret >= 0)
994  ret = av_opt_set_dict(codec_ctx, &ost->encoder_opts);
995  if (ret < 0) {
997  "Error setting up codec context options.\n");
998  goto fail;
999  }
1000 
1001  ret = avcodec_parameters_from_context(par, codec_ctx);
1002  if (ret < 0) {
1004  "Error getting reference codec parameters.\n");
1005  goto fail;
1006  }
1007 
1008  if (!codec_tag) {
1009  const struct AVCodecTag * const *ct = mux->fc->oformat->codec_tag;
1010  unsigned int codec_tag_tmp;
1011  if (!ct || av_codec_get_id (ct, par->codec_tag) == par->codec_id ||
1012  !av_codec_get_tag2(ct, par->codec_id, &codec_tag_tmp))
1013  codec_tag = par->codec_tag;
1014  }
1015 
1016  par->codec_tag = codec_tag;
1017 
1018  if (!fr.num)
1019  fr = ist->framerate;
1020 
1021  if (fr.num)
1022  ost->st->avg_frame_rate = fr;
1023  else
1024  ost->st->avg_frame_rate = ist->st->avg_frame_rate;
1025 
1027  ost->st, ist->st, copy_tb);
1028  if (ret < 0)
1029  goto fail;
1030 
1031  // copy timebase while removing common factors
1032  if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) {
1033  if (fr.num)
1034  ost->st->time_base = av_inv_q(fr);
1035  else
1037  }
1038 
1039  if (!ms->copy_prior_start) {
1040  ms->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ?
1041  0 : mux->of.start_time;
1042  if (copy_ts && ifile->start_time != AV_NOPTS_VALUE) {
1043  ms->ts_copy_start = FFMAX(ms->ts_copy_start,
1044  ifile->start_time + ifile->ts_offset);
1045  }
1046  }
1047 
1048  for (int i = 0; i < ist->st->nb_side_data; i++) {
1049  const AVPacketSideData *sd_src = &ist->st->side_data[i];
1050  uint8_t *dst_data;
1051 
1052  dst_data = av_stream_new_side_data(ost->st, sd_src->type, sd_src->size);
1053  if (!dst_data) {
1054  ret = AVERROR(ENOMEM);
1055  goto fail;
1056  }
1057  memcpy(dst_data, sd_src->data, sd_src->size);
1058  }
1059 
1060 #if FFMPEG_ROTATION_METADATA
1061  if (ost->rotate_overridden) {
1063  sizeof(int32_t) * 9);
1064  if (sd)
1065  av_display_rotation_set((int32_t *)sd, -ost->rotate_override_value);
1066  }
1067 #endif
1068 
1069  switch (par->codec_type) {
1070  case AVMEDIA_TYPE_AUDIO:
1071  if ((par->block_align == 1 || par->block_align == 1152 || par->block_align == 576) &&
1072  par->codec_id == AV_CODEC_ID_MP3)
1073  par->block_align = 0;
1074  if (par->codec_id == AV_CODEC_ID_AC3)
1075  par->block_align = 0;
1076  break;
1077  case AVMEDIA_TYPE_VIDEO: {
1078  AVRational sar;
1079  if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option
1080  sar =
1081  av_mul_q(ost->frame_aspect_ratio,
1082  (AVRational){ par->height, par->width });
1083  av_log(ost, AV_LOG_WARNING, "Overriding aspect ratio "
1084  "with stream copy may produce invalid files\n");
1085  }
1086  else if (ist->st->sample_aspect_ratio.num)
1087  sar = ist->st->sample_aspect_ratio;
1088  else
1089  sar = par->sample_aspect_ratio;
1090  ost->st->sample_aspect_ratio = par->sample_aspect_ratio = sar;
1091  ost->st->avg_frame_rate = ist->st->avg_frame_rate;
1092  ost->st->r_frame_rate = ist->st->r_frame_rate;
1093  break;
1094  }
1095  }
1096 
1097 fail:
1098  avcodec_free_context(&codec_ctx);
1100  return ret;
1101 }
1102 
1103 static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
1104  InputStream *ist, OutputFilter *ofilter,
1105  OutputStream **post)
1106 {
1107  AVFormatContext *oc = mux->fc;
1108  MuxStream *ms;
1109  OutputStream *ost;
1110  const AVCodec *enc;
1111  AVStream *st;
1112  int ret = 0;
1113  const char *bsfs = NULL, *time_base = NULL;
1114  char *filters = NULL, *next, *codec_tag = NULL;
1115  double qscale = -1;
1116  int i;
1117 
1118  st = avformat_new_stream(oc, NULL);
1119  if (!st)
1120  return AVERROR(ENOMEM);
1121 
1122  ms = mux_stream_alloc(mux, type);
1123  if (!ms)
1124  return AVERROR(ENOMEM);
1125 
1126  ost = &ms->ost;
1127 
1128  if (o->streamid) {
1129  AVDictionaryEntry *e;
1130  char idx[16], *p;
1131  snprintf(idx, sizeof(idx), "%d", ost->index);
1132 
1133  e = av_dict_get(o->streamid, idx, NULL, 0);
1134  if (e) {
1135  st->id = strtol(e->value, &p, 0);
1136  if (!e->value[0] || *p) {
1137  av_log(ost, AV_LOG_FATAL, "Invalid stream id: %s\n", e->value);
1138  return AVERROR(EINVAL);
1139  }
1140  }
1141  }
1142 
1143  ost->par_in = avcodec_parameters_alloc();
1144  if (!ost->par_in)
1145  return AVERROR(ENOMEM);
1146 
1147  ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
1148  if (!ms->muxing_queue)
1149  return AVERROR(ENOMEM);
1151 
1152  ost->st = st;
1153  ost->ist = ist;
1154  ost->kf.ref_pts = AV_NOPTS_VALUE;
1155  ost->par_in->codec_type = type;
1156  st->codecpar->codec_type = type;
1157 
1158  ret = choose_encoder(o, oc, ost, &enc);
1159  if (ret < 0) {
1160  av_log(ost, AV_LOG_FATAL, "Error selecting an encoder\n");
1161  return ret;
1162  }
1163 
1164  if (enc) {
1165  ost->enc_ctx = avcodec_alloc_context3(enc);
1166  if (!ost->enc_ctx)
1167  return AVERROR(ENOMEM);
1168 
1169  ret = enc_alloc(&ost->enc, enc);
1170  if (ret < 0)
1171  return ret;
1172 
1173  av_strlcat(ms->log_name, "/", sizeof(ms->log_name));
1174  av_strlcat(ms->log_name, enc->name, sizeof(ms->log_name));
1175  } else {
1176  if (ofilter) {
1178  "Streamcopy requested for output stream fed "
1179  "from a complex filtergraph. Filtering and streamcopy "
1180  "cannot be used together.\n");
1181  return AVERROR(EINVAL);
1182  }
1183 
1184  av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name));
1185  }
1186 
1187  av_log(ost, AV_LOG_VERBOSE, "Created %s stream from ",
1189  if (ist)
1190  av_log(ost, AV_LOG_VERBOSE, "input stream %d:%d",
1191  ist->file_index, ist->index);
1192  else if (ofilter)
1193  av_log(ost, AV_LOG_VERBOSE, "complex filtergraph %d:[%s]\n",
1194  ofilter->graph->index, ofilter->name);
1195  else if (type == AVMEDIA_TYPE_ATTACHMENT)
1196  av_log(ost, AV_LOG_VERBOSE, "attached file");
1197  else av_assert0(0);
1198  av_log(ost, AV_LOG_VERBOSE, "\n");
1199 
1200  ms->pkt = av_packet_alloc();
1201  if (!ms->pkt)
1202  return AVERROR(ENOMEM);
1203 
1204  if (ost->enc_ctx) {
1205  AVCodecContext *enc = ost->enc_ctx;
1206  AVIOContext *s = NULL;
1207  char *buf = NULL, *arg = NULL, *preset = NULL;
1208  const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL;
1209  const char *enc_time_base = NULL;
1210 
1212  oc, st, enc->codec, &ost->encoder_opts);
1213  if (ret < 0)
1214  return ret;
1215 
1216  MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
1217  ost->autoscale = 1;
1218  MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
1219  if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {
1220  AVBPrint bprint;
1222  do {
1223  av_bprint_clear(&bprint);
1224  buf = get_line(s, &bprint);
1225  if (!buf) {
1226  ret = AVERROR(ENOMEM);
1227  break;
1228  }
1229 
1230  if (!buf[0] || buf[0] == '#')
1231  continue;
1232  if (!(arg = strchr(buf, '='))) {
1233  av_log(ost, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1234  ret = AVERROR(EINVAL);
1235  break;
1236  }
1237  *arg++ = 0;
1238  av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1239  } while (!s->eof_reached);
1240  av_bprint_finalize(&bprint, NULL);
1241  avio_closep(&s);
1242  }
1243  if (ret) {
1245  "Preset %s specified, but could not be opened.\n", preset);
1246  return ret;
1247  }
1248 
1249  MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st);
1250  if (enc_stats_pre &&
1252  const char *format = "{fidx} {sidx} {n} {t}";
1253 
1254  MATCH_PER_STREAM_OPT(enc_stats_pre_fmt, str, format, oc, st);
1255 
1256  ret = enc_stats_init(ost, &ost->enc_stats_pre, 1, enc_stats_pre, format);
1257  if (ret < 0)
1258  return ret;
1259  }
1260 
1261  MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st);
1262  if (enc_stats_post &&
1264  const char *format = "{fidx} {sidx} {n} {t}";
1265 
1266  MATCH_PER_STREAM_OPT(enc_stats_post_fmt, str, format, oc, st);
1267 
1268  ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format);
1269  if (ret < 0)
1270  return ret;
1271  }
1272 
1273  MATCH_PER_STREAM_OPT(mux_stats, str, mux_stats, oc, st);
1274  if (mux_stats &&
1276  const char *format = "{fidx} {sidx} {n} {t}";
1277 
1278  MATCH_PER_STREAM_OPT(mux_stats_fmt, str, format, oc, st);
1279 
1280  ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format);
1281  if (ret < 0)
1282  return ret;
1283  }
1284 
1285  MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
1286  if (enc_time_base) {
1287  AVRational q;
1288  if (!strcmp(enc_time_base, "demux")) {
1289  q = (AVRational){ ENC_TIME_BASE_DEMUX, 0 };
1290  } else if (!strcmp(enc_time_base, "filter")) {
1291  q = (AVRational){ ENC_TIME_BASE_FILTER, 0 };
1292  } else {
1293  ret = av_parse_ratio(&q, enc_time_base, INT_MAX, 0, NULL);
1294  if (ret < 0 || q.den <= 0
1296  || q.num < 0
1297 #endif
1298  ) {
1299  av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base);
1300  return ret < 0 ? ret : AVERROR(EINVAL);
1301  }
1302 #if FFMPEG_OPT_ENC_TIME_BASE_NUM
1303  if (q.num < 0)
1304  av_log(ost, AV_LOG_WARNING, "-enc_time_base -1 is deprecated,"
1305  " use -enc_timebase demux\n");
1306 #endif
1307  }
1308 
1309  ost->enc_timebase = q;
1310  }
1311  } else {
1313  NULL, &ost->encoder_opts);
1314  if (ret < 0)
1315  return ret;
1316  }
1317 
1318 
1319  if (o->bitexact) {
1320  ost->bitexact = 1;
1321  } else if (ost->enc_ctx) {
1322  ost->bitexact = check_opt_bitexact(ost->enc_ctx, ost->encoder_opts, "flags",
1324  }
1325 
1326  MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1327  if (time_base) {
1328  AVRational q;
1329  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1330  q.num <= 0 || q.den <= 0) {
1331  av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1332  return AVERROR(EINVAL);
1333  }
1334  st->time_base = q;
1335  }
1336 
1337  ms->max_frames = INT64_MAX;
1338  MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st);
1339  for (i = 0; i<o->nb_max_frames; i++) {
1340  char *p = o->max_frames[i].specifier;
1341  if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1342  av_log(ost, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1343  break;
1344  }
1345  }
1346 
1347  ms->copy_prior_start = -1;
1348  MATCH_PER_STREAM_OPT(copy_prior_start, i, ms->copy_prior_start, oc ,st);
1349 
1350  MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1351  if (bsfs && *bsfs) {
1352  ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);
1353  if (ret < 0) {
1354  av_log(ost, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
1355  return ret;
1356  }
1357  }
1358 
1359  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1360  if (codec_tag) {
1361  uint32_t tag = strtol(codec_tag, &next, 0);
1362  if (*next) {
1363  uint8_t buf[4] = { 0 };
1364  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1365  tag = AV_RL32(buf);
1366  }
1367  ost->st->codecpar->codec_tag = tag;
1368  ost->par_in->codec_tag = tag;
1369  if (ost->enc_ctx)
1370  ost->enc_ctx->codec_tag = tag;
1371  }
1372 
1373  MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1374  if (ost->enc_ctx && qscale >= 0) {
1375  ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1376  ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1377  }
1378 
1379  ms->max_muxing_queue_size = 128;
1380  MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ms->max_muxing_queue_size, oc, st);
1381 
1382  ms->muxing_queue_data_threshold = 50*1024*1024;
1383  MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ms->muxing_queue_data_threshold, oc, st);
1384 
1385  MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample,
1386  oc, st);
1387 
1388  MATCH_PER_STREAM_OPT(fix_sub_duration_heartbeat, i, ost->fix_sub_duration_heartbeat,
1389  oc, st);
1390 
1391  if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)
1392  ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1393 
1394  av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1395 
1396  av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1397  if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24)
1398  av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1399 
1400  ost->last_mux_dts = AV_NOPTS_VALUE;
1401 
1402  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i,
1403  ms->copy_initial_nonkeyframes, oc, st);
1404 
1405  switch (type) {
1406  case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost); break;
1407  case AVMEDIA_TYPE_AUDIO: ret = new_stream_audio (mux, o, ost); break;
1408  case AVMEDIA_TYPE_SUBTITLE: ret = new_stream_subtitle (mux, o, ost); break;
1409  case AVMEDIA_TYPE_ATTACHMENT: ret = new_stream_attachment(mux, o, ost); break;
1410  }
1411  if (ret < 0)
1412  return ret;
1413 
1415  ret = ost_get_filters(o, oc, ost, &filters);
1416  if (ret < 0)
1417  return ret;
1418  }
1419 
1420  if (ost->enc &&
1422  if (ofilter) {
1423  ost->filter = ofilter;
1424  ret = ofilter_bind_ost(ofilter, ost);
1425  if (ret < 0)
1426  return ret;
1427  } else {
1429  if (ret < 0) {
1431  "Error initializing a simple filtergraph\n");
1432  return ret;
1433  }
1434  }
1435  } else if (ost->ist) {
1436  ret = ist_output_add(ost->ist, ost);
1437  if (ret < 0) {
1439  "Error binding an input stream\n");
1440  return ret;
1441  }
1442  }
1443 
1444  if (ost->ist && !ost->enc) {
1445  ret = streamcopy_init(mux, ost);
1446  if (ret < 0)
1447  return ret;
1448  }
1449 
1450  // copy estimated duration as a hint to the muxer
1451  if (ost->ist && ost->ist->st->duration > 0) {
1452  ms->stream_duration = ist->st->duration;
1453  ms->stream_duration_tb = ist->st->time_base;
1454  }
1455 
1456  if (post)
1457  *post = ost;
1458 
1459  return 0;
1460 }
1461 
1462 static int map_auto_video(Muxer *mux, const OptionsContext *o)
1463 {
1464  AVFormatContext *oc = mux->fc;
1465  InputStream *best_ist = NULL;
1466  int best_score = 0;
1467  int qcr;
1468 
1469  /* video: highest resolution */
1471  return 0;
1472 
1473  qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
1474  for (int j = 0; j < nb_input_files; j++) {
1475  InputFile *ifile = input_files[j];
1476  InputStream *file_best_ist = NULL;
1477  int file_best_score = 0;
1478  for (int i = 0; i < ifile->nb_streams; i++) {
1479  InputStream *ist = ifile->streams[i];
1480  int score;
1481 
1482  if (ist->user_set_discard == AVDISCARD_ALL ||
1484  continue;
1485 
1486  score = ist->st->codecpar->width * ist->st->codecpar->height
1487  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
1488  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
1489  if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1490  score = 1;
1491 
1492  if (score > file_best_score) {
1493  if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1494  continue;
1495  file_best_score = score;
1496  file_best_ist = ist;
1497  }
1498  }
1499  if (file_best_ist) {
1500  if((qcr == MKTAG('A', 'P', 'I', 'C')) ||
1501  !(file_best_ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1502  file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT);
1503  if (file_best_score > best_score) {
1504  best_score = file_best_score;
1505  best_ist = file_best_ist;
1506  }
1507  }
1508  }
1509  if (best_ist)
1510  return ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist, NULL, NULL);
1511 
1512  return 0;
1513 }
1514 
1515 static int map_auto_audio(Muxer *mux, const OptionsContext *o)
1516 {
1517  AVFormatContext *oc = mux->fc;
1518  InputStream *best_ist = NULL;
1519  int best_score = 0;
1520 
1521  /* audio: most channels */
1523  return 0;
1524 
1525  for (int j = 0; j < nb_input_files; j++) {
1526  InputFile *ifile = input_files[j];
1527  InputStream *file_best_ist = NULL;
1528  int file_best_score = 0;
1529  for (int i = 0; i < ifile->nb_streams; i++) {
1530  InputStream *ist = ifile->streams[i];
1531  int score;
1532 
1533  if (ist->user_set_discard == AVDISCARD_ALL ||
1535  continue;
1536 
1537  score = ist->st->codecpar->ch_layout.nb_channels
1538  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
1539  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
1540  if (score > file_best_score) {
1541  file_best_score = score;
1542  file_best_ist = ist;
1543  }
1544  }
1545  if (file_best_ist) {
1546  file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT);
1547  if (file_best_score > best_score) {
1548  best_score = file_best_score;
1549  best_ist = file_best_ist;
1550  }
1551  }
1552  }
1553  if (best_ist)
1554  return ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist, NULL, NULL);
1555 
1556  return 0;
1557 }
1558 
1559 static int map_auto_subtitle(Muxer *mux, const OptionsContext *o)
1560 {
1561  AVFormatContext *oc = mux->fc;
1562  char *subtitle_codec_name = NULL;
1563 
1564  /* subtitles: pick first */
1565  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
1567  return 0;
1568 
1569  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist))
1570  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1571  AVCodecDescriptor const *input_descriptor =
1572  avcodec_descriptor_get(ist->st->codecpar->codec_id);
1573  AVCodecDescriptor const *output_descriptor = NULL;
1574  AVCodec const *output_codec =
1576  int input_props = 0, output_props = 0;
1577  if (ist->user_set_discard == AVDISCARD_ALL)
1578  continue;
1579  if (output_codec)
1580  output_descriptor = avcodec_descriptor_get(output_codec->id);
1581  if (input_descriptor)
1582  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
1583  if (output_descriptor)
1584  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
1585  if (subtitle_codec_name ||
1586  input_props & output_props ||
1587  // Map dvb teletext which has neither property to any output subtitle encoder
1588  input_descriptor && output_descriptor &&
1589  (!input_descriptor->props ||
1590  !output_descriptor->props)) {
1591  return ost_add(mux, o, AVMEDIA_TYPE_SUBTITLE, ist, NULL, NULL);
1592  }
1593  }
1594 
1595  return 0;
1596 }
1597 
1598 static int map_auto_data(Muxer *mux, const OptionsContext *o)
1599 {
1600  AVFormatContext *oc = mux->fc;
1601  /* Data only if codec id match */
1603 
1604  if (codec_id == AV_CODEC_ID_NONE)
1605  return 0;
1606 
1607  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
1608  if (ist->user_set_discard == AVDISCARD_ALL)
1609  continue;
1610  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA &&
1611  ist->st->codecpar->codec_id == codec_id) {
1612  int ret = ost_add(mux, o, AVMEDIA_TYPE_DATA, ist, NULL, NULL);
1613  if (ret < 0)
1614  return ret;
1615  }
1616  }
1617 
1618  return 0;
1619 }
1620 
1621 static int map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map)
1622 {
1623  InputStream *ist;
1624  int ret;
1625 
1626  if (map->disabled)
1627  return 0;
1628 
1629  if (map->linklabel) {
1630  FilterGraph *fg;
1631  OutputFilter *ofilter = NULL;
1632  int j, k;
1633 
1634  for (j = 0; j < nb_filtergraphs; j++) {
1635  fg = filtergraphs[j];
1636  for (k = 0; k < fg->nb_outputs; k++) {
1637  const char *linklabel = fg->outputs[k]->linklabel;
1638  if (linklabel && !strcmp(linklabel, map->linklabel)) {
1639  ofilter = fg->outputs[k];
1640  goto loop_end;
1641  }
1642  }
1643  }
1644 loop_end:
1645  if (!ofilter) {
1646  av_log(mux, AV_LOG_FATAL, "Output with label '%s' does not exist "
1647  "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
1648  return AVERROR(EINVAL);
1649  }
1650 
1651  av_log(mux, AV_LOG_VERBOSE, "Creating output stream from an explicitly "
1652  "mapped complex filtergraph %d, output [%s]\n", fg->index, map->linklabel);
1653 
1654  ret = ost_add(mux, o, ofilter->type, NULL, ofilter, NULL);
1655  if (ret < 0)
1656  return ret;
1657  } else {
1658  ist = input_files[map->file_index]->streams[map->stream_index];
1659  if (ist->user_set_discard == AVDISCARD_ALL) {
1660  av_log(mux, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
1661  map->file_index, map->stream_index);
1662  return AVERROR(EINVAL);
1663  }
1665  return 0;
1667  return 0;
1669  return 0;
1670  if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
1671  return 0;
1672 
1673  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN &&
1676  "Cannot map stream #%d:%d - unsupported type.\n",
1677  map->file_index, map->stream_index);
1678  if (!ignore_unknown_streams) {
1679  av_log(mux, AV_LOG_FATAL,
1680  "If you want unsupported types ignored instead "
1681  "of failing, please use the -ignore_unknown option\n"
1682  "If you want them copied, please use -copy_unknown\n");
1683  return AVERROR(EINVAL);
1684  }
1685  return 0;
1686  }
1687 
1688  ret = ost_add(mux, o, ist->st->codecpar->codec_type, ist, NULL, NULL);
1689  if (ret < 0)
1690  return ret;
1691  }
1692 
1693  return 0;
1694 }
1695 
1696 static int of_add_attachments(Muxer *mux, const OptionsContext *o)
1697 {
1698  OutputStream *ost;
1699  int err;
1700 
1701  for (int i = 0; i < o->nb_attachments; i++) {
1702  AVIOContext *pb;
1703  uint8_t *attachment;
1704  const char *p;
1705  int64_t len;
1706 
1707  if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
1708  av_log(mux, AV_LOG_FATAL, "Could not open attachment file %s.\n",
1709  o->attachments[i]);
1710  return err;
1711  }
1712  if ((len = avio_size(pb)) <= 0) {
1713  av_log(mux, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
1714  o->attachments[i]);
1715  err = len ? len : AVERROR_INVALIDDATA;
1716  goto read_fail;
1717  }
1718  if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
1719  av_log(mux, AV_LOG_FATAL, "Attachment %s too large.\n",
1720  o->attachments[i]);
1721  err = AVERROR(ERANGE);
1722  goto read_fail;
1723  }
1724 
1725  attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE);
1726  if (!attachment) {
1727  err = AVERROR(ENOMEM);
1728  goto read_fail;
1729  }
1730 
1731  err = avio_read(pb, attachment, len);
1732  if (err < 0)
1733  av_log(mux, AV_LOG_FATAL, "Error reading attachment file %s: %s\n",
1734  o->attachments[i], av_err2str(err));
1735  else if (err != len) {
1736  av_log(mux, AV_LOG_FATAL, "Could not read all %"PRId64" bytes for "
1737  "attachment file %s\n", len, o->attachments[i]);
1738  err = AVERROR(EIO);
1739  }
1740 
1741 read_fail:
1742  avio_closep(&pb);
1743  if (err < 0)
1744  return err;
1745 
1746  memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1747 
1748  av_log(mux, AV_LOG_VERBOSE, "Creating attachment stream from file %s\n",
1749  o->attachments[i]);
1750 
1751  err = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL, NULL, &ost);
1752  if (err < 0) {
1753  av_freep(&attachment);
1754  return err;
1755  }
1756 
1757  ost->attachment_filename = o->attachments[i];
1758  ost->par_in->extradata = attachment;
1759  ost->par_in->extradata_size = len;
1760 
1761  p = strrchr(o->attachments[i], '/');
1762  av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
1763  }
1764 
1765  return 0;
1766 }
1767 
1768 static int create_streams(Muxer *mux, const OptionsContext *o)
1769 {
1770  static int (* const map_func[])(Muxer *mux, const OptionsContext *o) = {
1775  };
1776 
1777  AVFormatContext *oc = mux->fc;
1778 
1779  int auto_disable =
1780  o->video_disable * (1 << AVMEDIA_TYPE_VIDEO) |
1781  o->audio_disable * (1 << AVMEDIA_TYPE_AUDIO) |
1783  o->data_disable * (1 << AVMEDIA_TYPE_DATA);
1784 
1785  int ret;
1786 
1787  /* create streams for all unlabeled output pads */
1788  for (int i = 0; i < nb_filtergraphs; i++) {
1789  FilterGraph *fg = filtergraphs[i];
1790  for (int j = 0; j < fg->nb_outputs; j++) {
1791  OutputFilter *ofilter = fg->outputs[j];
1792 
1793  if (ofilter->linklabel || ofilter->ost)
1794  continue;
1795 
1796  auto_disable |= 1 << ofilter->type;
1797 
1798  av_log(mux, AV_LOG_VERBOSE, "Creating output stream from unlabeled "
1799  "output of complex filtergraph %d.", fg->index);
1800  if (!o->nb_stream_maps)
1801  av_log(mux, AV_LOG_VERBOSE, " This overrides automatic %s mapping.",
1802  av_get_media_type_string(ofilter->type));
1803  av_log(mux, AV_LOG_VERBOSE, "\n");
1804 
1805  ret = ost_add(mux, o, ofilter->type, NULL, ofilter, NULL);
1806  if (ret < 0)
1807  return ret;
1808  }
1809  }
1810 
1811  if (!o->nb_stream_maps) {
1812  av_log(mux, AV_LOG_VERBOSE, "No explicit maps, mapping streams automatically...\n");
1813 
1814  /* pick the "best" stream of each type */
1815  for (int i = 0; i < FF_ARRAY_ELEMS(map_func); i++) {
1816  if (!map_func[i] || auto_disable & (1 << i))
1817  continue;
1818  ret = map_func[i](mux, o);
1819  if (ret < 0)
1820  return ret;
1821  }
1822  } else {
1823  av_log(mux, AV_LOG_VERBOSE, "Adding streams from explicit maps...\n");
1824 
1825  for (int i = 0; i < o->nb_stream_maps; i++) {
1826  ret = map_manual(mux, o, &o->stream_maps[i]);
1827  if (ret < 0)
1828  return ret;
1829  }
1830  }
1831 
1832  ret = of_add_attachments(mux, o);
1833  if (ret < 0)
1834  return ret;
1835 
1836  if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
1837  av_dump_format(oc, nb_output_files - 1, oc->url, 1);
1838  av_log(mux, AV_LOG_ERROR, "Output file does not contain any stream\n");
1839  return AVERROR(EINVAL);
1840  }
1841 
1842  return 0;
1843 }
1844 
1845 static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_us)
1846 {
1847  OutputFile *of = &mux->of;
1848  int nb_av_enc = 0, nb_audio_fs = 0, nb_interleaved = 0;
1849  int limit_frames = 0, limit_frames_av_enc = 0;
1850 
1851 #define IS_AV_ENC(ost, type) \
1852  (ost->enc_ctx && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))
1853 #define IS_INTERLEAVED(type) (type != AVMEDIA_TYPE_ATTACHMENT)
1854 
1855  for (int i = 0; i < oc->nb_streams; i++) {
1856  OutputStream *ost = of->streams[i];
1857  MuxStream *ms = ms_from_ost(ost);
1858  enum AVMediaType type = ost->type;
1859 
1860  ost->sq_idx_encode = -1;
1861  ost->sq_idx_mux = -1;
1862 
1863  nb_interleaved += IS_INTERLEAVED(type);
1864  nb_av_enc += IS_AV_ENC(ost, type);
1865  nb_audio_fs += (ost->enc_ctx && type == AVMEDIA_TYPE_AUDIO &&
1866  !(ost->enc_ctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE));
1867 
1868  limit_frames |= ms->max_frames < INT64_MAX;
1869  limit_frames_av_enc |= (ms->max_frames < INT64_MAX) && IS_AV_ENC(ost, type);
1870  }
1871 
1872  if (!((nb_interleaved > 1 && of->shortest) ||
1873  (nb_interleaved > 0 && limit_frames) ||
1874  nb_audio_fs))
1875  return 0;
1876 
1877  /* we use a sync queue before encoding when:
1878  * - 'shortest' is in effect and we have two or more encoded audio/video
1879  * streams
1880  * - at least one encoded audio/video stream is frame-limited, since
1881  * that has similar semantics to 'shortest'
1882  * - at least one audio encoder requires constant frame sizes
1883  */
1884  if ((of->shortest && nb_av_enc > 1) || limit_frames_av_enc || nb_audio_fs) {
1885  of->sq_encode = sq_alloc(SYNC_QUEUE_FRAMES, buf_size_us, mux);
1886  if (!of->sq_encode)
1887  return AVERROR(ENOMEM);
1888 
1889  for (int i = 0; i < oc->nb_streams; i++) {
1890  OutputStream *ost = of->streams[i];
1891  MuxStream *ms = ms_from_ost(ost);
1892  enum AVMediaType type = ost->type;
1893 
1894  if (!IS_AV_ENC(ost, type))
1895  continue;
1896 
1897  ost->sq_idx_encode = sq_add_stream(of->sq_encode,
1898  of->shortest || ms->max_frames < INT64_MAX);
1899  if (ost->sq_idx_encode < 0)
1900  return ost->sq_idx_encode;
1901 
1902  if (ms->max_frames != INT64_MAX)
1903  sq_limit_frames(of->sq_encode, ost->sq_idx_encode, ms->max_frames);
1904  }
1905  }
1906 
1907  /* if there are any additional interleaved streams, then ALL the streams
1908  * are also synchronized before sending them to the muxer */
1909  if (nb_interleaved > nb_av_enc) {
1910  mux->sq_mux = sq_alloc(SYNC_QUEUE_PACKETS, buf_size_us, mux);
1911  if (!mux->sq_mux)
1912  return AVERROR(ENOMEM);
1913 
1914  mux->sq_pkt = av_packet_alloc();
1915  if (!mux->sq_pkt)
1916  return AVERROR(ENOMEM);
1917 
1918  for (int i = 0; i < oc->nb_streams; i++) {
1919  OutputStream *ost = of->streams[i];
1920  MuxStream *ms = ms_from_ost(ost);
1921  enum AVMediaType type = ost->type;
1922 
1923  if (!IS_INTERLEAVED(type))
1924  continue;
1925 
1926  ost->sq_idx_mux = sq_add_stream(mux->sq_mux,
1927  of->shortest || ms->max_frames < INT64_MAX);
1928  if (ost->sq_idx_mux < 0)
1929  return ost->sq_idx_mux;
1930 
1931  if (ms->max_frames != INT64_MAX)
1932  sq_limit_frames(mux->sq_mux, ost->sq_idx_mux, ms->max_frames);
1933  }
1934  }
1935 
1936 #undef IS_AV_ENC
1937 #undef IS_INTERLEAVED
1938 
1939  return 0;
1940 }
1941 
1942 static int of_add_programs(Muxer *mux, const OptionsContext *o)
1943 {
1944  AVFormatContext *oc = mux->fc;
1945  /* process manually set programs */
1946  for (int i = 0; i < o->nb_program; i++) {
1947  AVDictionary *dict = NULL;
1948  const AVDictionaryEntry *e;
1949  AVProgram *program;
1950  int ret, progid = i + 1;
1951 
1952  ret = av_dict_parse_string(&dict, o->program[i].u.str, "=", ":",
1954  if (ret < 0) {
1955  av_log(mux, AV_LOG_ERROR, "Error parsing program specification %s\n",
1956  o->program[i].u.str);
1957  return ret;
1958  }
1959 
1960  e = av_dict_get(dict, "program_num", NULL, 0);
1961  if (e) {
1962  progid = strtol(e->value, NULL, 0);
1963  av_dict_set(&dict, e->key, NULL, 0);
1964  }
1965 
1966  program = av_new_program(oc, progid);
1967  if (!program) {
1968  ret = AVERROR(ENOMEM);
1969  goto fail;
1970  }
1971 
1972  e = av_dict_get(dict, "title", NULL, 0);
1973  if (e) {
1974  av_dict_set(&program->metadata, e->key, e->value, 0);
1975  av_dict_set(&dict, e->key, NULL, 0);
1976  }
1977 
1978  e = NULL;
1979  while (e = av_dict_get(dict, "st", e, 0)) {
1980  int st_num = strtol(e->value, NULL, 0);
1981  av_program_add_stream_index(oc, progid, st_num);
1982  }
1983 
1984  // make sure that nothing but "st" entries are left in the dict
1985  e = NULL;
1986  while (e = av_dict_iterate(dict, e)) {
1987  if (!strcmp(e->key, "st"))
1988  continue;
1989 
1990  av_log(mux, AV_LOG_FATAL, "Unknown program key %s.\n", e->key);
1991  ret = AVERROR(EINVAL);
1992  goto fail;
1993  }
1994 
1995 fail:
1996  av_dict_free(&dict);
1997  if (ret < 0)
1998  return ret;
1999  }
2000 
2001  return 0;
2002 }
2003 
2004 /**
2005  * Parse a metadata specifier passed as 'arg' parameter.
2006  * @param arg metadata string to parse
2007  * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
2008  * @param index for type c/p, chapter/program index is written here
2009  * @param stream_spec for type s, the stream specifier is written here
2010  */
2011 static int parse_meta_type(void *logctx, const char *arg,
2012  char *type, int *index, const char **stream_spec)
2013 {
2014  if (*arg) {
2015  *type = *arg;
2016  switch (*arg) {
2017  case 'g':
2018  break;
2019  case 's':
2020  if (*(++arg) && *arg != ':') {
2021  av_log(logctx, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
2022  return AVERROR(EINVAL);
2023  }
2024  *stream_spec = *arg == ':' ? arg + 1 : "";
2025  break;
2026  case 'c':
2027  case 'p':
2028  if (*(++arg) == ':')
2029  *index = strtol(++arg, NULL, 0);
2030  break;
2031  default:
2032  av_log(logctx, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
2033  return AVERROR(EINVAL);
2034  }
2035  } else
2036  *type = 'g';
2037 
2038  return 0;
2039 }
2040 
2042  const OptionsContext *o)
2043 {
2044  for (int i = 0; i < o->nb_metadata; i++) {
2045  AVDictionary **m;
2046  char type, *val;
2047  const char *stream_spec;
2048  int index = 0, ret = 0;
2049 
2050  val = strchr(o->metadata[i].u.str, '=');
2051  if (!val) {
2052  av_log(of, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2053  o->metadata[i].u.str);
2054  return AVERROR(EINVAL);
2055  }
2056  *val++ = 0;
2057 
2058  ret = parse_meta_type(of, o->metadata[i].specifier, &type, &index, &stream_spec);
2059  if (ret < 0)
2060  return ret;
2061 
2062  if (type == 's') {
2063  for (int j = 0; j < oc->nb_streams; j++) {
2064  OutputStream *ost = of->streams[j];
2065  if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2066 #if FFMPEG_ROTATION_METADATA
2067  if (!strcmp(o->metadata[i].u.str, "rotate")) {
2068  char *tail;
2069  double theta = av_strtod(val, &tail);
2070  if (!*tail) {
2071  ost->rotate_overridden = 1;
2072  ost->rotate_override_value = theta;
2073  }
2074 
2076  "Conversion of a 'rotate' metadata key to a "
2077  "proper display matrix rotation is deprecated. "
2078  "See -display_rotation for setting rotation "
2079  "instead.");
2080  } else {
2081 #endif
2082  av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
2083 #if FFMPEG_ROTATION_METADATA
2084  }
2085 #endif
2086  } else if (ret < 0)
2087  return ret;
2088  }
2089  } else {
2090  switch (type) {
2091  case 'g':
2092  m = &oc->metadata;
2093  break;
2094  case 'c':
2095  if (index < 0 || index >= oc->nb_chapters) {
2096  av_log(of, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
2097  return AVERROR(EINVAL);
2098  }
2099  m = &oc->chapters[index]->metadata;
2100  break;
2101  case 'p':
2102  if (index < 0 || index >= oc->nb_programs) {
2103  av_log(of, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
2104  return AVERROR(EINVAL);
2105  }
2106  m = &oc->programs[index]->metadata;
2107  break;
2108  default:
2109  av_log(of, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
2110  return AVERROR(EINVAL);
2111  }
2112  av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
2113  }
2114  }
2115 
2116  return 0;
2117 }
2118 
2119 static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *os,
2120  int copy_metadata)
2121 {
2122  AVFormatContext *is = ifile->ctx;
2123  AVChapter **tmp;
2124  int i;
2125 
2126  tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
2127  if (!tmp)
2128  return AVERROR(ENOMEM);
2129  os->chapters = tmp;
2130 
2131  for (i = 0; i < is->nb_chapters; i++) {
2132  AVChapter *in_ch = is->chapters[i], *out_ch;
2133  int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2134  int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2135  AV_TIME_BASE_Q, in_ch->time_base);
2136  int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2138 
2139 
2140  if (in_ch->end < ts_off)
2141  continue;
2142  if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2143  break;
2144 
2145  out_ch = av_mallocz(sizeof(AVChapter));
2146  if (!out_ch)
2147  return AVERROR(ENOMEM);
2148 
2149  out_ch->id = in_ch->id;
2150  out_ch->time_base = in_ch->time_base;
2151  out_ch->start = FFMAX(0, in_ch->start - ts_off);
2152  out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2153 
2154  if (copy_metadata)
2155  av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2156 
2157  os->chapters[os->nb_chapters++] = out_ch;
2158  }
2159  return 0;
2160 }
2161 
2162 static int copy_metadata(Muxer *mux, AVFormatContext *ic,
2163  const char *outspec, const char *inspec,
2164  int *metadata_global_manual, int *metadata_streams_manual,
2165  int *metadata_chapters_manual)
2166 {
2167  AVFormatContext *oc = mux->fc;
2168  AVDictionary **meta_in = NULL;
2169  AVDictionary **meta_out = NULL;
2170  int i, ret = 0;
2171  char type_in, type_out;
2172  const char *istream_spec = NULL, *ostream_spec = NULL;
2173  int idx_in = 0, idx_out = 0;
2174 
2175  ret = parse_meta_type(mux, inspec, &type_in, &idx_in, &istream_spec);
2176  if (ret >= 0)
2177  ret = parse_meta_type(mux, outspec, &type_out, &idx_out, &ostream_spec);
2178  if (ret < 0)
2179  return ret;
2180 
2181  if (type_in == 'g' || type_out == 'g' || !*outspec)
2182  *metadata_global_manual = 1;
2183  if (type_in == 's' || type_out == 's' || !*outspec)
2184  *metadata_streams_manual = 1;
2185  if (type_in == 'c' || type_out == 'c' || !*outspec)
2186  *metadata_chapters_manual = 1;
2187 
2188  /* ic is NULL when just disabling automatic mappings */
2189  if (!ic)
2190  return 0;
2191 
2192 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
2193  if ((index) < 0 || (index) >= (nb_elems)) {\
2194  av_log(mux, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
2195  (desc), (index));\
2196  return AVERROR(EINVAL);\
2197  }
2198 
2199 #define SET_DICT(type, meta, context, index)\
2200  switch (type) {\
2201  case 'g':\
2202  meta = &context->metadata;\
2203  break;\
2204  case 'c':\
2205  METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
2206  meta = &context->chapters[index]->metadata;\
2207  break;\
2208  case 'p':\
2209  METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
2210  meta = &context->programs[index]->metadata;\
2211  break;\
2212  case 's':\
2213  break; /* handled separately below */ \
2214  default: av_assert0(0);\
2215  }\
2216 
2217  SET_DICT(type_in, meta_in, ic, idx_in);
2218  SET_DICT(type_out, meta_out, oc, idx_out);
2219 
2220  /* for input streams choose first matching stream */
2221  if (type_in == 's') {
2222  for (i = 0; i < ic->nb_streams; i++) {
2223  if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
2224  meta_in = &ic->streams[i]->metadata;
2225  break;
2226  } else if (ret < 0)
2227  return ret;
2228  }
2229  if (!meta_in) {
2230  av_log(mux, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
2231  return AVERROR(EINVAL);
2232  }
2233  }
2234 
2235  if (type_out == 's') {
2236  for (i = 0; i < oc->nb_streams; i++) {
2237  if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
2238  meta_out = &oc->streams[i]->metadata;
2239  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
2240  } else if (ret < 0)
2241  return ret;
2242  }
2243  } else
2244  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
2245 
2246  return 0;
2247 }
2248 
2249 static int copy_meta(Muxer *mux, const OptionsContext *o)
2250 {
2251  OutputFile *of = &mux->of;
2252  AVFormatContext *oc = mux->fc;
2253  int chapters_input_file = o->chapters_input_file;
2254  int metadata_global_manual = 0;
2255  int metadata_streams_manual = 0;
2256  int metadata_chapters_manual = 0;
2257  int ret;
2258 
2259  /* copy metadata */
2260  for (int i = 0; i < o->nb_metadata_map; i++) {
2261  char *p;
2262  int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2263 
2264  if (in_file_index >= nb_input_files) {
2265  av_log(mux, AV_LOG_FATAL, "Invalid input file index %d while "
2266  "processing metadata maps\n", in_file_index);
2267  return AVERROR(EINVAL);
2268  }
2269  ret = copy_metadata(mux,
2270  in_file_index >= 0 ? input_files[in_file_index]->ctx : NULL,
2271  o->metadata_map[i].specifier, *p ? p + 1 : p,
2272  &metadata_global_manual, &metadata_streams_manual,
2273  &metadata_chapters_manual);
2274  if (ret < 0)
2275  return ret;
2276  }
2277 
2278  /* copy chapters */
2279  if (chapters_input_file >= nb_input_files) {
2280  if (chapters_input_file == INT_MAX) {
2281  /* copy chapters from the first input file that has them*/
2282  chapters_input_file = -1;
2283  for (int i = 0; i < nb_input_files; i++)
2284  if (input_files[i]->ctx->nb_chapters) {
2285  chapters_input_file = i;
2286  break;
2287  }
2288  } else {
2289  av_log(mux, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2290  chapters_input_file);
2291  return AVERROR(EINVAL);
2292  }
2293  }
2294  if (chapters_input_file >= 0)
2295  copy_chapters(input_files[chapters_input_file], of, oc,
2296  !metadata_chapters_manual);
2297 
2298  /* copy global metadata by default */
2299  if (!metadata_global_manual && nb_input_files){
2302  if (of->recording_time != INT64_MAX)
2303  av_dict_set(&oc->metadata, "duration", NULL, 0);
2304  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2305  av_dict_set(&oc->metadata, "company_name", NULL, 0);
2306  av_dict_set(&oc->metadata, "product_name", NULL, 0);
2307  av_dict_set(&oc->metadata, "product_version", NULL, 0);
2308  }
2309  if (!metadata_streams_manual)
2310  for (int i = 0; i < of->nb_streams; i++) {
2311  OutputStream *ost = of->streams[i];
2312 
2313  if (!ost->ist) /* this is true e.g. for attached files */
2314  continue;
2316  if (ost->enc_ctx) {
2317  av_dict_set(&ost->st->metadata, "encoder", NULL, 0);
2318  }
2319  }
2320 
2321  return 0;
2322 }
2323 
2324 static int set_dispositions(Muxer *mux, const OptionsContext *o)
2325 {
2326  OutputFile *of = &mux->of;
2327  AVFormatContext *ctx = mux->fc;
2328 
2329  // indexed by type+1, because AVMEDIA_TYPE_UNKNOWN=-1
2330  int nb_streams[AVMEDIA_TYPE_NB + 1] = { 0 };
2331  int have_default[AVMEDIA_TYPE_NB + 1] = { 0 };
2332  int have_manual = 0;
2333  int ret = 0;
2334 
2335  const char **dispositions;
2336 
2337  dispositions = av_calloc(ctx->nb_streams, sizeof(*dispositions));
2338  if (!dispositions)
2339  return AVERROR(ENOMEM);
2340 
2341  // first, copy the input dispositions
2342  for (int i = 0; i < ctx->nb_streams; i++) {
2343  OutputStream *ost = of->streams[i];
2344 
2345  nb_streams[ost->type + 1]++;
2346 
2347  MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st);
2348 
2349  have_manual |= !!dispositions[i];
2350 
2351  if (ost->ist) {
2352  ost->st->disposition = ost->ist->st->disposition;
2353 
2355  have_default[ost->type + 1] = 1;
2356  }
2357  }
2358 
2359  if (have_manual) {
2360  // process manually set dispositions - they override the above copy
2361  for (int i = 0; i < ctx->nb_streams; i++) {
2362  OutputStream *ost = of->streams[i];
2363  const char *disp = dispositions[i];
2364 
2365  if (!disp)
2366  continue;
2367 
2368  ret = av_opt_set(ost->st, "disposition", disp, 0);
2369  if (ret < 0)
2370  goto finish;
2371  }
2372  } else {
2373  // For each media type with more than one stream, find a suitable stream to
2374  // mark as default, unless one is already marked default.
2375  // "Suitable" means the first of that type, skipping attached pictures.
2376  for (int i = 0; i < ctx->nb_streams; i++) {
2377  OutputStream *ost = of->streams[i];
2378  enum AVMediaType type = ost->type;
2379 
2380  if (nb_streams[type + 1] < 2 || have_default[type + 1] ||
2382  continue;
2383 
2385  have_default[type + 1] = 1;
2386  }
2387  }
2388 
2389 finish:
2390  av_freep(&dispositions);
2391 
2392  return ret;
2393 }
2394 
2395 const char *const forced_keyframes_const_names[] = {
2396  "n",
2397  "n_forced",
2398  "prev_forced_n",
2399  "prev_forced_t",
2400  "t",
2401  NULL
2402 };
2403 
2404 static int compare_int64(const void *a, const void *b)
2405 {
2406  return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
2407 }
2408 
2410  const Muxer *mux, const char *spec)
2411 {
2412  const char *p;
2413  int n = 1, i, ret, size, index = 0;
2414  int64_t t, *pts;
2415 
2416  for (p = spec; *p; p++)
2417  if (*p == ',')
2418  n++;
2419  size = n;
2420  pts = av_malloc_array(size, sizeof(*pts));
2421  if (!pts)
2422  return AVERROR(ENOMEM);
2423 
2424  p = spec;
2425  for (i = 0; i < n; i++) {
2426  char *next = strchr(p, ',');
2427 
2428  if (next)
2429  *next++ = 0;
2430 
2431  if (strstr(p, "chapters") == p) {
2432  AVChapter * const *ch = mux->fc->chapters;
2433  unsigned int nb_ch = mux->fc->nb_chapters;
2434  int j;
2435 
2436  if (nb_ch > INT_MAX - size ||
2437  !(pts = av_realloc_f(pts, size += nb_ch - 1,
2438  sizeof(*pts))))
2439  return AVERROR(ENOMEM);
2440 
2441  if (p[8]) {
2442  ret = av_parse_time(&t, p + 8, 1);
2443  if (ret < 0) {
2445  "Invalid chapter time offset: %s\n", p + 8);
2446  goto fail;
2447  }
2448  } else
2449  t = 0;
2450 
2451  for (j = 0; j < nb_ch; j++) {
2452  const AVChapter *c = ch[j];
2453  av_assert1(index < size);
2454  pts[index++] = av_rescale_q(c->start, c->time_base,
2455  AV_TIME_BASE_Q) + t;
2456  }
2457 
2458  } else {
2459  av_assert1(index < size);
2460  ret = av_parse_time(&t, p, 1);
2461  if (ret < 0) {
2462  av_log(log, AV_LOG_ERROR, "Invalid keyframe time: %s\n", p);
2463  goto fail;
2464  }
2465 
2466  pts[index++] = t;
2467  }
2468 
2469  p = next;
2470  }
2471 
2472  av_assert0(index == size);
2473  qsort(pts, size, sizeof(*pts), compare_int64);
2474  kf->nb_pts = size;
2475  kf->pts = pts;
2476 
2477  return 0;
2478 fail:
2479  av_freep(&pts);
2480  return ret;
2481 }
2482 
2484 {
2485  for (int i = 0; i < mux->of.nb_streams; i++) {
2486  OutputStream *ost = mux->of.streams[i];
2487  const char *forced_keyframes = NULL;
2488 
2489  MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_keyframes, mux->fc, ost->st);
2490 
2491  if (!(ost->type == AVMEDIA_TYPE_VIDEO &&
2492  ost->enc_ctx && forced_keyframes))
2493  continue;
2494 
2495  if (!strncmp(forced_keyframes, "expr:", 5)) {
2496  int ret = av_expr_parse(&ost->kf.pexpr, forced_keyframes + 5,
2498  if (ret < 0) {
2500  "Invalid force_key_frames expression '%s'\n", forced_keyframes + 5);
2501  return ret;
2502  }
2503  ost->kf.expr_const_values[FKF_N] = 0;
2504  ost->kf.expr_const_values[FKF_N_FORCED] = 0;
2505  ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN;
2506  ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN;
2507 
2508  // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
2509  // parse it only for static kf timings
2510  } else if (!strcmp(forced_keyframes, "source")) {
2511  ost->kf.type = KF_FORCE_SOURCE;
2512  } else if (!strcmp(forced_keyframes, "source_no_drop")) {
2513  ost->kf.type = KF_FORCE_SOURCE_NO_DROP;
2514  } else {
2515  int ret = parse_forced_key_frames(ost, &ost->kf, mux, forced_keyframes);
2516  if (ret < 0)
2517  return ret;
2518  }
2519  }
2520 
2521  return 0;
2522 }
2523 
2524 static int validate_enc_avopt(Muxer *mux, const AVDictionary *codec_avopt)
2525 {
2526  const AVClass *class = avcodec_get_class();
2527  const AVClass *fclass = avformat_get_class();
2528  const OutputFile *of = &mux->of;
2529 
2530  AVDictionary *unused_opts;
2531  const AVDictionaryEntry *e;
2532 
2533  unused_opts = strip_specifiers(codec_avopt);
2534  for (int i = 0; i < of->nb_streams; i++) {
2535  e = NULL;
2536  while ((e = av_dict_iterate(of->streams[i]->encoder_opts, e)))
2537  av_dict_set(&unused_opts, e->key, NULL, 0);
2538  }
2539 
2540  e = NULL;
2541  while ((e = av_dict_iterate(unused_opts, e))) {
2542  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2544  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2546  if (!option || foption)
2547  continue;
2548 
2549  if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2550  av_log(mux, AV_LOG_ERROR, "Codec AVOption %s (%s) is not an "
2551  "encoding option.\n", e->key, option->help ? option->help : "");
2552  return AVERROR(EINVAL);
2553  }
2554 
2555  // gop_timecode is injected by generic code but not always used
2556  if (!strcmp(e->key, "gop_timecode"))
2557  continue;
2558 
2559  av_log(mux, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
2560  "for any stream. The most likely reason is either wrong type "
2561  "(e.g. a video option with no video streams) or that it is a "
2562  "private option of some encoder which was not actually used for "
2563  "any stream.\n", e->key, option->help ? option->help : "");
2564  }
2565  av_dict_free(&unused_opts);
2566 
2567  return 0;
2568 }
2569 
2571 {
2572  int ret = 0;
2573 
2574  if (ost->enc_ctx) {
2575  ret = enc_open(ost, NULL);
2576  if (ret < 0)
2577  return ret;
2578  } else {
2579  ret = of_stream_init(output_files[ost->file_index], ost);
2580  if (ret < 0)
2581  return ret;
2582  }
2583 
2584  return ret;
2585 }
2586 
2587 static const char *output_file_item_name(void *obj)
2588 {
2589  const Muxer *mux = obj;
2590 
2591  return mux->log_name;
2592 }
2593 
2594 static const AVClass output_file_class = {
2595  .class_name = "OutputFile",
2596  .version = LIBAVUTIL_VERSION_INT,
2597  .item_name = output_file_item_name,
2598  .category = AV_CLASS_CATEGORY_MUXER,
2599 };
2600 
2601 static Muxer *mux_alloc(void)
2602 {
2603  Muxer *mux = allocate_array_elem(&output_files, sizeof(*mux), &nb_output_files);
2604 
2605  if (!mux)
2606  return NULL;
2607 
2608  mux->of.class = &output_file_class;
2609  mux->of.index = nb_output_files - 1;
2610 
2611  snprintf(mux->log_name, sizeof(mux->log_name), "out#%d", mux->of.index);
2612 
2613  return mux;
2614 }
2615 
2616 int of_open(const OptionsContext *o, const char *filename)
2617 {
2618  Muxer *mux;
2619  AVFormatContext *oc;
2620  int err;
2621  OutputFile *of;
2622 
2623  int64_t recording_time = o->recording_time;
2624  int64_t stop_time = o->stop_time;
2625 
2626  mux = mux_alloc();
2627  if (!mux)
2628  return AVERROR(ENOMEM);
2629 
2630  of = &mux->of;
2631 
2632  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
2633  stop_time = INT64_MAX;
2634  av_log(mux, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2635  }
2636 
2637  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
2638  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2639  if (stop_time <= start_time) {
2640  av_log(mux, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2641  return AVERROR(EINVAL);
2642  } else {
2643  recording_time = stop_time - start_time;
2644  }
2645  }
2646 
2647  of->recording_time = recording_time;
2648  of->start_time = o->start_time;
2649  of->shortest = o->shortest;
2650 
2651  mux->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
2652  mux->limit_filesize = o->limit_filesize;
2653  av_dict_copy(&mux->opts, o->g->format_opts, 0);
2654 
2655  if (!strcmp(filename, "-"))
2656  filename = "pipe:";
2657 
2658  err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2659  if (!oc) {
2660  av_log(mux, AV_LOG_FATAL, "Error initializing the muxer for %s: %s\n",
2661  filename, av_err2str(err));
2662  return err;
2663  }
2664  mux->fc = oc;
2665 
2666  av_strlcat(mux->log_name, "/", sizeof(mux->log_name));
2667  av_strlcat(mux->log_name, oc->oformat->name, sizeof(mux->log_name));
2668 
2669  if (strcmp(oc->oformat->name, "rtp"))
2670  want_sdp = 0;
2671 
2672  of->format = oc->oformat;
2673  if (recording_time != INT64_MAX)
2674  oc->duration = recording_time;
2675 
2676  oc->interrupt_callback = int_cb;
2677 
2678  if (o->bitexact) {
2679  oc->flags |= AVFMT_FLAG_BITEXACT;
2680  of->bitexact = 1;
2681  } else {
2682  of->bitexact = check_opt_bitexact(oc, mux->opts, "fflags",
2684  }
2685 
2686  /* create all output streams for this file */
2687  err = create_streams(mux, o);
2688  if (err < 0)
2689  return err;
2690 
2691  /* check if all codec options have been used */
2692  err = validate_enc_avopt(mux, o->g->codec_opts);
2693  if (err < 0)
2694  return err;
2695 
2696  /* check filename in case of an image number is expected */
2698  av_log(mux, AV_LOG_FATAL,
2699  "Output filename '%s' does not contain a numeric pattern like "
2700  "'%%d', which is required by output format '%s'.\n",
2701  oc->url, oc->oformat->name);
2702  return AVERROR(EINVAL);
2703  }
2704 
2705  if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2706  /* test if it already exists to avoid losing precious files */
2707  err = assert_file_overwrite(filename);
2708  if (err < 0)
2709  return err;
2710 
2711  /* open the file */
2712  if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2713  &oc->interrupt_callback,
2714  &mux->opts)) < 0) {
2715  av_log(mux, AV_LOG_FATAL, "Error opening output %s: %s\n",
2716  filename, av_err2str(err));
2717  return err;
2718  }
2719  } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename)) {
2720  err = assert_file_overwrite(filename);
2721  if (err < 0)
2722  return err;
2723  }
2724 
2725  if (o->mux_preload) {
2726  av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2727  }
2728  oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2729 
2730  /* copy metadata and chapters from input files */
2731  err = copy_meta(mux, o);
2732  if (err < 0)
2733  return err;
2734 
2735  err = of_add_programs(mux, o);
2736  if (err < 0)
2737  return err;
2738 
2739  err = of_add_metadata(of, oc, o);
2740  if (err < 0)
2741  return err;
2742 
2743  err = set_dispositions(mux, o);
2744  if (err < 0) {
2745  av_log(mux, AV_LOG_FATAL, "Error setting output stream dispositions\n");
2746  return err;
2747  }
2748 
2749  // parse forced keyframe specifications;
2750  // must be done after chapters are created
2751  err = process_forced_keyframes(mux, o);
2752  if (err < 0) {
2753  av_log(mux, AV_LOG_FATAL, "Error processing forced keyframes\n");
2754  return err;
2755  }
2756 
2758  if (err < 0) {
2759  av_log(mux, AV_LOG_FATAL, "Error setting up output sync queues\n");
2760  return err;
2761  }
2762 
2763  of->url = filename;
2764 
2765  /* initialize stream copy and subtitle/data streams.
2766  * Encoded AVFrame based streams will get initialized when the first AVFrame
2767  * is received in do_video_out
2768  */
2769  for (int i = 0; i < of->nb_streams; i++) {
2770  OutputStream *ost = of->streams[i];
2771 
2772  if (ost->filter)
2773  continue;
2774 
2776  if (err < 0)
2777  return err;
2778  }
2779 
2780  /* write the header for files with no streams */
2781  if (of->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) {
2782  int ret = mux_check_init(mux);
2783  if (ret < 0)
2784  return ret;
2785  }
2786 
2787  return 0;
2788 }
choose_encoder
static int choose_encoder(const OptionsContext *o, AVFormatContext *s, OutputStream *ost, const AVCodec **enc)
Definition: ffmpeg_mux_init.c:108
formats
formats
Definition: signature.h:48
KeyframeForceCtx::pts
int64_t * pts
Definition: ffmpeg.h:496
MuxStream::ost
OutputStream ost
Definition: ffmpeg_mux.h:38
fopen_utf8
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: fopen_utf8.h:65
streamcopy_init
static int streamcopy_init(const Muxer *mux, OutputStream *ost)
Definition: ffmpeg_mux_init.c:971
map_manual
static int map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map)
Definition: ffmpeg_mux_init.c:1621
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:65
AVCodec
AVCodec.
Definition: codec.h:187
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
av_codec_get_id
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
MuxStream::copy_initial_nonkeyframes
int copy_initial_nonkeyframes
Definition: ffmpeg_mux.h:84
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
InputFile::start_time
int64_t start_time
Definition: ffmpeg.h:413
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
Muxer::fc
AVFormatContext * fc
Definition: ffmpeg_mux.h:95
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
OptionsContext::stop_time
int64_t stop_time
Definition: ffmpeg.h:172
ost_get_filters
static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc, OutputStream *ost, char **dst)
Definition: ffmpeg_mux_init.c:445
opt_name_max_muxing_queue_size
static const char *const opt_name_max_muxing_queue_size[]
Definition: ffmpeg_mux_init.c:77
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:445
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
OutputFilter::graph
struct FilterGraph * graph
Definition: ffmpeg.h:293
FKF_PREV_FORCED_T
@ FKF_PREV_FORCED_T
Definition: ffmpeg.h:435
VSYNC_VFR
@ VSYNC_VFR
Definition: ffmpeg.h:66
ms_from_ost
static MuxStream * ms_from_ost(OutputStream *ost)
Definition: ffmpeg_mux.h:118
AVOutputFormat::name
const char * name
Definition: avformat.h:509
AVChapter::metadata
AVDictionary * metadata
Definition: avformat.h:1068
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:218
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:124
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:58
MATCH_PER_STREAM_OPT
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
Definition: ffmpeg.h:911
opt_name_muxing_queue_data_threshold
static const char *const opt_name_muxing_queue_data_threshold[]
Definition: ffmpeg_mux_init.c:78
AVSTREAM_EVENT_FLAG_NEW_PACKETS
#define AVSTREAM_EVENT_FLAG_NEW_PACKETS
Definition: avformat.h:987
ENC_STATS_PTS
@ ENC_STATS_PTS
Definition: ffmpeg.h:451
ENC_STATS_FRAME_NUM_IN
@ ENC_STATS_FRAME_NUM_IN
Definition: ffmpeg.h:448
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1060
KF_FORCE_SOURCE_NO_DROP
@ KF_FORCE_SOURCE_NO_DROP
Definition: ffmpeg.h:487
FKF_PREV_FORCED_N
@ FKF_PREV_FORCED_N
Definition: ffmpeg.h:434
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
is
The official guide to swscale for confused that is
Definition: swscale.txt:28
AVFormatContext::nb_chapters
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1322
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:54
opt_name_enc_stats_pre
static const char *const opt_name_enc_stats_pre[]
Definition: ffmpeg_mux_init.c:59
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:947
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2964
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:483
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:770
ENC_STATS_DTS
@ ENC_STATS_DTS
Definition: ffmpeg.h:455
MATCH_PER_TYPE_OPT
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
Definition: ffmpeg.h:928
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:649
MuxStream::muxing_queue
AVFifo * muxing_queue
Definition: ffmpeg_mux.h:44
avcodec_parameters_from_context
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:100
KeyframeForceCtx::nb_pts
int nb_pts
Definition: ffmpeg.h:497
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:480
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:328
FFMPEG_OPT_ENC_TIME_BASE_NUM
#define FFMPEG_OPT_ENC_TIME_BASE_NUM
Definition: ffmpeg.h:59
OptionsContext::nb_metadata
int nb_metadata
Definition: ffmpeg.h:189
ENC_STATS_AVG_BITRATE
@ ENC_STATS_AVG_BITRATE
Definition: ffmpeg.h:461
AVCodecContext::intra_matrix
uint16_t * intra_matrix
custom intra quantization matrix Must be allocated with the av_malloc() family of functions,...
Definition: avcodec.h:933
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:205
ist_iter
InputStream * ist_iter(InputStream *prev)
Definition: ffmpeg.c:413
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:186
normalize.log
log
Definition: normalize.py:21
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:717
OptionsContext::nb_attachments
int nb_attachments
Definition: ffmpeg.h:167
MuxStream::max_muxing_queue_size
int max_muxing_queue_size
Definition: ffmpeg_mux.h:61
AVCodec::pix_fmts
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:209
OutputFile::start_time
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:629
avcodec_find_encoder
const AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: allcodecs.c:970
Muxer::thread_queue_size
int thread_queue_size
Definition: ffmpeg_mux.h:102
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:1173
OptionsContext::mux_max_delay
float mux_max_delay
Definition: ffmpeg.h:175
AVPacketSideData
Definition: packet.h:315
MuxStream::muxing_queue_data_threshold
size_t muxing_queue_data_threshold
Definition: ffmpeg_mux.h:64
subtitle_codec_name
static const char * subtitle_codec_name
Definition: ffplay.c:342
new_stream_video
static int new_stream_video(Muxer *mux, const OptionsContext *o, OutputStream *ost)
Definition: ffmpeg_mux_init.c:589
ENC_STATS_LITERAL
@ ENC_STATS_LITERAL
Definition: ffmpeg.h:444
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:182
opt_name_disposition
static const char *const opt_name_disposition[]
Definition: ffmpeg_mux_init.c:57
AVOption
AVOption.
Definition: opt.h:251
OutputStream::index
int index
Definition: ffmpeg.h:514
opt_name_sample_fmts
static const char *const opt_name_sample_fmts[]
Definition: ffmpeg_mux_init.c:90
b
#define b
Definition: input.c:41
FilterGraph::index
int index
Definition: ffmpeg.h:308
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:928
opt_name_max_frames
static const char *const opt_name_max_frames[]
Definition: ffmpeg_mux_init.c:76
AVChapter::start
int64_t start
Definition: avformat.h:1067
Muxer::of
OutputFile of
Definition: ffmpeg_mux.h:90
opt_name_mux_stats
static const char *const opt_name_mux_stats[]
Definition: ffmpeg_mux_init.c:61
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
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
opt_name_fix_sub_duration_heartbeat
static const char *const opt_name_fix_sub_duration_heartbeat[]
Definition: ffmpeg_mux_init.c:67
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:220
ost_add
static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, InputStream *ist, OutputFilter *ofilter, OutputStream **post)
Definition: ffmpeg_mux_init.c:1103
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1273
IS_AV_ENC
#define IS_AV_ENC(ost, type)
OptionsContext::bitexact
int bitexact
Definition: ffmpeg.h:178
av_display_rotation_set
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
Definition: display.c:51
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:82
video_disable
static int video_disable
Definition: ffplay.c:317
AVDictionary
Definition: dict.c:34
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:318
MuxStream::copy_prior_start
int copy_prior_start
Definition: ffmpeg_mux.h:85
OptionsContext::format
const char * format
Definition: ffmpeg.h:116
parse_forced_key_frames
static int parse_forced_key_frames(void *log, KeyframeForceCtx *kf, const Muxer *mux, const char *spec)
Definition: ffmpeg_mux_init.c:2409
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
enc_stats_init
static int enc_stats_init(OutputStream *ost, EncStats *es, int pre, const char *path, const char *fmt_spec)
Definition: ffmpeg_mux_init.c:284
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:370
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
parse_matrix_coeffs
static int parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str)
Definition: ffmpeg_mux_init.c:492
opt_name_apad
static const char *const opt_name_apad[]
Definition: ffmpeg_mux_init.c:51
set_dispositions
static int set_dispositions(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:2324
MuxStream::ts_copy_start
int64_t ts_copy_start
Definition: ffmpeg_mux.h:69
AVOutputFormat::subtitle_codec
enum AVCodecID subtitle_codec
default subtitle codec
Definition: avformat.h:521
MuxStream::stream_duration_tb
AVRational stream_duration_tb
Definition: ffmpeg_mux.h:76
ENC_STATS_TIMEBASE_IN
@ ENC_STATS_TIMEBASE_IN
Definition: ffmpeg.h:450
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:330
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:164
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:624
av_filename_number_test
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition: utils.c:126
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
Muxer
Definition: ffmpeg_mux.h:89
InputStream
Definition: ffmpeg.h:320
OptionsContext::chapters_input_file
int chapters_input_file
Definition: ffmpeg.h:169
AVPacketSideData::size
size_t size
Definition: packet.h:317
SET_DICT
#define SET_DICT(type, meta, context, index)
EncStatsFile
Definition: ffmpeg_mux_init.c:194
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1371
map_auto_subtitle
static int map_auto_subtitle(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1559
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:1265
finish
static void finish(void)
Definition: movenc.c:342
fopen_utf8.h
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:446
presets
static const Preset presets[]
Definition: vf_pseudocolor.c:286
opt_name_audio_channels
static const char *const opt_name_audio_channels[]
Definition: ffmpeg_mux_init.c:85
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:110
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2101
mux_alloc
static Muxer * mux_alloc(void)
Definition: ffmpeg_mux_init.c:2601
fail
#define fail()
Definition: checkasm.h:138
opt_name_audio_ch_layouts
static const char *const opt_name_audio_ch_layouts[]
Definition: ffmpeg_mux_init.c:86
copy_meta
static int copy_meta(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:2249
opt_name_audio_sample_rate
static const char *const opt_name_audio_sample_rate[]
Definition: ffmpeg_mux_init.c:87
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:517
AVChapter
Definition: avformat.h:1064
val
static double val(void *priv, double ch)
Definition: aeval.c:78
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:643
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:1845
OptionsContext
Definition: ffmpeg.h:109
AV_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:109
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:307
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:443
Muxer::sq_pkt
AVPacket * sq_pkt
Definition: ffmpeg_mux.h:110
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:898
av_codec_get_tag2
int av_codec_get_tag2(const struct AVCodecTag *const *tags, enum AVCodecID id, unsigned int *tag)
Get the codec tag for the given codec id.
enc_stats_files
static EncStatsFile * enc_stats_files
Definition: ffmpeg_mux_init.c:199
AVRational::num
int num
Numerator.
Definition: rational.h:59
OptionsContext::nb_audio_channel_maps
int nb_audio_channel_maps
Definition: ffmpeg.h:164
InputFile
Definition: ffmpeg.h:395
FFDIFFSIGN
#define FFDIFFSIGN(x, y)
Comparator.
Definition: macros.h:45
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:171
OptionsContext::nb_stream_maps
int nb_stream_maps
Definition: ffmpeg.h:161
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:181
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:917
preset
preset
Definition: vf_curves.c:46
OutputFile::shortest
int shortest
Definition: ffmpeg.h:631
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:97
AVFormatContext::metadata
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1333
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:217
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
AVCodecTag
Definition: internal.h:48
ENC_STATS_PTS_IN
@ ENC_STATS_PTS_IN
Definition: ffmpeg.h:453
mask
static const uint16_t mask[17]
Definition: lzw.c:38
OptionsContext::nb_program
int nb_program
Definition: ffmpeg.h:263
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:62
av_opt_set_dict
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1767
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:417
VSYNC_VSCFR
@ VSYNC_VSCFR
Definition: ffmpeg.h:67
EncStats::components
EncStatsComponent * components
Definition: ffmpeg.h:472
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:153
assert_file_overwrite
int assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:704
AVChapter::end
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:1067
SpecifierOpt::specifier
char * specifier
stream/chapter/program/...
Definition: cmdutils.h:95
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
new_stream_attachment
static int new_stream_attachment(Muxer *mux, const OptionsContext *o, OutputStream *ost)
Definition: ffmpeg_mux_init.c:923
mux_stream_alloc
static MuxStream * mux_stream_alloc(Muxer *mux, enum AVMediaType type)
Definition: ffmpeg_mux_init.c:424
intreadwrite.h
opt_name_enc_stats_post_fmt
static const char *const opt_name_enc_stats_post_fmt[]
Definition: ffmpeg_mux_init.c:63
s
#define s(width, name)
Definition: cbs_vp9.c:198
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:1330
MuxStream::pkt
AVPacket * pkt
Definition: ffmpeg_mux.h:49
mux_check_init
int mux_check_init(Muxer *mux)
Definition: ffmpeg_mux.c:590
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:314
enc_stats_get_file
static int enc_stats_get_file(AVIOContext **io, const char *path)
Definition: ffmpeg_mux_init.c:202
InputStream::framerate
AVRational framerate
Definition: ffmpeg.h:349
do_psnr
int do_psnr
Definition: ffmpeg_opt.c:97
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1223
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
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:138
output_file_class
static const AVClass output_file_class
Definition: ffmpeg_mux_init.c:2594
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1272
RcOverride
Definition: avcodec.h:196
AVFormatContext::chapters
AVChapter ** chapters
Definition: avformat.h:1323
ENC_STATS_FILE_IDX
@ ENC_STATS_FILE_IDX
Definition: ffmpeg.h:445
AVDictionaryEntry::key
char * key
Definition: dict.h:90
frame_size
int frame_size
Definition: mxfenc.c:2307
OptionsContext::limit_filesize
int64_t limit_filesize
Definition: ffmpeg.h:173
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:128
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:395
OutputFilter::linklabel
uint8_t * linklabel
Definition: ffmpeg.h:298
get_line
static char * get_line(AVIOContext *s, AVBPrint *bprint)
Definition: ffmpeg_mux_init.c:151
filters
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
Definition: af_crystalizer.c:54
ENC_STATS_BITRATE
@ ENC_STATS_BITRATE
Definition: ffmpeg.h:460
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
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:410
of_add_metadata
static int of_add_metadata(OutputFile *of, AVFormatContext *oc, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:2041
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:637
OutputFilter::ost
struct OutputStream * ost
Definition: ffmpeg.h:292
AVPacketSideData::data
uint8_t * data
Definition: packet.h:316
ignore_unknown_streams
int ignore_unknown_streams
Definition: ffmpeg_opt.c:99
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:315
opt_name_enc_stats_pre_fmt
static const char *const opt_name_enc_stats_pre_fmt[]
Definition: ffmpeg_mux_init.c:62
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:72
choose_pixel_fmt
static enum AVPixelFormat choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
Definition: ffmpeg_mux_init.c:521
OptionsContext::shortest
int shortest
Definition: ffmpeg.h:177
AVOutputFormat::codec_tag
const struct AVCodecTag *const * codec_tag
List of supported codec_id-codec_tag pairs, ordered by "better choice first".
Definition: avformat.h:534
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:388
filter_codec_opts
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec, AVDictionary **dst)
Filter out options for given codec.
Definition: cmdutils.c:925
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
NAN
#define NAN
Definition: mathematics.h:115
MuxStream::max_frames
int64_t max_frames
Definition: ffmpeg_mux.h:53
AVFMT_NEEDNUMBER
#define AVFMT_NEEDNUMBER
Needs 'd' in filename.
Definition: avformat.h:470
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:447
Muxer::limit_filesize
int64_t limit_filesize
Definition: ffmpeg_mux.h:105
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
if
if(ret)
Definition: filter_design.txt:179
sq_add_stream
int sq_add_stream(SyncQueue *sq, int limiting)
Add a new stream to the sync queue.
Definition: sync_queue.c:620
option
option
Definition: libkvazaar.c:313
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:113
OutputStream::encoder_opts
AVDictionary * encoder_opts
Definition: ffmpeg.h:574
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:211
AVFormatContext
Format I/O context.
Definition: avformat.h:1105
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:32
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:218
opts
AVDictionary * opts
Definition: movenc.c:50
new_stream_subtitle
static int new_stream_subtitle(Muxer *mux, const OptionsContext *o, OutputStream *ost)
Definition: ffmpeg_mux_init.c:930
validate_enc_avopt
static int validate_enc_avopt(Muxer *mux, const AVDictionary *codec_avopt)
Definition: ffmpeg_mux_init.c:2524
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:862
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
avcodec_get_class
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:187
OutputFilter::name
uint8_t * name
Definition: ffmpeg.h:294
parse_meta_type
static int 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:2011
opt_name_inter_matrices
static const char *const opt_name_inter_matrices[]
Definition: ffmpeg_mux_init.c:73
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:878
DEFAULT_PASS_LOGFILENAME_PREFIX
#define DEFAULT_PASS_LOGFILENAME_PREFIX
Definition: ffmpeg_mux_init.c:49
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:338
InputStream::st
AVStream * st
Definition: ffmpeg.h:326
AV_DICT_MULTIKEY
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
Definition: dict.h:84
map_auto_video
static int map_auto_video(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1462
nb_enc_stats_files
static int nb_enc_stats_files
Definition: ffmpeg_mux_init.c:200
ENC_STATS_PTS_TIME
@ ENC_STATS_PTS_TIME
Definition: ffmpeg.h:452
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:168
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:318
opt_name_forced_key_frames
static const char *const opt_name_forced_key_frames[]
Definition: ffmpeg_mux_init.c:70
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1147
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:103
parseutils.h
EncStats
Definition: ffmpeg.h:471
EncStatsFile::io
AVIOContext * io
Definition: ffmpeg_mux_init.c:196
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:100
opt_name_time_bases
static const char *const opt_name_time_bases[]
Definition: ffmpeg_mux_init.c:84
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:919
MuxStream::bsf_ctx
AVBSFContext * bsf_ctx
Definition: ffmpeg_mux.h:46
AV_CODEC_CAP_VARIABLE_FRAME_SIZE
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: codec.h:128
av_parse_time
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Definition: parseutils.c:589
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:190
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:243
Muxer::log_name
char log_name[32]
Definition: ffmpeg_mux.h:93
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:213
OutputFile::index
int index
Definition: ffmpeg.h:618
OptionsContext::program
SpecifierOpt * program
Definition: ffmpeg.h:262
OutputFile::class
const AVClass * class
Definition: ffmpeg.h:616
ENC_STATS_PTS_TIME_IN
@ ENC_STATS_PTS_TIME_IN
Definition: ffmpeg.h:454
FilterGraph::nb_outputs
int nb_outputs
Definition: ffmpeg.h:315
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)
Definition: ffmpeg_mux_init.c:2162
of_open
int of_open(const OptionsContext *o, const char *filename)
Definition: ffmpeg_mux_init.c:2616
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
find_codec
int find_codec(void *logctx, const char *name, enum AVMediaType type, int encoder, const AVCodec **codec)
Definition: ffmpeg_opt.c:671
OptionsContext::nb_metadata_map
int nb_metadata_map
Definition: ffmpeg.h:227
opt_name_chroma_intra_matrices
static const char *const opt_name_chroma_intra_matrices[]
Definition: ffmpeg_mux_init.c:74
InputStream::par
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition: ffmpeg.h:338
input_files
InputFile ** input_files
Definition: ffmpeg.c:123
OutputFile::streams
OutputStream ** streams
Definition: ffmpeg.h:623
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:89
FilterGraph
Definition: ffmpeg.h:306
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1161
ENC_TIME_BASE_DEMUX
@ ENC_TIME_BASE_DEMUX
Definition: ffmpeg.h:72
of_add_programs
static int of_add_programs(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1942
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:528
codec_opts
AVDictionary * codec_opts
Definition: cmdutils.c:60
opt_name_filter_scripts
static const char *const opt_name_filter_scripts[]
Definition: ffmpeg_mux_init.c:66
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:462
frame_sizes
static const uint8_t frame_sizes[]
Definition: rtpdec_qcelp.c:24
opt_name_mux_stats_fmt
static const char *const opt_name_mux_stats_fmt[]
Definition: ffmpeg_mux_init.c:64
f
f
Definition: af_crystalizer.c:121
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
AVCodecContext::rc_override
RcOverride * rc_override
Definition: avcodec.h:1273
OptionsContext::thread_queue_size
int thread_queue_size
Definition: ffmpeg.h:142
AVMediaType
AVMediaType
Definition: avutil.h:199
Muxer::sq_mux
SyncQueue * sq_mux
Definition: ffmpeg_mux.h:109
opt_name_bits_per_raw_sample
static const char *const opt_name_bits_per_raw_sample[]
Definition: ffmpeg_mux_init.c:53
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:240
InputStream::file_index
int file_index
Definition: ffmpeg.h:323
output_files
OutputFile ** output_files
Definition: ffmpeg.c:126
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:88
start_time
static int64_t start_time
Definition: ffplay.c:328
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1188
EncStatsType
EncStatsType
Definition: ffmpeg.h:443
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1076
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
StreamMap
Definition: ffmpeg.h:89
ENC_STATS_NB_SAMPLES
@ ENC_STATS_NB_SAMPLES
Definition: ffmpeg.h:458
init_output_stream_nofilter
static int init_output_stream_nofilter(OutputStream *ost)
Definition: ffmpeg_mux_init.c:2570
size
int size
Definition: twinvq_data.h:10344
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:78
avio.h
copy_tb
int copy_tb
Definition: ffmpeg_opt.c:80
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:974
OptionsContext::streamid
AVDictionary * streamid
Definition: ffmpeg.h:186
av_stream_get_codec_timebase
AVRational av_stream_get_codec_timebase(const AVStream *st)
Get the internal codec timebase from a stream.
Definition: avformat.c:781
opt_name_pass
static const char *const opt_name_pass[]
Definition: ffmpeg_mux_init.c:79
OutputStream::type
enum AVMediaType type
Definition: ffmpeg.h:511
OutputFile::url
const char * url
Definition: ffmpeg.h:621
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:469
AVCodecContext::chroma_intra_matrix
uint16_t * chroma_intra_matrix
custom intra quantization matrix
Definition: avcodec.h:1875
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
Muxer::opts
AVDictionary * opts
Definition: ffmpeg_mux.h:100
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:917
AVFMT_NOSTREAMS
#define AVFMT_NOSTREAMS
Format does not require any streams.
Definition: avformat.h:485
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:1039
of_enc_stats_close
void of_enc_stats_close(void)
Definition: ffmpeg_mux_init.c:235
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:563
fix_sub_duration_heartbeat
int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts)
Definition: ffmpeg_dec.c:454
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:306
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:650
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
enc_alloc
int enc_alloc(Encoder **penc, const AVCodec *codec)
Definition: ffmpeg_enc.c:87
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition: mem.c:223
strip_specifiers
AVDictionary * strip_specifiers(const AVDictionary *dict)
Definition: ffmpeg_opt.c:169
OptionsContext::metadata
SpecifierOpt * metadata
Definition: ffmpeg.h:188
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:63
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:225
opt_name_enc_stats_post
static const char *const opt_name_enc_stats_post[]
Definition: ffmpeg_mux_init.c:60
OutputFile::sq_encode
SyncQueue * sq_encode
Definition: ffmpeg.h:626
KF_FORCE_SOURCE
@ KF_FORCE_SOURCE
Definition: ffmpeg.h:486
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:447
KeyframeForceCtx
Definition: ffmpeg.h:490
OutputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:300
opt_name_autoscale
static const char *const opt_name_autoscale[]
Definition: ffmpeg_mux_init.c:52
AVStream::side_data
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:957
AVCodec::id
enum AVCodecID id
Definition: codec.h:201
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
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:54
flag
#define flag(name)
Definition: cbs_av1.c:459
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:414
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:1304
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:408
bprint.h
map_auto_data
static int map_auto_data(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1598
log.h
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:479
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:244
RcOverride::end_frame
int end_frame
Definition: avcodec.h:198
OptionsContext::metadata_map
SpecifierOpt * metadata_map
Definition: ffmpeg.h:226
AVChapter::id
int64_t id
unique ID to identify the chapter
Definition: avformat.h:1065
MuxStream::stats
EncStats stats
Definition: ffmpeg_mux.h:51
OptionsContext::stream_maps
StreamMap * stream_maps
Definition: ffmpeg.h:160
pix_fmt_parse
static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
Definition: ffmpeg_mux_init.c:546
AVCodecParameters::height
int height
Definition: codec_par.h:129
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: codec_par.c:184
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
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:185
VSYNC_CFR
@ VSYNC_CFR
Definition: ffmpeg.h:65
OptionsContext::shortest_buf_duration
float shortest_buf_duration
Definition: ffmpeg.h:176
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AVProgram::metadata
AVDictionary * metadata
Definition: avformat.h:1035
OutputFile::bitexact
int bitexact
Definition: ffmpeg.h:632
display.h
opt_name_frame_aspect_ratios
static const char *const opt_name_frame_aspect_ratios[]
Definition: ffmpeg_mux_init.c:71
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
opt_name_enc_time_bases
static const char *const opt_name_enc_time_bases[]
Definition: ffmpeg_mux_init.c:58
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:403
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVFormatContext::max_delay
int max_delay
Definition: avformat.h:1217
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1029
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
len
int len
Definition: vorbis_enc_data.h:426
ENC_STATS_STREAM_IDX
@ ENC_STATS_STREAM_IDX
Definition: ffmpeg.h:446
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:129
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:346
AVCodecContext::height
int height
Definition: avcodec.h:617
fmt_in_list
static int fmt_in_list(const int *formats, int format)
Definition: ffmpeg_mux_init.c:512
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:654
ENC_STATS_SAMPLE_NUM
@ ENC_STATS_SAMPLE_NUM
Definition: ffmpeg.h:457
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
nb_output_files
int nb_output_files
Definition: ffmpeg.c:127
avcodec.h
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition: cmdutils.h:219
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:908
tag
uint32_t tag
Definition: movenc.c:1737
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:851
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1240
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:839
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:1124
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:95
output_file_item_name
static const char * output_file_item_name(void *obj)
Definition: ffmpeg_mux_init.c:2587
AVStream::nb_side_data
int nb_side_data
The number of elements in the AVStream.side_data array.
Definition: avformat.h:961
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:108
OptionsContext::audio_channel_maps
AudioChannelMap * audio_channel_maps
Definition: ffmpeg.h:163
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:419
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:115
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:2896
OptionsContext::nb_max_frames
int nb_max_frames
Definition: ffmpeg.h:191
of_add_attachments
static int of_add_attachments(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1696
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:437
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:845
AV_CLASS_CATEGORY_MUXER
@ AV_CLASS_CATEGORY_MUXER
Definition: log.h:32
avformat_transfer_internal_stream_timing_info
int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVStream *ost, const AVStream *ist, enum AVTimebaseSource copy_tb)
Transfer internal timing information from one stream to another.
Definition: avformat.c:703
av_find_best_pix_fmt_of_2
enum AVPixelFormat av_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
Compute what kind of losses will occur when converting from one specific pixel format to another.
Definition: pixdesc.c:3243
init_simple_filtergraph
int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc)
Definition: ffmpeg_filter.c:897
OptionsContext::mux_preload
float mux_preload
Definition: ffmpeg.h:174
ist_output_add
int ist_output_add(InputStream *ist, OutputStream *ost)
Definition: ffmpeg_demux.c:875
AVRational::den
int den
Denominator.
Definition: rational.h:60
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:97
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:232
av_dict_parse_string
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
Definition: dict.c:202
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:659
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:180
ofilter_bind_ost
int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
Definition: ffmpeg_filter.c:628
AVOutputFormat::video_codec
enum AVCodecID video_codec
default video codec
Definition: avformat.h:520
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:997
opt_name_passlogfiles
static const char *const opt_name_passlogfiles[]
Definition: ffmpeg_mux_init.c:80
opt_name_rc_overrides
static const char *const opt_name_rc_overrides[]
Definition: ffmpeg_mux_init.c:83
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1207
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
video_sync_method
enum VideoSyncMethod video_sync_method
Definition: ffmpeg_opt.c:72
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:401
InputFile::ts_offset
int64_t ts_offset
Definition: ffmpeg.h:412
VSYNC_AUTO
@ VSYNC_AUTO
Definition: ffmpeg.h:63
OutputFilter
Definition: ffmpeg.h:291
map_auto_audio
static int map_auto_audio(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1515
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:169
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:636
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
desc
const char * desc
Definition: libsvtav1.c:83
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:526
unescape
static int unescape(char **pdst, size_t *dst_len, const char **pstr, char delim)
Definition: ffmpeg_mux_init.c:245
avutil.h
mem.h
SpecifierOpt::u
union SpecifierOpt::@0 u
OutputStream::file_index
int file_index
Definition: ffmpeg.h:513
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:334
ffmpeg_mux.h
new_stream_audio
static int new_stream_audio(Muxer *mux, const OptionsContext *o, OutputStream *ost)
Definition: ffmpeg_mux_init.c:834
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
InputStream::index
int index
Definition: ffmpeg.h:324
EncStatsFile::path
char * path
Definition: ffmpeg_mux_init.c:195
compare_int64
static int compare_int64(const void *a, const void *b)
Definition: ffmpeg_mux_init.c:2404
FKF_N_FORCED
@ FKF_N_FORCED
Definition: ffmpeg.h:433
AVDictionaryEntry
Definition: dict.h:89
OptionsContext::attachments
const char ** attachments
Definition: ffmpeg.h:166
ENC_TIME_BASE_FILTER
@ ENC_TIME_BASE_FILTER
Definition: ffmpeg.h:73
av_add_q
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
Definition: rational.c:93
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:316
EncStatsComponent
Definition: ffmpeg.h:464
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:88
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:239
AVCodecContext::inter_matrix
uint16_t * inter_matrix
custom inter quantization matrix Must be allocated with the av_malloc() family of functions,...
Definition: avcodec.h:942
cmdutils.h
AVCodecContext::rc_override_count
int rc_override_count
ratecontrol override, see RcOverride
Definition: avcodec.h:1272
InputFile::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:406
file_read
char * file_read(const char *filename)
Definition: ffmpeg_opt.c:750
EncStats::nb_components
int nb_components
Definition: ffmpeg.h:473
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:183
av_stream_new_side_data
uint8_t * av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, size_t size)
Allocate new information from stream.
Definition: avformat.c:193
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:130
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:617
int32_t
int32_t
Definition: audioconvert.c:56
ENC_STATS_PKT_SIZE
@ ENC_STATS_PKT_SIZE
Definition: ffmpeg.h:459
OutputStream
Definition: mux.c:53
check_opt_bitexact
static int check_opt_bitexact(void *ctx, const AVDictionary *opts, const char *opt_name, int flag)
Definition: ffmpeg_mux_init.c:92
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:2395
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
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:2483
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:145
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3722
SYNC_QUEUE_FRAMES
@ SYNC_QUEUE_FRAMES
Definition: sync_queue.h:30
OutputFile::format
const AVOutputFormat * format
Definition: ffmpeg.h:620
sq_alloc
SyncQueue * sq_alloc(enum SyncQueueType type, int64_t buf_size_us, void *logctx)
Allocate a sync queue of the given type.
Definition: sync_queue.c:675
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
FF_QP2LAMBDA
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
opt_name_copy_initial_nonkeyframes
static const char *const opt_name_copy_initial_nonkeyframes[]
Definition: ffmpeg_mux_init.c:55
InputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:420
FKF_N
@ FKF_N
Definition: ffmpeg.h:432
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:93
ENC_STATS_DTS_TIME
@ ENC_STATS_DTS_TIME
Definition: ffmpeg.h:456
AVChapter::time_base
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1066
OutputFile::recording_time
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:628
int
int
Definition: ffmpeg_filter.c:331
of_stream_init
int of_stream_init(OutputFile *of, OutputStream *ost)
Definition: ffmpeg_mux.c:671
VSYNC_PASSTHROUGH
@ VSYNC_PASSTHROUGH
Definition: ffmpeg.h:64
opt_name_fps_mode
static const char *const opt_name_fps_mode[]
Definition: ffmpeg_mux_init.c:68
snprintf
#define snprintf
Definition: snprintf.h:34
EncStats::io
AVIOContext * io
Definition: ffmpeg.h:475
enc_open
int enc_open(OutputStream *ost, AVFrame *frame)
Definition: ffmpeg_enc.c:285
opt_name_bitstream_filters
static const char *const opt_name_bitstream_filters[]
Definition: ffmpeg_mux_init.c:54
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:44
opt_name_presets
static const char *const opt_name_presets[]
Definition: ffmpeg_mux_init.c:81
copy_chapters
static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *os, int copy_metadata)
Definition: ffmpeg_mux_init.c:2119
MuxStream::last_mux_dts
int64_t last_mux_dts
Definition: ffmpeg_mux.h:73
opt_name_max_frame_rates
static const char *const opt_name_max_frame_rates[]
Definition: ffmpeg_mux_init.c:75
ENC_STATS_TIMEBASE
@ ENC_STATS_TIMEBASE
Definition: ffmpeg.h:449
create_streams
static int create_streams(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1768
MuxStream::stream_duration
int64_t stream_duration
Definition: ffmpeg_mux.h:75
OutputStream::class
const AVClass * class
Definition: ffmpeg.h:509
opt_name_copy_prior_start
static const char *const opt_name_copy_prior_start[]
Definition: ffmpeg_mux_init.c:56
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2884
opt_name_force_fps
static const char *const opt_name_force_fps[]
Definition: ffmpeg_mux_init.c:69
OutputFile
Definition: ffmpeg.h:615
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:302