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->codecpar->nb_coded_side_data; i++) {
1049  const AVPacketSideData *sd_src = &ist->st->codecpar->coded_side_data[i];
1050  AVPacketSideData *sd_dst;
1051 
1054  sd_src->type, sd_src->size, 0);
1055  if (!sd_dst) {
1056  ret = AVERROR(ENOMEM);
1057  goto fail;
1058  }
1059  memcpy(sd_dst->data, sd_src->data, sd_src->size);
1060  }
1061 
1062 #if FFMPEG_ROTATION_METADATA
1063  if (ost->rotate_overridden) {
1067  sizeof(int32_t) * 9, 0);
1068  if (sd)
1069  av_display_rotation_set((int32_t *)sd->data, -ost->rotate_override_value);
1070  }
1071 #endif
1072 
1073  switch (par->codec_type) {
1074  case AVMEDIA_TYPE_AUDIO:
1075  if ((par->block_align == 1 || par->block_align == 1152 || par->block_align == 576) &&
1076  par->codec_id == AV_CODEC_ID_MP3)
1077  par->block_align = 0;
1078  if (par->codec_id == AV_CODEC_ID_AC3)
1079  par->block_align = 0;
1080  break;
1081  case AVMEDIA_TYPE_VIDEO: {
1082  AVRational sar;
1083  if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option
1084  sar =
1085  av_mul_q(ost->frame_aspect_ratio,
1086  (AVRational){ par->height, par->width });
1087  av_log(ost, AV_LOG_WARNING, "Overriding aspect ratio "
1088  "with stream copy may produce invalid files\n");
1089  }
1090  else if (ist->st->sample_aspect_ratio.num)
1091  sar = ist->st->sample_aspect_ratio;
1092  else
1093  sar = par->sample_aspect_ratio;
1094  ost->st->sample_aspect_ratio = par->sample_aspect_ratio = sar;
1095  ost->st->avg_frame_rate = ist->st->avg_frame_rate;
1096  ost->st->r_frame_rate = ist->st->r_frame_rate;
1097  break;
1098  }
1099  }
1100 
1101 fail:
1102  avcodec_free_context(&codec_ctx);
1104  return ret;
1105 }
1106 
1107 static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
1108  InputStream *ist, OutputFilter *ofilter,
1109  OutputStream **post)
1110 {
1111  AVFormatContext *oc = mux->fc;
1112  MuxStream *ms;
1113  OutputStream *ost;
1114  const AVCodec *enc;
1115  AVStream *st;
1116  int ret = 0;
1117  const char *bsfs = NULL, *time_base = NULL;
1118  char *filters = NULL, *next, *codec_tag = NULL;
1119  double qscale = -1;
1120  int i;
1121 
1122  st = avformat_new_stream(oc, NULL);
1123  if (!st)
1124  return AVERROR(ENOMEM);
1125 
1126  ms = mux_stream_alloc(mux, type);
1127  if (!ms)
1128  return AVERROR(ENOMEM);
1129 
1130  ost = &ms->ost;
1131 
1132  if (o->streamid) {
1133  AVDictionaryEntry *e;
1134  char idx[16], *p;
1135  snprintf(idx, sizeof(idx), "%d", ost->index);
1136 
1137  e = av_dict_get(o->streamid, idx, NULL, 0);
1138  if (e) {
1139  st->id = strtol(e->value, &p, 0);
1140  if (!e->value[0] || *p) {
1141  av_log(ost, AV_LOG_FATAL, "Invalid stream id: %s\n", e->value);
1142  return AVERROR(EINVAL);
1143  }
1144  }
1145  }
1146 
1147  ost->par_in = avcodec_parameters_alloc();
1148  if (!ost->par_in)
1149  return AVERROR(ENOMEM);
1150 
1151  ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
1152  if (!ms->muxing_queue)
1153  return AVERROR(ENOMEM);
1155 
1156  ost->st = st;
1157  ost->ist = ist;
1158  ost->kf.ref_pts = AV_NOPTS_VALUE;
1159  ost->par_in->codec_type = type;
1160  st->codecpar->codec_type = type;
1161 
1162  ret = choose_encoder(o, oc, ost, &enc);
1163  if (ret < 0) {
1164  av_log(ost, AV_LOG_FATAL, "Error selecting an encoder\n");
1165  return ret;
1166  }
1167 
1168  if (enc) {
1169  ost->enc_ctx = avcodec_alloc_context3(enc);
1170  if (!ost->enc_ctx)
1171  return AVERROR(ENOMEM);
1172 
1173  ret = enc_alloc(&ost->enc, enc);
1174  if (ret < 0)
1175  return ret;
1176 
1177  av_strlcat(ms->log_name, "/", sizeof(ms->log_name));
1178  av_strlcat(ms->log_name, enc->name, sizeof(ms->log_name));
1179  } else {
1180  if (ofilter) {
1182  "Streamcopy requested for output stream fed "
1183  "from a complex filtergraph. Filtering and streamcopy "
1184  "cannot be used together.\n");
1185  return AVERROR(EINVAL);
1186  }
1187 
1188  av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name));
1189  }
1190 
1191  av_log(ost, AV_LOG_VERBOSE, "Created %s stream from ",
1193  if (ist)
1194  av_log(ost, AV_LOG_VERBOSE, "input stream %d:%d",
1195  ist->file_index, ist->index);
1196  else if (ofilter)
1197  av_log(ost, AV_LOG_VERBOSE, "complex filtergraph %d:[%s]\n",
1198  ofilter->graph->index, ofilter->name);
1199  else if (type == AVMEDIA_TYPE_ATTACHMENT)
1200  av_log(ost, AV_LOG_VERBOSE, "attached file");
1201  else av_assert0(0);
1202  av_log(ost, AV_LOG_VERBOSE, "\n");
1203 
1204  ms->pkt = av_packet_alloc();
1205  if (!ms->pkt)
1206  return AVERROR(ENOMEM);
1207 
1208  if (ost->enc_ctx) {
1209  AVCodecContext *enc = ost->enc_ctx;
1210  AVIOContext *s = NULL;
1211  char *buf = NULL, *arg = NULL, *preset = NULL;
1212  const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL;
1213  const char *enc_time_base = NULL;
1214 
1216  oc, st, enc->codec, &ost->encoder_opts);
1217  if (ret < 0)
1218  return ret;
1219 
1220  MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
1221  ost->autoscale = 1;
1222  MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
1223  if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {
1224  AVBPrint bprint;
1226  do {
1227  av_bprint_clear(&bprint);
1228  buf = get_line(s, &bprint);
1229  if (!buf) {
1230  ret = AVERROR(ENOMEM);
1231  break;
1232  }
1233 
1234  if (!buf[0] || buf[0] == '#')
1235  continue;
1236  if (!(arg = strchr(buf, '='))) {
1237  av_log(ost, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1238  ret = AVERROR(EINVAL);
1239  break;
1240  }
1241  *arg++ = 0;
1242  av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1243  } while (!s->eof_reached);
1244  av_bprint_finalize(&bprint, NULL);
1245  avio_closep(&s);
1246  }
1247  if (ret) {
1249  "Preset %s specified, but could not be opened.\n", preset);
1250  return ret;
1251  }
1252 
1253  MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st);
1254  if (enc_stats_pre &&
1256  const char *format = "{fidx} {sidx} {n} {t}";
1257 
1258  MATCH_PER_STREAM_OPT(enc_stats_pre_fmt, str, format, oc, st);
1259 
1260  ret = enc_stats_init(ost, &ost->enc_stats_pre, 1, enc_stats_pre, format);
1261  if (ret < 0)
1262  return ret;
1263  }
1264 
1265  MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st);
1266  if (enc_stats_post &&
1268  const char *format = "{fidx} {sidx} {n} {t}";
1269 
1270  MATCH_PER_STREAM_OPT(enc_stats_post_fmt, str, format, oc, st);
1271 
1272  ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format);
1273  if (ret < 0)
1274  return ret;
1275  }
1276 
1277  MATCH_PER_STREAM_OPT(mux_stats, str, mux_stats, oc, st);
1278  if (mux_stats &&
1280  const char *format = "{fidx} {sidx} {n} {t}";
1281 
1282  MATCH_PER_STREAM_OPT(mux_stats_fmt, str, format, oc, st);
1283 
1284  ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format);
1285  if (ret < 0)
1286  return ret;
1287  }
1288 
1289  MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
1290  if (enc_time_base) {
1291  AVRational q;
1292  if (!strcmp(enc_time_base, "demux")) {
1293  q = (AVRational){ ENC_TIME_BASE_DEMUX, 0 };
1294  } else if (!strcmp(enc_time_base, "filter")) {
1295  q = (AVRational){ ENC_TIME_BASE_FILTER, 0 };
1296  } else {
1297  ret = av_parse_ratio(&q, enc_time_base, INT_MAX, 0, NULL);
1298  if (ret < 0 || q.den <= 0
1300  || q.num < 0
1301 #endif
1302  ) {
1303  av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base);
1304  return ret < 0 ? ret : AVERROR(EINVAL);
1305  }
1306 #if FFMPEG_OPT_ENC_TIME_BASE_NUM
1307  if (q.num < 0)
1308  av_log(ost, AV_LOG_WARNING, "-enc_time_base -1 is deprecated,"
1309  " use -enc_timebase demux\n");
1310 #endif
1311  }
1312 
1313  ost->enc_timebase = q;
1314  }
1315  } else {
1317  NULL, &ost->encoder_opts);
1318  if (ret < 0)
1319  return ret;
1320  }
1321 
1322 
1323  if (o->bitexact) {
1324  ost->bitexact = 1;
1325  } else if (ost->enc_ctx) {
1326  ost->bitexact = check_opt_bitexact(ost->enc_ctx, ost->encoder_opts, "flags",
1328  }
1329 
1330  MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1331  if (time_base) {
1332  AVRational q;
1333  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1334  q.num <= 0 || q.den <= 0) {
1335  av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1336  return AVERROR(EINVAL);
1337  }
1338  st->time_base = q;
1339  }
1340 
1341  ms->max_frames = INT64_MAX;
1342  MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st);
1343  for (i = 0; i<o->nb_max_frames; i++) {
1344  char *p = o->max_frames[i].specifier;
1345  if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1346  av_log(ost, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1347  break;
1348  }
1349  }
1350 
1351  ms->copy_prior_start = -1;
1352  MATCH_PER_STREAM_OPT(copy_prior_start, i, ms->copy_prior_start, oc ,st);
1353 
1354  MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1355  if (bsfs && *bsfs) {
1356  ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);
1357  if (ret < 0) {
1358  av_log(ost, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
1359  return ret;
1360  }
1361  }
1362 
1363  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1364  if (codec_tag) {
1365  uint32_t tag = strtol(codec_tag, &next, 0);
1366  if (*next) {
1367  uint8_t buf[4] = { 0 };
1368  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1369  tag = AV_RL32(buf);
1370  }
1371  ost->st->codecpar->codec_tag = tag;
1372  ost->par_in->codec_tag = tag;
1373  if (ost->enc_ctx)
1374  ost->enc_ctx->codec_tag = tag;
1375  }
1376 
1377  MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1378  if (ost->enc_ctx && qscale >= 0) {
1379  ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1380  ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1381  }
1382 
1383  ms->max_muxing_queue_size = 128;
1384  MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ms->max_muxing_queue_size, oc, st);
1385 
1386  ms->muxing_queue_data_threshold = 50*1024*1024;
1387  MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ms->muxing_queue_data_threshold, oc, st);
1388 
1389  MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample,
1390  oc, st);
1391 
1392  MATCH_PER_STREAM_OPT(fix_sub_duration_heartbeat, i, ost->fix_sub_duration_heartbeat,
1393  oc, st);
1394 
1395  if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)
1396  ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1397 
1398  av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1399 
1400  av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1401  if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24)
1402  av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1403 
1404  ost->last_mux_dts = AV_NOPTS_VALUE;
1405 
1406  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i,
1407  ms->copy_initial_nonkeyframes, oc, st);
1408 
1409  switch (type) {
1410  case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost); break;
1411  case AVMEDIA_TYPE_AUDIO: ret = new_stream_audio (mux, o, ost); break;
1412  case AVMEDIA_TYPE_SUBTITLE: ret = new_stream_subtitle (mux, o, ost); break;
1413  case AVMEDIA_TYPE_ATTACHMENT: ret = new_stream_attachment(mux, o, ost); break;
1414  }
1415  if (ret < 0)
1416  return ret;
1417 
1419  ret = ost_get_filters(o, oc, ost, &filters);
1420  if (ret < 0)
1421  return ret;
1422  }
1423 
1424  if (ost->enc &&
1426  if (ofilter) {
1427  ost->filter = ofilter;
1428  ret = ofilter_bind_ost(ofilter, ost);
1429  if (ret < 0)
1430  return ret;
1431  } else {
1433  if (ret < 0) {
1435  "Error initializing a simple filtergraph\n");
1436  return ret;
1437  }
1438  }
1439  } else if (ost->ist) {
1440  ret = ist_output_add(ost->ist, ost);
1441  if (ret < 0) {
1443  "Error binding an input stream\n");
1444  return ret;
1445  }
1446  }
1447 
1448  if (ost->ist && !ost->enc) {
1449  ret = streamcopy_init(mux, ost);
1450  if (ret < 0)
1451  return ret;
1452  }
1453 
1454  // copy estimated duration as a hint to the muxer
1455  if (ost->ist && ost->ist->st->duration > 0) {
1456  ms->stream_duration = ist->st->duration;
1457  ms->stream_duration_tb = ist->st->time_base;
1458  }
1459 
1460  if (post)
1461  *post = ost;
1462 
1463  return 0;
1464 }
1465 
1466 static int map_auto_video(Muxer *mux, const OptionsContext *o)
1467 {
1468  AVFormatContext *oc = mux->fc;
1469  InputStream *best_ist = NULL;
1470  int best_score = 0;
1471  int qcr;
1472 
1473  /* video: highest resolution */
1475  return 0;
1476 
1477  qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
1478  for (int j = 0; j < nb_input_files; j++) {
1479  InputFile *ifile = input_files[j];
1480  InputStream *file_best_ist = NULL;
1481  int file_best_score = 0;
1482  for (int i = 0; i < ifile->nb_streams; i++) {
1483  InputStream *ist = ifile->streams[i];
1484  int score;
1485 
1486  if (ist->user_set_discard == AVDISCARD_ALL ||
1488  continue;
1489 
1490  score = ist->st->codecpar->width * ist->st->codecpar->height
1491  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
1492  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
1493  if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1494  score = 1;
1495 
1496  if (score > file_best_score) {
1497  if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1498  continue;
1499  file_best_score = score;
1500  file_best_ist = ist;
1501  }
1502  }
1503  if (file_best_ist) {
1504  if((qcr == MKTAG('A', 'P', 'I', 'C')) ||
1505  !(file_best_ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1506  file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT);
1507  if (file_best_score > best_score) {
1508  best_score = file_best_score;
1509  best_ist = file_best_ist;
1510  }
1511  }
1512  }
1513  if (best_ist)
1514  return ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist, NULL, NULL);
1515 
1516  return 0;
1517 }
1518 
1519 static int map_auto_audio(Muxer *mux, const OptionsContext *o)
1520 {
1521  AVFormatContext *oc = mux->fc;
1522  InputStream *best_ist = NULL;
1523  int best_score = 0;
1524 
1525  /* audio: most channels */
1527  return 0;
1528 
1529  for (int j = 0; j < nb_input_files; j++) {
1530  InputFile *ifile = input_files[j];
1531  InputStream *file_best_ist = NULL;
1532  int file_best_score = 0;
1533  for (int i = 0; i < ifile->nb_streams; i++) {
1534  InputStream *ist = ifile->streams[i];
1535  int score;
1536 
1537  if (ist->user_set_discard == AVDISCARD_ALL ||
1539  continue;
1540 
1541  score = ist->st->codecpar->ch_layout.nb_channels
1542  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
1543  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
1544  if (score > file_best_score) {
1545  file_best_score = score;
1546  file_best_ist = ist;
1547  }
1548  }
1549  if (file_best_ist) {
1550  file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT);
1551  if (file_best_score > best_score) {
1552  best_score = file_best_score;
1553  best_ist = file_best_ist;
1554  }
1555  }
1556  }
1557  if (best_ist)
1558  return ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist, NULL, NULL);
1559 
1560  return 0;
1561 }
1562 
1563 static int map_auto_subtitle(Muxer *mux, const OptionsContext *o)
1564 {
1565  AVFormatContext *oc = mux->fc;
1566  char *subtitle_codec_name = NULL;
1567 
1568  /* subtitles: pick first */
1569  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
1571  return 0;
1572 
1573  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist))
1574  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1575  AVCodecDescriptor const *input_descriptor =
1576  avcodec_descriptor_get(ist->st->codecpar->codec_id);
1577  AVCodecDescriptor const *output_descriptor = NULL;
1578  AVCodec const *output_codec =
1580  int input_props = 0, output_props = 0;
1581  if (ist->user_set_discard == AVDISCARD_ALL)
1582  continue;
1583  if (output_codec)
1584  output_descriptor = avcodec_descriptor_get(output_codec->id);
1585  if (input_descriptor)
1586  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
1587  if (output_descriptor)
1588  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
1589  if (subtitle_codec_name ||
1590  input_props & output_props ||
1591  // Map dvb teletext which has neither property to any output subtitle encoder
1592  input_descriptor && output_descriptor &&
1593  (!input_descriptor->props ||
1594  !output_descriptor->props)) {
1595  return ost_add(mux, o, AVMEDIA_TYPE_SUBTITLE, ist, NULL, NULL);
1596  }
1597  }
1598 
1599  return 0;
1600 }
1601 
1602 static int map_auto_data(Muxer *mux, const OptionsContext *o)
1603 {
1604  AVFormatContext *oc = mux->fc;
1605  /* Data only if codec id match */
1607 
1608  if (codec_id == AV_CODEC_ID_NONE)
1609  return 0;
1610 
1611  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
1612  if (ist->user_set_discard == AVDISCARD_ALL)
1613  continue;
1614  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA &&
1615  ist->st->codecpar->codec_id == codec_id) {
1616  int ret = ost_add(mux, o, AVMEDIA_TYPE_DATA, ist, NULL, NULL);
1617  if (ret < 0)
1618  return ret;
1619  }
1620  }
1621 
1622  return 0;
1623 }
1624 
1625 static int map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map)
1626 {
1627  InputStream *ist;
1628  int ret;
1629 
1630  if (map->disabled)
1631  return 0;
1632 
1633  if (map->linklabel) {
1634  FilterGraph *fg;
1635  OutputFilter *ofilter = NULL;
1636  int j, k;
1637 
1638  for (j = 0; j < nb_filtergraphs; j++) {
1639  fg = filtergraphs[j];
1640  for (k = 0; k < fg->nb_outputs; k++) {
1641  const char *linklabel = fg->outputs[k]->linklabel;
1642  if (linklabel && !strcmp(linklabel, map->linklabel)) {
1643  ofilter = fg->outputs[k];
1644  goto loop_end;
1645  }
1646  }
1647  }
1648 loop_end:
1649  if (!ofilter) {
1650  av_log(mux, AV_LOG_FATAL, "Output with label '%s' does not exist "
1651  "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
1652  return AVERROR(EINVAL);
1653  }
1654 
1655  av_log(mux, AV_LOG_VERBOSE, "Creating output stream from an explicitly "
1656  "mapped complex filtergraph %d, output [%s]\n", fg->index, map->linklabel);
1657 
1658  ret = ost_add(mux, o, ofilter->type, NULL, ofilter, NULL);
1659  if (ret < 0)
1660  return ret;
1661  } else {
1662  ist = input_files[map->file_index]->streams[map->stream_index];
1663  if (ist->user_set_discard == AVDISCARD_ALL) {
1664  av_log(mux, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
1665  map->file_index, map->stream_index);
1666  return AVERROR(EINVAL);
1667  }
1669  return 0;
1671  return 0;
1673  return 0;
1674  if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
1675  return 0;
1676 
1677  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN &&
1680  "Cannot map stream #%d:%d - unsupported type.\n",
1681  map->file_index, map->stream_index);
1682  if (!ignore_unknown_streams) {
1683  av_log(mux, AV_LOG_FATAL,
1684  "If you want unsupported types ignored instead "
1685  "of failing, please use the -ignore_unknown option\n"
1686  "If you want them copied, please use -copy_unknown\n");
1687  return AVERROR(EINVAL);
1688  }
1689  return 0;
1690  }
1691 
1692  ret = ost_add(mux, o, ist->st->codecpar->codec_type, ist, NULL, NULL);
1693  if (ret < 0)
1694  return ret;
1695  }
1696 
1697  return 0;
1698 }
1699 
1700 static int of_add_attachments(Muxer *mux, const OptionsContext *o)
1701 {
1702  OutputStream *ost;
1703  int err;
1704 
1705  for (int i = 0; i < o->nb_attachments; i++) {
1706  AVIOContext *pb;
1707  uint8_t *attachment;
1708  const char *p;
1709  int64_t len;
1710 
1711  if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
1712  av_log(mux, AV_LOG_FATAL, "Could not open attachment file %s.\n",
1713  o->attachments[i]);
1714  return err;
1715  }
1716  if ((len = avio_size(pb)) <= 0) {
1717  av_log(mux, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
1718  o->attachments[i]);
1719  err = len ? len : AVERROR_INVALIDDATA;
1720  goto read_fail;
1721  }
1722  if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
1723  av_log(mux, AV_LOG_FATAL, "Attachment %s too large.\n",
1724  o->attachments[i]);
1725  err = AVERROR(ERANGE);
1726  goto read_fail;
1727  }
1728 
1729  attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE);
1730  if (!attachment) {
1731  err = AVERROR(ENOMEM);
1732  goto read_fail;
1733  }
1734 
1735  err = avio_read(pb, attachment, len);
1736  if (err < 0)
1737  av_log(mux, AV_LOG_FATAL, "Error reading attachment file %s: %s\n",
1738  o->attachments[i], av_err2str(err));
1739  else if (err != len) {
1740  av_log(mux, AV_LOG_FATAL, "Could not read all %"PRId64" bytes for "
1741  "attachment file %s\n", len, o->attachments[i]);
1742  err = AVERROR(EIO);
1743  }
1744 
1745 read_fail:
1746  avio_closep(&pb);
1747  if (err < 0)
1748  return err;
1749 
1750  memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1751 
1752  av_log(mux, AV_LOG_VERBOSE, "Creating attachment stream from file %s\n",
1753  o->attachments[i]);
1754 
1755  err = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL, NULL, &ost);
1756  if (err < 0) {
1757  av_freep(&attachment);
1758  return err;
1759  }
1760 
1761  ost->attachment_filename = o->attachments[i];
1762  ost->par_in->extradata = attachment;
1763  ost->par_in->extradata_size = len;
1764 
1765  p = strrchr(o->attachments[i], '/');
1766  av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
1767  }
1768 
1769  return 0;
1770 }
1771 
1772 static int create_streams(Muxer *mux, const OptionsContext *o)
1773 {
1774  static int (* const map_func[])(Muxer *mux, const OptionsContext *o) = {
1779  };
1780 
1781  AVFormatContext *oc = mux->fc;
1782 
1783  int auto_disable =
1784  o->video_disable * (1 << AVMEDIA_TYPE_VIDEO) |
1785  o->audio_disable * (1 << AVMEDIA_TYPE_AUDIO) |
1787  o->data_disable * (1 << AVMEDIA_TYPE_DATA);
1788 
1789  int ret;
1790 
1791  /* create streams for all unlabeled output pads */
1792  for (int i = 0; i < nb_filtergraphs; i++) {
1793  FilterGraph *fg = filtergraphs[i];
1794  for (int j = 0; j < fg->nb_outputs; j++) {
1795  OutputFilter *ofilter = fg->outputs[j];
1796 
1797  if (ofilter->linklabel || ofilter->ost)
1798  continue;
1799 
1800  auto_disable |= 1 << ofilter->type;
1801 
1802  av_log(mux, AV_LOG_VERBOSE, "Creating output stream from unlabeled "
1803  "output of complex filtergraph %d.", fg->index);
1804  if (!o->nb_stream_maps)
1805  av_log(mux, AV_LOG_VERBOSE, " This overrides automatic %s mapping.",
1806  av_get_media_type_string(ofilter->type));
1807  av_log(mux, AV_LOG_VERBOSE, "\n");
1808 
1809  ret = ost_add(mux, o, ofilter->type, NULL, ofilter, NULL);
1810  if (ret < 0)
1811  return ret;
1812  }
1813  }
1814 
1815  if (!o->nb_stream_maps) {
1816  av_log(mux, AV_LOG_VERBOSE, "No explicit maps, mapping streams automatically...\n");
1817 
1818  /* pick the "best" stream of each type */
1819  for (int i = 0; i < FF_ARRAY_ELEMS(map_func); i++) {
1820  if (!map_func[i] || auto_disable & (1 << i))
1821  continue;
1822  ret = map_func[i](mux, o);
1823  if (ret < 0)
1824  return ret;
1825  }
1826  } else {
1827  av_log(mux, AV_LOG_VERBOSE, "Adding streams from explicit maps...\n");
1828 
1829  for (int i = 0; i < o->nb_stream_maps; i++) {
1830  ret = map_manual(mux, o, &o->stream_maps[i]);
1831  if (ret < 0)
1832  return ret;
1833  }
1834  }
1835 
1836  ret = of_add_attachments(mux, o);
1837  if (ret < 0)
1838  return ret;
1839 
1840  if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
1841  av_dump_format(oc, nb_output_files - 1, oc->url, 1);
1842  av_log(mux, AV_LOG_ERROR, "Output file does not contain any stream\n");
1843  return AVERROR(EINVAL);
1844  }
1845 
1846  return 0;
1847 }
1848 
1849 static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_us)
1850 {
1851  OutputFile *of = &mux->of;
1852  int nb_av_enc = 0, nb_audio_fs = 0, nb_interleaved = 0;
1853  int limit_frames = 0, limit_frames_av_enc = 0;
1854 
1855 #define IS_AV_ENC(ost, type) \
1856  (ost->enc_ctx && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))
1857 #define IS_INTERLEAVED(type) (type != AVMEDIA_TYPE_ATTACHMENT)
1858 
1859  for (int i = 0; i < oc->nb_streams; i++) {
1860  OutputStream *ost = of->streams[i];
1861  MuxStream *ms = ms_from_ost(ost);
1862  enum AVMediaType type = ost->type;
1863 
1864  ost->sq_idx_encode = -1;
1865  ost->sq_idx_mux = -1;
1866 
1867  nb_interleaved += IS_INTERLEAVED(type);
1868  nb_av_enc += IS_AV_ENC(ost, type);
1869  nb_audio_fs += (ost->enc_ctx && type == AVMEDIA_TYPE_AUDIO &&
1870  !(ost->enc_ctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE));
1871 
1872  limit_frames |= ms->max_frames < INT64_MAX;
1873  limit_frames_av_enc |= (ms->max_frames < INT64_MAX) && IS_AV_ENC(ost, type);
1874  }
1875 
1876  if (!((nb_interleaved > 1 && of->shortest) ||
1877  (nb_interleaved > 0 && limit_frames) ||
1878  nb_audio_fs))
1879  return 0;
1880 
1881  /* we use a sync queue before encoding when:
1882  * - 'shortest' is in effect and we have two or more encoded audio/video
1883  * streams
1884  * - at least one encoded audio/video stream is frame-limited, since
1885  * that has similar semantics to 'shortest'
1886  * - at least one audio encoder requires constant frame sizes
1887  */
1888  if ((of->shortest && nb_av_enc > 1) || limit_frames_av_enc || nb_audio_fs) {
1889  of->sq_encode = sq_alloc(SYNC_QUEUE_FRAMES, buf_size_us, mux);
1890  if (!of->sq_encode)
1891  return AVERROR(ENOMEM);
1892 
1893  for (int i = 0; i < oc->nb_streams; i++) {
1894  OutputStream *ost = of->streams[i];
1895  MuxStream *ms = ms_from_ost(ost);
1896  enum AVMediaType type = ost->type;
1897 
1898  if (!IS_AV_ENC(ost, type))
1899  continue;
1900 
1901  ost->sq_idx_encode = sq_add_stream(of->sq_encode,
1902  of->shortest || ms->max_frames < INT64_MAX);
1903  if (ost->sq_idx_encode < 0)
1904  return ost->sq_idx_encode;
1905 
1906  if (ms->max_frames != INT64_MAX)
1907  sq_limit_frames(of->sq_encode, ost->sq_idx_encode, ms->max_frames);
1908  }
1909  }
1910 
1911  /* if there are any additional interleaved streams, then ALL the streams
1912  * are also synchronized before sending them to the muxer */
1913  if (nb_interleaved > nb_av_enc) {
1914  mux->sq_mux = sq_alloc(SYNC_QUEUE_PACKETS, buf_size_us, mux);
1915  if (!mux->sq_mux)
1916  return AVERROR(ENOMEM);
1917 
1918  mux->sq_pkt = av_packet_alloc();
1919  if (!mux->sq_pkt)
1920  return AVERROR(ENOMEM);
1921 
1922  for (int i = 0; i < oc->nb_streams; i++) {
1923  OutputStream *ost = of->streams[i];
1924  MuxStream *ms = ms_from_ost(ost);
1925  enum AVMediaType type = ost->type;
1926 
1927  if (!IS_INTERLEAVED(type))
1928  continue;
1929 
1930  ost->sq_idx_mux = sq_add_stream(mux->sq_mux,
1931  of->shortest || ms->max_frames < INT64_MAX);
1932  if (ost->sq_idx_mux < 0)
1933  return ost->sq_idx_mux;
1934 
1935  if (ms->max_frames != INT64_MAX)
1936  sq_limit_frames(mux->sq_mux, ost->sq_idx_mux, ms->max_frames);
1937  }
1938  }
1939 
1940 #undef IS_AV_ENC
1941 #undef IS_INTERLEAVED
1942 
1943  return 0;
1944 }
1945 
1946 static int of_add_programs(Muxer *mux, const OptionsContext *o)
1947 {
1948  AVFormatContext *oc = mux->fc;
1949  /* process manually set programs */
1950  for (int i = 0; i < o->nb_program; i++) {
1951  AVDictionary *dict = NULL;
1952  const AVDictionaryEntry *e;
1953  AVProgram *program;
1954  int ret, progid = i + 1;
1955 
1956  ret = av_dict_parse_string(&dict, o->program[i].u.str, "=", ":",
1958  if (ret < 0) {
1959  av_log(mux, AV_LOG_ERROR, "Error parsing program specification %s\n",
1960  o->program[i].u.str);
1961  return ret;
1962  }
1963 
1964  e = av_dict_get(dict, "program_num", NULL, 0);
1965  if (e) {
1966  progid = strtol(e->value, NULL, 0);
1967  av_dict_set(&dict, e->key, NULL, 0);
1968  }
1969 
1970  program = av_new_program(oc, progid);
1971  if (!program) {
1972  ret = AVERROR(ENOMEM);
1973  goto fail;
1974  }
1975 
1976  e = av_dict_get(dict, "title", NULL, 0);
1977  if (e) {
1978  av_dict_set(&program->metadata, e->key, e->value, 0);
1979  av_dict_set(&dict, e->key, NULL, 0);
1980  }
1981 
1982  e = NULL;
1983  while (e = av_dict_get(dict, "st", e, 0)) {
1984  int st_num = strtol(e->value, NULL, 0);
1985  av_program_add_stream_index(oc, progid, st_num);
1986  }
1987 
1988  // make sure that nothing but "st" entries are left in the dict
1989  e = NULL;
1990  while (e = av_dict_iterate(dict, e)) {
1991  if (!strcmp(e->key, "st"))
1992  continue;
1993 
1994  av_log(mux, AV_LOG_FATAL, "Unknown program key %s.\n", e->key);
1995  ret = AVERROR(EINVAL);
1996  goto fail;
1997  }
1998 
1999 fail:
2000  av_dict_free(&dict);
2001  if (ret < 0)
2002  return ret;
2003  }
2004 
2005  return 0;
2006 }
2007 
2008 /**
2009  * Parse a metadata specifier passed as 'arg' parameter.
2010  * @param arg metadata string to parse
2011  * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
2012  * @param index for type c/p, chapter/program index is written here
2013  * @param stream_spec for type s, the stream specifier is written here
2014  */
2015 static int parse_meta_type(void *logctx, const char *arg,
2016  char *type, int *index, const char **stream_spec)
2017 {
2018  if (*arg) {
2019  *type = *arg;
2020  switch (*arg) {
2021  case 'g':
2022  break;
2023  case 's':
2024  if (*(++arg) && *arg != ':') {
2025  av_log(logctx, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
2026  return AVERROR(EINVAL);
2027  }
2028  *stream_spec = *arg == ':' ? arg + 1 : "";
2029  break;
2030  case 'c':
2031  case 'p':
2032  if (*(++arg) == ':')
2033  *index = strtol(++arg, NULL, 0);
2034  break;
2035  default:
2036  av_log(logctx, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
2037  return AVERROR(EINVAL);
2038  }
2039  } else
2040  *type = 'g';
2041 
2042  return 0;
2043 }
2044 
2046  const OptionsContext *o)
2047 {
2048  for (int i = 0; i < o->nb_metadata; i++) {
2049  AVDictionary **m;
2050  char type, *val;
2051  const char *stream_spec;
2052  int index = 0, ret = 0;
2053 
2054  val = strchr(o->metadata[i].u.str, '=');
2055  if (!val) {
2056  av_log(of, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2057  o->metadata[i].u.str);
2058  return AVERROR(EINVAL);
2059  }
2060  *val++ = 0;
2061 
2062  ret = parse_meta_type(of, o->metadata[i].specifier, &type, &index, &stream_spec);
2063  if (ret < 0)
2064  return ret;
2065 
2066  if (type == 's') {
2067  for (int j = 0; j < oc->nb_streams; j++) {
2068  OutputStream *ost = of->streams[j];
2069  if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2070 #if FFMPEG_ROTATION_METADATA
2071  if (!strcmp(o->metadata[i].u.str, "rotate")) {
2072  char *tail;
2073  double theta = av_strtod(val, &tail);
2074  if (!*tail) {
2075  ost->rotate_overridden = 1;
2076  ost->rotate_override_value = theta;
2077  }
2078 
2080  "Conversion of a 'rotate' metadata key to a "
2081  "proper display matrix rotation is deprecated. "
2082  "See -display_rotation for setting rotation "
2083  "instead.");
2084  } else {
2085 #endif
2086  av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
2087 #if FFMPEG_ROTATION_METADATA
2088  }
2089 #endif
2090  } else if (ret < 0)
2091  return ret;
2092  }
2093  } else {
2094  switch (type) {
2095  case 'g':
2096  m = &oc->metadata;
2097  break;
2098  case 'c':
2099  if (index < 0 || index >= oc->nb_chapters) {
2100  av_log(of, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
2101  return AVERROR(EINVAL);
2102  }
2103  m = &oc->chapters[index]->metadata;
2104  break;
2105  case 'p':
2106  if (index < 0 || index >= oc->nb_programs) {
2107  av_log(of, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
2108  return AVERROR(EINVAL);
2109  }
2110  m = &oc->programs[index]->metadata;
2111  break;
2112  default:
2113  av_log(of, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
2114  return AVERROR(EINVAL);
2115  }
2116  av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
2117  }
2118  }
2119 
2120  return 0;
2121 }
2122 
2123 static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *os,
2124  int copy_metadata)
2125 {
2126  AVFormatContext *is = ifile->ctx;
2127  AVChapter **tmp;
2128  int i;
2129 
2130  tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
2131  if (!tmp)
2132  return AVERROR(ENOMEM);
2133  os->chapters = tmp;
2134 
2135  for (i = 0; i < is->nb_chapters; i++) {
2136  AVChapter *in_ch = is->chapters[i], *out_ch;
2137  int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2138  int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2139  AV_TIME_BASE_Q, in_ch->time_base);
2140  int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2142 
2143 
2144  if (in_ch->end < ts_off)
2145  continue;
2146  if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2147  break;
2148 
2149  out_ch = av_mallocz(sizeof(AVChapter));
2150  if (!out_ch)
2151  return AVERROR(ENOMEM);
2152 
2153  out_ch->id = in_ch->id;
2154  out_ch->time_base = in_ch->time_base;
2155  out_ch->start = FFMAX(0, in_ch->start - ts_off);
2156  out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2157 
2158  if (copy_metadata)
2159  av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2160 
2161  os->chapters[os->nb_chapters++] = out_ch;
2162  }
2163  return 0;
2164 }
2165 
2166 static int copy_metadata(Muxer *mux, AVFormatContext *ic,
2167  const char *outspec, const char *inspec,
2168  int *metadata_global_manual, int *metadata_streams_manual,
2169  int *metadata_chapters_manual)
2170 {
2171  AVFormatContext *oc = mux->fc;
2172  AVDictionary **meta_in = NULL;
2173  AVDictionary **meta_out = NULL;
2174  int i, ret = 0;
2175  char type_in, type_out;
2176  const char *istream_spec = NULL, *ostream_spec = NULL;
2177  int idx_in = 0, idx_out = 0;
2178 
2179  ret = parse_meta_type(mux, inspec, &type_in, &idx_in, &istream_spec);
2180  if (ret >= 0)
2181  ret = parse_meta_type(mux, outspec, &type_out, &idx_out, &ostream_spec);
2182  if (ret < 0)
2183  return ret;
2184 
2185  if (type_in == 'g' || type_out == 'g' || (!*outspec && !ic))
2186  *metadata_global_manual = 1;
2187  if (type_in == 's' || type_out == 's' || (!*outspec && !ic))
2188  *metadata_streams_manual = 1;
2189  if (type_in == 'c' || type_out == 'c' || (!*outspec && !ic))
2190  *metadata_chapters_manual = 1;
2191 
2192  /* ic is NULL when just disabling automatic mappings */
2193  if (!ic)
2194  return 0;
2195 
2196 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
2197  if ((index) < 0 || (index) >= (nb_elems)) {\
2198  av_log(mux, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
2199  (desc), (index));\
2200  return AVERROR(EINVAL);\
2201  }
2202 
2203 #define SET_DICT(type, meta, context, index)\
2204  switch (type) {\
2205  case 'g':\
2206  meta = &context->metadata;\
2207  break;\
2208  case 'c':\
2209  METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
2210  meta = &context->chapters[index]->metadata;\
2211  break;\
2212  case 'p':\
2213  METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
2214  meta = &context->programs[index]->metadata;\
2215  break;\
2216  case 's':\
2217  break; /* handled separately below */ \
2218  default: av_assert0(0);\
2219  }\
2220 
2221  SET_DICT(type_in, meta_in, ic, idx_in);
2222  SET_DICT(type_out, meta_out, oc, idx_out);
2223 
2224  /* for input streams choose first matching stream */
2225  if (type_in == 's') {
2226  for (i = 0; i < ic->nb_streams; i++) {
2227  if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
2228  meta_in = &ic->streams[i]->metadata;
2229  break;
2230  } else if (ret < 0)
2231  return ret;
2232  }
2233  if (!meta_in) {
2234  av_log(mux, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
2235  return AVERROR(EINVAL);
2236  }
2237  }
2238 
2239  if (type_out == 's') {
2240  for (i = 0; i < oc->nb_streams; i++) {
2241  if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
2242  meta_out = &oc->streams[i]->metadata;
2243  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
2244  } else if (ret < 0)
2245  return ret;
2246  }
2247  } else
2248  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
2249 
2250  return 0;
2251 }
2252 
2253 static int copy_meta(Muxer *mux, const OptionsContext *o)
2254 {
2255  OutputFile *of = &mux->of;
2256  AVFormatContext *oc = mux->fc;
2257  int chapters_input_file = o->chapters_input_file;
2258  int metadata_global_manual = 0;
2259  int metadata_streams_manual = 0;
2260  int metadata_chapters_manual = 0;
2261  int ret;
2262 
2263  /* copy metadata */
2264  for (int i = 0; i < o->nb_metadata_map; i++) {
2265  char *p;
2266  int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2267 
2268  if (in_file_index >= nb_input_files) {
2269  av_log(mux, AV_LOG_FATAL, "Invalid input file index %d while "
2270  "processing metadata maps\n", in_file_index);
2271  return AVERROR(EINVAL);
2272  }
2273  ret = copy_metadata(mux,
2274  in_file_index >= 0 ? input_files[in_file_index]->ctx : NULL,
2275  o->metadata_map[i].specifier, *p ? p + 1 : p,
2276  &metadata_global_manual, &metadata_streams_manual,
2277  &metadata_chapters_manual);
2278  if (ret < 0)
2279  return ret;
2280  }
2281 
2282  /* copy chapters */
2283  if (chapters_input_file >= nb_input_files) {
2284  if (chapters_input_file == INT_MAX) {
2285  /* copy chapters from the first input file that has them*/
2286  chapters_input_file = -1;
2287  for (int i = 0; i < nb_input_files; i++)
2288  if (input_files[i]->ctx->nb_chapters) {
2289  chapters_input_file = i;
2290  break;
2291  }
2292  } else {
2293  av_log(mux, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2294  chapters_input_file);
2295  return AVERROR(EINVAL);
2296  }
2297  }
2298  if (chapters_input_file >= 0)
2299  copy_chapters(input_files[chapters_input_file], of, oc,
2300  !metadata_chapters_manual);
2301 
2302  /* copy global metadata by default */
2303  if (!metadata_global_manual && nb_input_files){
2306  if (of->recording_time != INT64_MAX)
2307  av_dict_set(&oc->metadata, "duration", NULL, 0);
2308  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2309  av_dict_set(&oc->metadata, "company_name", NULL, 0);
2310  av_dict_set(&oc->metadata, "product_name", NULL, 0);
2311  av_dict_set(&oc->metadata, "product_version", NULL, 0);
2312  }
2313  if (!metadata_streams_manual)
2314  for (int i = 0; i < of->nb_streams; i++) {
2315  OutputStream *ost = of->streams[i];
2316 
2317  if (!ost->ist) /* this is true e.g. for attached files */
2318  continue;
2320  if (ost->enc_ctx) {
2321  av_dict_set(&ost->st->metadata, "encoder", NULL, 0);
2322  }
2323  }
2324 
2325  return 0;
2326 }
2327 
2328 static int set_dispositions(Muxer *mux, const OptionsContext *o)
2329 {
2330  OutputFile *of = &mux->of;
2331  AVFormatContext *ctx = mux->fc;
2332 
2333  // indexed by type+1, because AVMEDIA_TYPE_UNKNOWN=-1
2334  int nb_streams[AVMEDIA_TYPE_NB + 1] = { 0 };
2335  int have_default[AVMEDIA_TYPE_NB + 1] = { 0 };
2336  int have_manual = 0;
2337  int ret = 0;
2338 
2339  const char **dispositions;
2340 
2341  dispositions = av_calloc(ctx->nb_streams, sizeof(*dispositions));
2342  if (!dispositions)
2343  return AVERROR(ENOMEM);
2344 
2345  // first, copy the input dispositions
2346  for (int i = 0; i < ctx->nb_streams; i++) {
2347  OutputStream *ost = of->streams[i];
2348 
2349  nb_streams[ost->type + 1]++;
2350 
2351  MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st);
2352 
2353  have_manual |= !!dispositions[i];
2354 
2355  if (ost->ist) {
2356  ost->st->disposition = ost->ist->st->disposition;
2357 
2359  have_default[ost->type + 1] = 1;
2360  }
2361  }
2362 
2363  if (have_manual) {
2364  // process manually set dispositions - they override the above copy
2365  for (int i = 0; i < ctx->nb_streams; i++) {
2366  OutputStream *ost = of->streams[i];
2367  const char *disp = dispositions[i];
2368 
2369  if (!disp)
2370  continue;
2371 
2372  ret = av_opt_set(ost->st, "disposition", disp, 0);
2373  if (ret < 0)
2374  goto finish;
2375  }
2376  } else {
2377  // For each media type with more than one stream, find a suitable stream to
2378  // mark as default, unless one is already marked default.
2379  // "Suitable" means the first of that type, skipping attached pictures.
2380  for (int i = 0; i < ctx->nb_streams; i++) {
2381  OutputStream *ost = of->streams[i];
2382  enum AVMediaType type = ost->type;
2383 
2384  if (nb_streams[type + 1] < 2 || have_default[type + 1] ||
2386  continue;
2387 
2389  have_default[type + 1] = 1;
2390  }
2391  }
2392 
2393 finish:
2394  av_freep(&dispositions);
2395 
2396  return ret;
2397 }
2398 
2399 const char *const forced_keyframes_const_names[] = {
2400  "n",
2401  "n_forced",
2402  "prev_forced_n",
2403  "prev_forced_t",
2404  "t",
2405  NULL
2406 };
2407 
2408 static int compare_int64(const void *a, const void *b)
2409 {
2410  return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
2411 }
2412 
2414  const Muxer *mux, const char *spec)
2415 {
2416  const char *p;
2417  int n = 1, i, ret, size, index = 0;
2418  int64_t t, *pts;
2419 
2420  for (p = spec; *p; p++)
2421  if (*p == ',')
2422  n++;
2423  size = n;
2424  pts = av_malloc_array(size, sizeof(*pts));
2425  if (!pts)
2426  return AVERROR(ENOMEM);
2427 
2428  p = spec;
2429  for (i = 0; i < n; i++) {
2430  char *next = strchr(p, ',');
2431 
2432  if (next)
2433  *next++ = 0;
2434 
2435  if (strstr(p, "chapters") == p) {
2436  AVChapter * const *ch = mux->fc->chapters;
2437  unsigned int nb_ch = mux->fc->nb_chapters;
2438  int j;
2439 
2440  if (nb_ch > INT_MAX - size ||
2441  !(pts = av_realloc_f(pts, size += nb_ch - 1,
2442  sizeof(*pts))))
2443  return AVERROR(ENOMEM);
2444 
2445  if (p[8]) {
2446  ret = av_parse_time(&t, p + 8, 1);
2447  if (ret < 0) {
2449  "Invalid chapter time offset: %s\n", p + 8);
2450  goto fail;
2451  }
2452  } else
2453  t = 0;
2454 
2455  for (j = 0; j < nb_ch; j++) {
2456  const AVChapter *c = ch[j];
2457  av_assert1(index < size);
2458  pts[index++] = av_rescale_q(c->start, c->time_base,
2459  AV_TIME_BASE_Q) + t;
2460  }
2461 
2462  } else {
2463  av_assert1(index < size);
2464  ret = av_parse_time(&t, p, 1);
2465  if (ret < 0) {
2466  av_log(log, AV_LOG_ERROR, "Invalid keyframe time: %s\n", p);
2467  goto fail;
2468  }
2469 
2470  pts[index++] = t;
2471  }
2472 
2473  p = next;
2474  }
2475 
2476  av_assert0(index == size);
2477  qsort(pts, size, sizeof(*pts), compare_int64);
2478  kf->nb_pts = size;
2479  kf->pts = pts;
2480 
2481  return 0;
2482 fail:
2483  av_freep(&pts);
2484  return ret;
2485 }
2486 
2488 {
2489  for (int i = 0; i < mux->of.nb_streams; i++) {
2490  OutputStream *ost = mux->of.streams[i];
2491  const char *forced_keyframes = NULL;
2492 
2493  MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_keyframes, mux->fc, ost->st);
2494 
2495  if (!(ost->type == AVMEDIA_TYPE_VIDEO &&
2496  ost->enc_ctx && forced_keyframes))
2497  continue;
2498 
2499  if (!strncmp(forced_keyframes, "expr:", 5)) {
2500  int ret = av_expr_parse(&ost->kf.pexpr, forced_keyframes + 5,
2502  if (ret < 0) {
2504  "Invalid force_key_frames expression '%s'\n", forced_keyframes + 5);
2505  return ret;
2506  }
2507  ost->kf.expr_const_values[FKF_N] = 0;
2508  ost->kf.expr_const_values[FKF_N_FORCED] = 0;
2509  ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN;
2510  ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN;
2511 
2512  // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
2513  // parse it only for static kf timings
2514  } else if (!strcmp(forced_keyframes, "source")) {
2515  ost->kf.type = KF_FORCE_SOURCE;
2516 #if FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP
2517  } else if (!strcmp(forced_keyframes, "source_no_drop")) {
2518  av_log(ost, AV_LOG_WARNING, "The 'source_no_drop' value for "
2519  "-force_key_frames is deprecated, use just 'source'\n");
2520  ost->kf.type = KF_FORCE_SOURCE;
2521 #endif
2522  } else {
2523  int ret = parse_forced_key_frames(ost, &ost->kf, mux, forced_keyframes);
2524  if (ret < 0)
2525  return ret;
2526  }
2527  }
2528 
2529  return 0;
2530 }
2531 
2532 static int validate_enc_avopt(Muxer *mux, const AVDictionary *codec_avopt)
2533 {
2534  const AVClass *class = avcodec_get_class();
2535  const AVClass *fclass = avformat_get_class();
2536  const OutputFile *of = &mux->of;
2537 
2538  AVDictionary *unused_opts;
2539  const AVDictionaryEntry *e;
2540 
2541  unused_opts = strip_specifiers(codec_avopt);
2542  for (int i = 0; i < of->nb_streams; i++) {
2543  e = NULL;
2544  while ((e = av_dict_iterate(of->streams[i]->encoder_opts, e)))
2545  av_dict_set(&unused_opts, e->key, NULL, 0);
2546  }
2547 
2548  e = NULL;
2549  while ((e = av_dict_iterate(unused_opts, e))) {
2550  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2552  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2554  if (!option || foption)
2555  continue;
2556 
2557  if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2558  av_log(mux, AV_LOG_ERROR, "Codec AVOption %s (%s) is not an "
2559  "encoding option.\n", e->key, option->help ? option->help : "");
2560  return AVERROR(EINVAL);
2561  }
2562 
2563  // gop_timecode is injected by generic code but not always used
2564  if (!strcmp(e->key, "gop_timecode"))
2565  continue;
2566 
2567  av_log(mux, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
2568  "for any stream. The most likely reason is either wrong type "
2569  "(e.g. a video option with no video streams) or that it is a "
2570  "private option of some encoder which was not actually used for "
2571  "any stream.\n", e->key, option->help ? option->help : "");
2572  }
2573  av_dict_free(&unused_opts);
2574 
2575  return 0;
2576 }
2577 
2579 {
2580  int ret = 0;
2581 
2582  if (ost->enc_ctx) {
2583  ret = enc_open(ost, NULL);
2584  if (ret < 0)
2585  return ret;
2586  } else {
2587  ret = of_stream_init(output_files[ost->file_index], ost);
2588  if (ret < 0)
2589  return ret;
2590  }
2591 
2592  return ret;
2593 }
2594 
2595 static const char *output_file_item_name(void *obj)
2596 {
2597  const Muxer *mux = obj;
2598 
2599  return mux->log_name;
2600 }
2601 
2602 static const AVClass output_file_class = {
2603  .class_name = "OutputFile",
2604  .version = LIBAVUTIL_VERSION_INT,
2605  .item_name = output_file_item_name,
2606  .category = AV_CLASS_CATEGORY_MUXER,
2607 };
2608 
2609 static Muxer *mux_alloc(void)
2610 {
2611  Muxer *mux = allocate_array_elem(&output_files, sizeof(*mux), &nb_output_files);
2612 
2613  if (!mux)
2614  return NULL;
2615 
2616  mux->of.class = &output_file_class;
2617  mux->of.index = nb_output_files - 1;
2618 
2619  snprintf(mux->log_name, sizeof(mux->log_name), "out#%d", mux->of.index);
2620 
2621  return mux;
2622 }
2623 
2624 int of_open(const OptionsContext *o, const char *filename)
2625 {
2626  Muxer *mux;
2627  AVFormatContext *oc;
2628  int err;
2629  OutputFile *of;
2630 
2631  int64_t recording_time = o->recording_time;
2632  int64_t stop_time = o->stop_time;
2633 
2634  mux = mux_alloc();
2635  if (!mux)
2636  return AVERROR(ENOMEM);
2637 
2638  of = &mux->of;
2639 
2640  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
2641  stop_time = INT64_MAX;
2642  av_log(mux, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2643  }
2644 
2645  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
2646  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2647  if (stop_time <= start_time) {
2648  av_log(mux, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2649  return AVERROR(EINVAL);
2650  } else {
2651  recording_time = stop_time - start_time;
2652  }
2653  }
2654 
2655  of->recording_time = recording_time;
2656  of->start_time = o->start_time;
2657  of->shortest = o->shortest;
2658 
2659  mux->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
2660  mux->limit_filesize = o->limit_filesize;
2661  av_dict_copy(&mux->opts, o->g->format_opts, 0);
2662 
2663  if (!strcmp(filename, "-"))
2664  filename = "pipe:";
2665 
2666  err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2667  if (!oc) {
2668  av_log(mux, AV_LOG_FATAL, "Error initializing the muxer for %s: %s\n",
2669  filename, av_err2str(err));
2670  return err;
2671  }
2672  mux->fc = oc;
2673 
2674  av_strlcat(mux->log_name, "/", sizeof(mux->log_name));
2675  av_strlcat(mux->log_name, oc->oformat->name, sizeof(mux->log_name));
2676 
2677  if (strcmp(oc->oformat->name, "rtp"))
2678  want_sdp = 0;
2679 
2680  of->format = oc->oformat;
2681  if (recording_time != INT64_MAX)
2682  oc->duration = recording_time;
2683 
2684  oc->interrupt_callback = int_cb;
2685 
2686  if (o->bitexact) {
2687  oc->flags |= AVFMT_FLAG_BITEXACT;
2688  of->bitexact = 1;
2689  } else {
2690  of->bitexact = check_opt_bitexact(oc, mux->opts, "fflags",
2692  }
2693 
2694  /* create all output streams for this file */
2695  err = create_streams(mux, o);
2696  if (err < 0)
2697  return err;
2698 
2699  /* check if all codec options have been used */
2700  err = validate_enc_avopt(mux, o->g->codec_opts);
2701  if (err < 0)
2702  return err;
2703 
2704  /* check filename in case of an image number is expected */
2706  av_log(mux, AV_LOG_FATAL,
2707  "Output filename '%s' does not contain a numeric pattern like "
2708  "'%%d', which is required by output format '%s'.\n",
2709  oc->url, oc->oformat->name);
2710  return AVERROR(EINVAL);
2711  }
2712 
2713  if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2714  /* test if it already exists to avoid losing precious files */
2715  err = assert_file_overwrite(filename);
2716  if (err < 0)
2717  return err;
2718 
2719  /* open the file */
2720  if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2721  &oc->interrupt_callback,
2722  &mux->opts)) < 0) {
2723  av_log(mux, AV_LOG_FATAL, "Error opening output %s: %s\n",
2724  filename, av_err2str(err));
2725  return err;
2726  }
2727  } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename)) {
2728  err = assert_file_overwrite(filename);
2729  if (err < 0)
2730  return err;
2731  }
2732 
2733  if (o->mux_preload) {
2734  av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2735  }
2736  oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2737 
2738  /* copy metadata and chapters from input files */
2739  err = copy_meta(mux, o);
2740  if (err < 0)
2741  return err;
2742 
2743  err = of_add_programs(mux, o);
2744  if (err < 0)
2745  return err;
2746 
2747  err = of_add_metadata(of, oc, o);
2748  if (err < 0)
2749  return err;
2750 
2751  err = set_dispositions(mux, o);
2752  if (err < 0) {
2753  av_log(mux, AV_LOG_FATAL, "Error setting output stream dispositions\n");
2754  return err;
2755  }
2756 
2757  // parse forced keyframe specifications;
2758  // must be done after chapters are created
2759  err = process_forced_keyframes(mux, o);
2760  if (err < 0) {
2761  av_log(mux, AV_LOG_FATAL, "Error processing forced keyframes\n");
2762  return err;
2763  }
2764 
2766  if (err < 0) {
2767  av_log(mux, AV_LOG_FATAL, "Error setting up output sync queues\n");
2768  return err;
2769  }
2770 
2771  of->url = filename;
2772 
2773  /* initialize stream copy and subtitle/data streams.
2774  * Encoded AVFrame based streams will get initialized when the first AVFrame
2775  * is received in do_video_out
2776  */
2777  for (int i = 0; i < of->nb_streams; i++) {
2778  OutputStream *ost = of->streams[i];
2779 
2780  if (ost->filter)
2781  continue;
2782 
2784  if (err < 0)
2785  return err;
2786  }
2787 
2788  /* write the header for files with no streams */
2789  if (of->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) {
2790  int ret = mux_check_init(mux);
2791  if (ret < 0)
2792  return ret;
2793  }
2794 
2795  return 0;
2796 }
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:502
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:1625
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
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:417
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:173
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:294
FKF_PREV_FORCED_T
@ FKF_PREV_FORCED_T
Definition: ffmpeg.h:439
VSYNC_VFR
@ VSYNC_VFR
Definition: ffmpeg.h:67
ms_from_ost
static MuxStream * ms_from_ost(OutputStream *ost)
Definition: ffmpeg_mux.h:118
AVOutputFormat::name
const char * name
Definition: avformat.h:511
AVChapter::metadata
AVDictionary * metadata
Definition: avformat.h:1078
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:51
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:997
ENC_STATS_PTS
@ ENC_STATS_PTS
Definition: ffmpeg.h:455
ENC_STATS_FRAME_NUM_IN
@ ENC_STATS_FRAME_NUM_IN
Definition: ffmpeg.h:452
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1064
FKF_PREV_FORCED_N
@ FKF_PREV_FORCED_N
Definition: ffmpeg.h:438
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:1332
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
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:772
ENC_STATS_DTS
@ ENC_STATS_DTS
Definition: ffmpeg.h:459
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
KeyframeForceCtx::nb_pts
int nb_pts
Definition: ffmpeg.h:503
IS_INTERLEAVED
#define IS_INTERLEAVED(type)
AV_CODEC_FLAG_QSCALE
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:220
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:332
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:190
ENC_STATS_AVG_BITRATE
@ ENC_STATS_AVG_BITRATE
Definition: ffmpeg.h:465
AVCodecContext::intra_matrix
uint16_t * intra_matrix
custom intra quantization matrix Must be allocated with the av_malloc() family of functions,...
Definition: avcodec.h:937
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:719
OptionsContext::nb_attachments
int nb_attachments
Definition: ffmpeg.h:168
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:1183
OptionsContext::mux_max_delay
float mux_max_delay
Definition: ffmpeg.h:176
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:342
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:448
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:183
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:520
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:312
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:930
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:1077
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:203
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:1107
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1283
IS_AV_ENC
#define IS_AV_ENC(ost, type)
OptionsContext::bitexact
int bitexact
Definition: ffmpeg.h:179
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:59
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:312
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:322
MuxStream::copy_prior_start
int copy_prior_start
Definition: ffmpeg_mux.h:85
OptionsContext::format
const char * format
Definition: ffmpeg.h:117
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:2413
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
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:2328
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:523
MuxStream::stream_duration_tb
AVRational stream_duration_tb
Definition: ffmpeg_mux.h:76
ENC_STATS_TIMEBASE_IN
@ ENC_STATS_TIMEBASE_IN
Definition: ffmpeg.h:454
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:334
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:324
OptionsContext::chapters_input_file
int chapters_input_file
Definition: ffmpeg.h:170
AVPacketSideData::size
size_t size
Definition: packet.h:344
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:1381
map_auto_subtitle
static int map_auto_subtitle(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1563
enc_open
int enc_open(OutputStream *ost, const AVFrame *frame)
Definition: ffmpeg_enc.c:168
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:450
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:111
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2107
mux_alloc
static Muxer * mux_alloc(void)
Definition: ffmpeg_mux_init.c:2609
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:2253
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:521
AVChapter
Definition: avformat.h:1074
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:1849
OptionsContext
Definition: ffmpeg.h:110
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:281
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:900
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:165
InputFile
Definition: ffmpeg.h:399
FFDIFFSIGN
#define FFDIFFSIGN(x, y)
Comparator.
Definition: macros.h:45
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:172
OptionsContext::nb_stream_maps
int nb_stream_maps
Definition: ffmpeg.h:162
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:182
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:204
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:98
AVFormatContext::metadata
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1343
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:457
mask
static const uint16_t mask[17]
Definition: lzw.c:38
OptionsContext::nb_program
int nb_program
Definition: ffmpeg.h:264
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:68
EncStats::components
EncStatsComponent * components
Definition: ffmpeg.h:476
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:1077
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:1334
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:318
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:353
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:1233
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:131
output_file_class
static const AVClass output_file_class
Definition: ffmpeg_mux_init.c:2602
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1282
RcOverride
Definition: avcodec.h:200
AVFormatContext::chapters
AVChapter ** chapters
Definition: avformat.h:1333
ENC_STATS_FILE_IDX
@ ENC_STATS_FILE_IDX
Definition: ffmpeg.h:449
AVDictionaryEntry::key
char * key
Definition: dict.h:90
frame_size
int frame_size
Definition: mxfenc.c:2311
OptionsContext::limit_filesize
int64_t limit_filesize
Definition: ffmpeg.h:174
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:121
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:399
OutputFilter::linklabel
uint8_t * linklabel
Definition: ffmpeg.h:299
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:464
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:2045
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:637
OutputFilter::ost
struct OutputStream * ost
Definition: ffmpeg.h:293
AVPacketSideData::data
uint8_t * data
Definition: packet.h:343
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:201
channels
channels
Definition: aptx.h:31
nb_streams
static int nb_streams
Definition: ffprobe.c:328
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:178
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:536
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:389
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
AVCodecParameters::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: codec_par.h:228
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:451
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:320
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:114
OutputStream::encoder_opts
AVDictionary * encoder_opts
Definition: ffmpeg.h:576
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:219
AVFormatContext
Format I/O context.
Definition: avformat.h:1115
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:2532
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:864
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
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:295
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:2015
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:880
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:312
InputStream::st
AVStream * st
Definition: ffmpeg.h:330
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:1466
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:456
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:345
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:1157
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:475
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:921
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:191
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:247
Muxer::log_name
char log_name[32]
Definition: ffmpeg_mux.h:93
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:206
OutputFile::index
int index
Definition: ffmpeg.h:618
OptionsContext::program
SpecifierOpt * program
Definition: ffmpeg.h:263
OutputFile::class
const AVClass * class
Definition: ffmpeg.h:616
ENC_STATS_PTS_TIME_IN
@ ENC_STATS_PTS_TIME_IN
Definition: ffmpeg.h:458
FilterGraph::nb_outputs
int nb_outputs
Definition: ffmpeg.h:319
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:2166
of_open
int of_open(const OptionsContext *o, const char *filename)
Definition: ffmpeg_mux_init.c:2624
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:228
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:342
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:310
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1171
ENC_TIME_BASE_DEMUX
@ ENC_TIME_BASE_DEMUX
Definition: ffmpeg.h:73
of_add_programs
static int of_add_programs(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1946
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:530
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:465
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:1277
OptionsContext::thread_queue_size
int thread_queue_size
Definition: ffmpeg.h:143
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:327
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:1198
EncStatsType
EncStatsType
Definition: ffmpeg.h:447
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1080
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
StreamMap
Definition: ffmpeg.h:90
ENC_STATS_NB_SAMPLES
@ ENC_STATS_NB_SAMPLES
Definition: ffmpeg.h:462
init_output_stream_nofilter
static int init_output_stream_nofilter(OutputStream *ost)
Definition: ffmpeg_mux_init.c:2578
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:984
OptionsContext::streamid
AVDictionary * streamid
Definition: ffmpeg.h:187
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:755
opt_name_pass
static const char *const opt_name_pass[]
Definition: ffmpeg_mux_init.c:79
OutputStream::type
enum AVMediaType type
Definition: ffmpeg.h:517
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:1881
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:919
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:310
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:70
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:189
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:490
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:451
KeyframeForceCtx
Definition: ffmpeg.h:496
OutputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:301
opt_name_autoscale
static const char *const opt_name_autoscale[]
Definition: ffmpeg_mux_init.c:52
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:56
flag
#define flag(name)
Definition: cbs_av1.c:466
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:417
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:412
bprint.h
map_auto_data
static int map_auto_data(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1602
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:255
RcOverride::end_frame
int end_frame
Definition: avcodec.h:202
OptionsContext::metadata_map
SpecifierOpt * metadata_map
Definition: ffmpeg.h:227
AVChapter::id
int64_t id
unique ID to identify the chapter
Definition: avformat.h:1075
MuxStream::stats
EncStats stats
Definition: ffmpeg_mux.h:51
OptionsContext::stream_maps
StreamMap * stream_maps
Definition: ffmpeg.h:161
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:122
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:178
VSYNC_CFR
@ VSYNC_CFR
Definition: ffmpeg.h:66
OptionsContext::shortest_buf_duration
float shortest_buf_duration
Definition: ffmpeg.h:177
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AVProgram::metadata
AVDictionary * metadata
Definition: avformat.h:1045
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:407
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVFormatContext::max_delay
int max_delay
Definition: avformat.h:1227
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:1039
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:450
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:129
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:346
AVCodecContext::height
int height
Definition: avcodec.h:621
fmt_in_list
static int fmt_in_list(const int *formats, int format)
Definition: ffmpeg_mux_init.c:512
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:223
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:658
ENC_STATS_SAMPLE_NUM
@ ENC_STATS_SAMPLE_NUM
Definition: ffmpeg.h:461
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:910
tag
uint32_t tag
Definition: movenc.c:1737
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:853
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1250
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:841
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:1134
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:2595
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:164
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:423
avformat.h
dict.h
av_packet_side_data_new
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
Definition: avpacket.c:700
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:192
of_add_attachments
static int of_add_attachments(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1700
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:441
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:847
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:677
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:957
OptionsContext::mux_preload
float mux_preload
Definition: ffmpeg.h:175
ist_output_add
int ist_output_add(InputStream *ist, OutputStream *ost)
Definition: ffmpeg_demux.c:853
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:181
ofilter_bind_ost
int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
Definition: ffmpeg_filter.c:665
AVOutputFormat::video_codec
enum AVCodecID video_codec
default video codec
Definition: avformat.h:522
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1007
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:1217
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:416
VSYNC_AUTO
@ VSYNC_AUTO
Definition: ffmpeg.h:64
OutputFilter
Definition: ffmpeg.h:292
map_auto_audio
static int map_auto_audio(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1519
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:519
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:338
ffmpeg_mux.h
avcodec_parameters_from_context
int avcodec_parameters_from_context(struct AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:137
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:328
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:2408
FKF_N_FORCED
@ FKF_N_FORCED
Definition: ffmpeg.h:437
AVDictionaryEntry
Definition: dict.h:89
OptionsContext::attachments
const char ** attachments
Definition: ffmpeg.h:167
ENC_TIME_BASE_FILTER
@ ENC_TIME_BASE_FILTER
Definition: ffmpeg.h:74
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:55
AVPacket
This structure stores compressed data.
Definition: packet.h:468
audio_disable
static int audio_disable
Definition: ffplay.c:316
EncStatsComponent
Definition: ffmpeg.h:468
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:946
cmdutils.h
AVCodecContext::rc_override_count
int rc_override_count
ratecontrol override, see RcOverride
Definition: avcodec.h:1276
InputFile::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:410
file_read
char * file_read(const char *filename)
Definition: ffmpeg_opt.c:750
EncStats::nb_components
int nb_components
Definition: ffmpeg.h:477
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:184
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:130
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
int32_t
int32_t
Definition: audioconvert.c:56
ENC_STATS_PKT_SIZE
@ ENC_STATS_PKT_SIZE
Definition: ffmpeg.h:463
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:2399
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:2487
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:424
FKF_N
@ FKF_N
Definition: ffmpeg.h:436
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:460
AVChapter::time_base
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1076
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:368
of_stream_init
int of_stream_init(OutputFile *of, OutputStream *ost)
Definition: ffmpeg_mux.c:671
VSYNC_PASSTHROUGH
@ VSYNC_PASSTHROUGH
Definition: ffmpeg.h:65
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:479
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:2123
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:453
create_streams
static int create_streams(Muxer *mux, const OptionsContext *o)
Definition: ffmpeg_mux_init.c:1772
MuxStream::stream_duration
int64_t stream_duration
Definition: ffmpeg_mux.h:75
OutputStream::class
const AVClass * class
Definition: ffmpeg.h:515
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:306