FFmpeg
ffmpeg_opt.c
Go to the documentation of this file.
1 /*
2  * ffmpeg option parsing
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 "config.h"
22 
23 #include <stdint.h>
24 
25 #if HAVE_SYS_RESOURCE_H
26 #include <sys/time.h>
27 #include <sys/resource.h>
28 #endif
29 
30 #include "ffmpeg.h"
31 #include "fopen_utf8.h"
32 #include "cmdutils.h"
33 #include "opt_common.h"
34 
35 #include "libavformat/avformat.h"
36 
37 #include "libavcodec/avcodec.h"
38 #include "libavcodec/bsf.h"
39 
40 #include "libavfilter/avfilter.h"
41 
42 #include "libavutil/avassert.h"
43 #include "libavutil/avstring.h"
44 #include "libavutil/avutil.h"
45 #include "libavutil/bprint.h"
47 #include "libavutil/intreadwrite.h"
48 #include "libavutil/fifo.h"
49 #include "libavutil/mathematics.h"
50 #include "libavutil/opt.h"
51 #include "libavutil/parseutils.h"
52 #include "libavutil/pixdesc.h"
53 #include "libavutil/pixfmt.h"
54 
55 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
56 
57 #define SPECIFIER_OPT_FMT_str "%s"
58 #define SPECIFIER_OPT_FMT_i "%i"
59 #define SPECIFIER_OPT_FMT_i64 "%"PRId64
60 #define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
61 #define SPECIFIER_OPT_FMT_f "%f"
62 #define SPECIFIER_OPT_FMT_dbl "%lf"
63 
64 static const char *const opt_name_codec_names[] = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL};
65 static const char *const opt_name_audio_channels[] = {"ac", NULL};
66 static const char *const opt_name_audio_ch_layouts[] = {"channel_layout", "ch_layout", NULL};
67 static const char *const opt_name_audio_sample_rate[] = {"ar", NULL};
68 static const char *const opt_name_frame_rates[] = {"r", NULL};
69 static const char *const opt_name_max_frame_rates[] = {"fpsmax", NULL};
70 static const char *const opt_name_frame_sizes[] = {"s", NULL};
71 static const char *const opt_name_frame_pix_fmts[] = {"pix_fmt", NULL};
72 static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
73 static const char *const opt_name_hwaccels[] = {"hwaccel", NULL};
74 static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL};
75 static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL};
76 static const char *const opt_name_autorotate[] = {"autorotate", NULL};
77 static const char *const opt_name_autoscale[] = {"autoscale", NULL};
78 static const char *const opt_name_max_frames[] = {"frames", "aframes", "vframes", "dframes", NULL};
79 static const char *const opt_name_bitstream_filters[] = {"bsf", "absf", "vbsf", NULL};
80 static const char *const opt_name_codec_tags[] = {"tag", "atag", "vtag", "stag", NULL};
81 static const char *const opt_name_sample_fmts[] = {"sample_fmt", NULL};
82 static const char *const opt_name_qscale[] = {"q", "qscale", NULL};
83 static const char *const opt_name_forced_key_frames[] = {"forced_key_frames", NULL};
84 static const char *const opt_name_force_fps[] = {"force_fps", NULL};
85 static const char *const opt_name_frame_aspect_ratios[] = {"aspect", NULL};
86 static const char *const opt_name_rc_overrides[] = {"rc_override", NULL};
87 static const char *const opt_name_intra_matrices[] = {"intra_matrix", NULL};
88 static const char *const opt_name_inter_matrices[] = {"inter_matrix", NULL};
89 static const char *const opt_name_chroma_intra_matrices[] = {"chroma_intra_matrix", NULL};
90 static const char *const opt_name_top_field_first[] = {"top", NULL};
91 static const char *const opt_name_presets[] = {"pre", "apre", "vpre", "spre", NULL};
92 static const char *const opt_name_copy_initial_nonkeyframes[] = {"copyinkf", NULL};
93 static const char *const opt_name_copy_prior_start[] = {"copypriorss", NULL};
94 static const char *const opt_name_filters[] = {"filter", "af", "vf", NULL};
95 static const char *const opt_name_filter_scripts[] = {"filter_script", NULL};
96 static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL};
97 static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL};
98 static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL};
99 static const char *const opt_name_pass[] = {"pass", NULL};
100 static const char *const opt_name_passlogfiles[] = {"passlogfile", NULL};
101 static const char *const opt_name_max_muxing_queue_size[] = {"max_muxing_queue_size", NULL};
102 static const char *const opt_name_muxing_queue_data_threshold[] = {"muxing_queue_data_threshold", NULL};
103 static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL};
104 static const char *const opt_name_apad[] = {"apad", NULL};
105 static const char *const opt_name_discard[] = {"discard", NULL};
106 static const char *const opt_name_disposition[] = {"disposition", NULL};
107 static const char *const opt_name_time_bases[] = {"time_base", NULL};
108 static const char *const opt_name_enc_time_bases[] = {"enc_time_base", NULL};
109 static const char *const opt_name_bits_per_raw_sample[] = {"bits_per_raw_sample", NULL};
110 
111 #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
112 {\
113  char namestr[128] = "";\
114  const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
115  for (i = 0; opt_name_##name[i]; i++)\
116  av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[i], opt_name_##name[i+1] ? (opt_name_##name[i+2] ? ", " : " or ") : "");\
117  av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
118  namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\
119 }
120 
121 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
122 {\
123  int i, ret, matches = 0;\
124  SpecifierOpt *so;\
125  for (i = 0; i < o->nb_ ## name; i++) {\
126  char *spec = o->name[i].specifier;\
127  if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\
128  outvar = o->name[i].u.type;\
129  so = &o->name[i];\
130  matches++;\
131  } else if (ret < 0)\
132  exit_program(1);\
133  }\
134  if (matches > 1)\
135  WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
136 }
137 
138 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
139 {\
140  int i;\
141  for (i = 0; i < o->nb_ ## name; i++) {\
142  char *spec = o->name[i].specifier;\
143  if (!strcmp(spec, mediatype))\
144  outvar = o->name[i].u.type;\
145  }\
146 }
147 
149 
152 
155 float dts_error_threshold = 3600*30;
156 
157 int audio_volume = 256;
161 int do_benchmark = 0;
163 int do_hex_dump = 0;
164 int do_pkt_dump = 0;
165 int copy_ts = 0;
167 int copy_tb = -1;
168 int debug_ts = 0;
171 int print_stats = -1;
172 int qp_hist = 0;
174 float max_error_rate = 2.0/3;
179 int64_t stats_period = 500000;
180 
181 
182 static int file_overwrite = 0;
183 static int no_file_overwrite = 0;
184 static int do_psnr = 0;
186 static int ignore_unknown_streams = 0;
187 static int copy_unknown_streams = 0;
188 static int recast_media = 0;
189 static int find_stream_info = 1;
190 
192 {
193  const OptionDef *po = options;
194  int i;
195 
196  /* all OPT_SPEC and OPT_STRING can be freed in generic way */
197  while (po->name) {
198  void *dst = (uint8_t*)o + po->u.off;
199 
200  if (po->flags & OPT_SPEC) {
201  SpecifierOpt **so = dst;
202  int i, *count = (int*)(so + 1);
203  for (i = 0; i < *count; i++) {
204  av_freep(&(*so)[i].specifier);
205  if (po->flags & OPT_STRING)
206  av_freep(&(*so)[i].u.str);
207  }
208  av_freep(so);
209  *count = 0;
210  } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
211  av_freep(dst);
212  po++;
213  }
214 
215  for (i = 0; i < o->nb_stream_maps; i++)
217  av_freep(&o->stream_maps);
219  av_freep(&o->streamid_map);
220  av_freep(&o->attachments);
221 }
222 
224 {
225  memset(o, 0, sizeof(*o));
226 
227  o->stop_time = INT64_MAX;
228  o->mux_max_delay = 0.7;
231  o->recording_time = INT64_MAX;
232  o->limit_filesize = UINT64_MAX;
233  o->chapters_input_file = INT_MAX;
234  o->accurate_seek = 1;
235  o->thread_queue_size = -1;
236 }
237 
238 static int show_hwaccels(void *optctx, const char *opt, const char *arg)
239 {
241 
242  printf("Hardware acceleration methods:\n");
243  while ((type = av_hwdevice_iterate_types(type)) !=
246  printf("\n");
247  return 0;
248 }
249 
250 /* return a copy of the input with the stream specifiers removed from the keys */
252 {
253  const AVDictionaryEntry *e = NULL;
254  AVDictionary *ret = NULL;
255 
256  while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
257  char *p = strchr(e->key, ':');
258 
259  if (p)
260  *p = 0;
261  av_dict_set(&ret, e->key, e->value, 0);
262  if (p)
263  *p = ':';
264  }
265  return ret;
266 }
267 
268 static int opt_filter_threads(void *optctx, const char *opt, const char *arg)
269 {
272  return 0;
273 }
274 
275 static int opt_abort_on(void *optctx, const char *opt, const char *arg)
276 {
277  static const AVOption opts[] = {
278  { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
279  { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
280  { "empty_output_stream", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM }, .unit = "flags" },
281  { NULL },
282  };
283  static const AVClass class = {
284  .class_name = "",
285  .item_name = av_default_item_name,
286  .option = opts,
287  .version = LIBAVUTIL_VERSION_INT,
288  };
289  const AVClass *pclass = &class;
290 
291  return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
292 }
293 
294 static int opt_stats_period(void *optctx, const char *opt, const char *arg)
295 {
296  int64_t user_stats_period = parse_time_or_die(opt, arg, 1);
297 
298  if (user_stats_period <= 0) {
299  av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg);
300  return AVERROR(EINVAL);
301  }
302 
303  stats_period = user_stats_period;
304  av_log(NULL, AV_LOG_INFO, "ffmpeg stats and -progress period set to %s.\n", arg);
305 
306  return 0;
307 }
308 
309 static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
310 {
311  OptionsContext *o = optctx;
312  return parse_option(o, "codec:a", arg, options);
313 }
314 
315 static int opt_video_codec(void *optctx, const char *opt, const char *arg)
316 {
317  OptionsContext *o = optctx;
318  return parse_option(o, "codec:v", arg, options);
319 }
320 
321 static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
322 {
323  OptionsContext *o = optctx;
324  return parse_option(o, "codec:s", arg, options);
325 }
326 
327 static int opt_data_codec(void *optctx, const char *opt, const char *arg)
328 {
329  OptionsContext *o = optctx;
330  return parse_option(o, "codec:d", arg, options);
331 }
332 
333 static int opt_map(void *optctx, const char *opt, const char *arg)
334 {
335  OptionsContext *o = optctx;
336  StreamMap *m = NULL;
337  int i, negative = 0, file_idx, disabled = 0;
338  int sync_file_idx = -1, sync_stream_idx = 0;
339  char *p, *sync;
340  char *map;
341  char *allow_unused;
342 
343  if (*arg == '-') {
344  negative = 1;
345  arg++;
346  }
347  map = av_strdup(arg);
348  if (!map)
349  return AVERROR(ENOMEM);
350 
351  /* parse sync stream first, just pick first matching stream */
352  if (sync = strchr(map, ',')) {
353  *sync = 0;
354  sync_file_idx = strtol(sync + 1, &sync, 0);
355  if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
356  av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
357  exit_program(1);
358  }
359  if (*sync)
360  sync++;
361  for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
362  if (check_stream_specifier(input_files[sync_file_idx]->ctx,
363  input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
364  sync_stream_idx = i;
365  break;
366  }
367  if (i == input_files[sync_file_idx]->nb_streams) {
368  av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
369  "match any streams.\n", arg);
370  exit_program(1);
371  }
372  if (input_streams[input_files[sync_file_idx]->ist_index + sync_stream_idx]->user_set_discard == AVDISCARD_ALL) {
373  av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s matches a disabled input "
374  "stream.\n", arg);
375  exit_program(1);
376  }
377  }
378 
379 
380  if (map[0] == '[') {
381  /* this mapping refers to lavfi output */
382  const char *c = map + 1;
384  m = &o->stream_maps[o->nb_stream_maps - 1];
385  m->linklabel = av_get_token(&c, "]");
386  if (!m->linklabel) {
387  av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
388  exit_program(1);
389  }
390  } else {
391  if (allow_unused = strchr(map, '?'))
392  *allow_unused = 0;
393  file_idx = strtol(map, &p, 0);
394  if (file_idx >= nb_input_files || file_idx < 0) {
395  av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
396  exit_program(1);
397  }
398  if (negative)
399  /* disable some already defined maps */
400  for (i = 0; i < o->nb_stream_maps; i++) {
401  m = &o->stream_maps[i];
402  if (file_idx == m->file_index &&
405  *p == ':' ? p + 1 : p) > 0)
406  m->disabled = 1;
407  }
408  else
409  for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
410  if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
411  *p == ':' ? p + 1 : p) <= 0)
412  continue;
413  if (input_streams[input_files[file_idx]->ist_index + i]->user_set_discard == AVDISCARD_ALL) {
414  disabled = 1;
415  continue;
416  }
418  m = &o->stream_maps[o->nb_stream_maps - 1];
419 
420  m->file_index = file_idx;
421  m->stream_index = i;
422 
423  if (sync_file_idx >= 0) {
424  m->sync_file_index = sync_file_idx;
425  m->sync_stream_index = sync_stream_idx;
426  } else {
427  m->sync_file_index = file_idx;
428  m->sync_stream_index = i;
429  }
430  }
431  }
432 
433  if (!m) {
434  if (allow_unused) {
435  av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
436  } else if (disabled) {
437  av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
438  "To ignore this, add a trailing '?' to the map.\n", arg);
439  exit_program(1);
440  } else {
441  av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
442  "To ignore this, add a trailing '?' to the map.\n", arg);
443  exit_program(1);
444  }
445  }
446 
447  av_freep(&map);
448  return 0;
449 }
450 
451 static int opt_attach(void *optctx, const char *opt, const char *arg)
452 {
453  OptionsContext *o = optctx;
455  o->attachments[o->nb_attachments - 1] = arg;
456  return 0;
457 }
458 
459 static int opt_map_channel(void *optctx, const char *opt, const char *arg)
460 {
461  OptionsContext *o = optctx;
462  int n;
463  AVStream *st;
464  AudioChannelMap *m;
465  char *allow_unused;
466  char *mapchan;
467  mapchan = av_strdup(arg);
468  if (!mapchan)
469  return AVERROR(ENOMEM);
470 
473 
474  /* muted channel syntax */
475  n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
476  if ((n == 1 || n == 3) && m->channel_idx == -1) {
477  m->file_idx = m->stream_idx = -1;
478  if (n == 1)
479  m->ofile_idx = m->ostream_idx = -1;
480  av_free(mapchan);
481  return 0;
482  }
483 
484  /* normal syntax */
485  n = sscanf(arg, "%d.%d.%d:%d.%d",
486  &m->file_idx, &m->stream_idx, &m->channel_idx,
487  &m->ofile_idx, &m->ostream_idx);
488 
489  if (n != 3 && n != 5) {
490  av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
491  "[file.stream.channel|-1][:syncfile:syncstream]\n");
492  exit_program(1);
493  }
494 
495  if (n != 5) // only file.stream.channel specified
496  m->ofile_idx = m->ostream_idx = -1;
497 
498  /* check input */
499  if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
500  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
501  m->file_idx);
502  exit_program(1);
503  }
504  if (m->stream_idx < 0 ||
506  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
507  m->file_idx, m->stream_idx);
508  exit_program(1);
509  }
510  st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
511  if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
512  av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
513  m->file_idx, m->stream_idx);
514  exit_program(1);
515  }
516  /* allow trailing ? to map_channel */
517  if (allow_unused = strchr(mapchan, '?'))
518  *allow_unused = 0;
519  if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels ||
521  if (allow_unused) {
522  av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
523  m->file_idx, m->stream_idx, m->channel_idx);
524  } else {
525  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
526  "To ignore this, add a trailing '?' to the map_channel.\n",
527  m->file_idx, m->stream_idx, m->channel_idx);
528  exit_program(1);
529  }
530 
531  }
532  av_free(mapchan);
533  return 0;
534 }
535 
536 static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
537 {
540  return 0;
541 }
542 
543 #if CONFIG_VAAPI
544 static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
545 {
546  const char *prefix = "vaapi:";
547  char *tmp;
548  int err;
549  tmp = av_asprintf("%s%s", prefix, arg);
550  if (!tmp)
551  return AVERROR(ENOMEM);
553  av_free(tmp);
554  return err;
555 }
556 #endif
557 
558 #if CONFIG_QSV
559 static int opt_qsv_device(void *optctx, const char *opt, const char *arg)
560 {
561  const char *prefix = "qsv=__qsv_device:hw_any,child_device=";
562  int err;
563  char *tmp = av_asprintf("%s%s", prefix, arg);
564 
565  if (!tmp)
566  return AVERROR(ENOMEM);
567 
569  av_free(tmp);
570 
571  return err;
572 }
573 #endif
574 
575 static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
576 {
577  if (!strcmp(arg, "list")) {
579  printf("Supported hardware device types:\n");
580  while ((type = av_hwdevice_iterate_types(type)) !=
583  printf("\n");
584  exit_program(0);
585  } else {
587  }
588 }
589 
590 static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
591 {
592  if (filter_hw_device) {
593  av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
594  return AVERROR(EINVAL);
595  }
597  if (!filter_hw_device) {
598  av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
599  return AVERROR(EINVAL);
600  }
601  return 0;
602 }
603 
604 /**
605  * Parse a metadata specifier passed as 'arg' parameter.
606  * @param arg metadata string to parse
607  * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
608  * @param index for type c/p, chapter/program index is written here
609  * @param stream_spec for type s, the stream specifier is written here
610  */
611 static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
612 {
613  if (*arg) {
614  *type = *arg;
615  switch (*arg) {
616  case 'g':
617  break;
618  case 's':
619  if (*(++arg) && *arg != ':') {
620  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
621  exit_program(1);
622  }
623  *stream_spec = *arg == ':' ? arg + 1 : "";
624  break;
625  case 'c':
626  case 'p':
627  if (*(++arg) == ':')
628  *index = strtol(++arg, NULL, 0);
629  break;
630  default:
631  av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
632  exit_program(1);
633  }
634  } else
635  *type = 'g';
636 }
637 
638 static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
639 {
640  AVDictionary **meta_in = NULL;
641  AVDictionary **meta_out = NULL;
642  int i, ret = 0;
643  char type_in, type_out;
644  const char *istream_spec = NULL, *ostream_spec = NULL;
645  int idx_in = 0, idx_out = 0;
646 
647  parse_meta_type(inspec, &type_in, &idx_in, &istream_spec);
648  parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);
649 
650  if (!ic) {
651  if (type_out == 'g' || !*outspec)
652  o->metadata_global_manual = 1;
653  if (type_out == 's' || !*outspec)
655  if (type_out == 'c' || !*outspec)
657  return 0;
658  }
659 
660  if (type_in == 'g' || type_out == 'g')
661  o->metadata_global_manual = 1;
662  if (type_in == 's' || type_out == 's')
664  if (type_in == 'c' || type_out == 'c')
666 
667  /* ic is NULL when just disabling automatic mappings */
668  if (!ic)
669  return 0;
670 
671 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
672  if ((index) < 0 || (index) >= (nb_elems)) {\
673  av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
674  (desc), (index));\
675  exit_program(1);\
676  }
677 
678 #define SET_DICT(type, meta, context, index)\
679  switch (type) {\
680  case 'g':\
681  meta = &context->metadata;\
682  break;\
683  case 'c':\
684  METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
685  meta = &context->chapters[index]->metadata;\
686  break;\
687  case 'p':\
688  METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
689  meta = &context->programs[index]->metadata;\
690  break;\
691  case 's':\
692  break; /* handled separately below */ \
693  default: av_assert0(0);\
694  }\
695 
696  SET_DICT(type_in, meta_in, ic, idx_in);
697  SET_DICT(type_out, meta_out, oc, idx_out);
698 
699  /* for input streams choose first matching stream */
700  if (type_in == 's') {
701  for (i = 0; i < ic->nb_streams; i++) {
702  if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
703  meta_in = &ic->streams[i]->metadata;
704  break;
705  } else if (ret < 0)
706  exit_program(1);
707  }
708  if (!meta_in) {
709  av_log(NULL, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
710  exit_program(1);
711  }
712  }
713 
714  if (type_out == 's') {
715  for (i = 0; i < oc->nb_streams; i++) {
716  if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
717  meta_out = &oc->streams[i]->metadata;
718  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
719  } else if (ret < 0)
720  exit_program(1);
721  }
722  } else
723  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
724 
725  return 0;
726 }
727 
728 static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
729 {
730  OptionsContext *o = optctx;
731  char buf[128];
732  int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
733  struct tm time = *gmtime((time_t*)&recording_timestamp);
734  if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
735  return -1;
736  parse_option(o, "metadata", buf, options);
737 
738  av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
739  "tag instead.\n", opt);
740  return 0;
741 }
742 
743 static const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
744 {
745  const AVCodecDescriptor *desc;
746  const char *codec_string = encoder ? "encoder" : "decoder";
747  const AVCodec *codec;
748 
749  codec = encoder ?
752 
753  if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
754  codec = encoder ? avcodec_find_encoder(desc->id) :
756  if (codec)
757  av_log(NULL, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
758  codec_string, codec->name, desc->name);
759  }
760 
761  if (!codec) {
762  av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
763  exit_program(1);
764  }
765  if (codec->type != type && !recast_media) {
766  av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
767  exit_program(1);
768  }
769  return codec;
770 }
771 
773 {
774  char *codec_name = NULL;
775 
776  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
777  if (codec_name) {
778  const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
779  st->codecpar->codec_id = codec->id;
780  if (recast_media && st->codecpar->codec_type != codec->type)
781  st->codecpar->codec_type = codec->type;
782  return codec;
783  } else
785 }
786 
787 /* Add all the streams from the given input file to the global
788  * list of input streams. */
790 {
791  int i, ret;
792 
793  for (i = 0; i < ic->nb_streams; i++) {
794  AVStream *st = ic->streams[i];
795  AVCodecParameters *par = st->codecpar;
796  InputStream *ist;
797  char *framerate = NULL, *hwaccel_device = NULL;
798  const char *hwaccel = NULL;
799  char *hwaccel_output_format = NULL;
800  char *codec_tag = NULL;
801  char *next;
802  char *discard_str = NULL;
803  const AVClass *cc = avcodec_get_class();
804  const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL,
806 
808  ist->st = st;
809  ist->file_index = nb_input_files;
810  ist->discard = 1;
811  st->discard = AVDISCARD_ALL;
812  ist->nb_samples = 0;
813  ist->first_dts = AV_NOPTS_VALUE;
814  ist->min_pts = INT64_MAX;
815  ist->max_pts = INT64_MIN;
816 
817  ist->ts_scale = 1.0;
818  MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
819 
820  ist->autorotate = 1;
822 
823  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
824  if (codec_tag) {
825  uint32_t tag = strtol(codec_tag, &next, 0);
826  if (*next)
827  tag = AV_RL32(codec_tag);
828  st->codecpar->codec_tag = tag;
829  }
830 
831  ist->dec = choose_decoder(o, ic, st);
832  ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
833 
834  ist->reinit_filters = -1;
835  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
836 
837  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
839 
840  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
845 
846  if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
847  av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
848  discard_str);
849  exit_program(1);
850  }
851 
854 
855  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
856  if (!ist->dec_ctx) {
857  av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
858  exit_program(1);
859  }
860 
862  if (ret < 0) {
863  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
864  exit_program(1);
865  }
866 
867  ist->decoded_frame = av_frame_alloc();
868  if (!ist->decoded_frame)
869  exit_program(1);
870 
871  ist->pkt = av_packet_alloc();
872  if (!ist->pkt)
873  exit_program(1);
874 
875  if (o->bitexact)
877 
878  switch (par->codec_type) {
879  case AVMEDIA_TYPE_VIDEO:
880  if(!ist->dec)
881  ist->dec = avcodec_find_decoder(par->codec_id);
882 
883  // avformat_find_stream_info() doesn't set this for us anymore.
884  ist->dec_ctx->framerate = st->avg_frame_rate;
885 
886  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
888  framerate) < 0) {
889  av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
890  framerate);
891  exit_program(1);
892  }
893 
894  ist->top_field_first = -1;
895  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
896 
897  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
898  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
899  hwaccel_output_format, ic, st);
900 
901  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
903  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
904  "with old commandlines. This behaviour is DEPRECATED and will be removed "
905  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
907  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
909  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
910  "with old commandlines. This behaviour is DEPRECATED and will be removed "
911  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
913  } else if (hwaccel_output_format) {
914  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
916  av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
917  "format: %s", hwaccel_output_format);
918  }
919  } else {
921  }
922 
923  if (hwaccel) {
924  // The NVDEC hwaccels use a CUDA device, so remap the name here.
925  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
926  hwaccel = "cuda";
927 
928  if (!strcmp(hwaccel, "none"))
929  ist->hwaccel_id = HWACCEL_NONE;
930  else if (!strcmp(hwaccel, "auto"))
931  ist->hwaccel_id = HWACCEL_AUTO;
932  else {
934  if (type != AV_HWDEVICE_TYPE_NONE) {
936  ist->hwaccel_device_type = type;
937  }
938 
939  if (!ist->hwaccel_id) {
940  av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
941  hwaccel);
942  av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
944  while ((type = av_hwdevice_iterate_types(type)) !=
946  av_log(NULL, AV_LOG_FATAL, "%s ",
948  av_log(NULL, AV_LOG_FATAL, "\n");
949  exit_program(1);
950  }
951  }
952  }
953 
954  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
955  if (hwaccel_device) {
956  ist->hwaccel_device = av_strdup(hwaccel_device);
957  if (!ist->hwaccel_device)
958  exit_program(1);
959  }
960 
962 
963  break;
964  case AVMEDIA_TYPE_AUDIO:
965  ist->guess_layout_max = INT_MAX;
966  MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
968  break;
969  case AVMEDIA_TYPE_DATA:
970  case AVMEDIA_TYPE_SUBTITLE: {
971  char *canvas_size = NULL;
972  if(!ist->dec)
973  ist->dec = avcodec_find_decoder(par->codec_id);
974  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
975  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
976  if (canvas_size &&
977  av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
978  av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
979  exit_program(1);
980  }
981  break;
982  }
985  break;
986  default:
987  abort();
988  }
989 
991  if (ret < 0) {
992  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
993  exit_program(1);
994  }
995  }
996 }
997 
998 static void assert_file_overwrite(const char *filename)
999 {
1000  const char *proto_name = avio_find_protocol_name(filename);
1001 
1003  fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
1004  exit_program(1);
1005  }
1006 
1007  if (!file_overwrite) {
1008  if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
1010  fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", filename);
1011  fflush(stderr);
1012  term_exit();
1013  signal(SIGINT, SIG_DFL);
1014  if (!read_yesno()) {
1015  av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
1016  exit_program(1);
1017  }
1018  term_init();
1019  }
1020  else {
1021  av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
1022  exit_program(1);
1023  }
1024  }
1025  }
1026 
1027  if (proto_name && !strcmp(proto_name, "file")) {
1028  for (int i = 0; i < nb_input_files; i++) {
1029  InputFile *file = input_files[i];
1030  if (file->ctx->iformat->flags & AVFMT_NOFILE)
1031  continue;
1032  if (!strcmp(filename, file->ctx->url)) {
1033  av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
1034  av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
1035  exit_program(1);
1036  }
1037  }
1038  }
1039 }
1040 
1041 static void dump_attachment(AVStream *st, const char *filename)
1042 {
1043  int ret;
1044  AVIOContext *out = NULL;
1045  const AVDictionaryEntry *e;
1046 
1047  if (!st->codecpar->extradata_size) {
1048  av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
1049  nb_input_files - 1, st->index);
1050  return;
1051  }
1052  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1053  filename = e->value;
1054  if (!*filename) {
1055  av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
1056  "in stream #%d:%d.\n", nb_input_files - 1, st->index);
1057  exit_program(1);
1058  }
1059 
1060  assert_file_overwrite(filename);
1061 
1062  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1063  av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1064  filename);
1065  exit_program(1);
1066  }
1067 
1069  avio_flush(out);
1070  avio_close(out);
1071 }
1072 
1073 static int open_input_file(OptionsContext *o, const char *filename)
1074 {
1075  InputFile *f;
1076  AVFormatContext *ic;
1077  const AVInputFormat *file_iformat = NULL;
1078  int err, i, ret;
1079  int64_t timestamp;
1080  AVDictionary *unused_opts = NULL;
1081  const AVDictionaryEntry *e = NULL;
1082  char * video_codec_name = NULL;
1083  char * audio_codec_name = NULL;
1084  char *subtitle_codec_name = NULL;
1085  char * data_codec_name = NULL;
1086  int scan_all_pmts_set = 0;
1087 
1088  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
1089  o->stop_time = INT64_MAX;
1090  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1091  }
1092 
1093  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
1094  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
1095  if (o->stop_time <= start_time) {
1096  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1097  exit_program(1);
1098  } else {
1100  }
1101  }
1102 
1103  if (o->format) {
1104  if (!(file_iformat = av_find_input_format(o->format))) {
1105  av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1106  exit_program(1);
1107  }
1108  }
1109 
1110  if (!strcmp(filename, "-"))
1111  filename = "pipe:";
1112 
1113  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1114  strcmp(filename, "/dev/stdin");
1115 
1116  /* get default parameters from command line */
1117  ic = avformat_alloc_context();
1118  if (!ic) {
1119  print_error(filename, AVERROR(ENOMEM));
1120  exit_program(1);
1121  }
1122  if (o->nb_audio_sample_rate) {
1123  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1124  }
1125  if (o->nb_audio_channels) {
1126  const AVClass *priv_class;
1127  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1128  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1130  char buf[32];
1131  snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
1132  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
1133  }
1134  }
1135  if (o->nb_audio_ch_layouts) {
1136  const AVClass *priv_class;
1137  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1138  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1140  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0);
1141  }
1142  }
1143  if (o->nb_frame_rates) {
1144  const AVClass *priv_class;
1145  /* set the format-level framerate option;
1146  * this is important for video grabbers, e.g. x11 */
1147  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1148  av_opt_find(&priv_class, "framerate", NULL, 0,
1150  av_dict_set(&o->g->format_opts, "framerate",
1151  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1152  }
1153  }
1154  if (o->nb_frame_sizes) {
1155  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1156  }
1157  if (o->nb_frame_pix_fmts)
1158  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1159 
1160  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1161  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1162  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1163  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1164 
1165  if (video_codec_name)
1167  if (audio_codec_name)
1169  if (subtitle_codec_name)
1171  if (data_codec_name)
1172  ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
1173 
1177  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1178 
1179  ic->flags |= AVFMT_FLAG_NONBLOCK;
1180  if (o->bitexact)
1181  ic->flags |= AVFMT_FLAG_BITEXACT;
1182  ic->interrupt_callback = int_cb;
1183 
1184  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1185  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1186  scan_all_pmts_set = 1;
1187  }
1188  /* open the input file with generic avformat function */
1189  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1190  if (err < 0) {
1191  print_error(filename, err);
1192  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1193  av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1194  exit_program(1);
1195  }
1196  if (scan_all_pmts_set)
1197  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1200 
1201  /* apply forced codec ids */
1202  for (i = 0; i < ic->nb_streams; i++)
1203  choose_decoder(o, ic, ic->streams[i]);
1204 
1205  if (find_stream_info) {
1207  int orig_nb_streams = ic->nb_streams;
1208 
1209  /* If not enough info to get the stream parameters, we decode the
1210  first frames to get it. (used in mpeg case for example) */
1212 
1213  for (i = 0; i < orig_nb_streams; i++)
1214  av_dict_free(&opts[i]);
1215  av_freep(&opts);
1216 
1217  if (ret < 0) {
1218  av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
1219  if (ic->nb_streams == 0) {
1220  avformat_close_input(&ic);
1221  exit_program(1);
1222  }
1223  }
1224  }
1225 
1227  av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1229  }
1230 
1231  if (o->start_time_eof != AV_NOPTS_VALUE) {
1232  if (o->start_time_eof >= 0) {
1233  av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1234  exit_program(1);
1235  }
1236  if (ic->duration > 0) {
1237  o->start_time = o->start_time_eof + ic->duration;
1238  if (o->start_time < 0) {
1239  av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
1241  }
1242  } else
1243  av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
1244  }
1245  timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
1246  /* add the stream start time */
1247  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1248  timestamp += ic->start_time;
1249 
1250  /* if seeking requested, we execute it */
1251  if (o->start_time != AV_NOPTS_VALUE) {
1252  int64_t seek_timestamp = timestamp;
1253 
1254  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1255  int dts_heuristic = 0;
1256  for (i=0; i<ic->nb_streams; i++) {
1257  const AVCodecParameters *par = ic->streams[i]->codecpar;
1258  if (par->video_delay) {
1259  dts_heuristic = 1;
1260  break;
1261  }
1262  }
1263  if (dts_heuristic) {
1264  seek_timestamp -= 3*AV_TIME_BASE / 23;
1265  }
1266  }
1267  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1268  if (ret < 0) {
1269  av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
1270  filename, (double)timestamp / AV_TIME_BASE);
1271  }
1272  }
1273 
1274  /* update the current parameters so that they match the one of the input stream */
1275  add_input_streams(o, ic);
1276 
1277  /* dump the file content */
1278  av_dump_format(ic, nb_input_files, filename, 0);
1279 
1281 
1282  f->ctx = ic;
1283  f->ist_index = nb_input_streams - ic->nb_streams;
1284  f->start_time = o->start_time;
1285  f->recording_time = o->recording_time;
1286  f->input_ts_offset = o->input_ts_offset;
1287  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1288  f->nb_streams = ic->nb_streams;
1289  f->rate_emu = o->rate_emu;
1290  f->accurate_seek = o->accurate_seek;
1291  f->loop = o->loop;
1292  f->duration = 0;
1293  f->time_base = (AVRational){ 1, 1 };
1294 
1295  f->readrate = o->readrate ? o->readrate : 0.0;
1296  if (f->readrate < 0.0f) {
1297  av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", nb_input_files, f->readrate);
1298  exit_program(1);
1299  }
1300  if (f->readrate && f->rate_emu) {
1301  av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", nb_input_files, f->readrate);
1302  f->rate_emu = 0;
1303  }
1304 
1305  f->pkt = av_packet_alloc();
1306  if (!f->pkt)
1307  exit_program(1);
1308 #if HAVE_THREADS
1309  f->thread_queue_size = o->thread_queue_size;
1310 #endif
1311 
1312  /* check if all codec options have been used */
1313  unused_opts = strip_specifiers(o->g->codec_opts);
1314  for (i = f->ist_index; i < nb_input_streams; i++) {
1315  e = NULL;
1316  while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e,
1318  av_dict_set(&unused_opts, e->key, NULL, 0);
1319  }
1320 
1321  e = NULL;
1322  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
1323  const AVClass *class = avcodec_get_class();
1324  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1326  const AVClass *fclass = avformat_get_class();
1327  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1329  if (!option || foption)
1330  continue;
1331 
1332 
1333  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1334  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
1335  "input file #%d (%s) is not a decoding option.\n", e->key,
1336  option->help ? option->help : "", nb_input_files - 1,
1337  filename);
1338  exit_program(1);
1339  }
1340 
1341  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
1342  "input file #%d (%s) has not been used for any stream. The most "
1343  "likely reason is either wrong type (e.g. a video option with "
1344  "no video streams) or that it is a private option of some decoder "
1345  "which was not actually used for any stream.\n", e->key,
1346  option->help ? option->help : "", nb_input_files - 1, filename);
1347  }
1348  av_dict_free(&unused_opts);
1349 
1350  for (i = 0; i < o->nb_dump_attachment; i++) {
1351  int j;
1352 
1353  for (j = 0; j < ic->nb_streams; j++) {
1354  AVStream *st = ic->streams[j];
1355 
1356  if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
1358  }
1359  }
1360 
1362 
1363  return 0;
1364 }
1365 
1366 static char *get_line(AVIOContext *s, AVBPrint *bprint)
1367 {
1368  char c;
1369 
1370  while ((c = avio_r8(s)) && c != '\n')
1371  av_bprint_chars(bprint, c, 1);
1372 
1373  if (!av_bprint_is_complete(bprint)) {
1374  av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
1375  exit_program(1);
1376  }
1377  return bprint->str;
1378 }
1379 
1380 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
1381 {
1382  int i, ret = -1;
1383  char filename[1000];
1384  const char *base[3] = { getenv("AVCONV_DATADIR"),
1385  getenv("HOME"),
1386  AVCONV_DATADIR,
1387  };
1388 
1389  for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1390  if (!base[i])
1391  continue;
1392  if (codec_name) {
1393  snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
1394  i != 1 ? "" : "/.avconv", codec_name, preset_name);
1395  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1396  }
1397  if (ret < 0) {
1398  snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
1399  i != 1 ? "" : "/.avconv", preset_name);
1400  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1401  }
1402  }
1403  return ret;
1404 }
1405 
1407 {
1408  enum AVMediaType type = ost->st->codecpar->codec_type;
1409  char *codec_name = NULL;
1410 
1412  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
1413  if (!codec_name) {
1414  ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1415  NULL, ost->st->codecpar->codec_type);
1417  if (!ost->enc) {
1418  av_log(NULL, AV_LOG_FATAL, "Automatic encoder selection failed for "
1419  "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1420  "probably disabled. Please choose an encoder manually.\n",
1421  ost->file_index, ost->index, s->oformat->name,
1424  }
1425  } else if (!strcmp(codec_name, "copy"))
1426  ost->stream_copy = 1;
1427  else {
1428  ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
1429  ost->st->codecpar->codec_id = ost->enc->id;
1430  }
1431  ost->encoding_needed = !ost->stream_copy;
1432  } else {
1433  /* no encoding supported for other media types */
1434  ost->stream_copy = 1;
1435  ost->encoding_needed = 0;
1436  }
1437 
1438  return 0;
1439 }
1440 
1442 {
1443  OutputStream *ost;
1444  AVStream *st = avformat_new_stream(oc, NULL);
1445  int idx = oc->nb_streams - 1, ret = 0;
1446  const char *bsfs = NULL, *time_base = NULL;
1447  char *next, *codec_tag = NULL;
1448  double qscale = -1;
1449  int i;
1450 
1451  if (!st) {
1452  av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
1453  exit_program(1);
1454  }
1455 
1456  if (oc->nb_streams - 1 < o->nb_streamid_map)
1457  st->id = o->streamid_map[oc->nb_streams - 1];
1458 
1460 
1461  ost->file_index = nb_output_files - 1;
1462  ost->index = idx;
1463  ost->st = st;
1464  ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
1465  st->codecpar->codec_type = type;
1466 
1467  ret = choose_encoder(o, oc, ost);
1468  if (ret < 0) {
1469  av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream "
1470  "%d:%d\n", ost->file_index, ost->index);
1471  exit_program(1);
1472  }
1473 
1474  ost->enc_ctx = avcodec_alloc_context3(ost->enc);
1475  if (!ost->enc_ctx) {
1476  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
1477  exit_program(1);
1478  }
1479  ost->enc_ctx->codec_type = type;
1480 
1481  ost->ref_par = avcodec_parameters_alloc();
1482  if (!ost->ref_par) {
1483  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n");
1484  exit_program(1);
1485  }
1486 
1487  ost->filtered_frame = av_frame_alloc();
1488  if (!ost->filtered_frame)
1489  exit_program(1);
1490 
1491  ost->pkt = av_packet_alloc();
1492  if (!ost->pkt)
1493  exit_program(1);
1494 
1495  if (ost->enc) {
1496  AVIOContext *s = NULL;
1497  char *buf = NULL, *arg = NULL, *preset = NULL;
1498 
1499  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
1500 
1502  ost->autoscale = 1;
1503  MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
1504  if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
1505  AVBPrint bprint;
1507  do {
1508  av_bprint_clear(&bprint);
1509  buf = get_line(s, &bprint);
1510  if (!buf[0] || buf[0] == '#')
1511  continue;
1512  if (!(arg = strchr(buf, '='))) {
1513  av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1514  exit_program(1);
1515  }
1516  *arg++ = 0;
1517  av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1518  } while (!s->eof_reached);
1519  av_bprint_finalize(&bprint, NULL);
1520  avio_closep(&s);
1521  }
1522  if (ret) {
1524  "Preset %s specified for stream %d:%d, but could not be opened.\n",
1525  preset, ost->file_index, ost->index);
1526  exit_program(1);
1527  }
1528  } else {
1529  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
1530  }
1531 
1532 
1533  if (o->bitexact)
1534  ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
1535 
1536  MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1537  if (time_base) {
1538  AVRational q;
1539  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1540  q.num <= 0 || q.den <= 0) {
1541  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1542  exit_program(1);
1543  }
1544  st->time_base = q;
1545  }
1546 
1547  MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
1548  if (time_base) {
1549  AVRational q;
1550  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1551  q.den <= 0) {
1552  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1553  exit_program(1);
1554  }
1555  ost->enc_timebase = q;
1556  }
1557 
1558  ost->max_frames = INT64_MAX;
1559  MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
1560  for (i = 0; i<o->nb_max_frames; i++) {
1561  char *p = o->max_frames[i].specifier;
1562  if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1563  av_log(NULL, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1564  break;
1565  }
1566  }
1567 
1568  ost->copy_prior_start = -1;
1569  MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
1570 
1571  MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1572  if (bsfs && *bsfs) {
1573  ret = av_bsf_list_parse_str(bsfs, &ost->bsf_ctx);
1574  if (ret < 0) {
1575  av_log(NULL, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
1576  exit_program(1);
1577  }
1578  }
1579 
1580  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1581  if (codec_tag) {
1582  uint32_t tag = strtol(codec_tag, &next, 0);
1583  if (*next)
1584  tag = AV_RL32(codec_tag);
1585  ost->st->codecpar->codec_tag =
1586  ost->enc_ctx->codec_tag = tag;
1587  }
1588 
1589  MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1590  if (qscale >= 0) {
1591  ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1592  ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1593  }
1594 
1595  MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
1597 
1598  ost->max_muxing_queue_size = 128;
1599  MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
1600 
1601  ost->muxing_queue_data_size = 0;
1602 
1603  ost->muxing_queue_data_threshold = 50*1024*1024;
1604  MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ost->muxing_queue_data_threshold, oc, st);
1605 
1606  MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample,
1607  oc, st);
1608 
1609  if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1610  ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1611 
1612  av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1613 
1614  av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1615  if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
1616  av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1617 
1618  ost->source_index = source_index;
1619  if (source_index >= 0) {
1620  ost->sync_ist = input_streams[source_index];
1621  input_streams[source_index]->discard = 0;
1622  input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
1623  }
1624  ost->last_mux_dts = AV_NOPTS_VALUE;
1625 
1626  ost->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
1627  if (!ost->muxing_queue)
1628  exit_program(1);
1629 
1630  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i,
1631  ost->copy_initial_nonkeyframes, oc, st);
1632 
1633  return ost;
1634 }
1635 
1636 static void parse_matrix_coeffs(uint16_t *dest, const char *str)
1637 {
1638  int i;
1639  const char *p = str;
1640  for (i = 0;; i++) {
1641  dest[i] = atoi(p);
1642  if (i == 63)
1643  break;
1644  p = strchr(p, ',');
1645  if (!p) {
1646  av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1647  exit_program(1);
1648  }
1649  p++;
1650  }
1651 }
1652 
1653 /* read file contents into a string */
1654 static char *read_file(const char *filename)
1655 {
1656  AVIOContext *pb = NULL;
1657  int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1658  AVBPrint bprint;
1659  char *str;
1660 
1661  if (ret < 0) {
1662  av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1663  return NULL;
1664  }
1665 
1667  ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
1668  avio_closep(&pb);
1669  if (ret < 0) {
1670  av_bprint_finalize(&bprint, NULL);
1671  return NULL;
1672  }
1673  ret = av_bprint_finalize(&bprint, &str);
1674  if (ret < 0)
1675  return NULL;
1676  return str;
1677 }
1678 
1680  OutputStream *ost)
1681 {
1682  AVStream *st = ost->st;
1683 
1684  if (ost->filters_script && ost->filters) {
1685  av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
1686  "output stream #%d:%d.\n", nb_output_files, st->index);
1687  exit_program(1);
1688  }
1689 
1690  if (ost->filters_script)
1691  return read_file(ost->filters_script);
1692  else if (ost->filters)
1693  return av_strdup(ost->filters);
1694 
1696  "null" : "anull");
1697 }
1698 
1700  const OutputStream *ost, enum AVMediaType type)
1701 {
1702  if (ost->filters_script || ost->filters) {
1704  "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1705  "Filtering and streamcopy cannot be used together.\n",
1706  ost->filters ? "Filtergraph" : "Filtergraph script",
1707  ost->filters ? ost->filters : ost->filters_script,
1708  av_get_media_type_string(type), ost->file_index, ost->index);
1709  exit_program(1);
1710  }
1711 }
1712 
1714 {
1715  AVStream *st;
1716  OutputStream *ost;
1717  AVCodecContext *video_enc;
1718  char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL;
1719 
1720  ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
1721  st = ost->st;
1722  video_enc = ost->enc_ctx;
1723 
1724  MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
1725  if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
1726  av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
1727  exit_program(1);
1728  }
1729 
1730  MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
1731  if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
1732  av_log(NULL, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
1733  exit_program(1);
1734  }
1735 
1736  if (frame_rate && max_frame_rate) {
1737  av_log(NULL, AV_LOG_ERROR, "Only one of -fpsmax and -r can be set for a stream.\n");
1738  exit_program(1);
1739  }
1740 
1741  if ((frame_rate || max_frame_rate) &&
1743  av_log(NULL, AV_LOG_ERROR, "Using -vsync passthrough and -r/-fpsmax can produce invalid output files\n");
1744 
1745  MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
1746  if (frame_aspect_ratio) {
1747  AVRational q;
1748  if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1749  q.num <= 0 || q.den <= 0) {
1750  av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
1751  exit_program(1);
1752  }
1753  ost->frame_aspect_ratio = q;
1754  }
1755 
1756  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1757  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1758 
1759  if (!ost->stream_copy) {
1760  const char *p = NULL;
1761  char *frame_size = NULL;
1762  char *frame_pix_fmt = NULL;
1763  char *intra_matrix = NULL, *inter_matrix = NULL;
1764  char *chroma_intra_matrix = NULL;
1765  int do_pass = 0;
1766  int i;
1767 
1769  if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1770  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1771  exit_program(1);
1772  }
1773 
1774  MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
1775  if (frame_pix_fmt && *frame_pix_fmt == '+') {
1776  ost->keep_pix_fmt = 1;
1777  if (!*++frame_pix_fmt)
1778  frame_pix_fmt = NULL;
1779  }
1780  if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1781  av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
1782  exit_program(1);
1783  }
1784  st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1785 
1786  MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
1787  if (intra_matrix) {
1788  if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
1789  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1790  exit_program(1);
1791  }
1792  parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
1793  }
1794  MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
1795  if (chroma_intra_matrix) {
1796  uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
1797  if (!p) {
1798  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1799  exit_program(1);
1800  }
1801  video_enc->chroma_intra_matrix = p;
1802  parse_matrix_coeffs(p, chroma_intra_matrix);
1803  }
1804  MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
1805  if (inter_matrix) {
1806  if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
1807  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
1808  exit_program(1);
1809  }
1810  parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
1811  }
1812 
1813  MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
1814  for (i = 0; p; i++) {
1815  int start, end, q;
1816  int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
1817  if (e != 3) {
1818  av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
1819  exit_program(1);
1820  }
1821  video_enc->rc_override =
1822  av_realloc_array(video_enc->rc_override,
1823  i + 1, sizeof(RcOverride));
1824  if (!video_enc->rc_override) {
1825  av_log(NULL, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
1826  exit_program(1);
1827  }
1828  video_enc->rc_override[i].start_frame = start;
1829  video_enc->rc_override[i].end_frame = end;
1830  if (q > 0) {
1831  video_enc->rc_override[i].qscale = q;
1832  video_enc->rc_override[i].quality_factor = 1.0;
1833  }
1834  else {
1835  video_enc->rc_override[i].qscale = 0;
1836  video_enc->rc_override[i].quality_factor = -q/100.0;
1837  }
1838  p = strchr(p, '/');
1839  if (p) p++;
1840  }
1841  video_enc->rc_override_count = i;
1842 
1843  if (do_psnr)
1844  video_enc->flags|= AV_CODEC_FLAG_PSNR;
1845 
1846  /* two pass mode */
1847  MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
1848  if (do_pass) {
1849  if (do_pass & 1) {
1850  video_enc->flags |= AV_CODEC_FLAG_PASS1;
1851  av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
1852  }
1853  if (do_pass & 2) {
1854  video_enc->flags |= AV_CODEC_FLAG_PASS2;
1855  av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
1856  }
1857  }
1858 
1859  MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
1860  if (ost->logfile_prefix &&
1861  !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
1862  exit_program(1);
1863 
1864  if (do_pass) {
1865  char logfilename[1024];
1866  FILE *f;
1867 
1868  snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
1869  ost->logfile_prefix ? ost->logfile_prefix :
1871  nb_output_streams - 1);
1872  if (!strcmp(ost->enc->name, "libx264")) {
1873  av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
1874  } else {
1875  if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1876  char *logbuffer = read_file(logfilename);
1877 
1878  if (!logbuffer) {
1879  av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
1880  logfilename);
1881  exit_program(1);
1882  }
1883  video_enc->stats_in = logbuffer;
1884  }
1885  if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1886  f = fopen_utf8(logfilename, "wb");
1887  if (!f) {
1889  "Cannot write log file '%s' for pass-1 encoding: %s\n",
1890  logfilename, strerror(errno));
1891  exit_program(1);
1892  }
1893  ost->logfile = f;
1894  }
1895  }
1896  }
1897 
1898  MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
1899  if (ost->forced_keyframes)
1900  ost->forced_keyframes = av_strdup(ost->forced_keyframes);
1901 
1902  MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
1903 
1904  ost->top_field_first = -1;
1905  MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
1906 
1907  ost->vsync_method = video_sync_method;
1908  if (ost->vsync_method == VSYNC_AUTO) {
1909  if (!strcmp(oc->oformat->name, "avi")) {
1910  ost->vsync_method = VSYNC_VFR;
1911  } else {
1912  ost->vsync_method = (oc->oformat->flags & AVFMT_VARIABLE_FPS) ?
1913  ((oc->oformat->flags & AVFMT_NOTIMESTAMPS) ?
1915  VSYNC_CFR;
1916  }
1917 
1918  if (ost->source_index >= 0 && ost->vsync_method == VSYNC_CFR) {
1919  const InputStream *ist = input_streams[ost->source_index];
1920  const InputFile *ifile = input_files[ist->file_index];
1921 
1922  if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0)
1923  ost->vsync_method = VSYNC_VSCFR;
1924  }
1925 
1926  if (ost->vsync_method == VSYNC_CFR && copy_ts) {
1927  ost->vsync_method = VSYNC_VSCFR;
1928  }
1929  }
1930  ost->is_cfr = (ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR);
1931 
1932  ost->avfilter = get_ost_filters(o, oc, ost);
1933  if (!ost->avfilter)
1934  exit_program(1);
1935 
1936  ost->last_frame = av_frame_alloc();
1937  if (!ost->last_frame)
1938  exit_program(1);
1939  }
1940 
1941  if (ost->stream_copy)
1943 
1944  return ost;
1945 }
1946 
1948 {
1949  int n;
1950  AVStream *st;
1951  OutputStream *ost;
1952  AVCodecContext *audio_enc;
1953 
1954  ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index);
1955  st = ost->st;
1956 
1957  audio_enc = ost->enc_ctx;
1958  audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1959 
1960  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1961  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1962 
1963  if (!ost->stream_copy) {
1964  int channels = 0;
1965  char *layout = NULL;
1966  char *sample_fmt = NULL;
1967 
1969  if (channels) {
1971  audio_enc->ch_layout.nb_channels = channels;
1972  }
1973 
1974  MATCH_PER_STREAM_OPT(audio_ch_layouts, str, layout, oc, st);
1975  if (layout) {
1976  if (av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) {
1977 #if FF_API_OLD_CHANNEL_LAYOUT
1978  uint64_t mask;
1981  })
1982  if (!mask) {
1983 #endif
1984  av_log(NULL, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout);
1985  exit_program(1);
1986 #if FF_API_OLD_CHANNEL_LAYOUT
1987  }
1988  av_log(NULL, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
1989  layout);
1991 #endif
1992  }
1993  }
1994 
1995  MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
1996  if (sample_fmt &&
1997  (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
1998  av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
1999  exit_program(1);
2000  }
2001 
2002  MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
2003 
2004  MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
2005  ost->apad = av_strdup(ost->apad);
2006 
2007  ost->avfilter = get_ost_filters(o, oc, ost);
2008  if (!ost->avfilter)
2009  exit_program(1);
2010 
2011  /* check for channel mapping for this audio stream */
2012  for (n = 0; n < o->nb_audio_channel_maps; n++) {
2014  if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
2015  (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
2016  InputStream *ist;
2017 
2018  if (map->channel_idx == -1) {
2019  ist = NULL;
2020  } else if (ost->source_index < 0) {
2021  av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
2022  ost->file_index, ost->st->index);
2023  continue;
2024  } else {
2025  ist = input_streams[ost->source_index];
2026  }
2027 
2028  if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
2029  if (av_reallocp_array(&ost->audio_channels_map,
2030  ost->audio_channels_mapped + 1,
2031  sizeof(*ost->audio_channels_map)
2032  ) < 0 )
2033  exit_program(1);
2034 
2035  ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
2036  }
2037  }
2038  }
2039  }
2040 
2041  if (ost->stream_copy)
2043 
2044  return ost;
2045 }
2046 
2048 {
2049  OutputStream *ost;
2050 
2051  ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
2052  if (!ost->stream_copy) {
2053  av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
2054  exit_program(1);
2055  }
2056 
2057  return ost;
2058 }
2059 
2061 {
2062  OutputStream *ost;
2063 
2064  ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
2065  if (!ost->stream_copy) {
2066  av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
2067  exit_program(1);
2068  }
2069 
2070  return ost;
2071 }
2072 
2074 {
2075  OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
2076  ost->stream_copy = 1;
2077  ost->finished = 1;
2078  return ost;
2079 }
2080 
2082 {
2083  AVStream *st;
2084  OutputStream *ost;
2085  AVCodecContext *subtitle_enc;
2086 
2087  ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
2088  st = ost->st;
2089  subtitle_enc = ost->enc_ctx;
2090 
2091  subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2092 
2093  if (!ost->stream_copy) {
2094  char *frame_size = NULL;
2095 
2097  if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
2098  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
2099  exit_program(1);
2100  }
2101  }
2102 
2103  return ost;
2104 }
2105 
2106 /* arg format is "output-stream-index:streamid-value". */
2107 static int opt_streamid(void *optctx, const char *opt, const char *arg)
2108 {
2109  OptionsContext *o = optctx;
2110  int idx;
2111  char *p;
2112  char idx_str[16];
2113 
2114  av_strlcpy(idx_str, arg, sizeof(idx_str));
2115  p = strchr(idx_str, ':');
2116  if (!p) {
2118  "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
2119  arg, opt);
2120  exit_program(1);
2121  }
2122  *p++ = '\0';
2123  idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
2124  o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
2125  o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
2126  return 0;
2127 }
2128 
2130  int copy_metadata)
2131 {
2132  AVFormatContext *is = ifile->ctx;
2133  AVChapter **tmp;
2134  int i;
2135 
2136  tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
2137  if (!tmp)
2138  return AVERROR(ENOMEM);
2139  os->chapters = tmp;
2140 
2141  for (i = 0; i < is->nb_chapters; i++) {
2142  AVChapter *in_ch = is->chapters[i], *out_ch;
2143  int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2144  int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2145  AV_TIME_BASE_Q, in_ch->time_base);
2146  int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2147  av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
2148 
2149 
2150  if (in_ch->end < ts_off)
2151  continue;
2152  if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2153  break;
2154 
2155  out_ch = av_mallocz(sizeof(AVChapter));
2156  if (!out_ch)
2157  return AVERROR(ENOMEM);
2158 
2159  out_ch->id = in_ch->id;
2160  out_ch->time_base = in_ch->time_base;
2161  out_ch->start = FFMAX(0, in_ch->start - ts_off);
2162  out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2163 
2164  if (copy_metadata)
2165  av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2166 
2167  os->chapters[os->nb_chapters++] = out_ch;
2168  }
2169  return 0;
2170 }
2171 
2173 {
2174  int nb_streams[AVMEDIA_TYPE_NB] = { 0 };
2175  int have_default[AVMEDIA_TYPE_NB] = { 0 };
2176  int have_manual = 0;
2177 
2178  // first, copy the input dispositions
2179  for (int i = 0; i < ctx->nb_streams; i++) {
2181 
2182  nb_streams[ost->st->codecpar->codec_type]++;
2183 
2184  have_manual |= !!ost->disposition;
2185 
2186  if (ost->source_index >= 0) {
2187  ost->st->disposition = input_streams[ost->source_index]->st->disposition;
2188 
2190  have_default[ost->st->codecpar->codec_type] = 1;
2191  }
2192  }
2193 
2194  if (have_manual) {
2195  // process manually set dispositions - they override the above copy
2196  for (int i = 0; i < ctx->nb_streams; i++) {
2198  int ret;
2199 
2200  if (!ost->disposition)
2201  continue;
2202 
2203 #if LIBAVFORMAT_VERSION_MAJOR >= 60
2204  ret = av_opt_set(ost->st, "disposition", ost->disposition, 0);
2205 #else
2206  {
2207  const AVClass *class = av_stream_get_class();
2208  const AVOption *o = av_opt_find(&class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ);
2209 
2210  av_assert0(o);
2211  ret = av_opt_eval_flags(&class, o, ost->disposition, &ost->st->disposition);
2212  }
2213 #endif
2214 
2215  if (ret < 0)
2216  return ret;
2217  }
2218  } else {
2219  // For each media type with more than one stream, find a suitable stream to
2220  // mark as default, unless one is already marked default.
2221  // "Suitable" means the first of that type, skipping attached pictures.
2222  for (int i = 0; i < ctx->nb_streams; i++) {
2224  enum AVMediaType type = ost->st->codecpar->codec_type;
2225 
2226  if (nb_streams[type] < 2 || have_default[type] ||
2228  continue;
2229 
2231  have_default[type] = 1;
2232  }
2233  }
2234 
2235  return 0;
2236 }
2237 
2239  AVFormatContext *oc)
2240 {
2241  OutputStream *ost;
2242 
2243  switch (ofilter->type) {
2244  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
2245  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
2246  default:
2247  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported "
2248  "currently.\n");
2249  exit_program(1);
2250  }
2251 
2252  ost->filter = ofilter;
2253 
2254  ofilter->ost = ost;
2255  ofilter->format = -1;
2256 
2257  if (ost->stream_copy) {
2258  av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
2259  "which is fed from a complex filtergraph. Filtering and streamcopy "
2260  "cannot be used together.\n", ost->file_index, ost->index);
2261  exit_program(1);
2262  }
2263 
2264  if (ost->avfilter && (ost->filters || ost->filters_script)) {
2265  const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
2267  "%s '%s' was specified through the %s option "
2268  "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2269  "%s and -filter_complex cannot be used together for the same stream.\n",
2270  ost->filters ? "Filtergraph" : "Filtergraph script",
2271  ost->filters ? ost->filters : ost->filters_script,
2272  opt, ost->file_index, ost->index, opt);
2273  exit_program(1);
2274  }
2275 
2276  avfilter_inout_free(&ofilter->out_tmp);
2277 }
2278 
2279 static int init_complex_filters(void)
2280 {
2281  int i, ret = 0;
2282 
2283  for (i = 0; i < nb_filtergraphs; i++) {
2285  if (ret < 0)
2286  return ret;
2287  }
2288  return 0;
2289 }
2290 
2291 static int open_output_file(OptionsContext *o, const char *filename)
2292 {
2293  AVFormatContext *oc;
2294  int i, j, err;
2295  OutputFile *of;
2296  OutputStream *ost;
2297  InputStream *ist;
2298  AVDictionary *unused_opts = NULL;
2299  const AVDictionaryEntry *e = NULL;
2300 
2301  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
2302  o->stop_time = INT64_MAX;
2303  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2304  }
2305 
2306  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
2307  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2308  if (o->stop_time <= start_time) {
2309  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2310  exit_program(1);
2311  } else {
2313  }
2314  }
2315 
2317 
2318  of->index = nb_output_files - 1;
2320  of->recording_time = o->recording_time;
2321  of->start_time = o->start_time;
2322  of->limit_filesize = o->limit_filesize;
2323  of->shortest = o->shortest;
2324  av_dict_copy(&of->opts, o->g->format_opts, 0);
2325 
2326  if (!strcmp(filename, "-"))
2327  filename = "pipe:";
2328 
2329  err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2330  if (!oc) {
2331  print_error(filename, err);
2332  exit_program(1);
2333  }
2334 
2335  of->ctx = oc;
2336  of->format = oc->oformat;
2337  if (o->recording_time != INT64_MAX)
2338  oc->duration = o->recording_time;
2339 
2340  oc->interrupt_callback = int_cb;
2341 
2342  if (o->bitexact) {
2343  oc->flags |= AVFMT_FLAG_BITEXACT;
2344  }
2345 
2346  /* create streams for all unlabeled output pads */
2347  for (i = 0; i < nb_filtergraphs; i++) {
2348  FilterGraph *fg = filtergraphs[i];
2349  for (j = 0; j < fg->nb_outputs; j++) {
2350  OutputFilter *ofilter = fg->outputs[j];
2351 
2352  if (!ofilter->out_tmp || ofilter->out_tmp->name)
2353  continue;
2354 
2355  switch (ofilter->type) {
2356  case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break;
2357  case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break;
2358  case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
2359  }
2360  init_output_filter(ofilter, o, oc);
2361  }
2362  }
2363 
2364  if (!o->nb_stream_maps) {
2365  char *subtitle_codec_name = NULL;
2366  /* pick the "best" stream of each type */
2367 
2368  /* video: highest resolution */
2370  int best_score = 0, idx = -1;
2371  int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2372  for (j = 0; j < nb_input_files; j++) {
2373  InputFile *ifile = input_files[j];
2374  int file_best_score = 0, file_best_idx = -1;
2375  for (i = 0; i < ifile->nb_streams; i++) {
2376  int score;
2377  ist = input_streams[ifile->ist_index + i];
2378  score = ist->st->codecpar->width * ist->st->codecpar->height
2379  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
2380  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2381  if (ist->user_set_discard == AVDISCARD_ALL)
2382  continue;
2383  if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2384  score = 1;
2385  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2386  score > file_best_score) {
2387  if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2388  continue;
2389  file_best_score = score;
2390  file_best_idx = ifile->ist_index + i;
2391  }
2392  }
2393  if (file_best_idx >= 0) {
2394  if((qcr == MKTAG('A', 'P', 'I', 'C')) || !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2395  file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT);
2396  if (file_best_score > best_score) {
2397  best_score = file_best_score;
2398  idx = file_best_idx;
2399  }
2400  }
2401  }
2402  if (idx >= 0)
2403  new_video_stream(o, oc, idx);
2404  }
2405 
2406  /* audio: most channels */
2408  int best_score = 0, idx = -1;
2409  for (j = 0; j < nb_input_files; j++) {
2410  InputFile *ifile = input_files[j];
2411  int file_best_score = 0, file_best_idx = -1;
2412  for (i = 0; i < ifile->nb_streams; i++) {
2413  int score;
2414  ist = input_streams[ifile->ist_index + i];
2415  score = ist->st->codecpar->ch_layout.nb_channels
2416  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
2417  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2418  if (ist->user_set_discard == AVDISCARD_ALL)
2419  continue;
2420  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2421  score > file_best_score) {
2422  file_best_score = score;
2423  file_best_idx = ifile->ist_index + i;
2424  }
2425  }
2426  if (file_best_idx >= 0) {
2427  file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT);
2428  if (file_best_score > best_score) {
2429  best_score = file_best_score;
2430  idx = file_best_idx;
2431  }
2432  }
2433  }
2434  if (idx >= 0)
2435  new_audio_stream(o, oc, idx);
2436  }
2437 
2438  /* subtitles: pick first */
2439  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
2441  for (i = 0; i < nb_input_streams; i++)
2442  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2443  AVCodecDescriptor const *input_descriptor =
2444  avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id);
2445  AVCodecDescriptor const *output_descriptor = NULL;
2446  AVCodec const *output_codec =
2448  int input_props = 0, output_props = 0;
2449  if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2450  continue;
2451  if (output_codec)
2452  output_descriptor = avcodec_descriptor_get(output_codec->id);
2453  if (input_descriptor)
2454  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2455  if (output_descriptor)
2456  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2457  if (subtitle_codec_name ||
2458  input_props & output_props ||
2459  // Map dvb teletext which has neither property to any output subtitle encoder
2460  input_descriptor && output_descriptor &&
2461  (!input_descriptor->props ||
2462  !output_descriptor->props)) {
2463  new_subtitle_stream(o, oc, i);
2464  break;
2465  }
2466  }
2467  }
2468  /* Data only if codec id match */
2469  if (!o->data_disable ) {
2471  for (i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) {
2472  if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2473  continue;
2474  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2476  new_data_stream(o, oc, i);
2477  }
2478  }
2479  } else {
2480  for (i = 0; i < o->nb_stream_maps; i++) {
2481  StreamMap *map = &o->stream_maps[i];
2482 
2483  if (map->disabled)
2484  continue;
2485 
2486  if (map->linklabel) {
2487  FilterGraph *fg;
2488  OutputFilter *ofilter = NULL;
2489  int j, k;
2490 
2491  for (j = 0; j < nb_filtergraphs; j++) {
2492  fg = filtergraphs[j];
2493  for (k = 0; k < fg->nb_outputs; k++) {
2494  AVFilterInOut *out = fg->outputs[k]->out_tmp;
2495  if (out && !strcmp(out->name, map->linklabel)) {
2496  ofilter = fg->outputs[k];
2497  goto loop_end;
2498  }
2499  }
2500  }
2501 loop_end:
2502  if (!ofilter) {
2503  av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2504  "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2505  exit_program(1);
2506  }
2507  init_output_filter(ofilter, o, oc);
2508  } else {
2509  int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2510 
2511  ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
2512  if (ist->user_set_discard == AVDISCARD_ALL) {
2513  av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
2514  map->file_index, map->stream_index);
2515  exit_program(1);
2516  }
2518  continue;
2520  continue;
2522  continue;
2523  if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2524  continue;
2525 
2526  ost = NULL;
2527  switch (ist->st->codecpar->codec_type) {
2528  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2529  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2530  case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2531  case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2532  case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2533  case AVMEDIA_TYPE_UNKNOWN:
2534  if (copy_unknown_streams) {
2535  ost = new_unknown_stream (o, oc, src_idx);
2536  break;
2537  }
2538  default:
2540  "Cannot map stream #%d:%d - unsupported type.\n",
2541  map->file_index, map->stream_index);
2542  if (!ignore_unknown_streams) {
2544  "If you want unsupported types ignored instead "
2545  "of failing, please use the -ignore_unknown option\n"
2546  "If you want them copied, please use -copy_unknown\n");
2547  exit_program(1);
2548  }
2549  }
2550  if (ost)
2551  ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
2552  + map->sync_stream_index];
2553  }
2554  }
2555  }
2556 
2557  /* handle attached files */
2558  for (i = 0; i < o->nb_attachments; i++) {
2559  AVIOContext *pb;
2560  uint8_t *attachment;
2561  const char *p;
2562  int64_t len;
2563 
2564  if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
2565  av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
2566  o->attachments[i]);
2567  exit_program(1);
2568  }
2569  if ((len = avio_size(pb)) <= 0) {
2570  av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
2571  o->attachments[i]);
2572  exit_program(1);
2573  }
2574  if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
2575  !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
2576  av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
2577  o->attachments[i]);
2578  exit_program(1);
2579  }
2580  avio_read(pb, attachment, len);
2581  memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
2582 
2583  ost = new_attachment_stream(o, oc, -1);
2584  ost->stream_copy = 0;
2585  ost->attachment_filename = o->attachments[i];
2586  ost->st->codecpar->extradata = attachment;
2587  ost->st->codecpar->extradata_size = len;
2588 
2589  p = strrchr(o->attachments[i], '/');
2590  av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
2591  avio_closep(&pb);
2592  }
2593 
2594  if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2595  av_dump_format(oc, nb_output_files - 1, oc->url, 1);
2596  av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
2597  exit_program(1);
2598  }
2599 
2600  /* check if all codec options have been used */
2601  unused_opts = strip_specifiers(o->g->codec_opts);
2602  for (i = of->ost_index; i < nb_output_streams; i++) {
2603  e = NULL;
2604  while ((e = av_dict_get(output_streams[i]->encoder_opts, "", e,
2606  av_dict_set(&unused_opts, e->key, NULL, 0);
2607  }
2608 
2609  e = NULL;
2610  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
2611  const AVClass *class = avcodec_get_class();
2612  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2614  const AVClass *fclass = avformat_get_class();
2615  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2617  if (!option || foption)
2618  continue;
2619 
2620 
2621  if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2622  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
2623  "output file #%d (%s) is not an encoding option.\n", e->key,
2624  option->help ? option->help : "", nb_output_files - 1,
2625  filename);
2626  exit_program(1);
2627  }
2628 
2629  // gop_timecode is injected by generic code but not always used
2630  if (!strcmp(e->key, "gop_timecode"))
2631  continue;
2632 
2633  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
2634  "output file #%d (%s) has not been used for any stream. The most "
2635  "likely reason is either wrong type (e.g. a video option with "
2636  "no video streams) or that it is a private option of some encoder "
2637  "which was not actually used for any stream.\n", e->key,
2638  option->help ? option->help : "", nb_output_files - 1, filename);
2639  }
2640  av_dict_free(&unused_opts);
2641 
2642  /* set the decoding_needed flags and create simple filtergraphs */
2643  for (i = of->ost_index; i < nb_output_streams; i++) {
2645 
2646  if (ost->encoding_needed && ost->source_index >= 0) {
2647  InputStream *ist = input_streams[ost->source_index];
2649  ist->processing_needed = 1;
2650 
2651  if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2653  err = init_simple_filtergraph(ist, ost);
2654  if (err < 0) {
2656  "Error initializing a simple filtergraph between streams "
2657  "%d:%d->%d:%d\n", ist->file_index, ost->source_index,
2658  nb_output_files - 1, ost->st->index);
2659  exit_program(1);
2660  }
2661  }
2662  } else if (ost->stream_copy && ost->source_index >= 0) {
2663  InputStream *ist = input_streams[ost->source_index];
2664  ist->processing_needed = 1;
2665  }
2666 
2667  /* set the filter output constraints */
2668  if (ost->filter) {
2669  OutputFilter *f = ost->filter;
2670  switch (ost->enc_ctx->codec_type) {
2671  case AVMEDIA_TYPE_VIDEO:
2672  f->frame_rate = ost->frame_rate;
2673  f->width = ost->enc_ctx->width;
2674  f->height = ost->enc_ctx->height;
2675  if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2676  f->format = ost->enc_ctx->pix_fmt;
2677  } else {
2678  f->formats = ost->enc->pix_fmts;
2679  }
2680  break;
2681  case AVMEDIA_TYPE_AUDIO:
2682  if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2683  f->format = ost->enc_ctx->sample_fmt;
2684  } else {
2685  f->formats = ost->enc->sample_fmts;
2686  }
2687  if (ost->enc_ctx->sample_rate) {
2688  f->sample_rate = ost->enc_ctx->sample_rate;
2689  } else {
2690  f->sample_rates = ost->enc->supported_samplerates;
2691  }
2692  if (ost->enc_ctx->ch_layout.nb_channels) {
2693  av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
2694  } else if (ost->enc->ch_layouts) {
2695  f->ch_layouts = ost->enc->ch_layouts;
2696  }
2697  break;
2698  }
2699  }
2700  }
2701 
2702  /* check filename in case of an image number is expected */
2703  if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2704  if (!av_filename_number_test(oc->url)) {
2705  print_error(oc->url, AVERROR(EINVAL));
2706  exit_program(1);
2707  }
2708  }
2709 
2712  "No input streams but output needs an input stream\n");
2713  exit_program(1);
2714  }
2715 
2716  if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2717  /* test if it already exists to avoid losing precious files */
2718  assert_file_overwrite(filename);
2719 
2720  /* open the file */
2721  if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2722  &oc->interrupt_callback,
2723  &of->opts)) < 0) {
2724  print_error(filename, err);
2725  exit_program(1);
2726  }
2727  } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
2728  assert_file_overwrite(filename);
2729 
2730  if (o->mux_preload) {
2731  av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2732  }
2733  oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2734 
2735  /* copy metadata */
2736  for (i = 0; i < o->nb_metadata_map; i++) {
2737  char *p;
2738  int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2739 
2740  if (in_file_index >= nb_input_files) {
2741  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
2742  exit_program(1);
2743  }
2744  copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc,
2745  in_file_index >= 0 ?
2746  input_files[in_file_index]->ctx : NULL, o);
2747  }
2748 
2749  /* copy chapters */
2750  if (o->chapters_input_file >= nb_input_files) {
2751  if (o->chapters_input_file == INT_MAX) {
2752  /* copy chapters from the first input file that has them*/
2753  o->chapters_input_file = -1;
2754  for (i = 0; i < nb_input_files; i++)
2755  if (input_files[i]->ctx->nb_chapters) {
2756  o->chapters_input_file = i;
2757  break;
2758  }
2759  } else {
2760  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2761  o->chapters_input_file);
2762  exit_program(1);
2763  }
2764  }
2765  if (o->chapters_input_file >= 0)
2768 
2769  /* copy global metadata by default */
2773  if(o->recording_time != INT64_MAX)
2774  av_dict_set(&oc->metadata, "duration", NULL, 0);
2775  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2776  av_dict_set(&oc->metadata, "company_name", NULL, 0);
2777  av_dict_set(&oc->metadata, "product_name", NULL, 0);
2778  av_dict_set(&oc->metadata, "product_version", NULL, 0);
2779  }
2780  if (!o->metadata_streams_manual)
2781  for (i = of->ost_index; i < nb_output_streams; i++) {
2782  InputStream *ist;
2783  if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
2784  continue;
2787  if (!output_streams[i]->stream_copy) {
2788  av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
2789  }
2790  }
2791 
2792  /* process manually set programs */
2793  for (i = 0; i < o->nb_program; i++) {
2794  const char *p = o->program[i].u.str;
2795  int progid = i+1;
2796  AVProgram *program;
2797 
2798  while(*p) {
2799  const char *p2 = av_get_token(&p, ":");
2800  const char *to_dealloc = p2;
2801  char *key;
2802  if (!p2)
2803  break;
2804 
2805  if(*p) p++;
2806 
2807  key = av_get_token(&p2, "=");
2808  if (!key || !*p2) {
2809  av_freep(&to_dealloc);
2810  av_freep(&key);
2811  break;
2812  }
2813  p2++;
2814 
2815  if (!strcmp(key, "program_num"))
2816  progid = strtol(p2, NULL, 0);
2817  av_freep(&to_dealloc);
2818  av_freep(&key);
2819  }
2820 
2821  program = av_new_program(oc, progid);
2822 
2823  p = o->program[i].u.str;
2824  while(*p) {
2825  const char *p2 = av_get_token(&p, ":");
2826  const char *to_dealloc = p2;
2827  char *key;
2828  if (!p2)
2829  break;
2830  if(*p) p++;
2831 
2832  key = av_get_token(&p2, "=");
2833  if (!key) {
2835  "No '=' character in program string %s.\n",
2836  p2);
2837  exit_program(1);
2838  }
2839  if (!*p2)
2840  exit_program(1);
2841  p2++;
2842 
2843  if (!strcmp(key, "title")) {
2844  av_dict_set(&program->metadata, "title", p2, 0);
2845  } else if (!strcmp(key, "program_num")) {
2846  } else if (!strcmp(key, "st")) {
2847  int st_num = strtol(p2, NULL, 0);
2848  av_program_add_stream_index(oc, progid, st_num);
2849  } else {
2850  av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
2851  exit_program(1);
2852  }
2853  av_freep(&to_dealloc);
2854  av_freep(&key);
2855  }
2856  }
2857 
2858  /* process manually set metadata */
2859  for (i = 0; i < o->nb_metadata; i++) {
2860  AVDictionary **m;
2861  char type, *val;
2862  const char *stream_spec;
2863  int index = 0, j, ret = 0;
2864 
2865  val = strchr(o->metadata[i].u.str, '=');
2866  if (!val) {
2867  av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2868  o->metadata[i].u.str);
2869  exit_program(1);
2870  }
2871  *val++ = 0;
2872 
2873  parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
2874  if (type == 's') {
2875  for (j = 0; j < oc->nb_streams; j++) {
2877  if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2878  if (!strcmp(o->metadata[i].u.str, "rotate")) {
2879  char *tail;
2880  double theta = av_strtod(val, &tail);
2881  if (!*tail) {
2882  ost->rotate_overridden = 1;
2883  ost->rotate_override_value = theta;
2884  }
2885  } else {
2886  av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
2887  }
2888  } else if (ret < 0)
2889  exit_program(1);
2890  }
2891  }
2892  else {
2893  switch (type) {
2894  case 'g':
2895  m = &oc->metadata;
2896  break;
2897  case 'c':
2898  if (index < 0 || index >= oc->nb_chapters) {
2899  av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
2900  exit_program(1);
2901  }
2902  m = &oc->chapters[index]->metadata;
2903  break;
2904  case 'p':
2905  if (index < 0 || index >= oc->nb_programs) {
2906  av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
2907  exit_program(1);
2908  }
2909  m = &oc->programs[index]->metadata;
2910  break;
2911  default:
2912  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
2913  exit_program(1);
2914  }
2915  av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
2916  }
2917  }
2918 
2919  err = set_dispositions(of, oc);
2920  if (err < 0) {
2921  av_log(NULL, AV_LOG_FATAL, "Error setting output stream dispositions\n");
2922  exit_program(1);
2923  }
2924 
2925  return 0;
2926 }
2927 
2928 static int opt_target(void *optctx, const char *opt, const char *arg)
2929 {
2930  OptionsContext *o = optctx;
2931  enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
2932  static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
2933 
2934  if (!strncmp(arg, "pal-", 4)) {
2935  norm = PAL;
2936  arg += 4;
2937  } else if (!strncmp(arg, "ntsc-", 5)) {
2938  norm = NTSC;
2939  arg += 5;
2940  } else if (!strncmp(arg, "film-", 5)) {
2941  norm = FILM;
2942  arg += 5;
2943  } else {
2944  /* Try to determine PAL/NTSC by peeking in the input files */
2945  if (nb_input_files) {
2946  int i, j;
2947  for (j = 0; j < nb_input_files; j++) {
2948  for (i = 0; i < input_files[j]->nb_streams; i++) {
2949  AVStream *st = input_files[j]->ctx->streams[i];
2950  int64_t fr;
2952  continue;
2953  fr = st->time_base.den * 1000LL / st->time_base.num;
2954  if (fr == 25000) {
2955  norm = PAL;
2956  break;
2957  } else if ((fr == 29970) || (fr == 23976)) {
2958  norm = NTSC;
2959  break;
2960  }
2961  }
2962  if (norm != UNKNOWN)
2963  break;
2964  }
2965  }
2966  if (norm != UNKNOWN)
2967  av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
2968  }
2969 
2970  if (norm == UNKNOWN) {
2971  av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
2972  av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
2973  av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
2974  exit_program(1);
2975  }
2976 
2977  if (!strcmp(arg, "vcd")) {
2978  opt_video_codec(o, "c:v", "mpeg1video");
2979  opt_audio_codec(o, "c:a", "mp2");
2980  parse_option(o, "f", "vcd", options);
2981 
2982  parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
2983  parse_option(o, "r", frame_rates[norm], options);
2984  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2985 
2986  opt_default(NULL, "b:v", "1150000");
2987  opt_default(NULL, "maxrate:v", "1150000");
2988  opt_default(NULL, "minrate:v", "1150000");
2989  opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
2990 
2991  opt_default(NULL, "b:a", "224000");
2992  parse_option(o, "ar", "44100", options);
2993  parse_option(o, "ac", "2", options);
2994 
2995  opt_default(NULL, "packetsize", "2324");
2996  opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
2997 
2998  /* We have to offset the PTS, so that it is consistent with the SCR.
2999  SCR starts at 36000, but the first two packs contain only padding
3000  and the first pack from the other stream, respectively, may also have
3001  been written before.
3002  So the real data starts at SCR 36000+3*1200. */
3003  o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
3004  } else if (!strcmp(arg, "svcd")) {
3005 
3006  opt_video_codec(o, "c:v", "mpeg2video");
3007  opt_audio_codec(o, "c:a", "mp2");
3008  parse_option(o, "f", "svcd", options);
3009 
3010  parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
3011  parse_option(o, "r", frame_rates[norm], options);
3012  parse_option(o, "pix_fmt", "yuv420p", options);
3013  opt_default(NULL, "g", norm == PAL ? "15" : "18");
3014 
3015  opt_default(NULL, "b:v", "2040000");
3016  opt_default(NULL, "maxrate:v", "2516000");
3017  opt_default(NULL, "minrate:v", "0"); // 1145000;
3018  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
3019  opt_default(NULL, "scan_offset", "1");
3020 
3021  opt_default(NULL, "b:a", "224000");
3022  parse_option(o, "ar", "44100", options);
3023 
3024  opt_default(NULL, "packetsize", "2324");
3025 
3026  } else if (!strcmp(arg, "dvd")) {
3027 
3028  opt_video_codec(o, "c:v", "mpeg2video");
3029  opt_audio_codec(o, "c:a", "ac3");
3030  parse_option(o, "f", "dvd", options);
3031 
3032  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
3033  parse_option(o, "r", frame_rates[norm], options);
3034  parse_option(o, "pix_fmt", "yuv420p", options);
3035  opt_default(NULL, "g", norm == PAL ? "15" : "18");
3036 
3037  opt_default(NULL, "b:v", "6000000");
3038  opt_default(NULL, "maxrate:v", "9000000");
3039  opt_default(NULL, "minrate:v", "0"); // 1500000;
3040  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
3041 
3042  opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
3043  opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
3044 
3045  opt_default(NULL, "b:a", "448000");
3046  parse_option(o, "ar", "48000", options);
3047 
3048  } else if (!strncmp(arg, "dv", 2)) {
3049 
3050  parse_option(o, "f", "dv", options);
3051 
3052  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
3053  parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
3054  norm == PAL ? "yuv420p" : "yuv411p", options);
3055  parse_option(o, "r", frame_rates[norm], options);
3056 
3057  parse_option(o, "ar", "48000", options);
3058  parse_option(o, "ac", "2", options);
3059 
3060  } else {
3061  av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
3062  return AVERROR(EINVAL);
3063  }
3064 
3067 
3068  return 0;
3069 }
3070 
3071 static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
3072 {
3075  return 0;
3076 }
3077 
3078 static int opt_vstats(void *optctx, const char *opt, const char *arg)
3079 {
3080  char filename[40];
3081  time_t today2 = time(NULL);
3082  struct tm *today = localtime(&today2);
3083 
3084  if (!today) { // maybe tomorrow
3085  av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
3086  exit_program(1);
3087  }
3088 
3089  snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
3090  today->tm_sec);
3091  return opt_vstats_file(NULL, opt, filename);
3092 }
3093 
3094 static int opt_video_frames(void *optctx, const char *opt, const char *arg)
3095 {
3096  OptionsContext *o = optctx;
3097  return parse_option(o, "frames:v", arg, options);
3098 }
3099 
3100 static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
3101 {
3102  OptionsContext *o = optctx;
3103  return parse_option(o, "frames:a", arg, options);
3104 }
3105 
3106 static int opt_data_frames(void *optctx, const char *opt, const char *arg)
3107 {
3108  OptionsContext *o = optctx;
3109  return parse_option(o, "frames:d", arg, options);
3110 }
3111 
3112 static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
3113 {
3114  int ret;
3115  AVDictionary *cbak = codec_opts;
3116  AVDictionary *fbak = format_opts;
3117  codec_opts = NULL;
3118  format_opts = NULL;
3119 
3120  ret = opt_default(NULL, opt, arg);
3121 
3122  av_dict_copy(&o->g->codec_opts , codec_opts, 0);
3126  codec_opts = cbak;
3127  format_opts = fbak;
3128 
3129  return ret;
3130 }
3131 
3132 static int opt_preset(void *optctx, const char *opt, const char *arg)
3133 {
3134  OptionsContext *o = optctx;
3135  FILE *f=NULL;
3136  char filename[1000], line[1000], tmp_line[1000];
3137  const char *codec_name = NULL;
3138 
3139  tmp_line[0] = *opt;
3140  tmp_line[1] = 0;
3141  MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
3142 
3143  if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
3144  if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
3145  av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
3146  }else
3147  av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
3148  exit_program(1);
3149  }
3150 
3151  while (fgets(line, sizeof(line), f)) {
3152  char *key = tmp_line, *value, *endptr;
3153 
3154  if (strcspn(line, "#\n\r") == 0)
3155  continue;
3156  av_strlcpy(tmp_line, line, sizeof(tmp_line));
3157  if (!av_strtok(key, "=", &value) ||
3158  !av_strtok(value, "\r\n", &endptr)) {
3159  av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
3160  exit_program(1);
3161  }
3162  av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
3163 
3164  if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
3165  else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
3166  else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
3167  else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
3168  else if (opt_default_new(o, key, value) < 0) {
3169  av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
3170  filename, line, key, value);
3171  exit_program(1);
3172  }
3173  }
3174 
3175  fclose(f);
3176 
3177  return 0;
3178 }
3179 
3180 static int opt_old2new(void *optctx, const char *opt, const char *arg)
3181 {
3182  OptionsContext *o = optctx;
3183  int ret;
3184  char *s = av_asprintf("%s:%c", opt + 1, *opt);
3185  if (!s)
3186  return AVERROR(ENOMEM);
3187  ret = parse_option(o, s, arg, options);
3188  av_free(s);
3189  return ret;
3190 }
3191 
3192 static int opt_bitrate(void *optctx, const char *opt, const char *arg)
3193 {
3194  OptionsContext *o = optctx;
3195 
3196  if(!strcmp(opt, "ab")){
3197  av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
3198  return 0;
3199  } else if(!strcmp(opt, "b")){
3200  av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
3201  av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
3202  return 0;
3203  }
3204  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3205  return 0;
3206 }
3207 
3208 static int opt_qscale(void *optctx, const char *opt, const char *arg)
3209 {
3210  OptionsContext *o = optctx;
3211  char *s;
3212  int ret;
3213  if(!strcmp(opt, "qscale")){
3214  av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
3215  return parse_option(o, "q:v", arg, options);
3216  }
3217  s = av_asprintf("q%s", opt + 6);
3218  if (!s)
3219  return AVERROR(ENOMEM);
3220  ret = parse_option(o, s, arg, options);
3221  av_free(s);
3222  return ret;
3223 }
3224 
3225 static int opt_profile(void *optctx, const char *opt, const char *arg)
3226 {
3227  OptionsContext *o = optctx;
3228  if(!strcmp(opt, "profile")){
3229  av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
3230  av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
3231  return 0;
3232  }
3233  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3234  return 0;
3235 }
3236 
3237 static int opt_video_filters(void *optctx, const char *opt, const char *arg)
3238 {
3239  OptionsContext *o = optctx;
3240  return parse_option(o, "filter:v", arg, options);
3241 }
3242 
3243 static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
3244 {
3245  OptionsContext *o = optctx;
3246  return parse_option(o, "filter:a", arg, options);
3247 }
3248 
3249 static int opt_vsync(void *optctx, const char *opt, const char *arg)
3250 {
3251  if (!av_strcasecmp(arg, "cfr")) video_sync_method = VSYNC_CFR;
3252  else if (!av_strcasecmp(arg, "vfr")) video_sync_method = VSYNC_VFR;
3253  else if (!av_strcasecmp(arg, "passthrough")) video_sync_method = VSYNC_PASSTHROUGH;
3254  else if (!av_strcasecmp(arg, "drop")) video_sync_method = VSYNC_DROP;
3255 
3256  if (video_sync_method == VSYNC_AUTO) {
3258  av_log(NULL, AV_LOG_WARNING, "Passing a number to -vsync is deprecated,"
3259  " use a string argument as described in the manual.\n");
3260  }
3261  return 0;
3262 }
3263 
3264 static int opt_timecode(void *optctx, const char *opt, const char *arg)
3265 {
3266  OptionsContext *o = optctx;
3267  int ret;
3268  char *tcr = av_asprintf("timecode=%s", arg);
3269  if (!tcr)
3270  return AVERROR(ENOMEM);
3271  ret = parse_option(o, "metadata:g", tcr, options);
3272  if (ret >= 0)
3273  ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
3274  av_free(tcr);
3275  return ret;
3276 }
3277 
3278 static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
3279 {
3280  OptionsContext *o = optctx;
3281  return parse_option(o, "q:a", arg, options);
3282 }
3283 
3284 static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
3285 {
3287 
3288  fg->index = nb_filtergraphs - 1;
3289  fg->graph_desc = av_strdup(arg);
3290  if (!fg->graph_desc)
3291  return AVERROR(ENOMEM);
3292 
3294 
3295  return 0;
3296 }
3297 
3298 static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
3299 {
3300  FilterGraph *fg;
3301  char *graph_desc = read_file(arg);
3302  if (!graph_desc)
3303  return AVERROR(EINVAL);
3304 
3306  fg->index = nb_filtergraphs - 1;
3307  fg->graph_desc = graph_desc;
3308 
3310 
3311  return 0;
3312 }
3313 
3314 void show_help_default(const char *opt, const char *arg)
3315 {
3316  /* per-file options have at least one of those set */
3317  const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
3318  int show_advanced = 0, show_avoptions = 0;
3319 
3320  if (opt && *opt) {
3321  if (!strcmp(opt, "long"))
3322  show_advanced = 1;
3323  else if (!strcmp(opt, "full"))
3324  show_advanced = show_avoptions = 1;
3325  else
3326  av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
3327  }
3328 
3329  show_usage();
3330 
3331  printf("Getting help:\n"
3332  " -h -- print basic options\n"
3333  " -h long -- print more options\n"
3334  " -h full -- print all options (including all format and codec specific options, very long)\n"
3335  " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
3336  " See man %s for detailed description of the options.\n"
3337  "\n", program_name);
3338 
3339  show_help_options(options, "Print help / information / capabilities:",
3340  OPT_EXIT, 0, 0);
3341 
3342  show_help_options(options, "Global options (affect whole program "
3343  "instead of just one file):",
3344  0, per_file | OPT_EXIT | OPT_EXPERT, 0);
3345  if (show_advanced)
3346  show_help_options(options, "Advanced global options:", OPT_EXPERT,
3347  per_file | OPT_EXIT, 0);
3348 
3349  show_help_options(options, "Per-file main options:", 0,
3351  OPT_EXIT, per_file);
3352  if (show_advanced)
3353  show_help_options(options, "Advanced per-file options:",
3354  OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file);
3355 
3356  show_help_options(options, "Video options:",
3358  if (show_advanced)
3359  show_help_options(options, "Advanced Video options:",
3361 
3362  show_help_options(options, "Audio options:",
3364  if (show_advanced)
3365  show_help_options(options, "Advanced Audio options:",
3367  show_help_options(options, "Subtitle options:",
3368  OPT_SUBTITLE, 0, 0);
3369  printf("\n");
3370 
3371  if (show_avoptions) {
3375 #if CONFIG_SWSCALE
3377 #endif
3378 #if CONFIG_SWRESAMPLE
3380 #endif
3383  }
3384 }
3385 
3386 void show_usage(void)
3387 {
3388  av_log(NULL, AV_LOG_INFO, "Hyper fast Audio and Video encoder\n");
3389  av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
3390  av_log(NULL, AV_LOG_INFO, "\n");
3391 }
3392 
3393 enum OptGroup {
3394  GROUP_OUTFILE,
3395  GROUP_INFILE,
3396 };
3397 
3398 static const OptionGroupDef groups[] = {
3399  [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
3400  [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
3401 };
3402 
3403 static int open_files(OptionGroupList *l, const char *inout,
3404  int (*open_file)(OptionsContext*, const char*))
3405 {
3406  int i, ret;
3407 
3408  for (i = 0; i < l->nb_groups; i++) {
3409  OptionGroup *g = &l->groups[i];
3410  OptionsContext o;
3411 
3412  init_options(&o);
3413  o.g = g;
3414 
3415  ret = parse_optgroup(&o, g);
3416  if (ret < 0) {
3417  av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
3418  "%s.\n", inout, g->arg);
3419  uninit_options(&o);
3420  return ret;
3421  }
3422 
3423  av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
3424  ret = open_file(&o, g->arg);
3425  uninit_options(&o);
3426  if (ret < 0) {
3427  av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
3428  inout, g->arg);
3429  return ret;
3430  }
3431  av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
3432  }
3433 
3434  return 0;
3435 }
3436 
3437 int ffmpeg_parse_options(int argc, char **argv)
3438 {
3439  OptionParseContext octx;
3440  uint8_t error[128];
3441  int ret;
3442 
3443  memset(&octx, 0, sizeof(octx));
3444 
3445  /* split the commandline into an internal representation */
3446  ret = split_commandline(&octx, argc, argv, options, groups,
3447  FF_ARRAY_ELEMS(groups));
3448  if (ret < 0) {
3449  av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
3450  goto fail;
3451  }
3452 
3453  /* apply global options */
3454  ret = parse_optgroup(NULL, &octx.global_opts);
3455  if (ret < 0) {
3456  av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
3457  goto fail;
3458  }
3459 
3460  /* configure terminal and setup signal handlers */
3461  term_init();
3462 
3463  /* open input files */
3464  ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file);
3465  if (ret < 0) {
3466  av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
3467  goto fail;
3468  }
3469 
3470  /* create the complex filtergraphs */
3472  if (ret < 0) {
3473  av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
3474  goto fail;
3475  }
3476 
3477  /* open output files */
3478  ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file);
3479  if (ret < 0) {
3480  av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
3481  goto fail;
3482  }
3483 
3485 
3486 fail:
3487  uninit_parse_context(&octx);
3488  if (ret < 0) {
3489  av_strerror(ret, error, sizeof(error));
3490  av_log(NULL, AV_LOG_FATAL, "%s\n", error);
3491  }
3492  return ret;
3493 }
3494 
3495 static int opt_progress(void *optctx, const char *opt, const char *arg)
3496 {
3497  AVIOContext *avio = NULL;
3498  int ret;
3499 
3500  if (!strcmp(arg, "-"))
3501  arg = "pipe:";
3502  ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
3503  if (ret < 0) {
3504  av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
3505  arg, av_err2str(ret));
3506  return ret;
3507  }
3508  progress_avio = avio;
3509  return 0;
3510 }
3511 
3512 int opt_timelimit(void *optctx, const char *opt, const char *arg)
3513 {
3514 #if HAVE_SETRLIMIT
3515  int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
3516  struct rlimit rl = { lim, lim + 1 };
3517  if (setrlimit(RLIMIT_CPU, &rl))
3518  perror("setrlimit");
3519 #else
3520  av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
3521 #endif
3522  return 0;
3523 }
3524 
3525 #define OFFSET(x) offsetof(OptionsContext, x)
3526 const OptionDef options[] = {
3527  /* main options */
3529  { "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
3530  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
3531  "force format", "fmt" },
3532  { "y", OPT_BOOL, { &file_overwrite },
3533  "overwrite output files" },
3534  { "n", OPT_BOOL, { &no_file_overwrite },
3535  "never overwrite output files" },
3536  { "ignore_unknown", OPT_BOOL, { &ignore_unknown_streams },
3537  "Ignore unknown stream types" },
3538  { "copy_unknown", OPT_BOOL | OPT_EXPERT, { &copy_unknown_streams },
3539  "Copy unknown stream types" },
3540  { "recast_media", OPT_BOOL | OPT_EXPERT, { &recast_media },
3541  "allow recasting stream type in order to force a decoder of different media type" },
3542  { "c", HAS_ARG | OPT_STRING | OPT_SPEC |
3543  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3544  "codec name", "codec" },
3545  { "codec", HAS_ARG | OPT_STRING | OPT_SPEC |
3546  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3547  "codec name", "codec" },
3548  { "pre", HAS_ARG | OPT_STRING | OPT_SPEC |
3549  OPT_OUTPUT, { .off = OFFSET(presets) },
3550  "preset name", "preset" },
3551  { "map", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3552  OPT_OUTPUT, { .func_arg = opt_map },
3553  "set input stream mapping",
3554  "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
3555  { "map_channel", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map_channel },
3556  "map an audio channel from one stream to another", "file.stream.channel[:syncfile.syncstream]" },
3557  { "map_metadata", HAS_ARG | OPT_STRING | OPT_SPEC |
3558  OPT_OUTPUT, { .off = OFFSET(metadata_map) },
3559  "set metadata information of outfile from infile",
3560  "outfile[,metadata]:infile[,metadata]" },
3561  { "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
3562  OPT_OUTPUT, { .off = OFFSET(chapters_input_file) },
3563  "set chapters mapping", "input_file_index" },
3564  { "t", HAS_ARG | OPT_TIME | OPT_OFFSET |
3565  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) },
3566  "record or transcode \"duration\" seconds of audio/video",
3567  "duration" },
3568  { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) },
3569  "record or transcode stop time", "time_stop" },
3570  { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) },
3571  "set the limit file size in bytes", "limit_size" },
3572  { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |
3573  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(start_time) },
3574  "set the start time offset", "time_off" },
3575  { "sseof", HAS_ARG | OPT_TIME | OPT_OFFSET |
3576  OPT_INPUT, { .off = OFFSET(start_time_eof) },
3577  "set the start time offset relative to EOF", "time_off" },
3578  { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
3579  OPT_INPUT, { .off = OFFSET(seek_timestamp) },
3580  "enable/disable seeking by timestamp with -ss" },
3581  { "accurate_seek", OPT_BOOL | OPT_OFFSET | OPT_EXPERT |
3582  OPT_INPUT, { .off = OFFSET(accurate_seek) },
3583  "enable/disable accurate seeking with -ss" },
3584  { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET |
3585  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_ts_offset) },
3586  "set the input ts offset", "time_off" },
3587  { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC |
3588  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(ts_scale) },
3589  "set the input ts scale", "scale" },
3590  { "timestamp", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_recording_timestamp },
3591  "set the recording timestamp ('now' to set the current time)", "time" },
3592  { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(metadata) },
3593  "add metadata", "string=string" },
3594  { "program", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(program) },
3595  "add program with specified streams", "title=string:st=number..." },
3596  { "dframes", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3597  OPT_OUTPUT, { .func_arg = opt_data_frames },
3598  "set the number of data frames to output", "number" },
3599  { "benchmark", OPT_BOOL | OPT_EXPERT, { &do_benchmark },
3600  "add timings for benchmarking" },
3601  { "benchmark_all", OPT_BOOL | OPT_EXPERT, { &do_benchmark_all },
3602  "add timings for each task" },
3603  { "progress", HAS_ARG | OPT_EXPERT, { .func_arg = opt_progress },
3604  "write program-readable progress information", "url" },
3605  { "stdin", OPT_BOOL | OPT_EXPERT, { &stdin_interaction },
3606  "enable or disable interaction on standard input" },
3607  { "timelimit", HAS_ARG | OPT_EXPERT, { .func_arg = opt_timelimit },
3608  "set max runtime in seconds in CPU user time", "limit" },
3609  { "dump", OPT_BOOL | OPT_EXPERT, { &do_pkt_dump },
3610  "dump each input packet" },
3611  { "hex", OPT_BOOL | OPT_EXPERT, { &do_hex_dump },
3612  "when dumping packets, also dump the payload" },
3613  { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3614  OPT_INPUT, { .off = OFFSET(rate_emu) },
3615  "read input at native frame rate; equivalent to -readrate 1", "" },
3616  { "readrate", HAS_ARG | OPT_FLOAT | OPT_OFFSET |
3617  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(readrate) },
3618  "read input at specified rate", "speed" },
3619  { "target", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_target },
3620  "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
3621  "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")", "type" },
3622  { "vsync", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vsync },
3623  "video sync method", "" },
3624  { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &frame_drop_threshold },
3625  "frame drop threshold", "" },
3626  { "async", HAS_ARG | OPT_INT | OPT_EXPERT, { &audio_sync_method },
3627  "audio sync method", "" },
3628  { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &audio_drift_threshold },
3629  "audio drift threshold", "threshold" },
3630  { "copyts", OPT_BOOL | OPT_EXPERT, { &copy_ts },
3631  "copy timestamps" },
3632  { "start_at_zero", OPT_BOOL | OPT_EXPERT, { &start_at_zero },
3633  "shift input timestamps to start at 0 when using copyts" },
3634  { "copytb", HAS_ARG | OPT_INT | OPT_EXPERT, { &copy_tb },
3635  "copy input stream time base when stream copying", "mode" },
3636  { "shortest", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3637  OPT_OUTPUT, { .off = OFFSET(shortest) },
3638  "finish encoding within shortest input" },
3639  { "bitexact", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3640  OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(bitexact) },
3641  "bitexact mode" },
3642  { "apad", OPT_STRING | HAS_ARG | OPT_SPEC |
3643  OPT_OUTPUT, { .off = OFFSET(apad) },
3644  "audio pad", "" },
3645  { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_delta_threshold },
3646  "timestamp discontinuity delta threshold", "threshold" },
3647  { "dts_error_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_error_threshold },
3648  "timestamp error delta threshold", "threshold" },
3649  { "xerror", OPT_BOOL | OPT_EXPERT, { &exit_on_error },
3650  "exit on error", "error" },
3651  { "abort_on", HAS_ARG | OPT_EXPERT, { .func_arg = opt_abort_on },
3652  "abort on the specified condition flags", "flags" },
3653  { "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3654  OPT_OUTPUT, { .off = OFFSET(copy_initial_nonkeyframes) },
3655  "copy initial non-keyframes" },
3656  { "copypriorss", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(copy_prior_start) },
3657  "copy or discard frames before start time" },
3658  { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(max_frames) },
3659  "set the number of frames to output", "number" },
3660  { "tag", OPT_STRING | HAS_ARG | OPT_SPEC |
3661  OPT_EXPERT | OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(codec_tags) },
3662  "force codec tag/fourcc", "fourcc/tag" },
3663  { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE |
3664  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(qscale) },
3665  "use fixed quality scale (VBR)", "q" },
3666  { "qscale", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3667  OPT_OUTPUT, { .func_arg = opt_qscale },
3668  "use fixed quality scale (VBR)", "q" },
3669  { "profile", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_profile },
3670  "set profile", "profile" },
3671  { "filter", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filters) },
3672  "set stream filtergraph", "filter_graph" },
3673  { "filter_threads", HAS_ARG, { .func_arg = opt_filter_threads },
3674  "number of non-complex filter threads" },
3675  { "filter_script", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filter_scripts) },
3676  "read stream filtergraph description from a file", "filename" },
3677  { "reinit_filter", HAS_ARG | OPT_INT | OPT_SPEC | OPT_INPUT, { .off = OFFSET(reinit_filters) },
3678  "reinit filtergraph on input parameter changes", "" },
3679  { "filter_complex", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3680  "create a complex filtergraph", "graph_description" },
3681  { "filter_complex_threads", HAS_ARG | OPT_INT, { &filter_complex_nbthreads },
3682  "number of threads for -filter_complex" },
3683  { "lavfi", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3684  "create a complex filtergraph", "graph_description" },
3685  { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script },
3686  "read complex filtergraph description from a file", "filename" },
3687  { "auto_conversion_filters", OPT_BOOL | OPT_EXPERT, { &auto_conversion_filters },
3688  "enable automatic conversion filters globally" },
3689  { "stats", OPT_BOOL, { &print_stats },
3690  "print progress report during encoding", },
3691  { "stats_period", HAS_ARG | OPT_EXPERT, { .func_arg = opt_stats_period },
3692  "set the period at which ffmpeg updates stats and -progress output", "time" },
3693  { "attach", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3694  OPT_OUTPUT, { .func_arg = opt_attach },
3695  "add an attachment to the output file", "filename" },
3696  { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC |
3697  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(dump_attachment) },
3698  "extract an attachment into a file", "filename" },
3699  { "stream_loop", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_INPUT |
3700  OPT_OFFSET, { .off = OFFSET(loop) }, "set number of times input stream shall be looped", "loop count" },
3701  { "debug_ts", OPT_BOOL | OPT_EXPERT, { &debug_ts },
3702  "print timestamp debugging info" },
3703  { "max_error_rate", HAS_ARG | OPT_FLOAT, { &max_error_rate },
3704  "ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.", "maximum error rate" },
3705  { "discard", OPT_STRING | HAS_ARG | OPT_SPEC |
3706  OPT_INPUT, { .off = OFFSET(discard) },
3707  "discard", "" },
3708  { "disposition", OPT_STRING | HAS_ARG | OPT_SPEC |
3709  OPT_OUTPUT, { .off = OFFSET(disposition) },
3710  "disposition", "" },
3711  { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
3712  { .off = OFFSET(thread_queue_size) },
3713  "set the maximum number of queued packets from the demuxer" },
3714  { "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3715  "read and decode the streams to fill missing information with heuristics" },
3716  { "bits_per_raw_sample", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT,
3717  { .off = OFFSET(bits_per_raw_sample) },
3718  "set the number of bits per raw sample", "number" },
3719 
3720  /* video options */
3721  { "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },
3722  "set the number of video frames to output", "number" },
3723  { "r", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3724  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_rates) },
3725  "set frame rate (Hz value, fraction or abbreviation)", "rate" },
3726  { "fpsmax", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3727  OPT_OUTPUT, { .off = OFFSET(max_frame_rates) },
3728  "set max frame rate (Hz value, fraction or abbreviation)", "rate" },
3730  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_sizes) },
3731  "set frame size (WxH or abbreviation)", "size" },
3732  { "aspect", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3733  OPT_OUTPUT, { .off = OFFSET(frame_aspect_ratios) },
3734  "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
3735  { "pix_fmt", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3736  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_pix_fmts) },
3737  "set pixel format", "format" },
3739  "disable video" },
3740  { "rc_override", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3741  OPT_OUTPUT, { .off = OFFSET(rc_overrides) },
3742  "rate control override for specific intervals", "override" },
3743  { "vcodec", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_INPUT |
3744  OPT_OUTPUT, { .func_arg = opt_video_codec },
3745  "force video codec ('copy' to copy stream)", "codec" },
3746  { "timecode", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_timecode },
3747  "set initial TimeCode value.", "hh:mm:ss[:;.]ff" },
3748  { "pass", OPT_VIDEO | HAS_ARG | OPT_SPEC | OPT_INT | OPT_OUTPUT, { .off = OFFSET(pass) },
3749  "select the pass number (1 to 3)", "n" },
3750  { "passlogfile", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC |
3751  OPT_OUTPUT, { .off = OFFSET(passlogfiles) },
3752  "select two pass log file name prefix", "prefix" },
3753  { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr },
3754  "calculate PSNR of compressed frames" },
3755  { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats },
3756  "dump video coding statistics to file" },
3757  { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file },
3758  "dump video coding statistics to file", "file" },
3759  { "vstats_version", OPT_VIDEO | OPT_INT | HAS_ARG | OPT_EXPERT , { &vstats_version },
3760  "Version of the vstats format to use."},
3761  { "vf", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_filters },
3762  "set video filters", "filter_graph" },
3763  { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3764  OPT_OUTPUT, { .off = OFFSET(intra_matrices) },
3765  "specify intra matrix coeffs", "matrix" },
3766  { "inter_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3767  OPT_OUTPUT, { .off = OFFSET(inter_matrices) },
3768  "specify inter matrix coeffs", "matrix" },
3769  { "chroma_intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3770  OPT_OUTPUT, { .off = OFFSET(chroma_intra_matrices) },
3771  "specify intra matrix coeffs", "matrix" },
3772  { "top", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_INT| OPT_SPEC |
3773  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(top_field_first) },
3774  "top=1/bottom=0/auto=-1 field first", "" },
3775  { "vtag", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3776  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_old2new },
3777  "force video tag/fourcc", "fourcc/tag" },
3778  { "qphist", OPT_VIDEO | OPT_BOOL | OPT_EXPERT , { &qp_hist },
3779  "show QP histogram" },
3780  { "force_fps", OPT_VIDEO | OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3781  OPT_OUTPUT, { .off = OFFSET(force_fps) },
3782  "force the selected framerate, disable the best supported framerate selection" },
3783  { "streamid", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3784  OPT_OUTPUT, { .func_arg = opt_streamid },
3785  "set the value of an outfile streamid", "streamIndex:value" },
3786  { "force_key_frames", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3787  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(forced_key_frames) },
3788  "force key frames at specified timestamps", "timestamps" },
3789  { "ab", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3790  "audio bitrate (please use -b:a)", "bitrate" },
3791  { "b", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3792  "video bitrate (please use -b:v)", "bitrate" },
3793  { "hwaccel", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3794  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccels) },
3795  "use HW accelerated decoding", "hwaccel name" },
3796  { "hwaccel_device", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3797  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_devices) },
3798  "select a device for HW acceleration", "devicename" },
3799  { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3800  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) },
3801  "select output format used with HW accelerated decoding", "format" },
3802  { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels },
3803  "show available HW acceleration methods" },
3804  { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC |
3805  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) },
3806  "automatically insert correct rotate filters" },
3807  { "autoscale", HAS_ARG | OPT_BOOL | OPT_SPEC |
3808  OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(autoscale) },
3809  "automatically insert a scale filter at the end of the filter graph" },
3810 
3811  /* audio options */
3812  { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },
3813  "set the number of audio frames to output", "number" },
3814  { "aq", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_qscale },
3815  "set audio quality (codec-specific)", "quality", },
3816  { "ar", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3817  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_sample_rate) },
3818  "set audio sampling rate (in Hz)", "rate" },
3819  { "ac", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3820  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_channels) },
3821  "set number of audio channels", "channels" },
3823  "disable audio" },
3824  { "acodec", OPT_AUDIO | HAS_ARG | OPT_PERFILE |
3825  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_audio_codec },
3826  "force audio codec ('copy' to copy stream)", "codec" },
3827  { "atag", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3828  OPT_OUTPUT, { .func_arg = opt_old2new },
3829  "force audio tag/fourcc", "fourcc/tag" },
3830  { "vol", OPT_AUDIO | HAS_ARG | OPT_INT, { &audio_volume },
3831  "change audio volume (256=normal)" , "volume" },
3832  { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3834  "set sample format", "format" },
3835  { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3836  OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) },
3837  "set channel layout", "layout" },
3838  { "ch_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3839  OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) },
3840  "set channel layout", "layout" },
3841  { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters },
3842  "set audio filters", "filter_graph" },
3843  { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) },
3844  "set the maximum number of channels to try to guess the channel layout" },
3845 
3846  /* subtitle options */
3848  "disable subtitle" },
3849  { "scodec", OPT_SUBTITLE | HAS_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_subtitle_codec },
3850  "force subtitle codec ('copy' to copy stream)", "codec" },
3851  { "stag", OPT_SUBTITLE | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new }
3852  , "force subtitle tag/fourcc", "fourcc/tag" },
3853  { "fix_sub_duration", OPT_BOOL | OPT_EXPERT | OPT_SUBTITLE | OPT_SPEC | OPT_INPUT, { .off = OFFSET(fix_sub_duration) },
3854  "fix subtitles duration" },
3855  { "canvas_size", OPT_SUBTITLE | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_INPUT, { .off = OFFSET(canvas_sizes) },
3856  "set canvas size (WxH or abbreviation)", "size" },
3857 
3858  /* muxer options */
3859  { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_max_delay) },
3860  "set the maximum demux-decode delay", "seconds" },
3861  { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_preload) },
3862  "set the initial demux-decode delay", "seconds" },
3863  { "sdp_file", HAS_ARG | OPT_EXPERT | OPT_OUTPUT, { .func_arg = opt_sdp_file },
3864  "specify a file in which to print sdp information", "file" },
3865 
3866  { "time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(time_bases) },
3867  "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)", "ratio" },
3868  { "enc_time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(enc_time_bases) },
3869  "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
3870  "two special values are defined - "
3871  "0 = use frame rate (video) or sample rate (audio),"
3872  "-1 = match source time base", "ratio" },
3873 
3874  { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(bitstream_filters) },
3875  "A comma-separated list of bitstream filters", "bitstream_filters" },
3876  { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3877  "deprecated", "audio bitstream_filters" },
3878  { "vbsf", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3879  "deprecated", "video bitstream_filters" },
3880 
3881  { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3882  "set the audio options to the indicated preset", "preset" },
3883  { "vpre", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3884  "set the video options to the indicated preset", "preset" },
3885  { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3886  "set the subtitle options to the indicated preset", "preset" },
3887  { "fpre", HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3888  "set options from indicated preset file", "filename" },
3889 
3890  { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) },
3891  "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" },
3892  { "muxing_queue_data_threshold", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(muxing_queue_data_threshold) },
3893  "set the threshold after which max_muxing_queue_size is taken into account", "bytes" },
3894 
3895  /* data codec support */
3896  { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec },
3897  "force data codec ('copy' to copy stream)", "codec" },
3898  { "dn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(data_disable) },
3899  "disable data" },
3900 
3901 #if CONFIG_VAAPI
3902  { "vaapi_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vaapi_device },
3903  "set VAAPI hardware device (DRM path or X11 display name)", "device" },
3904 #endif
3905 
3906 #if CONFIG_QSV
3907  { "qsv_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_qsv_device },
3908  "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
3909 #endif
3910 
3911  { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
3912  "initialise hardware device", "args" },
3913  { "filter_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_hw_device },
3914  "set hardware device used when filtering", "device" },
3915 
3916  { NULL, },
3917 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:118
OPT_FLOAT
#define OPT_FLOAT
Definition: cmdutils.h:145
fopen_utf8
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: fopen_utf8.h:65
OPT_EXIT
#define OPT_EXIT
Definition: cmdutils.h:148
AVCodec
AVCodec.
Definition: codec.h:196
OptionsContext::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:115
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:225
ignore_unknown_streams
static int ignore_unknown_streams
Definition: ffmpeg_opt.c:186
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:75
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:149
StreamMap::file_index
int file_index
Definition: ffmpeg.h:76
new_output_stream
static OutputStream * new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
Definition: ffmpeg_opt.c:1441
show_hwaccels
static int show_hwaccels(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:238
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
InputStream::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:376
opt_abort_on
static int opt_abort_on(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:275
VSYNC_VFR
@ VSYNC_VFR
Definition: ffmpeg.h:54
AVOutputFormat::name
const char * name
Definition: avformat.h:510
AVChapter::metadata
AVDictionary * metadata
Definition: avformat.h:1176
OptionsContext::dump_attachment
SpecifierOpt * dump_attachment
Definition: ffmpeg.h:124
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