FFmpeg  4.1.11
ffmpeg_opt.c
Go to the documentation of this file.
1 
2 /*
3  * ffmpeg option parsing
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdint.h>
23 
24 #include "ffmpeg.h"
25 #include "cmdutils.h"
26 
27 #include "libavformat/avformat.h"
28 
29 #include "libavcodec/avcodec.h"
30 
31 #include "libavfilter/avfilter.h"
32 
33 #include "libavutil/avassert.h"
34 #include "libavutil/avstring.h"
35 #include "libavutil/avutil.h"
37 #include "libavutil/intreadwrite.h"
38 #include "libavutil/fifo.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/opt.h"
41 #include "libavutil/parseutils.h"
42 #include "libavutil/pixdesc.h"
43 #include "libavutil/pixfmt.h"
44 
45 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
46 
47 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
48 {\
49  int i, ret;\
50  for (i = 0; i < o->nb_ ## name; i++) {\
51  char *spec = o->name[i].specifier;\
52  if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\
53  outvar = o->name[i].u.type;\
54  else if (ret < 0)\
55  exit_program(1);\
56  }\
57 }
58 
59 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
60 {\
61  int i;\
62  for (i = 0; i < o->nb_ ## name; i++) {\
63  char *spec = o->name[i].specifier;\
64  if (!strcmp(spec, mediatype))\
65  outvar = o->name[i].u.type;\
66  }\
67 }
68 
69 const HWAccel hwaccels[] = {
70 #if CONFIG_VIDEOTOOLBOX
72 #endif
73 #if CONFIG_LIBMFX
74  { "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV },
75 #endif
76 #if CONFIG_CUVID
78 #endif
79  { 0 },
80 };
83 
86 
89 float dts_error_threshold = 3600*30;
90 
91 int audio_volume = 256;
96 int do_benchmark = 0;
98 int do_hex_dump = 0;
99 int do_pkt_dump = 0;
100 int copy_ts = 0;
102 int copy_tb = -1;
103 int debug_ts = 0;
106 int print_stats = -1;
107 int qp_hist = 0;
110 float max_error_rate = 2.0/3;
114 
115 
116 static int intra_only = 0;
117 static int file_overwrite = 0;
118 static int no_file_overwrite = 0;
119 static int do_psnr = 0;
120 static int input_sync;
122 static int ignore_unknown_streams = 0;
123 static int copy_unknown_streams = 0;
124 static int find_stream_info = 1;
125 
127 {
128  const OptionDef *po = options;
129  int i;
130 
131  /* all OPT_SPEC and OPT_STRING can be freed in generic way */
132  while (po->name) {
133  void *dst = (uint8_t*)o + po->u.off;
134 
135  if (po->flags & OPT_SPEC) {
136  SpecifierOpt **so = dst;
137  int i, *count = (int*)(so + 1);
138  for (i = 0; i < *count; i++) {
139  av_freep(&(*so)[i].specifier);
140  if (po->flags & OPT_STRING)
141  av_freep(&(*so)[i].u.str);
142  }
143  av_freep(so);
144  *count = 0;
145  } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
146  av_freep(dst);
147  po++;
148  }
149 
150  for (i = 0; i < o->nb_stream_maps; i++)
152  av_freep(&o->stream_maps);
154  av_freep(&o->streamid_map);
155  av_freep(&o->attachments);
156 }
157 
159 {
160  memset(o, 0, sizeof(*o));
161 
162  o->stop_time = INT64_MAX;
163  o->mux_max_delay = 0.7;
166  o->recording_time = INT64_MAX;
167  o->limit_filesize = UINT64_MAX;
168  o->chapters_input_file = INT_MAX;
169  o->accurate_seek = 1;
170 }
171 
172 static int show_hwaccels(void *optctx, const char *opt, const char *arg)
173 {
175  int i;
176 
177  printf("Hardware acceleration methods:\n");
178  while ((type = av_hwdevice_iterate_types(type)) !=
180  printf("%s\n", av_hwdevice_get_type_name(type));
181  for (i = 0; hwaccels[i].name; i++)
182  printf("%s\n", hwaccels[i].name);
183  printf("\n");
184  return 0;
185 }
186 
187 /* return a copy of the input with the stream specifiers removed from the keys */
189 {
190  AVDictionaryEntry *e = NULL;
191  AVDictionary *ret = NULL;
192 
193  while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
194  char *p = strchr(e->key, ':');
195 
196  if (p)
197  *p = 0;
198  av_dict_set(&ret, e->key, e->value, 0);
199  if (p)
200  *p = ':';
201  }
202  return ret;
203 }
204 
205 static int opt_abort_on(void *optctx, const char *opt, const char *arg)
206 {
207  static const AVOption opts[] = {
208  { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
209  { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
210  { NULL },
211  };
212  static const AVClass class = {
213  .class_name = "",
214  .item_name = av_default_item_name,
215  .option = opts,
216  .version = LIBAVUTIL_VERSION_INT,
217  };
218  const AVClass *pclass = &class;
219 
220  return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
221 }
222 
223 static int opt_sameq(void *optctx, const char *opt, const char *arg)
224 {
225  av_log(NULL, AV_LOG_ERROR, "Option '%s' was removed. "
226  "If you are looking for an option to preserve the quality (which is not "
227  "what -%s was for), use -qscale 0 or an equivalent quality factor option.\n",
228  opt, opt);
229  return AVERROR(EINVAL);
230 }
231 
232 static int opt_video_channel(void *optctx, const char *opt, const char *arg)
233 {
234  av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -channel.\n");
235  return opt_default(optctx, "channel", arg);
236 }
237 
238 static int opt_video_standard(void *optctx, const char *opt, const char *arg)
239 {
240  av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -standard.\n");
241  return opt_default(optctx, "standard", arg);
242 }
243 
244 static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
245 {
246  OptionsContext *o = optctx;
247  return parse_option(o, "codec:a", arg, options);
248 }
249 
250 static int opt_video_codec(void *optctx, const char *opt, const char *arg)
251 {
252  OptionsContext *o = optctx;
253  return parse_option(o, "codec:v", arg, options);
254 }
255 
256 static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
257 {
258  OptionsContext *o = optctx;
259  return parse_option(o, "codec:s", arg, options);
260 }
261 
262 static int opt_data_codec(void *optctx, const char *opt, const char *arg)
263 {
264  OptionsContext *o = optctx;
265  return parse_option(o, "codec:d", arg, options);
266 }
267 
268 static int opt_map(void *optctx, const char *opt, const char *arg)
269 {
270  OptionsContext *o = optctx;
271  StreamMap *m = NULL;
272  int i, negative = 0, file_idx;
273  int sync_file_idx = -1, sync_stream_idx = 0;
274  char *p, *sync;
275  char *map;
276  char *allow_unused;
277 
278  if (*arg == '-') {
279  negative = 1;
280  arg++;
281  }
282  map = av_strdup(arg);
283  if (!map)
284  return AVERROR(ENOMEM);
285 
286  /* parse sync stream first, just pick first matching stream */
287  if (sync = strchr(map, ',')) {
288  *sync = 0;
289  sync_file_idx = strtol(sync + 1, &sync, 0);
290  if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
291  av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
292  exit_program(1);
293  }
294  if (*sync)
295  sync++;
296  for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
297  if (check_stream_specifier(input_files[sync_file_idx]->ctx,
298  input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
299  sync_stream_idx = i;
300  break;
301  }
302  if (i == input_files[sync_file_idx]->nb_streams) {
303  av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
304  "match any streams.\n", arg);
305  exit_program(1);
306  }
307  }
308 
309 
310  if (map[0] == '[') {
311  /* this mapping refers to lavfi output */
312  const char *c = map + 1;
314  m = &o->stream_maps[o->nb_stream_maps - 1];
315  m->linklabel = av_get_token(&c, "]");
316  if (!m->linklabel) {
317  av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
318  exit_program(1);
319  }
320  } else {
321  if (allow_unused = strchr(map, '?'))
322  *allow_unused = 0;
323  file_idx = strtol(map, &p, 0);
324  if (file_idx >= nb_input_files || file_idx < 0) {
325  av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
326  exit_program(1);
327  }
328  if (negative)
329  /* disable some already defined maps */
330  for (i = 0; i < o->nb_stream_maps; i++) {
331  m = &o->stream_maps[i];
332  if (file_idx == m->file_index &&
335  *p == ':' ? p + 1 : p) > 0)
336  m->disabled = 1;
337  }
338  else
339  for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
340  if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
341  *p == ':' ? p + 1 : p) <= 0)
342  continue;
344  m = &o->stream_maps[o->nb_stream_maps - 1];
345 
346  m->file_index = file_idx;
347  m->stream_index = i;
348 
349  if (sync_file_idx >= 0) {
350  m->sync_file_index = sync_file_idx;
351  m->sync_stream_index = sync_stream_idx;
352  } else {
353  m->sync_file_index = file_idx;
354  m->sync_stream_index = i;
355  }
356  }
357  }
358 
359  if (!m) {
360  if (allow_unused) {
361  av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
362  } else {
363  av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
364  "To ignore this, add a trailing '?' to the map.\n", arg);
365  exit_program(1);
366  }
367  }
368 
369  av_freep(&map);
370  return 0;
371 }
372 
373 static int opt_attach(void *optctx, const char *opt, const char *arg)
374 {
375  OptionsContext *o = optctx;
377  o->attachments[o->nb_attachments - 1] = arg;
378  return 0;
379 }
380 
381 static int opt_map_channel(void *optctx, const char *opt, const char *arg)
382 {
383  OptionsContext *o = optctx;
384  int n;
385  AVStream *st;
386  AudioChannelMap *m;
387  char *allow_unused;
388  char *mapchan;
389  mapchan = av_strdup(arg);
390  if (!mapchan)
391  return AVERROR(ENOMEM);
392 
395 
396  /* muted channel syntax */
397  n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
398  if ((n == 1 || n == 3) && m->channel_idx == -1) {
399  m->file_idx = m->stream_idx = -1;
400  if (n == 1)
401  m->ofile_idx = m->ostream_idx = -1;
402  av_free(mapchan);
403  return 0;
404  }
405 
406  /* normal syntax */
407  n = sscanf(arg, "%d.%d.%d:%d.%d",
408  &m->file_idx, &m->stream_idx, &m->channel_idx,
409  &m->ofile_idx, &m->ostream_idx);
410 
411  if (n != 3 && n != 5) {
412  av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
413  "[file.stream.channel|-1][:syncfile:syncstream]\n");
414  exit_program(1);
415  }
416 
417  if (n != 5) // only file.stream.channel specified
418  m->ofile_idx = m->ostream_idx = -1;
419 
420  /* check input */
421  if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
422  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
423  m->file_idx);
424  exit_program(1);
425  }
426  if (m->stream_idx < 0 ||
428  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
429  m->file_idx, m->stream_idx);
430  exit_program(1);
431  }
432  st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
433  if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
434  av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
435  m->file_idx, m->stream_idx);
436  exit_program(1);
437  }
438  /* allow trailing ? to map_channel */
439  if (allow_unused = strchr(mapchan, '?'))
440  *allow_unused = 0;
441  if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels) {
442  if (allow_unused) {
443  av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
444  m->file_idx, m->stream_idx, m->channel_idx);
445  } else {
446  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
447  "To ignore this, add a trailing '?' to the map_channel.\n",
448  m->file_idx, m->stream_idx, m->channel_idx);
449  exit_program(1);
450  }
451 
452  }
453  av_free(mapchan);
454  return 0;
455 }
456 
457 static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
458 {
460  sdp_filename = av_strdup(arg);
461  return 0;
462 }
463 
464 #if CONFIG_VAAPI
465 static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
466 {
467  HWDevice *dev;
468  const char *prefix = "vaapi:";
469  char *tmp;
470  int err;
471  tmp = av_asprintf("%s%s", prefix, arg);
472  if (!tmp)
473  return AVERROR(ENOMEM);
474  err = hw_device_init_from_string(tmp, &dev);
475  av_free(tmp);
476  if (err < 0)
477  return err;
478  hw_device_ctx = av_buffer_ref(dev->device_ref);
479  if (!hw_device_ctx)
480  return AVERROR(ENOMEM);
481  return 0;
482 }
483 #endif
484 
485 static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
486 {
487  if (!strcmp(arg, "list")) {
489  printf("Supported hardware device types:\n");
490  while ((type = av_hwdevice_iterate_types(type)) !=
492  printf("%s\n", av_hwdevice_get_type_name(type));
493  printf("\n");
494  exit_program(0);
495  } else {
496  return hw_device_init_from_string(arg, NULL);
497  }
498 }
499 
500 static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
501 {
502  if (filter_hw_device) {
503  av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
504  return AVERROR(EINVAL);
505  }
506  filter_hw_device = hw_device_get_by_name(arg);
507  if (!filter_hw_device) {
508  av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
509  return AVERROR(EINVAL);
510  }
511  return 0;
512 }
513 
514 /**
515  * Parse a metadata specifier passed as 'arg' parameter.
516  * @param arg metadata string to parse
517  * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
518  * @param index for type c/p, chapter/program index is written here
519  * @param stream_spec for type s, the stream specifier is written here
520  */
521 static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
522 {
523  if (*arg) {
524  *type = *arg;
525  switch (*arg) {
526  case 'g':
527  break;
528  case 's':
529  if (*(++arg) && *arg != ':') {
530  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
531  exit_program(1);
532  }
533  *stream_spec = *arg == ':' ? arg + 1 : "";
534  break;
535  case 'c':
536  case 'p':
537  if (*(++arg) == ':')
538  *index = strtol(++arg, NULL, 0);
539  break;
540  default:
541  av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
542  exit_program(1);
543  }
544  } else
545  *type = 'g';
546 }
547 
548 static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
549 {
550  AVDictionary **meta_in = NULL;
551  AVDictionary **meta_out = NULL;
552  int i, ret = 0;
553  char type_in, type_out;
554  const char *istream_spec = NULL, *ostream_spec = NULL;
555  int idx_in = 0, idx_out = 0;
556 
557  parse_meta_type(inspec, &type_in, &idx_in, &istream_spec);
558  parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);
559 
560  if (!ic) {
561  if (type_out == 'g' || !*outspec)
562  o->metadata_global_manual = 1;
563  if (type_out == 's' || !*outspec)
565  if (type_out == 'c' || !*outspec)
567  return 0;
568  }
569 
570  if (type_in == 'g' || type_out == 'g')
571  o->metadata_global_manual = 1;
572  if (type_in == 's' || type_out == 's')
574  if (type_in == 'c' || type_out == 'c')
576 
577  /* ic is NULL when just disabling automatic mappings */
578  if (!ic)
579  return 0;
580 
581 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
582  if ((index) < 0 || (index) >= (nb_elems)) {\
583  av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
584  (desc), (index));\
585  exit_program(1);\
586  }
587 
588 #define SET_DICT(type, meta, context, index)\
589  switch (type) {\
590  case 'g':\
591  meta = &context->metadata;\
592  break;\
593  case 'c':\
594  METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
595  meta = &context->chapters[index]->metadata;\
596  break;\
597  case 'p':\
598  METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
599  meta = &context->programs[index]->metadata;\
600  break;\
601  case 's':\
602  break; /* handled separately below */ \
603  default: av_assert0(0);\
604  }\
605 
606  SET_DICT(type_in, meta_in, ic, idx_in);
607  SET_DICT(type_out, meta_out, oc, idx_out);
608 
609  /* for input streams choose first matching stream */
610  if (type_in == 's') {
611  for (i = 0; i < ic->nb_streams; i++) {
612  if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
613  meta_in = &ic->streams[i]->metadata;
614  break;
615  } else if (ret < 0)
616  exit_program(1);
617  }
618  if (!meta_in) {
619  av_log(NULL, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
620  exit_program(1);
621  }
622  }
623 
624  if (type_out == 's') {
625  for (i = 0; i < oc->nb_streams; i++) {
626  if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
627  meta_out = &oc->streams[i]->metadata;
628  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
629  } else if (ret < 0)
630  exit_program(1);
631  }
632  } else
633  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
634 
635  return 0;
636 }
637 
638 static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
639 {
640  OptionsContext *o = optctx;
641  char buf[128];
642  int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
643  struct tm time = *gmtime((time_t*)&recording_timestamp);
644  if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
645  return -1;
646  parse_option(o, "metadata", buf, options);
647 
648  av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
649  "tag instead.\n", opt);
650  return 0;
651 }
652 
653 static AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
654 {
655  const AVCodecDescriptor *desc;
656  const char *codec_string = encoder ? "encoder" : "decoder";
657  AVCodec *codec;
658 
659  codec = encoder ?
662 
663  if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
664  codec = encoder ? avcodec_find_encoder(desc->id) :
665  avcodec_find_decoder(desc->id);
666  if (codec)
667  av_log(NULL, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
668  codec_string, codec->name, desc->name);
669  }
670 
671  if (!codec) {
672  av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
673  exit_program(1);
674  }
675  if (codec->type != type) {
676  av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
677  exit_program(1);
678  }
679  return codec;
680 }
681 
683 {
684  char *codec_name = NULL;
685 
686  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
687  if (codec_name) {
688  AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
689  st->codecpar->codec_id = codec->id;
690  return codec;
691  } else
693 }
694 
695 /* Add all the streams from the given input file to the global
696  * list of input streams. */
698 {
699  int i, ret;
700 
701  for (i = 0; i < ic->nb_streams; i++) {
702  AVStream *st = ic->streams[i];
703  AVCodecParameters *par = st->codecpar;
704  InputStream *ist = av_mallocz(sizeof(*ist));
705  char *framerate = NULL, *hwaccel_device = NULL;
706  const char *hwaccel = NULL;
707  char *hwaccel_output_format = NULL;
708  char *codec_tag = NULL;
709  char *next;
710  char *discard_str = NULL;
711  const AVClass *cc = avcodec_get_class();
712  const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, 0);
713 
714  if (!ist)
715  exit_program(1);
716 
718  input_streams[nb_input_streams - 1] = ist;
719 
720  ist->st = st;
721  ist->file_index = nb_input_files;
722  ist->discard = 1;
723  st->discard = AVDISCARD_ALL;
724  ist->nb_samples = 0;
725  ist->min_pts = INT64_MAX;
726  ist->max_pts = INT64_MIN;
727 
728  ist->ts_scale = 1.0;
729  MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
730 
731  ist->autorotate = 1;
732  MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
733 
734  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
735  if (codec_tag) {
736  uint32_t tag = strtol(codec_tag, &next, 0);
737  if (*next)
738  tag = AV_RL32(codec_tag);
739  st->codecpar->codec_tag = tag;
740  }
741 
742  ist->dec = choose_decoder(o, ic, st);
743  ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
744 
745  ist->reinit_filters = -1;
746  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
747 
748  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
750  if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
751  av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
752  discard_str);
753  exit_program(1);
754  }
755 
757 
758  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
759  if (!ist->dec_ctx) {
760  av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
761  exit_program(1);
762  }
763 
764  ret = avcodec_parameters_to_context(ist->dec_ctx, par);
765  if (ret < 0) {
766  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
767  exit_program(1);
768  }
769 
770  if (o->bitexact)
772 
773  switch (par->codec_type) {
774  case AVMEDIA_TYPE_VIDEO:
775  if(!ist->dec)
776  ist->dec = avcodec_find_decoder(par->codec_id);
777 #if FF_API_LOWRES
778  if (st->codec->lowres) {
779  ist->dec_ctx->lowres = st->codec->lowres;
780  ist->dec_ctx->width = st->codec->width;
781  ist->dec_ctx->height = st->codec->height;
782  ist->dec_ctx->coded_width = st->codec->coded_width;
783  ist->dec_ctx->coded_height = st->codec->coded_height;
784  }
785 #endif
786 
787  // avformat_find_stream_info() doesn't set this for us anymore.
788  ist->dec_ctx->framerate = st->avg_frame_rate;
789 
790  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
791  if (framerate && av_parse_video_rate(&ist->framerate,
792  framerate) < 0) {
793  av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
794  framerate);
795  exit_program(1);
796  }
797 
798  ist->top_field_first = -1;
799  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
800 
801  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
802  if (hwaccel) {
803  // The NVDEC hwaccels use a CUDA device, so remap the name here.
804  if (!strcmp(hwaccel, "nvdec"))
805  hwaccel = "cuda";
806 
807  if (!strcmp(hwaccel, "none"))
808  ist->hwaccel_id = HWACCEL_NONE;
809  else if (!strcmp(hwaccel, "auto"))
810  ist->hwaccel_id = HWACCEL_AUTO;
811  else {
812  enum AVHWDeviceType type;
813  int i;
814  for (i = 0; hwaccels[i].name; i++) {
815  if (!strcmp(hwaccels[i].name, hwaccel)) {
816  ist->hwaccel_id = hwaccels[i].id;
817  break;
818  }
819  }
820 
821  if (!ist->hwaccel_id) {
822  type = av_hwdevice_find_type_by_name(hwaccel);
823  if (type != AV_HWDEVICE_TYPE_NONE) {
825  ist->hwaccel_device_type = type;
826  }
827  }
828 
829  if (!ist->hwaccel_id) {
830  av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
831  hwaccel);
832  av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
833  type = AV_HWDEVICE_TYPE_NONE;
834  while ((type = av_hwdevice_iterate_types(type)) !=
836  av_log(NULL, AV_LOG_FATAL, "%s ",
838  for (i = 0; hwaccels[i].name; i++)
839  av_log(NULL, AV_LOG_FATAL, "%s ", hwaccels[i].name);
840  av_log(NULL, AV_LOG_FATAL, "\n");
841  exit_program(1);
842  }
843  }
844  }
845 
846  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
847  if (hwaccel_device) {
848  ist->hwaccel_device = av_strdup(hwaccel_device);
849  if (!ist->hwaccel_device)
850  exit_program(1);
851  }
852 
853  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
854  hwaccel_output_format, ic, st);
855  if (hwaccel_output_format) {
856  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
858  av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
859  "format: %s", hwaccel_output_format);
860  }
861  } else {
863  }
864 
866 
867  break;
868  case AVMEDIA_TYPE_AUDIO:
869  ist->guess_layout_max = INT_MAX;
870  MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
872  break;
873  case AVMEDIA_TYPE_DATA:
874  case AVMEDIA_TYPE_SUBTITLE: {
875  char *canvas_size = NULL;
876  if(!ist->dec)
877  ist->dec = avcodec_find_decoder(par->codec_id);
878  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
879  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
880  if (canvas_size &&
881  av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
882  av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
883  exit_program(1);
884  }
885  break;
886  }
889  break;
890  default:
891  abort();
892  }
893 
894  ret = avcodec_parameters_from_context(par, ist->dec_ctx);
895  if (ret < 0) {
896  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
897  exit_program(1);
898  }
899  }
900 }
901 
902 static void assert_file_overwrite(const char *filename)
903 {
904  const char *proto_name = avio_find_protocol_name(filename);
905 
907  fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
908  exit_program(1);
909  }
910 
911  if (!file_overwrite) {
912  if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
914  fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
915  fflush(stderr);
916  term_exit();
917  signal(SIGINT, SIG_DFL);
918  if (!read_yesno()) {
919  av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
920  exit_program(1);
921  }
922  term_init();
923  }
924  else {
925  av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
926  exit_program(1);
927  }
928  }
929  }
930 
931  if (proto_name && !strcmp(proto_name, "file")) {
932  for (int i = 0; i < nb_input_files; i++) {
933  InputFile *file = input_files[i];
934  if (file->ctx->iformat->flags & AVFMT_NOFILE)
935  continue;
936  if (!strcmp(filename, file->ctx->url)) {
937  av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
938  av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
939  exit_program(1);
940  }
941  }
942  }
943 }
944 
945 static void dump_attachment(AVStream *st, const char *filename)
946 {
947  int ret;
948  AVIOContext *out = NULL;
950 
951  if (!st->codecpar->extradata_size) {
952  av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
953  nb_input_files - 1, st->index);
954  return;
955  }
956  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
957  filename = e->value;
958  if (!*filename) {
959  av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
960  "in stream #%d:%d.\n", nb_input_files - 1, st->index);
961  exit_program(1);
962  }
963 
964  assert_file_overwrite(filename);
965 
966  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
967  av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
968  filename);
969  exit_program(1);
970  }
971 
973  avio_flush(out);
974  avio_close(out);
975 }
976 
977 static int open_input_file(OptionsContext *o, const char *filename)
978 {
979  InputFile *f;
980  AVFormatContext *ic;
982  int err, i, ret;
983  int64_t timestamp;
984  AVDictionary *unused_opts = NULL;
985  AVDictionaryEntry *e = NULL;
986  char * video_codec_name = NULL;
987  char * audio_codec_name = NULL;
988  char *subtitle_codec_name = NULL;
989  char * data_codec_name = NULL;
990  int scan_all_pmts_set = 0;
991 
992  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
993  o->stop_time = INT64_MAX;
994  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
995  }
996 
997  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
998  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
999  if (o->stop_time <= start_time) {
1000  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1001  exit_program(1);
1002  } else {
1004  }
1005  }
1006 
1007  if (o->format) {
1008  if (!(file_iformat = av_find_input_format(o->format))) {
1009  av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1010  exit_program(1);
1011  }
1012  }
1013 
1014  if (!strcmp(filename, "-"))
1015  filename = "pipe:";
1016 
1017  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1018  strcmp(filename, "/dev/stdin");
1019 
1020  /* get default parameters from command line */
1021  ic = avformat_alloc_context();
1022  if (!ic) {
1023  print_error(filename, AVERROR(ENOMEM));
1024  exit_program(1);
1025  }
1026  if (o->nb_audio_sample_rate) {
1027  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1028  }
1029  if (o->nb_audio_channels) {
1030  /* because we set audio_channels based on both the "ac" and
1031  * "channel_layout" options, we need to check that the specified
1032  * demuxer actually has the "channels" option before setting it */
1033  if (file_iformat && file_iformat->priv_class &&
1034  av_opt_find(&file_iformat->priv_class, "channels", NULL, 0,
1036  av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);
1037  }
1038  }
1039  if (o->nb_frame_rates) {
1040  /* set the format-level framerate option;
1041  * this is important for video grabbers, e.g. x11 */
1042  if (file_iformat && file_iformat->priv_class &&
1043  av_opt_find(&file_iformat->priv_class, "framerate", NULL, 0,
1045  av_dict_set(&o->g->format_opts, "framerate",
1046  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1047  }
1048  }
1049  if (o->nb_frame_sizes) {
1050  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1051  }
1052  if (o->nb_frame_pix_fmts)
1053  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1054 
1055  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1056  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1057  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1058  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1059 
1060  if (video_codec_name)
1061  ic->video_codec = find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
1062  if (audio_codec_name)
1063  ic->audio_codec = find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
1064  if (subtitle_codec_name)
1065  ic->subtitle_codec = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
1066  if (data_codec_name)
1067  ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
1068 
1069  ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
1070  ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
1071  ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
1072  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1073 
1074  ic->flags |= AVFMT_FLAG_NONBLOCK;
1075  if (o->bitexact)
1076  ic->flags |= AVFMT_FLAG_BITEXACT;
1077  ic->interrupt_callback = int_cb;
1078 
1079  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1080  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1081  scan_all_pmts_set = 1;
1082  }
1083  /* open the input file with generic avformat function */
1084  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1085  if (err < 0) {
1086  print_error(filename, err);
1087  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1088  av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1089  exit_program(1);
1090  }
1091  if (scan_all_pmts_set)
1092  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1095 
1096  /* apply forced codec ids */
1097  for (i = 0; i < ic->nb_streams; i++)
1098  choose_decoder(o, ic, ic->streams[i]);
1099 
1100  if (find_stream_info) {
1102  int orig_nb_streams = ic->nb_streams;
1103 
1104  /* If not enough info to get the stream parameters, we decode the
1105  first frames to get it. (used in mpeg case for example) */
1106  ret = avformat_find_stream_info(ic, opts);
1107 
1108  for (i = 0; i < orig_nb_streams; i++)
1109  av_dict_free(&opts[i]);
1110  av_freep(&opts);
1111 
1112  if (ret < 0) {
1113  av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
1114  if (ic->nb_streams == 0) {
1115  avformat_close_input(&ic);
1116  exit_program(1);
1117  }
1118  }
1119  }
1120 
1122  av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1124  }
1125 
1126  if (o->start_time_eof != AV_NOPTS_VALUE) {
1127  if (o->start_time_eof >= 0) {
1128  av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1129  exit_program(1);
1130  }
1131  if (ic->duration > 0) {
1132  o->start_time = o->start_time_eof + ic->duration;
1133  if (o->start_time < 0) {
1134  av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
1136  }
1137  } else
1138  av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
1139  }
1140  timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
1141  /* add the stream start time */
1142  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1143  timestamp += ic->start_time;
1144 
1145  /* if seeking requested, we execute it */
1146  if (o->start_time != AV_NOPTS_VALUE) {
1147  int64_t seek_timestamp = timestamp;
1148 
1149  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1150  int dts_heuristic = 0;
1151  for (i=0; i<ic->nb_streams; i++) {
1152  const AVCodecParameters *par = ic->streams[i]->codecpar;
1153  if (par->video_delay) {
1154  dts_heuristic = 1;
1155  break;
1156  }
1157  }
1158  if (dts_heuristic) {
1159  seek_timestamp -= 3*AV_TIME_BASE / 23;
1160  }
1161  }
1162  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1163  if (ret < 0) {
1164  av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
1165  filename, (double)timestamp / AV_TIME_BASE);
1166  }
1167  }
1168 
1169  /* update the current parameters so that they match the one of the input stream */
1170  add_input_streams(o, ic);
1171 
1172  /* dump the file content */
1173  av_dump_format(ic, nb_input_files, filename, 0);
1174 
1176  f = av_mallocz(sizeof(*f));
1177  if (!f)
1178  exit_program(1);
1179  input_files[nb_input_files - 1] = f;
1180 
1181  f->ctx = ic;
1183  f->start_time = o->start_time;
1186  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1187  f->nb_streams = ic->nb_streams;
1188  f->rate_emu = o->rate_emu;
1189  f->accurate_seek = o->accurate_seek;
1190  f->loop = o->loop;
1191  f->duration = 0;
1192  f->time_base = (AVRational){ 1, 1 };
1193 #if HAVE_THREADS
1194  f->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
1195 #endif
1196 
1197  /* check if all codec options have been used */
1198  unused_opts = strip_specifiers(o->g->codec_opts);
1199  for (i = f->ist_index; i < nb_input_streams; i++) {
1200  e = NULL;
1201  while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e,
1203  av_dict_set(&unused_opts, e->key, NULL, 0);
1204  }
1205 
1206  e = NULL;
1207  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
1208  const AVClass *class = avcodec_get_class();
1209  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1211  const AVClass *fclass = avformat_get_class();
1212  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1214  if (!option || foption)
1215  continue;
1216 
1217 
1218  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1219  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
1220  "input file #%d (%s) is not a decoding option.\n", e->key,
1221  option->help ? option->help : "", nb_input_files - 1,
1222  filename);
1223  exit_program(1);
1224  }
1225 
1226  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
1227  "input file #%d (%s) has not been used for any stream. The most "
1228  "likely reason is either wrong type (e.g. a video option with "
1229  "no video streams) or that it is a private option of some decoder "
1230  "which was not actually used for any stream.\n", e->key,
1231  option->help ? option->help : "", nb_input_files - 1, filename);
1232  }
1233  av_dict_free(&unused_opts);
1234 
1235  for (i = 0; i < o->nb_dump_attachment; i++) {
1236  int j;
1237 
1238  for (j = 0; j < ic->nb_streams; j++) {
1239  AVStream *st = ic->streams[j];
1240 
1241  if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
1242  dump_attachment(st, o->dump_attachment[i].u.str);
1243  }
1244  }
1245 
1247 
1248  return 0;
1249 }
1250 
1252 {
1253  AVIOContext *line;
1254  uint8_t *buf;
1255  char c;
1256 
1257  if (avio_open_dyn_buf(&line) < 0) {
1258  av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
1259  exit_program(1);
1260  }
1261 
1262  while ((c = avio_r8(s)) && c != '\n')
1263  avio_w8(line, c);
1264  avio_w8(line, 0);
1265  avio_close_dyn_buf(line, &buf);
1266 
1267  return buf;
1268 }
1269 
1270 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
1271 {
1272  int i, ret = -1;
1273  char filename[1000];
1274  const char *base[3] = { getenv("AVCONV_DATADIR"),
1275  getenv("HOME"),
1277  };
1278 
1279  for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1280  if (!base[i])
1281  continue;
1282  if (codec_name) {
1283  snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
1284  i != 1 ? "" : "/.avconv", codec_name, preset_name);
1285  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1286  }
1287  if (ret < 0) {
1288  snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
1289  i != 1 ? "" : "/.avconv", preset_name);
1290  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1291  }
1292  }
1293  return ret;
1294 }
1295 
1297 {
1298  enum AVMediaType type = ost->st->codecpar->codec_type;
1299  char *codec_name = NULL;
1300 
1301  if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
1302  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
1303  if (!codec_name) {
1304  ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1305  NULL, ost->st->codecpar->codec_type);
1306  ost->enc = avcodec_find_encoder(ost->st->codecpar->codec_id);
1307  if (!ost->enc) {
1308  av_log(NULL, AV_LOG_FATAL, "Automatic encoder selection failed for "
1309  "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1310  "probably disabled. Please choose an encoder manually.\n",
1311  ost->file_index, ost->index, s->oformat->name,
1314  }
1315  } else if (!strcmp(codec_name, "copy"))
1316  ost->stream_copy = 1;
1317  else {
1318  ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
1319  ost->st->codecpar->codec_id = ost->enc->id;
1320  }
1321  ost->encoding_needed = !ost->stream_copy;
1322  } else {
1323  /* no encoding supported for other media types */
1324  ost->stream_copy = 1;
1325  ost->encoding_needed = 0;
1326  }
1327 
1328  return 0;
1329 }
1330 
1332 {
1333  OutputStream *ost;
1334  AVStream *st = avformat_new_stream(oc, NULL);
1335  int idx = oc->nb_streams - 1, ret = 0;
1336  const char *bsfs = NULL, *time_base = NULL;
1337  char *next, *codec_tag = NULL;
1338  double qscale = -1;
1339  int i;
1340 
1341  if (!st) {
1342  av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
1343  exit_program(1);
1344  }
1345 
1346  if (oc->nb_streams - 1 < o->nb_streamid_map)
1347  st->id = o->streamid_map[oc->nb_streams - 1];
1348 
1350  if (!(ost = av_mallocz(sizeof(*ost))))
1351  exit_program(1);
1353 
1354  ost->file_index = nb_output_files - 1;
1355  ost->index = idx;
1356  ost->st = st;
1358  st->codecpar->codec_type = type;
1359 
1360  ret = choose_encoder(o, oc, ost);
1361  if (ret < 0) {
1362  av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream "
1363  "%d:%d\n", ost->file_index, ost->index);
1364  exit_program(1);
1365  }
1366 
1367  ost->enc_ctx = avcodec_alloc_context3(ost->enc);
1368  if (!ost->enc_ctx) {
1369  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
1370  exit_program(1);
1371  }
1372  ost->enc_ctx->codec_type = type;
1373 
1375  if (!ost->ref_par) {
1376  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n");
1377  exit_program(1);
1378  }
1379 
1380  if (ost->enc) {
1381  AVIOContext *s = NULL;
1382  char *buf = NULL, *arg = NULL, *preset = NULL;
1383 
1384  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
1385 
1386  MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
1387  if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
1388  do {
1389  buf = get_line(s);
1390  if (!buf[0] || buf[0] == '#') {
1391  av_free(buf);
1392  continue;
1393  }
1394  if (!(arg = strchr(buf, '='))) {
1395  av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1396  exit_program(1);
1397  }
1398  *arg++ = 0;
1400  av_free(buf);
1401  } while (!s->eof_reached);
1402  avio_closep(&s);
1403  }
1404  if (ret) {
1406  "Preset %s specified for stream %d:%d, but could not be opened.\n",
1407  preset, ost->file_index, ost->index);
1408  exit_program(1);
1409  }
1410  } else {
1412  }
1413 
1414 
1415  if (o->bitexact)
1417 
1418  MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1419  if (time_base) {
1420  AVRational q;
1421  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1422  q.num <= 0 || q.den <= 0) {
1423  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1424  exit_program(1);
1425  }
1426  st->time_base = q;
1427  }
1428 
1429  MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
1430  if (time_base) {
1431  AVRational q;
1432  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1433  q.den <= 0) {
1434  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1435  exit_program(1);
1436  }
1437  ost->enc_timebase = q;
1438  }
1439 
1440  ost->max_frames = INT64_MAX;
1441  MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
1442  for (i = 0; i<o->nb_max_frames; i++) {
1443  char *p = o->max_frames[i].specifier;
1444  if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1445  av_log(NULL, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1446  break;
1447  }
1448  }
1449 
1450  ost->copy_prior_start = -1;
1451  MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
1452 
1453  MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1454  while (bsfs && *bsfs) {
1455  const AVBitStreamFilter *filter;
1456  char *bsf, *bsf_options_str, *bsf_name;
1457 
1458  bsf = av_get_token(&bsfs, ",");
1459  if (!bsf)
1460  exit_program(1);
1461  bsf_name = av_strtok(bsf, "=", &bsf_options_str);
1462  if (!bsf_name)
1463  exit_program(1);
1464 
1465  filter = av_bsf_get_by_name(bsf_name);
1466  if (!filter) {
1467  av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
1468  exit_program(1);
1469  }
1470 
1471  ost->bsf_ctx = av_realloc_array(ost->bsf_ctx,
1472  ost->nb_bitstream_filters + 1,
1473  sizeof(*ost->bsf_ctx));
1474  if (!ost->bsf_ctx)
1475  exit_program(1);
1476 
1477  ret = av_bsf_alloc(filter, &ost->bsf_ctx[ost->nb_bitstream_filters]);
1478  if (ret < 0) {
1479  av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream filter context\n");
1480  exit_program(1);
1481  }
1482 
1483  ost->nb_bitstream_filters++;
1484 
1485  if (bsf_options_str && filter->priv_class) {
1486  const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, NULL);
1487  const char * shorthand[2] = {NULL};
1488 
1489  if (opt)
1490  shorthand[0] = opt->name;
1491 
1492  ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, bsf_options_str, shorthand, "=", ":");
1493  if (ret < 0) {
1494  av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
1495  exit_program(1);
1496  }
1497  }
1498  av_freep(&bsf);
1499 
1500  if (*bsfs)
1501  bsfs++;
1502  }
1503 
1504  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1505  if (codec_tag) {
1506  uint32_t tag = strtol(codec_tag, &next, 0);
1507  if (*next)
1508  tag = AV_RL32(codec_tag);
1509  ost->st->codecpar->codec_tag =
1510  ost->enc_ctx->codec_tag = tag;
1511  }
1512 
1513  MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1514  if (qscale >= 0) {
1516  ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1517  }
1518 
1519  MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
1520  ost->disposition = av_strdup(ost->disposition);
1521 
1522  ost->max_muxing_queue_size = 128;
1523  MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
1524  ost->max_muxing_queue_size *= sizeof(AVPacket);
1525 
1526  if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1528 
1529  av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1530 
1531  av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1532  if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
1533  av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1534 
1535  av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0);
1536 
1537  ost->source_index = source_index;
1538  if (source_index >= 0) {
1539  ost->sync_ist = input_streams[source_index];
1540  input_streams[source_index]->discard = 0;
1541  input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
1542  }
1544 
1545  ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket));
1546  if (!ost->muxing_queue)
1547  exit_program(1);
1548 
1549  return ost;
1550 }
1551 
1552 static void parse_matrix_coeffs(uint16_t *dest, const char *str)
1553 {
1554  int i;
1555  const char *p = str;
1556  for (i = 0;; i++) {
1557  dest[i] = atoi(p);
1558  if (i == 63)
1559  break;
1560  p = strchr(p, ',');
1561  if (!p) {
1562  av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1563  exit_program(1);
1564  }
1565  p++;
1566  }
1567 }
1568 
1569 /* read file contents into a string */
1570 static uint8_t *read_file(const char *filename)
1571 {
1572  AVIOContext *pb = NULL;
1573  AVIOContext *dyn_buf = NULL;
1574  int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1575  uint8_t buf[1024], *str;
1576 
1577  if (ret < 0) {
1578  av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1579  return NULL;
1580  }
1581 
1582  ret = avio_open_dyn_buf(&dyn_buf);
1583  if (ret < 0) {
1584  avio_closep(&pb);
1585  return NULL;
1586  }
1587  while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
1588  avio_write(dyn_buf, buf, ret);
1589  avio_w8(dyn_buf, 0);
1590  avio_closep(&pb);
1591 
1592  ret = avio_close_dyn_buf(dyn_buf, &str);
1593  if (ret < 0)
1594  return NULL;
1595  return str;
1596 }
1597 
1599  OutputStream *ost)
1600 {
1601  AVStream *st = ost->st;
1602 
1603  if (ost->filters_script && ost->filters) {
1604  av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
1605  "output stream #%d:%d.\n", nb_output_files, st->index);
1606  exit_program(1);
1607  }
1608 
1609  if (ost->filters_script)
1610  return read_file(ost->filters_script);
1611  else if (ost->filters)
1612  return av_strdup(ost->filters);
1613 
1615  "null" : "anull");
1616 }
1617 
1619  const OutputStream *ost, enum AVMediaType type)
1620 {
1621  if (ost->filters_script || ost->filters) {
1623  "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1624  "Filtering and streamcopy cannot be used together.\n",
1625  ost->filters ? "Filtergraph" : "Filtergraph script",
1626  ost->filters ? ost->filters : ost->filters_script,
1627  av_get_media_type_string(type), ost->file_index, ost->index);
1628  exit_program(1);
1629  }
1630 }
1631 
1633 {
1634  AVStream *st;
1635  OutputStream *ost;
1636  AVCodecContext *video_enc;
1637  char *frame_rate = NULL, *frame_aspect_ratio = NULL;
1638 
1639  ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
1640  st = ost->st;
1641  video_enc = ost->enc_ctx;
1642 
1643  MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
1644  if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
1645  av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
1646  exit_program(1);
1647  }
1648  if (frame_rate && video_sync_method == VSYNC_PASSTHROUGH)
1649  av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r can produce invalid output files\n");
1650 
1651  MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
1652  if (frame_aspect_ratio) {
1653  AVRational q;
1654  if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1655  q.num <= 0 || q.den <= 0) {
1656  av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
1657  exit_program(1);
1658  }
1659  ost->frame_aspect_ratio = q;
1660  }
1661 
1662  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1663  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1664 
1665  if (!ost->stream_copy) {
1666  const char *p = NULL;
1667  char *frame_size = NULL;
1668  char *frame_pix_fmt = NULL;
1669  char *intra_matrix = NULL, *inter_matrix = NULL;
1670  char *chroma_intra_matrix = NULL;
1671  int do_pass = 0;
1672  int i;
1673 
1674  MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
1675  if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1676  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1677  exit_program(1);
1678  }
1679 
1681  MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
1682  if (frame_pix_fmt && *frame_pix_fmt == '+') {
1683  ost->keep_pix_fmt = 1;
1684  if (!*++frame_pix_fmt)
1685  frame_pix_fmt = NULL;
1686  }
1687  if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1688  av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
1689  exit_program(1);
1690  }
1691  st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1692 
1693  if (intra_only)
1694  video_enc->gop_size = 0;
1695  MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
1696  if (intra_matrix) {
1697  if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
1698  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1699  exit_program(1);
1700  }
1701  parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
1702  }
1703  MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
1704  if (chroma_intra_matrix) {
1705  uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
1706  if (!p) {
1707  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1708  exit_program(1);
1709  }
1710  video_enc->chroma_intra_matrix = p;
1711  parse_matrix_coeffs(p, chroma_intra_matrix);
1712  }
1713  MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
1714  if (inter_matrix) {
1715  if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
1716  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
1717  exit_program(1);
1718  }
1719  parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
1720  }
1721 
1722  MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
1723  for (i = 0; p; i++) {
1724  int start, end, q;
1725  int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
1726  if (e != 3) {
1727  av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
1728  exit_program(1);
1729  }
1730  video_enc->rc_override =
1731  av_realloc_array(video_enc->rc_override,
1732  i + 1, sizeof(RcOverride));
1733  if (!video_enc->rc_override) {
1734  av_log(NULL, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
1735  exit_program(1);
1736  }
1737  video_enc->rc_override[i].start_frame = start;
1738  video_enc->rc_override[i].end_frame = end;
1739  if (q > 0) {
1740  video_enc->rc_override[i].qscale = q;
1741  video_enc->rc_override[i].quality_factor = 1.0;
1742  }
1743  else {
1744  video_enc->rc_override[i].qscale = 0;
1745  video_enc->rc_override[i].quality_factor = -q/100.0;
1746  }
1747  p = strchr(p, '/');
1748  if (p) p++;
1749  }
1750  video_enc->rc_override_count = i;
1751 
1752  if (do_psnr)
1753  video_enc->flags|= AV_CODEC_FLAG_PSNR;
1754 
1755  /* two pass mode */
1756  MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
1757  if (do_pass) {
1758  if (do_pass & 1) {
1759  video_enc->flags |= AV_CODEC_FLAG_PASS1;
1760  av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
1761  }
1762  if (do_pass & 2) {
1763  video_enc->flags |= AV_CODEC_FLAG_PASS2;
1764  av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
1765  }
1766  }
1767 
1768  MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
1769  if (ost->logfile_prefix &&
1770  !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
1771  exit_program(1);
1772 
1773  if (do_pass) {
1774  char logfilename[1024];
1775  FILE *f;
1776 
1777  snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
1778  ost->logfile_prefix ? ost->logfile_prefix :
1780  i);
1781  if (!strcmp(ost->enc->name, "libx264")) {
1782  av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
1783  } else {
1784  if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1785  char *logbuffer = read_file(logfilename);
1786 
1787  if (!logbuffer) {
1788  av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
1789  logfilename);
1790  exit_program(1);
1791  }
1792  video_enc->stats_in = logbuffer;
1793  }
1794  if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1795  f = av_fopen_utf8(logfilename, "wb");
1796  if (!f) {
1798  "Cannot write log file '%s' for pass-1 encoding: %s\n",
1799  logfilename, strerror(errno));
1800  exit_program(1);
1801  }
1802  ost->logfile = f;
1803  }
1804  }
1805  }
1806 
1807  MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
1808  if (ost->forced_keyframes)
1810 
1811  MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
1812 
1813  ost->top_field_first = -1;
1814  MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
1815 
1816 
1817  ost->avfilter = get_ost_filters(o, oc, ost);
1818  if (!ost->avfilter)
1819  exit_program(1);
1820  } else {
1821  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
1822  }
1823 
1824  if (ost->stream_copy)
1826 
1827  return ost;
1828 }
1829 
1831 {
1832  int n;
1833  AVStream *st;
1834  OutputStream *ost;
1835  AVCodecContext *audio_enc;
1836 
1837  ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index);
1838  st = ost->st;
1839 
1840  audio_enc = ost->enc_ctx;
1841  audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1842 
1843  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1844  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1845 
1846  if (!ost->stream_copy) {
1847  char *sample_fmt = NULL;
1848 
1849  MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
1850 
1851  MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
1852  if (sample_fmt &&
1853  (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
1854  av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
1855  exit_program(1);
1856  }
1857 
1858  MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
1859 
1860  MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
1861  ost->apad = av_strdup(ost->apad);
1862 
1863  ost->avfilter = get_ost_filters(o, oc, ost);
1864  if (!ost->avfilter)
1865  exit_program(1);
1866 
1867  /* check for channel mapping for this audio stream */
1868  for (n = 0; n < o->nb_audio_channel_maps; n++) {
1870  if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
1871  (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
1872  InputStream *ist;
1873 
1874  if (map->channel_idx == -1) {
1875  ist = NULL;
1876  } else if (ost->source_index < 0) {
1877  av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
1878  ost->file_index, ost->st->index);
1879  continue;
1880  } else {
1881  ist = input_streams[ost->source_index];
1882  }
1883 
1884  if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
1886  ost->audio_channels_mapped + 1,
1887  sizeof(*ost->audio_channels_map)
1888  ) < 0 )
1889  exit_program(1);
1890 
1892  }
1893  }
1894  }
1895  }
1896 
1897  if (ost->stream_copy)
1899 
1900  return ost;
1901 }
1902 
1904 {
1905  OutputStream *ost;
1906 
1907  ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
1908  if (!ost->stream_copy) {
1909  av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
1910  exit_program(1);
1911  }
1912 
1913  return ost;
1914 }
1915 
1917 {
1918  OutputStream *ost;
1919 
1920  ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
1921  if (!ost->stream_copy) {
1922  av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
1923  exit_program(1);
1924  }
1925 
1926  return ost;
1927 }
1928 
1930 {
1931  OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
1932  ost->stream_copy = 1;
1933  ost->finished = 1;
1934  return ost;
1935 }
1936 
1938 {
1939  AVStream *st;
1940  OutputStream *ost;
1941  AVCodecContext *subtitle_enc;
1942 
1943  ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
1944  st = ost->st;
1945  subtitle_enc = ost->enc_ctx;
1946 
1947  subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
1948 
1949  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc, st);
1950 
1951  if (!ost->stream_copy) {
1952  char *frame_size = NULL;
1953 
1954  MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
1955  if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
1956  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1957  exit_program(1);
1958  }
1959  }
1960 
1961  return ost;
1962 }
1963 
1964 /* arg format is "output-stream-index:streamid-value". */
1965 static int opt_streamid(void *optctx, const char *opt, const char *arg)
1966 {
1967  OptionsContext *o = optctx;
1968  int idx;
1969  char *p;
1970  char idx_str[16];
1971 
1972  av_strlcpy(idx_str, arg, sizeof(idx_str));
1973  p = strchr(idx_str, ':');
1974  if (!p) {
1976  "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
1977  arg, opt);
1978  exit_program(1);
1979  }
1980  *p++ = '\0';
1981  idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
1982  o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
1983  o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
1984  return 0;
1985 }
1986 
1988 {
1989  AVFormatContext *is = ifile->ctx;
1990  AVFormatContext *os = ofile->ctx;
1991  AVChapter **tmp;
1992  int i;
1993 
1994  tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
1995  if (!tmp)
1996  return AVERROR(ENOMEM);
1997  os->chapters = tmp;
1998 
1999  for (i = 0; i < is->nb_chapters; i++) {
2000  AVChapter *in_ch = is->chapters[i], *out_ch;
2001  int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2002  int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2003  AV_TIME_BASE_Q, in_ch->time_base);
2004  int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2006 
2007 
2008  if (in_ch->end < ts_off)
2009  continue;
2010  if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2011  break;
2012 
2013  out_ch = av_mallocz(sizeof(AVChapter));
2014  if (!out_ch)
2015  return AVERROR(ENOMEM);
2016 
2017  out_ch->id = in_ch->id;
2018  out_ch->time_base = in_ch->time_base;
2019  out_ch->start = FFMAX(0, in_ch->start - ts_off);
2020  out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2021 
2022  if (copy_metadata)
2023  av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2024 
2025  os->chapters[os->nb_chapters++] = out_ch;
2026  }
2027  return 0;
2028 }
2029 
2031  AVFormatContext *oc)
2032 {
2033  OutputStream *ost;
2034 
2035  switch (ofilter->type) {
2036  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
2037  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
2038  default:
2039  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported "
2040  "currently.\n");
2041  exit_program(1);
2042  }
2043 
2044  ost->source_index = -1;
2045  ost->filter = ofilter;
2046 
2047  ofilter->ost = ost;
2048  ofilter->format = -1;
2049 
2050  if (ost->stream_copy) {
2051  av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
2052  "which is fed from a complex filtergraph. Filtering and streamcopy "
2053  "cannot be used together.\n", ost->file_index, ost->index);
2054  exit_program(1);
2055  }
2056 
2057  if (ost->avfilter && (ost->filters || ost->filters_script)) {
2058  const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
2060  "%s '%s' was specified through the %s option "
2061  "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2062  "%s and -filter_complex cannot be used together for the same stream.\n",
2063  ost->filters ? "Filtergraph" : "Filtergraph script",
2064  ost->filters ? ost->filters : ost->filters_script,
2065  opt, ost->file_index, ost->index, opt);
2066  exit_program(1);
2067  }
2068 
2069  avfilter_inout_free(&ofilter->out_tmp);
2070 }
2071 
2072 static int init_complex_filters(void)
2073 {
2074  int i, ret = 0;
2075 
2076  for (i = 0; i < nb_filtergraphs; i++) {
2078  if (ret < 0)
2079  return ret;
2080  }
2081  return 0;
2082 }
2083 
2084 static int open_output_file(OptionsContext *o, const char *filename)
2085 {
2086  AVFormatContext *oc;
2087  int i, j, err;
2088  OutputFile *of;
2089  OutputStream *ost;
2090  InputStream *ist;
2091  AVDictionary *unused_opts = NULL;
2092  AVDictionaryEntry *e = NULL;
2093  int format_flags = 0;
2094 
2095  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
2096  o->stop_time = INT64_MAX;
2097  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2098  }
2099 
2100  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
2101  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2102  if (o->stop_time <= start_time) {
2103  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2104  exit_program(1);
2105  } else {
2107  }
2108  }
2109 
2111  of = av_mallocz(sizeof(*of));
2112  if (!of)
2113  exit_program(1);
2114  output_files[nb_output_files - 1] = of;
2115 
2117  of->recording_time = o->recording_time;
2118  of->start_time = o->start_time;
2119  of->limit_filesize = o->limit_filesize;
2120  of->shortest = o->shortest;
2121  av_dict_copy(&of->opts, o->g->format_opts, 0);
2122 
2123  if (!strcmp(filename, "-"))
2124  filename = "pipe:";
2125 
2126  err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2127  if (!oc) {
2128  print_error(filename, err);
2129  exit_program(1);
2130  }
2131 
2132  of->ctx = oc;
2133  if (o->recording_time != INT64_MAX)
2134  oc->duration = o->recording_time;
2135 
2136  oc->interrupt_callback = int_cb;
2137 
2138  e = av_dict_get(o->g->format_opts, "fflags", NULL, 0);
2139  if (e) {
2140  const AVOption *o = av_opt_find(oc, "fflags", NULL, 0, 0);
2141  av_opt_eval_flags(oc, o, e->value, &format_flags);
2142  }
2143  if (o->bitexact) {
2144  format_flags |= AVFMT_FLAG_BITEXACT;
2145  oc->flags |= AVFMT_FLAG_BITEXACT;
2146  }
2147 
2148  /* create streams for all unlabeled output pads */
2149  for (i = 0; i < nb_filtergraphs; i++) {
2150  FilterGraph *fg = filtergraphs[i];
2151  for (j = 0; j < fg->nb_outputs; j++) {
2152  OutputFilter *ofilter = fg->outputs[j];
2153 
2154  if (!ofilter->out_tmp || ofilter->out_tmp->name)
2155  continue;
2156 
2157  switch (ofilter->type) {
2158  case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break;
2159  case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break;
2160  case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
2161  }
2162  init_output_filter(ofilter, o, oc);
2163  }
2164  }
2165 
2166  if (!o->nb_stream_maps) {
2167  char *subtitle_codec_name = NULL;
2168  /* pick the "best" stream of each type */
2169 
2170  /* video: highest resolution */
2172  int area = 0, idx = -1;
2173  int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2174  for (i = 0; i < nb_input_streams; i++) {
2175  int new_area;
2176  ist = input_streams[i];
2177  new_area = ist->st->codecpar->width * ist->st->codecpar->height + 100000000*!!ist->st->codec_info_nb_frames;
2178  if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2179  new_area = 1;
2180  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2181  new_area > area) {
2182  if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2183  continue;
2184  area = new_area;
2185  idx = i;
2186  }
2187  }
2188  if (idx >= 0)
2189  new_video_stream(o, oc, idx);
2190  }
2191 
2192  /* audio: most channels */
2194  int best_score = 0, idx = -1;
2195  for (i = 0; i < nb_input_streams; i++) {
2196  int score;
2197  ist = input_streams[i];
2198  score = ist->st->codecpar->channels + 100000000*!!ist->st->codec_info_nb_frames;
2199  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2200  score > best_score) {
2201  best_score = score;
2202  idx = i;
2203  }
2204  }
2205  if (idx >= 0)
2206  new_audio_stream(o, oc, idx);
2207  }
2208 
2209  /* subtitles: pick first */
2210  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
2211  if (!o->subtitle_disable && (avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) {
2212  for (i = 0; i < nb_input_streams; i++)
2213  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2214  AVCodecDescriptor const *input_descriptor =
2215  avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id);
2216  AVCodecDescriptor const *output_descriptor = NULL;
2217  AVCodec const *output_codec =
2219  int input_props = 0, output_props = 0;
2220  if (output_codec)
2221  output_descriptor = avcodec_descriptor_get(output_codec->id);
2222  if (input_descriptor)
2223  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2224  if (output_descriptor)
2225  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2226  if (subtitle_codec_name ||
2227  input_props & output_props ||
2228  // Map dvb teletext which has neither property to any output subtitle encoder
2229  input_descriptor && output_descriptor &&
2230  (!input_descriptor->props ||
2231  !output_descriptor->props)) {
2232  new_subtitle_stream(o, oc, i);
2233  break;
2234  }
2235  }
2236  }
2237  /* Data only if codec id match */
2238  if (!o->data_disable ) {
2240  for (i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) {
2241  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2242  && input_streams[i]->st->codecpar->codec_id == codec_id )
2243  new_data_stream(o, oc, i);
2244  }
2245  }
2246  } else {
2247  for (i = 0; i < o->nb_stream_maps; i++) {
2248  StreamMap *map = &o->stream_maps[i];
2249 
2250  if (map->disabled)
2251  continue;
2252 
2253  if (map->linklabel) {
2254  FilterGraph *fg;
2255  OutputFilter *ofilter = NULL;
2256  int j, k;
2257 
2258  for (j = 0; j < nb_filtergraphs; j++) {
2259  fg = filtergraphs[j];
2260  for (k = 0; k < fg->nb_outputs; k++) {
2261  AVFilterInOut *out = fg->outputs[k]->out_tmp;
2262  if (out && !strcmp(out->name, map->linklabel)) {
2263  ofilter = fg->outputs[k];
2264  goto loop_end;
2265  }
2266  }
2267  }
2268 loop_end:
2269  if (!ofilter) {
2270  av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2271  "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2272  exit_program(1);
2273  }
2274  init_output_filter(ofilter, o, oc);
2275  } else {
2276  int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2277 
2280  continue;
2282  continue;
2284  continue;
2285  if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2286  continue;
2287 
2288  ost = NULL;
2289  switch (ist->st->codecpar->codec_type) {
2290  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2291  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2292  case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2293  case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2294  case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2295  case AVMEDIA_TYPE_UNKNOWN:
2296  if (copy_unknown_streams) {
2297  ost = new_unknown_stream (o, oc, src_idx);
2298  break;
2299  }
2300  default:
2302  "Cannot map stream #%d:%d - unsupported type.\n",
2303  map->file_index, map->stream_index);
2304  if (!ignore_unknown_streams) {
2305  av_log(NULL, AV_LOG_FATAL,
2306  "If you want unsupported types ignored instead "
2307  "of failing, please use the -ignore_unknown option\n"
2308  "If you want them copied, please use -copy_unknown\n");
2309  exit_program(1);
2310  }
2311  }
2312  if (ost)
2313  ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
2314  + map->sync_stream_index];
2315  }
2316  }
2317  }
2318 
2319  /* handle attached files */
2320  for (i = 0; i < o->nb_attachments; i++) {
2321  AVIOContext *pb;
2322  uint8_t *attachment;
2323  const char *p;
2324  int64_t len;
2325 
2326  if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
2327  av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
2328  o->attachments[i]);
2329  exit_program(1);
2330  }
2331  if ((len = avio_size(pb)) <= 0) {
2332  av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
2333  o->attachments[i]);
2334  exit_program(1);
2335  }
2336  if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
2337  !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
2338  av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
2339  o->attachments[i]);
2340  exit_program(1);
2341  }
2342  avio_read(pb, attachment, len);
2343  memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
2344 
2345  ost = new_attachment_stream(o, oc, -1);
2346  ost->stream_copy = 0;
2347  ost->attachment_filename = o->attachments[i];
2348  ost->st->codecpar->extradata = attachment;
2349  ost->st->codecpar->extradata_size = len;
2350 
2351  p = strrchr(o->attachments[i], '/');
2352  av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
2353  avio_closep(&pb);
2354  }
2355 
2356 #if FF_API_LAVF_AVCTX
2357  for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file
2358  AVDictionaryEntry *e;
2359  ost = output_streams[i];
2360 
2361  if ((ost->stream_copy || ost->attachment_filename)
2362  && (e = av_dict_get(o->g->codec_opts, "flags", NULL, AV_DICT_IGNORE_SUFFIX))
2363  && (!e->key[5] || check_stream_specifier(oc, ost->st, e->key+6)))
2364  if (av_opt_set(ost->st->codec, "flags", e->value, 0) < 0)
2365  exit_program(1);
2366  }
2367 #endif
2368 
2369  if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2370  av_dump_format(oc, nb_output_files - 1, oc->url, 1);
2371  av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
2372  exit_program(1);
2373  }
2374 
2375  /* check if all codec options have been used */
2376  unused_opts = strip_specifiers(o->g->codec_opts);
2377  for (i = of->ost_index; i < nb_output_streams; i++) {
2378  e = NULL;
2379  while ((e = av_dict_get(output_streams[i]->encoder_opts, "", e,
2381  av_dict_set(&unused_opts, e->key, NULL, 0);
2382  }
2383 
2384  e = NULL;
2385  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
2386  const AVClass *class = avcodec_get_class();
2387  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2389  const AVClass *fclass = avformat_get_class();
2390  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2392  if (!option || foption)
2393  continue;
2394 
2395 
2396  if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2397  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
2398  "output file #%d (%s) is not an encoding option.\n", e->key,
2399  option->help ? option->help : "", nb_output_files - 1,
2400  filename);
2401  exit_program(1);
2402  }
2403 
2404  // gop_timecode is injected by generic code but not always used
2405  if (!strcmp(e->key, "gop_timecode"))
2406  continue;
2407 
2408  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
2409  "output file #%d (%s) has not been used for any stream. The most "
2410  "likely reason is either wrong type (e.g. a video option with "
2411  "no video streams) or that it is a private option of some encoder "
2412  "which was not actually used for any stream.\n", e->key,
2413  option->help ? option->help : "", nb_output_files - 1, filename);
2414  }
2415  av_dict_free(&unused_opts);
2416 
2417  /* set the decoding_needed flags and create simple filtergraphs */
2418  for (i = of->ost_index; i < nb_output_streams; i++) {
2419  OutputStream *ost = output_streams[i];
2420 
2421  if (ost->encoding_needed && ost->source_index >= 0) {
2422  InputStream *ist = input_streams[ost->source_index];
2424 
2425  if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2427  err = init_simple_filtergraph(ist, ost);
2428  if (err < 0) {
2430  "Error initializing a simple filtergraph between streams "
2431  "%d:%d->%d:%d\n", ist->file_index, ost->source_index,
2432  nb_output_files - 1, ost->st->index);
2433  exit_program(1);
2434  }
2435  }
2436  }
2437 
2438  /* set the filter output constraints */
2439  if (ost->filter) {
2440  OutputFilter *f = ost->filter;
2441  int count;
2442  switch (ost->enc_ctx->codec_type) {
2443  case AVMEDIA_TYPE_VIDEO:
2444  f->frame_rate = ost->frame_rate;
2445  f->width = ost->enc_ctx->width;
2446  f->height = ost->enc_ctx->height;
2447  if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2448  f->format = ost->enc_ctx->pix_fmt;
2449  } else if (ost->enc->pix_fmts) {
2450  count = 0;
2451  while (ost->enc->pix_fmts[count] != AV_PIX_FMT_NONE)
2452  count++;
2453  f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2454  if (!f->formats)
2455  exit_program(1);
2456  memcpy(f->formats, ost->enc->pix_fmts, (count + 1) * sizeof(*f->formats));
2457  }
2458  break;
2459  case AVMEDIA_TYPE_AUDIO:
2460  if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2461  f->format = ost->enc_ctx->sample_fmt;
2462  } else if (ost->enc->sample_fmts) {
2463  count = 0;
2464  while (ost->enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
2465  count++;
2466  f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2467  if (!f->formats)
2468  exit_program(1);
2469  memcpy(f->formats, ost->enc->sample_fmts, (count + 1) * sizeof(*f->formats));
2470  }
2471  if (ost->enc_ctx->sample_rate) {
2472  f->sample_rate = ost->enc_ctx->sample_rate;
2473  } else if (ost->enc->supported_samplerates) {
2474  count = 0;
2475  while (ost->enc->supported_samplerates[count])
2476  count++;
2477  f->sample_rates = av_mallocz_array(count + 1, sizeof(*f->sample_rates));
2478  if (!f->sample_rates)
2479  exit_program(1);
2480  memcpy(f->sample_rates, ost->enc->supported_samplerates,
2481  (count + 1) * sizeof(*f->sample_rates));
2482  }
2483  if (ost->enc_ctx->channels) {
2485  } else if (ost->enc->channel_layouts) {
2486  count = 0;
2487  while (ost->enc->channel_layouts[count])
2488  count++;
2489  f->channel_layouts = av_mallocz_array(count + 1, sizeof(*f->channel_layouts));
2490  if (!f->channel_layouts)
2491  exit_program(1);
2492  memcpy(f->channel_layouts, ost->enc->channel_layouts,
2493  (count + 1) * sizeof(*f->channel_layouts));
2494  }
2495  break;
2496  }
2497  }
2498  }
2499 
2500  /* check filename in case of an image number is expected */
2501  if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2502  if (!av_filename_number_test(oc->url)) {
2503  print_error(oc->url, AVERROR(EINVAL));
2504  exit_program(1);
2505  }
2506  }
2507 
2510  "No input streams but output needs an input stream\n");
2511  exit_program(1);
2512  }
2513 
2514  if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2515  /* test if it already exists to avoid losing precious files */
2516  assert_file_overwrite(filename);
2517 
2518  /* open the file */
2519  if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2520  &oc->interrupt_callback,
2521  &of->opts)) < 0) {
2522  print_error(filename, err);
2523  exit_program(1);
2524  }
2525  } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
2526  assert_file_overwrite(filename);
2527 
2528  if (o->mux_preload) {
2529  av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2530  }
2531  oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2532 
2533  /* copy metadata */
2534  for (i = 0; i < o->nb_metadata_map; i++) {
2535  char *p;
2536  int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2537 
2538  if (in_file_index >= nb_input_files) {
2539  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
2540  exit_program(1);
2541  }
2542  copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc,
2543  in_file_index >= 0 ?
2544  input_files[in_file_index]->ctx : NULL, o);
2545  }
2546 
2547  /* copy chapters */
2548  if (o->chapters_input_file >= nb_input_files) {
2549  if (o->chapters_input_file == INT_MAX) {
2550  /* copy chapters from the first input file that has them*/
2551  o->chapters_input_file = -1;
2552  for (i = 0; i < nb_input_files; i++)
2553  if (input_files[i]->ctx->nb_chapters) {
2554  o->chapters_input_file = i;
2555  break;
2556  }
2557  } else {
2558  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2559  o->chapters_input_file);
2560  exit_program(1);
2561  }
2562  }
2563  if (o->chapters_input_file >= 0)
2566 
2567  /* copy global metadata by default */
2571  if(o->recording_time != INT64_MAX)
2572  av_dict_set(&oc->metadata, "duration", NULL, 0);
2573  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2574  }
2575  if (!o->metadata_streams_manual)
2576  for (i = of->ost_index; i < nb_output_streams; i++) {
2577  InputStream *ist;
2578  if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
2579  continue;
2581  av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
2582  if (!output_streams[i]->stream_copy) {
2583  av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
2584  }
2585  }
2586 
2587  /* process manually set programs */
2588  for (i = 0; i < o->nb_program; i++) {
2589  const char *p = o->program[i].u.str;
2590  int progid = i+1;
2591  AVProgram *program;
2592 
2593  while(*p) {
2594  const char *p2 = av_get_token(&p, ":");
2595  const char *to_dealloc = p2;
2596  char *key;
2597  if (!p2)
2598  break;
2599 
2600  if(*p) p++;
2601 
2602  key = av_get_token(&p2, "=");
2603  if (!key || !*p2) {
2604  av_freep(&to_dealloc);
2605  av_freep(&key);
2606  break;
2607  }
2608  p2++;
2609 
2610  if (!strcmp(key, "program_num"))
2611  progid = strtol(p2, NULL, 0);
2612  av_freep(&to_dealloc);
2613  av_freep(&key);
2614  }
2615 
2616  program = av_new_program(oc, progid);
2617 
2618  p = o->program[i].u.str;
2619  while(*p) {
2620  const char *p2 = av_get_token(&p, ":");
2621  const char *to_dealloc = p2;
2622  char *key;
2623  if (!p2)
2624  break;
2625  if(*p) p++;
2626 
2627  key = av_get_token(&p2, "=");
2628  if (!key) {
2630  "No '=' character in program string %s.\n",
2631  p2);
2632  exit_program(1);
2633  }
2634  if (!*p2)
2635  exit_program(1);
2636  p2++;
2637 
2638  if (!strcmp(key, "title")) {
2639  av_dict_set(&program->metadata, "title", p2, 0);
2640  } else if (!strcmp(key, "program_num")) {
2641  } else if (!strcmp(key, "st")) {
2642  int st_num = strtol(p2, NULL, 0);
2643  av_program_add_stream_index(oc, progid, st_num);
2644  } else {
2645  av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
2646  exit_program(1);
2647  }
2648  av_freep(&to_dealloc);
2649  av_freep(&key);
2650  }
2651  }
2652 
2653  /* process manually set metadata */
2654  for (i = 0; i < o->nb_metadata; i++) {
2655  AVDictionary **m;
2656  char type, *val;
2657  const char *stream_spec;
2658  int index = 0, j, ret = 0;
2659 
2660  val = strchr(o->metadata[i].u.str, '=');
2661  if (!val) {
2662  av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2663  o->metadata[i].u.str);
2664  exit_program(1);
2665  }
2666  *val++ = 0;
2667 
2668  parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
2669  if (type == 's') {
2670  for (j = 0; j < oc->nb_streams; j++) {
2671  ost = output_streams[nb_output_streams - oc->nb_streams + j];
2672  if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2673  if (!strcmp(o->metadata[i].u.str, "rotate")) {
2674  char *tail;
2675  double theta = av_strtod(val, &tail);
2676  if (!*tail) {
2677  ost->rotate_overridden = 1;
2678  ost->rotate_override_value = theta;
2679  }
2680  } else {
2681  av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
2682  }
2683  } else if (ret < 0)
2684  exit_program(1);
2685  }
2686  }
2687  else {
2688  switch (type) {
2689  case 'g':
2690  m = &oc->metadata;
2691  break;
2692  case 'c':
2693  if (index < 0 || index >= oc->nb_chapters) {
2694  av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
2695  exit_program(1);
2696  }
2697  m = &oc->chapters[index]->metadata;
2698  break;
2699  case 'p':
2700  if (index < 0 || index >= oc->nb_programs) {
2701  av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
2702  exit_program(1);
2703  }
2704  m = &oc->programs[index]->metadata;
2705  break;
2706  default:
2707  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
2708  exit_program(1);
2709  }
2710  av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
2711  }
2712  }
2713 
2714  return 0;
2715 }
2716 
2717 static int opt_target(void *optctx, const char *opt, const char *arg)
2718 {
2719  OptionsContext *o = optctx;
2720  enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
2721  static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
2722 
2723  if (!strncmp(arg, "pal-", 4)) {
2724  norm = PAL;
2725  arg += 4;
2726  } else if (!strncmp(arg, "ntsc-", 5)) {
2727  norm = NTSC;
2728  arg += 5;
2729  } else if (!strncmp(arg, "film-", 5)) {
2730  norm = FILM;
2731  arg += 5;
2732  } else {
2733  /* Try to determine PAL/NTSC by peeking in the input files */
2734  if (nb_input_files) {
2735  int i, j;
2736  for (j = 0; j < nb_input_files; j++) {
2737  for (i = 0; i < input_files[j]->nb_streams; i++) {
2738  AVStream *st = input_files[j]->ctx->streams[i];
2739  int64_t fr;
2741  continue;
2742  fr = st->time_base.den * 1000LL / st->time_base.num;
2743  if (fr == 25000) {
2744  norm = PAL;
2745  break;
2746  } else if ((fr == 29970) || (fr == 23976)) {
2747  norm = NTSC;
2748  break;
2749  }
2750  }
2751  if (norm != UNKNOWN)
2752  break;
2753  }
2754  }
2755  if (norm != UNKNOWN)
2756  av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
2757  }
2758 
2759  if (norm == UNKNOWN) {
2760  av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
2761  av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
2762  av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
2763  exit_program(1);
2764  }
2765 
2766  if (!strcmp(arg, "vcd")) {
2767  opt_video_codec(o, "c:v", "mpeg1video");
2768  opt_audio_codec(o, "c:a", "mp2");
2769  parse_option(o, "f", "vcd", options);
2770 
2771  parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
2772  parse_option(o, "r", frame_rates[norm], options);
2773  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2774 
2775  opt_default(NULL, "b:v", "1150000");
2776  opt_default(NULL, "maxrate:v", "1150000");
2777  opt_default(NULL, "minrate:v", "1150000");
2778  opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
2779 
2780  opt_default(NULL, "b:a", "224000");
2781  parse_option(o, "ar", "44100", options);
2782  parse_option(o, "ac", "2", options);
2783 
2784  opt_default(NULL, "packetsize", "2324");
2785  opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
2786 
2787  /* We have to offset the PTS, so that it is consistent with the SCR.
2788  SCR starts at 36000, but the first two packs contain only padding
2789  and the first pack from the other stream, respectively, may also have
2790  been written before.
2791  So the real data starts at SCR 36000+3*1200. */
2792  o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
2793  } else if (!strcmp(arg, "svcd")) {
2794 
2795  opt_video_codec(o, "c:v", "mpeg2video");
2796  opt_audio_codec(o, "c:a", "mp2");
2797  parse_option(o, "f", "svcd", options);
2798 
2799  parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
2800  parse_option(o, "r", frame_rates[norm], options);
2801  parse_option(o, "pix_fmt", "yuv420p", options);
2802  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2803 
2804  opt_default(NULL, "b:v", "2040000");
2805  opt_default(NULL, "maxrate:v", "2516000");
2806  opt_default(NULL, "minrate:v", "0"); // 1145000;
2807  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2808  opt_default(NULL, "scan_offset", "1");
2809 
2810  opt_default(NULL, "b:a", "224000");
2811  parse_option(o, "ar", "44100", options);
2812 
2813  opt_default(NULL, "packetsize", "2324");
2814 
2815  } else if (!strcmp(arg, "dvd")) {
2816 
2817  opt_video_codec(o, "c:v", "mpeg2video");
2818  opt_audio_codec(o, "c:a", "ac3");
2819  parse_option(o, "f", "dvd", options);
2820 
2821  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2822  parse_option(o, "r", frame_rates[norm], options);
2823  parse_option(o, "pix_fmt", "yuv420p", options);
2824  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2825 
2826  opt_default(NULL, "b:v", "6000000");
2827  opt_default(NULL, "maxrate:v", "9000000");
2828  opt_default(NULL, "minrate:v", "0"); // 1500000;
2829  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2830 
2831  opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
2832  opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
2833 
2834  opt_default(NULL, "b:a", "448000");
2835  parse_option(o, "ar", "48000", options);
2836 
2837  } else if (!strncmp(arg, "dv", 2)) {
2838 
2839  parse_option(o, "f", "dv", options);
2840 
2841  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2842  parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
2843  norm == PAL ? "yuv420p" : "yuv411p", options);
2844  parse_option(o, "r", frame_rates[norm], options);
2845 
2846  parse_option(o, "ar", "48000", options);
2847  parse_option(o, "ac", "2", options);
2848 
2849  } else {
2850  av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
2851  return AVERROR(EINVAL);
2852  }
2853 
2856 
2857  return 0;
2858 }
2859 
2860 static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
2861 {
2863  vstats_filename = av_strdup (arg);
2864  return 0;
2865 }
2866 
2867 static int opt_vstats(void *optctx, const char *opt, const char *arg)
2868 {
2869  char filename[40];
2870  time_t today2 = time(NULL);
2871  struct tm *today = localtime(&today2);
2872 
2873  if (!today) { // maybe tomorrow
2874  av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
2875  exit_program(1);
2876  }
2877 
2878  snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
2879  today->tm_sec);
2880  return opt_vstats_file(NULL, opt, filename);
2881 }
2882 
2883 static int opt_video_frames(void *optctx, const char *opt, const char *arg)
2884 {
2885  OptionsContext *o = optctx;
2886  return parse_option(o, "frames:v", arg, options);
2887 }
2888 
2889 static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
2890 {
2891  OptionsContext *o = optctx;
2892  return parse_option(o, "frames:a", arg, options);
2893 }
2894 
2895 static int opt_data_frames(void *optctx, const char *opt, const char *arg)
2896 {
2897  OptionsContext *o = optctx;
2898  return parse_option(o, "frames:d", arg, options);
2899 }
2900 
2901 static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
2902 {
2903  int ret;
2904  AVDictionary *cbak = codec_opts;
2905  AVDictionary *fbak = format_opts;
2906  codec_opts = NULL;
2907  format_opts = NULL;
2908 
2909  ret = opt_default(NULL, opt, arg);
2910 
2911  av_dict_copy(&o->g->codec_opts , codec_opts, 0);
2915  codec_opts = cbak;
2916  format_opts = fbak;
2917 
2918  return ret;
2919 }
2920 
2921 static int opt_preset(void *optctx, const char *opt, const char *arg)
2922 {
2923  OptionsContext *o = optctx;
2924  FILE *f=NULL;
2925  char filename[1000], line[1000], tmp_line[1000];
2926  const char *codec_name = NULL;
2927 
2928  tmp_line[0] = *opt;
2929  tmp_line[1] = 0;
2930  MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
2931 
2932  if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
2933  if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
2934  av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
2935  }else
2936  av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
2937  exit_program(1);
2938  }
2939 
2940  while (fgets(line, sizeof(line), f)) {
2941  char *key = tmp_line, *value, *endptr;
2942 
2943  if (strcspn(line, "#\n\r") == 0)
2944  continue;
2945  av_strlcpy(tmp_line, line, sizeof(tmp_line));
2946  if (!av_strtok(key, "=", &value) ||
2947  !av_strtok(value, "\r\n", &endptr)) {
2948  av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
2949  exit_program(1);
2950  }
2951  av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
2952 
2953  if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
2954  else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
2955  else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
2956  else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
2957  else if (opt_default_new(o, key, value) < 0) {
2958  av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
2959  filename, line, key, value);
2960  exit_program(1);
2961  }
2962  }
2963 
2964  fclose(f);
2965 
2966  return 0;
2967 }
2968 
2969 static int opt_old2new(void *optctx, const char *opt, const char *arg)
2970 {
2971  OptionsContext *o = optctx;
2972  char *s = av_asprintf("%s:%c", opt + 1, *opt);
2973  int ret = parse_option(o, s, arg, options);
2974  av_free(s);
2975  return ret;
2976 }
2977 
2978 static int opt_bitrate(void *optctx, const char *opt, const char *arg)
2979 {
2980  OptionsContext *o = optctx;
2981 
2982  if(!strcmp(opt, "ab")){
2983  av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
2984  return 0;
2985  } else if(!strcmp(opt, "b")){
2986  av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
2987  av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
2988  return 0;
2989  }
2990  av_dict_set(&o->g->codec_opts, opt, arg, 0);
2991  return 0;
2992 }
2993 
2994 static int opt_qscale(void *optctx, const char *opt, const char *arg)
2995 {
2996  OptionsContext *o = optctx;
2997  char *s;
2998  int ret;
2999  if(!strcmp(opt, "qscale")){
3000  av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
3001  return parse_option(o, "q:v", arg, options);
3002  }
3003  s = av_asprintf("q%s", opt + 6);
3004  ret = parse_option(o, s, arg, options);
3005  av_free(s);
3006  return ret;
3007 }
3008 
3009 static int opt_profile(void *optctx, const char *opt, const char *arg)
3010 {
3011  OptionsContext *o = optctx;
3012  if(!strcmp(opt, "profile")){
3013  av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
3014  av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
3015  return 0;
3016  }
3017  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3018  return 0;
3019 }
3020 
3021 static int opt_video_filters(void *optctx, const char *opt, const char *arg)
3022 {
3023  OptionsContext *o = optctx;
3024  return parse_option(o, "filter:v", arg, options);
3025 }
3026 
3027 static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
3028 {
3029  OptionsContext *o = optctx;
3030  return parse_option(o, "filter:a", arg, options);
3031 }
3032 
3033 static int opt_vsync(void *optctx, const char *opt, const char *arg)
3034 {
3035  if (!av_strcasecmp(arg, "cfr")) video_sync_method = VSYNC_CFR;
3036  else if (!av_strcasecmp(arg, "vfr")) video_sync_method = VSYNC_VFR;
3037  else if (!av_strcasecmp(arg, "passthrough")) video_sync_method = VSYNC_PASSTHROUGH;
3038  else if (!av_strcasecmp(arg, "drop")) video_sync_method = VSYNC_DROP;
3039 
3042  return 0;
3043 }
3044 
3045 static int opt_timecode(void *optctx, const char *opt, const char *arg)
3046 {
3047  OptionsContext *o = optctx;
3048  char *tcr = av_asprintf("timecode=%s", arg);
3049  int ret = parse_option(o, "metadata:g", tcr, options);
3050  if (ret >= 0)
3051  ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
3052  av_free(tcr);
3053  return ret;
3054 }
3055 
3056 static int opt_channel_layout(void *optctx, const char *opt, const char *arg)
3057 {
3058  OptionsContext *o = optctx;
3059  char layout_str[32];
3060  char *stream_str;
3061  char *ac_str;
3062  int ret, channels, ac_str_size;
3063  uint64_t layout;
3064 
3065  layout = av_get_channel_layout(arg);
3066  if (!layout) {
3067  av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg);
3068  return AVERROR(EINVAL);
3069  }
3070  snprintf(layout_str, sizeof(layout_str), "%"PRIu64, layout);
3071  ret = opt_default_new(o, opt, layout_str);
3072  if (ret < 0)
3073  return ret;
3074 
3075  /* set 'ac' option based on channel layout */
3076  channels = av_get_channel_layout_nb_channels(layout);
3077  snprintf(layout_str, sizeof(layout_str), "%d", channels);
3078  stream_str = strchr(opt, ':');
3079  ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
3080  ac_str = av_mallocz(ac_str_size);
3081  if (!ac_str)
3082  return AVERROR(ENOMEM);
3083  av_strlcpy(ac_str, "ac", 3);
3084  if (stream_str)
3085  av_strlcat(ac_str, stream_str, ac_str_size);
3086  ret = parse_option(o, ac_str, layout_str, options);
3087  av_free(ac_str);
3088 
3089  return ret;
3090 }
3091 
3092 static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
3093 {
3094  OptionsContext *o = optctx;
3095  return parse_option(o, "q:a", arg, options);
3096 }
3097 
3098 static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
3099 {
3101  if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
3102  return AVERROR(ENOMEM);
3105  if (!filtergraphs[nb_filtergraphs - 1]->graph_desc)
3106  return AVERROR(ENOMEM);
3107 
3109 
3110  return 0;
3111 }
3112 
3113 static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
3114 {
3115  uint8_t *graph_desc = read_file(arg);
3116  if (!graph_desc)
3117  return AVERROR(EINVAL);
3118 
3120  if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
3121  return AVERROR(ENOMEM);
3123  filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc;
3124 
3126 
3127  return 0;
3128 }
3129 
3130 void show_help_default(const char *opt, const char *arg)
3131 {
3132  /* per-file options have at least one of those set */
3133  const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
3134  int show_advanced = 0, show_avoptions = 0;
3135 
3136  if (opt && *opt) {
3137  if (!strcmp(opt, "long"))
3138  show_advanced = 1;
3139  else if (!strcmp(opt, "full"))
3140  show_advanced = show_avoptions = 1;
3141  else
3142  av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
3143  }
3144 
3145  show_usage();
3146 
3147  printf("Getting help:\n"
3148  " -h -- print basic options\n"
3149  " -h long -- print more options\n"
3150  " -h full -- print all options (including all format and codec specific options, very long)\n"
3151  " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf\n"
3152  " See man %s for detailed description of the options.\n"
3153  "\n", program_name);
3154 
3155  show_help_options(options, "Print help / information / capabilities:",
3156  OPT_EXIT, 0, 0);
3157 
3158  show_help_options(options, "Global options (affect whole program "
3159  "instead of just one file:",
3160  0, per_file | OPT_EXIT | OPT_EXPERT, 0);
3161  if (show_advanced)
3162  show_help_options(options, "Advanced global options:", OPT_EXPERT,
3163  per_file | OPT_EXIT, 0);
3164 
3165  show_help_options(options, "Per-file main options:", 0,
3167  OPT_EXIT, per_file);
3168  if (show_advanced)
3169  show_help_options(options, "Advanced per-file options:",
3170  OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file);
3171 
3172  show_help_options(options, "Video options:",
3174  if (show_advanced)
3175  show_help_options(options, "Advanced Video options:",
3177 
3178  show_help_options(options, "Audio options:",
3180  if (show_advanced)
3181  show_help_options(options, "Advanced Audio options:",
3183  show_help_options(options, "Subtitle options:",
3184  OPT_SUBTITLE, 0, 0);
3185  printf("\n");
3186 
3187  if (show_avoptions) {
3191 #if CONFIG_SWSCALE
3193 #endif
3194 #if CONFIG_SWRESAMPLE
3196 #endif
3199  }
3200 }
3201 
3202 void show_usage(void)
3203 {
3204  av_log(NULL, AV_LOG_INFO, "Hyper fast Audio and Video encoder\n");
3205  av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
3206  av_log(NULL, AV_LOG_INFO, "\n");
3207 }
3208 
3209 enum OptGroup {
3212 };
3213 
3214 static const OptionGroupDef groups[] = {
3215  [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
3216  [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
3217 };
3218 
3219 static int open_files(OptionGroupList *l, const char *inout,
3220  int (*open_file)(OptionsContext*, const char*))
3221 {
3222  int i, ret;
3223 
3224  for (i = 0; i < l->nb_groups; i++) {
3225  OptionGroup *g = &l->groups[i];
3226  OptionsContext o;
3227 
3228  init_options(&o);
3229  o.g = g;
3230 
3231  ret = parse_optgroup(&o, g);
3232  if (ret < 0) {
3233  av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
3234  "%s.\n", inout, g->arg);
3235  uninit_options(&o);
3236  return ret;
3237  }
3238 
3239  av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
3240  ret = open_file(&o, g->arg);
3241  uninit_options(&o);
3242  if (ret < 0) {
3243  av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
3244  inout, g->arg);
3245  return ret;
3246  }
3247  av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
3248  }
3249 
3250  return 0;
3251 }
3252 
3253 int ffmpeg_parse_options(int argc, char **argv)
3254 {
3255  OptionParseContext octx;
3256  uint8_t error[128];
3257  int ret;
3258 
3259  memset(&octx, 0, sizeof(octx));
3260 
3261  /* split the commandline into an internal representation */
3262  ret = split_commandline(&octx, argc, argv, options, groups,
3263  FF_ARRAY_ELEMS(groups));
3264  if (ret < 0) {
3265  av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
3266  goto fail;
3267  }
3268 
3269  /* apply global options */
3270  ret = parse_optgroup(NULL, &octx.global_opts);
3271  if (ret < 0) {
3272  av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
3273  goto fail;
3274  }
3275 
3276  /* configure terminal and setup signal handlers */
3277  term_init();
3278 
3279  /* open input files */
3280  ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file);
3281  if (ret < 0) {
3282  av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
3283  goto fail;
3284  }
3285 
3286  /* create the complex filtergraphs */
3287  ret = init_complex_filters();
3288  if (ret < 0) {
3289  av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
3290  goto fail;
3291  }
3292 
3293  /* open output files */
3294  ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file);
3295  if (ret < 0) {
3296  av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
3297  goto fail;
3298  }
3299 
3301 
3302 fail:
3303  uninit_parse_context(&octx);
3304  if (ret < 0) {
3305  av_strerror(ret, error, sizeof(error));
3306  av_log(NULL, AV_LOG_FATAL, "%s\n", error);
3307  }
3308  return ret;
3309 }
3310 
3311 static int opt_progress(void *optctx, const char *opt, const char *arg)
3312 {
3313  AVIOContext *avio = NULL;
3314  int ret;
3315 
3316  if (!strcmp(arg, "-"))
3317  arg = "pipe:";
3318  ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
3319  if (ret < 0) {
3320  av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
3321  arg, av_err2str(ret));
3322  return ret;
3323  }
3324  progress_avio = avio;
3325  return 0;
3326 }
3327 
3328 #define OFFSET(x) offsetof(OptionsContext, x)
3329 const OptionDef options[] = {
3330  /* main options */
3332  { "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
3333  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
3334  "force format", "fmt" },
3335  { "y", OPT_BOOL, { &file_overwrite },
3336  "overwrite output files" },
3337  { "n", OPT_BOOL, { &no_file_overwrite },
3338  "never overwrite output files" },
3339  { "ignore_unknown", OPT_BOOL, { &ignore_unknown_streams },
3340  "Ignore unknown stream types" },
3341  { "copy_unknown", OPT_BOOL | OPT_EXPERT, { &copy_unknown_streams },
3342  "Copy unknown stream types" },
3343  { "c", HAS_ARG | OPT_STRING | OPT_SPEC |
3344  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3345  "codec name", "codec" },
3346  { "codec", HAS_ARG | OPT_STRING | OPT_SPEC |
3347  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3348  "codec name", "codec" },
3349  { "pre", HAS_ARG | OPT_STRING | OPT_SPEC |
3350  OPT_OUTPUT, { .off = OFFSET(presets) },
3351  "preset name", "preset" },
3352  { "map", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3353  OPT_OUTPUT, { .func_arg = opt_map },
3354  "set input stream mapping",
3355  "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
3356  { "map_channel", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map_channel },
3357  "map an audio channel from one stream to another", "file.stream.channel[:syncfile.syncstream]" },
3358  { "map_metadata", HAS_ARG | OPT_STRING | OPT_SPEC |
3359  OPT_OUTPUT, { .off = OFFSET(metadata_map) },
3360  "set metadata information of outfile from infile",
3361  "outfile[,metadata]:infile[,metadata]" },
3362  { "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
3363  OPT_OUTPUT, { .off = OFFSET(chapters_input_file) },
3364  "set chapters mapping", "input_file_index" },
3365  { "t", HAS_ARG | OPT_TIME | OPT_OFFSET |
3366  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) },
3367  "record or transcode \"duration\" seconds of audio/video",
3368  "duration" },
3369  { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) },
3370  "record or transcode stop time", "time_stop" },
3371  { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) },
3372  "set the limit file size in bytes", "limit_size" },
3373  { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |
3374  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(start_time) },
3375  "set the start time offset", "time_off" },
3376  { "sseof", HAS_ARG | OPT_TIME | OPT_OFFSET |
3377  OPT_INPUT, { .off = OFFSET(start_time_eof) },
3378  "set the start time offset relative to EOF", "time_off" },
3379  { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
3380  OPT_INPUT, { .off = OFFSET(seek_timestamp) },
3381  "enable/disable seeking by timestamp with -ss" },
3382  { "accurate_seek", OPT_BOOL | OPT_OFFSET | OPT_EXPERT |
3383  OPT_INPUT, { .off = OFFSET(accurate_seek) },
3384  "enable/disable accurate seeking with -ss" },
3385  { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET |
3386  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_ts_offset) },
3387  "set the input ts offset", "time_off" },
3388  { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC |
3389  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(ts_scale) },
3390  "set the input ts scale", "scale" },
3391  { "timestamp", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_recording_timestamp },
3392  "set the recording timestamp ('now' to set the current time)", "time" },
3393  { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(metadata) },
3394  "add metadata", "string=string" },
3395  { "program", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(program) },
3396  "add program with specified streams", "title=string:st=number..." },
3397  { "dframes", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3398  OPT_OUTPUT, { .func_arg = opt_data_frames },
3399  "set the number of data frames to output", "number" },
3400  { "benchmark", OPT_BOOL | OPT_EXPERT, { &do_benchmark },
3401  "add timings for benchmarking" },
3402  { "benchmark_all", OPT_BOOL | OPT_EXPERT, { &do_benchmark_all },
3403  "add timings for each task" },
3404  { "progress", HAS_ARG | OPT_EXPERT, { .func_arg = opt_progress },
3405  "write program-readable progress information", "url" },
3406  { "stdin", OPT_BOOL | OPT_EXPERT, { &stdin_interaction },
3407  "enable or disable interaction on standard input" },
3408  { "timelimit", HAS_ARG | OPT_EXPERT, { .func_arg = opt_timelimit },
3409  "set max runtime in seconds", "limit" },
3410  { "dump", OPT_BOOL | OPT_EXPERT, { &do_pkt_dump },
3411  "dump each input packet" },
3412  { "hex", OPT_BOOL | OPT_EXPERT, { &do_hex_dump },
3413  "when dumping packets, also dump the payload" },
3414  { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3415  OPT_INPUT, { .off = OFFSET(rate_emu) },
3416  "read input at native frame rate", "" },
3417  { "target", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_target },
3418  "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
3419  "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")", "type" },
3420  { "vsync", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vsync },
3421  "video sync method", "" },
3422  { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &frame_drop_threshold },
3423  "frame drop threshold", "" },
3424  { "async", HAS_ARG | OPT_INT | OPT_EXPERT, { &audio_sync_method },
3425  "audio sync method", "" },
3426  { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &audio_drift_threshold },
3427  "audio drift threshold", "threshold" },
3428  { "copyts", OPT_BOOL | OPT_EXPERT, { &copy_ts },
3429  "copy timestamps" },
3430  { "start_at_zero", OPT_BOOL | OPT_EXPERT, { &start_at_zero },
3431  "shift input timestamps to start at 0 when using copyts" },
3432  { "copytb", HAS_ARG | OPT_INT | OPT_EXPERT, { &copy_tb },
3433  "copy input stream time base when stream copying", "mode" },
3434  { "shortest", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3435  OPT_OUTPUT, { .off = OFFSET(shortest) },
3436  "finish encoding within shortest input" },
3437  { "bitexact", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3438  OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(bitexact) },
3439  "bitexact mode" },
3440  { "apad", OPT_STRING | HAS_ARG | OPT_SPEC |
3441  OPT_OUTPUT, { .off = OFFSET(apad) },
3442  "audio pad", "" },
3443  { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_delta_threshold },
3444  "timestamp discontinuity delta threshold", "threshold" },
3445  { "dts_error_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_error_threshold },
3446  "timestamp error delta threshold", "threshold" },
3447  { "xerror", OPT_BOOL | OPT_EXPERT, { &exit_on_error },
3448  "exit on error", "error" },
3449  { "abort_on", HAS_ARG | OPT_EXPERT, { .func_arg = opt_abort_on },
3450  "abort on the specified condition flags", "flags" },
3451  { "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3452  OPT_OUTPUT, { .off = OFFSET(copy_initial_nonkeyframes) },
3453  "copy initial non-keyframes" },
3454  { "copypriorss", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(copy_prior_start) },
3455  "copy or discard frames before start time" },
3456  { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(max_frames) },
3457  "set the number of frames to output", "number" },
3458  { "tag", OPT_STRING | HAS_ARG | OPT_SPEC |
3459  OPT_EXPERT | OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(codec_tags) },
3460  "force codec tag/fourcc", "fourcc/tag" },
3461  { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE |
3462  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(qscale) },
3463  "use fixed quality scale (VBR)", "q" },
3464  { "qscale", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3465  OPT_OUTPUT, { .func_arg = opt_qscale },
3466  "use fixed quality scale (VBR)", "q" },
3467  { "profile", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_profile },
3468  "set profile", "profile" },
3469  { "filter", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filters) },
3470  "set stream filtergraph", "filter_graph" },
3471  { "filter_threads", HAS_ARG | OPT_INT, { &filter_nbthreads },
3472  "number of non-complex filter threads" },
3473  { "filter_script", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filter_scripts) },
3474  "read stream filtergraph description from a file", "filename" },
3475  { "reinit_filter", HAS_ARG | OPT_INT | OPT_SPEC | OPT_INPUT, { .off = OFFSET(reinit_filters) },
3476  "reinit filtergraph on input parameter changes", "" },
3477  { "filter_complex", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3478  "create a complex filtergraph", "graph_description" },
3479  { "filter_complex_threads", HAS_ARG | OPT_INT, { &filter_complex_nbthreads },
3480  "number of threads for -filter_complex" },
3481  { "lavfi", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3482  "create a complex filtergraph", "graph_description" },
3483  { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script },
3484  "read complex filtergraph description from a file", "filename" },
3485  { "stats", OPT_BOOL, { &print_stats },
3486  "print progress report during encoding", },
3487  { "attach", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3488  OPT_OUTPUT, { .func_arg = opt_attach },
3489  "add an attachment to the output file", "filename" },
3490  { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC |
3491  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(dump_attachment) },
3492  "extract an attachment into a file", "filename" },
3493  { "stream_loop", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_INPUT |
3494  OPT_OFFSET, { .off = OFFSET(loop) }, "set number of times input stream shall be looped", "loop count" },
3495  { "debug_ts", OPT_BOOL | OPT_EXPERT, { &debug_ts },
3496  "print timestamp debugging info" },
3497  { "max_error_rate", HAS_ARG | OPT_FLOAT, { &max_error_rate },
3498  "ratio of errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.", "maximum error rate" },
3499  { "discard", OPT_STRING | HAS_ARG | OPT_SPEC |
3500  OPT_INPUT, { .off = OFFSET(discard) },
3501  "discard", "" },
3502  { "disposition", OPT_STRING | HAS_ARG | OPT_SPEC |
3503  OPT_OUTPUT, { .off = OFFSET(disposition) },
3504  "disposition", "" },
3505  { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
3506  { .off = OFFSET(thread_queue_size) },
3507  "set the maximum number of queued packets from the demuxer" },
3508  { "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3509  "read and decode the streams to fill missing information with heuristics" },
3510 
3511  /* video options */
3512  { "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },
3513  "set the number of video frames to output", "number" },
3514  { "r", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3515  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_rates) },
3516  "set frame rate (Hz value, fraction or abbreviation)", "rate" },
3518  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_sizes) },
3519  "set frame size (WxH or abbreviation)", "size" },
3520  { "aspect", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3521  OPT_OUTPUT, { .off = OFFSET(frame_aspect_ratios) },
3522  "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
3523  { "pix_fmt", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3524  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_pix_fmts) },
3525  "set pixel format", "format" },
3526  { "bits_per_raw_sample", OPT_VIDEO | OPT_INT | HAS_ARG, { &frame_bits_per_raw_sample },
3527  "set the number of bits per raw sample", "number" },
3528  { "intra", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &intra_only },
3529  "deprecated use -g 1" },
3531  "disable video" },
3532  { "rc_override", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3533  OPT_OUTPUT, { .off = OFFSET(rc_overrides) },
3534  "rate control override for specific intervals", "override" },
3535  { "vcodec", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_INPUT |
3536  OPT_OUTPUT, { .func_arg = opt_video_codec },
3537  "force video codec ('copy' to copy stream)", "codec" },
3538  { "sameq", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_sameq },
3539  "Removed" },
3540  { "same_quant", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_sameq },
3541  "Removed" },
3542  { "timecode", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_timecode },
3543  "set initial TimeCode value.", "hh:mm:ss[:;.]ff" },
3544  { "pass", OPT_VIDEO | HAS_ARG | OPT_SPEC | OPT_INT | OPT_OUTPUT, { .off = OFFSET(pass) },
3545  "select the pass number (1 to 3)", "n" },
3546  { "passlogfile", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC |
3547  OPT_OUTPUT, { .off = OFFSET(passlogfiles) },
3548  "select two pass log file name prefix", "prefix" },
3549  { "deinterlace", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_deinterlace },
3550  "this option is deprecated, use the yadif filter instead" },
3551  { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr },
3552  "calculate PSNR of compressed frames" },
3553  { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats },
3554  "dump video coding statistics to file" },
3555  { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file },
3556  "dump video coding statistics to file", "file" },
3557  { "vstats_version", OPT_VIDEO | OPT_INT | HAS_ARG | OPT_EXPERT , { &vstats_version },
3558  "Version of the vstats format to use."},
3559  { "vf", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_filters },
3560  "set video filters", "filter_graph" },
3561  { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3562  OPT_OUTPUT, { .off = OFFSET(intra_matrices) },
3563  "specify intra matrix coeffs", "matrix" },
3564  { "inter_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3565  OPT_OUTPUT, { .off = OFFSET(inter_matrices) },
3566  "specify inter matrix coeffs", "matrix" },
3567  { "chroma_intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3568  OPT_OUTPUT, { .off = OFFSET(chroma_intra_matrices) },
3569  "specify intra matrix coeffs", "matrix" },
3570  { "top", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_INT| OPT_SPEC |
3571  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(top_field_first) },
3572  "top=1/bottom=0/auto=-1 field first", "" },
3573  { "vtag", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3574  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_old2new },
3575  "force video tag/fourcc", "fourcc/tag" },
3576  { "qphist", OPT_VIDEO | OPT_BOOL | OPT_EXPERT , { &qp_hist },
3577  "show QP histogram" },
3578  { "force_fps", OPT_VIDEO | OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3579  OPT_OUTPUT, { .off = OFFSET(force_fps) },
3580  "force the selected framerate, disable the best supported framerate selection" },
3581  { "streamid", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3582  OPT_OUTPUT, { .func_arg = opt_streamid },
3583  "set the value of an outfile streamid", "streamIndex:value" },
3584  { "force_key_frames", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3585  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(forced_key_frames) },
3586  "force key frames at specified timestamps", "timestamps" },
3587  { "ab", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3588  "audio bitrate (please use -b:a)", "bitrate" },
3589  { "b", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3590  "video bitrate (please use -b:v)", "bitrate" },
3591  { "hwaccel", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3592  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccels) },
3593  "use HW accelerated decoding", "hwaccel name" },
3594  { "hwaccel_device", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3595  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_devices) },
3596  "select a device for HW acceleration", "devicename" },
3597  { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3598  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) },
3599  "select output format used with HW accelerated decoding", "format" },
3600 #if CONFIG_VIDEOTOOLBOX
3601  { "videotoolbox_pixfmt", HAS_ARG | OPT_STRING | OPT_EXPERT, { &videotoolbox_pixfmt}, "" },
3602 #endif
3603  { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels },
3604  "show available HW acceleration methods" },
3605  { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC |
3606  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) },
3607  "automatically insert correct rotate filters" },
3608 
3609  /* audio options */
3610  { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },
3611  "set the number of audio frames to output", "number" },
3612  { "aq", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_qscale },
3613  "set audio quality (codec-specific)", "quality", },
3614  { "ar", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3615  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_sample_rate) },
3616  "set audio sampling rate (in Hz)", "rate" },
3617  { "ac", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3618  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_channels) },
3619  "set number of audio channels", "channels" },
3621  "disable audio" },
3622  { "acodec", OPT_AUDIO | HAS_ARG | OPT_PERFILE |
3623  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_audio_codec },
3624  "force audio codec ('copy' to copy stream)", "codec" },
3625  { "atag", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3626  OPT_OUTPUT, { .func_arg = opt_old2new },
3627  "force audio tag/fourcc", "fourcc/tag" },
3628  { "vol", OPT_AUDIO | HAS_ARG | OPT_INT, { &audio_volume },
3629  "change audio volume (256=normal)" , "volume" },
3630  { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3632  "set sample format", "format" },
3633  { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3634  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_channel_layout },
3635  "set channel layout", "layout" },
3636  { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters },
3637  "set audio filters", "filter_graph" },
3638  { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) },
3639  "set the maximum number of channels to try to guess the channel layout" },
3640 
3641  /* subtitle options */
3643  "disable subtitle" },
3644  { "scodec", OPT_SUBTITLE | HAS_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_subtitle_codec },
3645  "force subtitle codec ('copy' to copy stream)", "codec" },
3646  { "stag", OPT_SUBTITLE | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new }
3647  , "force subtitle tag/fourcc", "fourcc/tag" },
3648  { "fix_sub_duration", OPT_BOOL | OPT_EXPERT | OPT_SUBTITLE | OPT_SPEC | OPT_INPUT, { .off = OFFSET(fix_sub_duration) },
3649  "fix subtitles duration" },
3650  { "canvas_size", OPT_SUBTITLE | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_INPUT, { .off = OFFSET(canvas_sizes) },
3651  "set canvas size (WxH or abbreviation)", "size" },
3652 
3653  /* grab options */
3654  { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_video_channel },
3655  "deprecated, use -channel", "channel" },
3656  { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_video_standard },
3657  "deprecated, use -standard", "standard" },
3658  { "isync", OPT_BOOL | OPT_EXPERT, { &input_sync }, "this option is deprecated and does nothing", "" },
3659 
3660  /* muxer options */
3661  { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_max_delay) },
3662  "set the maximum demux-decode delay", "seconds" },
3663  { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_preload) },
3664  "set the initial demux-decode delay", "seconds" },
3665  { "sdp_file", HAS_ARG | OPT_EXPERT | OPT_OUTPUT, { .func_arg = opt_sdp_file },
3666  "specify a file in which to print sdp information", "file" },
3667 
3668  { "time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(time_bases) },
3669  "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)", "ratio" },
3670  { "enc_time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(enc_time_bases) },
3671  "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
3672  "two special values are defined - "
3673  "0 = use frame rate (video) or sample rate (audio),"
3674  "-1 = match source time base", "ratio" },
3675 
3677  "A comma-separated list of bitstream filters", "bitstream_filters" },
3678  { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3679  "deprecated", "audio bitstream_filters" },
3680  { "vbsf", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3681  "deprecated", "video bitstream_filters" },
3682 
3683  { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3684  "set the audio options to the indicated preset", "preset" },
3685  { "vpre", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3686  "set the video options to the indicated preset", "preset" },
3687  { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3688  "set the subtitle options to the indicated preset", "preset" },
3689  { "fpre", HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3690  "set options from indicated preset file", "filename" },
3691 
3692  { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) },
3693  "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" },
3694 
3695  /* data codec support */
3696  { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec },
3697  "force data codec ('copy' to copy stream)", "codec" },
3698  { "dn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(data_disable) },
3699  "disable data" },
3700 
3701 #if CONFIG_VAAPI
3702  { "vaapi_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vaapi_device },
3703  "set VAAPI hardware device (DRM path or X11 display name)", "device" },
3704 #endif
3705 
3706 #if CONFIG_QSV
3707  { "qsv_device", HAS_ARG | OPT_STRING | OPT_EXPERT, { &qsv_device },
3708  "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
3709 #endif
3710 
3711  { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
3712  "initialise hardware device", "args" },
3713  { "filter_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_hw_device },
3714  "set hardware device used when filtering", "device" },
3715 
3716  { NULL, },
3717 };
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1580
int nb_bitstream_filters
Definition: ffmpeg.h:462
const char * name
Definition: avisynth_c.h:775
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
Definition: error.h:54
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1153
int parse_optgroup(void *optctx, OptionGroup *g)
Parse an options group and write results into optctx.
Definition: cmdutils.c:414
AVRational enc_timebase
Definition: ffmpeg.h:460
char * vstats_filename
Definition: ffmpeg_opt.c:84
int av_parse_ratio(AVRational *q, const char *str, int max, int log_offset, void *log_ctx)
Parse str and store the parsed ratio in q.
Definition: parseutils.c:45
int nb_dump_attachment
Definition: ffmpeg.h:127
int guess_input_channel_layout(InputStream *ist)
Definition: ffmpeg.c:2086
void show_usage(void)
Definition: ffmpeg_opt.c:3202
int nb_metadata
Definition: ffmpeg.h:168
int nb_streamid_map
Definition: ffmpeg.h:165
#define NULL
Definition: coverity.c:32
int width
Definition: ffmpeg.h:270
AVRational framerate
Definition: avcodec.h:3056
const char const char void * val
Definition: avisynth_c.h:771
int audio_sync_method
Definition: ffmpeg_opt.c:92
AVDictionary * resample_opts
Definition: cmdutils.h:320
int keep_pix_fmt
Definition: ffmpeg.h:528
Bytestream IO Context.
Definition: avio.h:161
float mux_preload
Definition: ffmpeg.h:153
static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:500
const AVClass * priv_class
A class for the private data, used to declare bitstream filter private AVOptions. ...
Definition: avcodec.h:5771
#define OPT_EXPERT
Definition: cmdutils.h:163
int start_at_zero
Definition: ffmpeg_opt.c:101
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:558
void term_init(void)
Definition: ffmpeg.c:387
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:336
int nb_outputs
Definition: ffmpeg.h:292
int copy_tb
Definition: ffmpeg_opt.c:102
static const char * format[]
Definition: af_aiir.c:330
char * qsv_device
Definition: ffmpeg_qsv.c:31
AVDictionary * swr_opts
Definition: ffmpeg.h:509
int qp_hist
Definition: ffmpeg_opt.c:107
AVDictionary * swr_opts
Definition: cmdutils.h:322
#define av_realloc_f(p, o, n)
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:179
void term_exit(void)
Definition: ffmpeg.c:328
int stream_copy
Definition: ffmpeg.h:514
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: allcodecs.c:875
static int opt_data_frames(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2895
int do_benchmark
Definition: ffmpeg_opt.c:96
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1629
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1419
AVOption.
Definition: opt.h:246
AVRational frame_rate
Definition: ffmpeg.h:477
int audio_channels
Definition: rtp.c:40
int64_t start_time_eof
Definition: ffmpeg.h:100
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:148
static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, AVFormatContext *oc)
Definition: ffmpeg_opt.c:2030
char * filters
filtergraph associated to the -filter option
Definition: ffmpeg.h:504
static AVInputFormat * file_iformat
Definition: ffplay.c:310
#define OPT_VIDEO
Definition: cmdutils.h:165
int data_disable
Definition: ffmpeg.h:161
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1721
float mux_max_delay
Definition: ffmpeg.h:154
int accurate_seek
Definition: ffmpeg.h:413
int64_t forced_kf_ref_pts
Definition: ffmpeg.h:487
int * streamid_map
Definition: ffmpeg.h:164
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int video_sync_method
Definition: ffmpeg_opt.c:93
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
Main libavfilter public API header.
int nb_stream_maps
Definition: ffmpeg.h:139
static void assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:902
int ostream_idx
Definition: ffmpeg.h:92
#define AV_DICT_DONT_OVERWRITE
Don&#39;t overwrite existing entries.
Definition: dict.h:79
static int input_sync
Definition: ffmpeg_opt.c:120
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
Definition: hwcontext.c:78
const char * g
Definition: vf_curves.c:115
const char * desc
Definition: nvenc.c:65
hardware decoding through Videotoolbox
Definition: pixfmt.h:282
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
Split the commandline into an intermediate form convenient for further processing.
Definition: cmdutils.c:753
AVRational framerate
Definition: ffmpeg.h:333
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:203
enum AVCodecID video_codec
default video codec
Definition: avformat.h:518
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:2071
channels
Definition: aptx.c:30
#define OPT_AUDIO
Definition: cmdutils.h:166
int64_t max_pts
Definition: ffmpeg.h:322
FILE * av_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
Definition: file_open.c:158
AVFilterInOut * out_tmp
Definition: ffmpeg.h:266
int bitexact
Definition: ffmpeg.h:156
int decoding_needed
Definition: ffmpeg.h:300
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3900
int qscale
Definition: avcodec.h:825
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:936
int num
Numerator.
Definition: rational.h:59
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:278
int rotate_overridden
Definition: ffmpeg.h:481
int index
stream index in AVFormatContext
Definition: avformat.h:875
int max_muxing_queue_size
Definition: ffmpeg.h:542
int nb_frame_pix_fmts
Definition: ffmpeg.h:115
#define AVIO_FLAG_READ
read-only
Definition: avio.h:654
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
int do_deinterlace
Definition: ffmpeg_opt.c:95
static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3027
static OutputStream * new_unknown_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:1916
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:655
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1912
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: avcodec.h:772
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1743
Convenience header that includes libavutil&#39;s core.
const char * arg
Definition: cmdutils.h:313
static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3098
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
int cuvid_init(AVCodecContext *s)
Definition: ffmpeg_cuvid.c:30
#define OPT_DATA
Definition: cmdutils.h:172
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:2556
static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
Definition: ffmpeg_opt.c:1987
enum AVMediaType type
Definition: avcodec.h:3437
int nb_program
Definition: ffmpeg.h:228
const char * key
static int file_overwrite
Definition: ffmpeg_opt.c:117
static OutputStream * new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
Definition: ffmpeg_opt.c:1331
discard all
Definition: avcodec.h:803
static int find_stream_info
Definition: ffmpeg_opt.c:124
int64_t input_ts_offset
Definition: ffmpeg.h:402
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
Definition: options.c:95
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2757
int nb_input_streams
Definition: ffmpeg.c:148
static int audio_disable
Definition: ffplay.c:319
const char * name
Definition: ffmpeg.h:68
AVDictionary * metadata
Definition: avformat.h:1312
static const char * audio_codec_name
Definition: ffplay.c:343
static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
Definition: ffmpeg_opt.c:1296
void * priv_data
Opaque filter-specific private data.
Definition: avcodec.h:5724
#define OPT_DOUBLE
Definition: cmdutils.h:180
enum AVCodecID subtitle_codec_id
Forced subtitle codec_id.
Definition: avformat.h:1549
#define OPT_FLOAT
Definition: cmdutils.h:168
AVCodec.
Definition: avcodec.h:3424
#define VSYNC_VFR
Definition: ffmpeg.h:52
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1390
#define CMDUTILS_COMMON_OPTIONS
Definition: cmdutils.h:215
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Filter out options for given codec.
Definition: cmdutils.c:2079
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3892
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:559
int index
Definition: ffmpeg.h:283
static int opt_preset(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2921
AVBSFContext ** bsf_ctx
Definition: ffmpeg.h:463
Definition: ftp.c:34
SpecifierOpt * frame_pix_fmts
Definition: ffmpeg.h:114
static int opt_data_codec(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:262
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
Definition: ffmpeg_opt.c:47
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:727
int encoding_needed
Definition: ffmpeg.h:447
static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3092
Format I/O context.
Definition: avformat.h:1351
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:294
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url...
Definition: avio.c:483
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx)
Allocate a context for a given bitstream filter.
Definition: bsf.c:82
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
Definition: opt.c:1506
enum HWAccelID id
Definition: ffmpeg.h:70
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
static const uint8_t frame_sizes[]
Definition: rtpdec_qcelp.c:24
static int do_psnr
Definition: ffmpeg_opt.c:119
const char * name
Definition: opt.h:247
char * logfile_prefix
Definition: ffmpeg.h:499
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1485
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhd.c:153
int user_set_discard
Definition: ffmpeg.h:299
static int ignore_unknown_streams
Definition: ffmpeg_opt.c:122
static int64_t start_time
Definition: ffplay.c:330
int copy_initial_nonkeyframes
Definition: ffmpeg.h:524
int filter_nbthreads
Definition: ffmpeg_opt.c:111
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2197
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, AVFMT_TS_NONSTRICT, AVFMT_TS_NEGATIVE
Definition: avformat.h:526
uint8_t
static int nb_streams
Definition: ffprobe.c:276
#define av_malloc(s)
AVDictionary * sws_dict
Definition: ffmpeg.h:508
Opaque data information usually continuous.
Definition: avutil.h:203
int opt_default(void *optctx, const char *opt, const char *arg)
Fallback for options that are not explicitly handled, these will be parsed through AVOptions...
Definition: cmdutils.c:545
#define OPT_OUTPUT
Definition: cmdutils.h:182
int width
Video only.
Definition: avcodec.h:3966
AVOptions.
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
Definition: avformat.h:661
#define HAS_ARG
Definition: cmdutils.h:161
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: utils.c:2065
static int open_input_file(OptionsContext *o, const char *filename)
Definition: ffmpeg_opt.c:977
static const OptionGroupDef groups[]
Definition: ffmpeg_opt.c:3214
FILE * logfile
Definition: ffmpeg.h:500
static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:457
#define f(width, name)
Definition: cbs_vp9.c:255
AVDictionary * opts
Definition: ffmpeg.h:556
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
uint16_t * chroma_intra_matrix
custom intra quantization matrix
Definition: avcodec.h:3155
int id
unique ID to identify the chapter
Definition: avformat.h:1309
static int opt_vsync(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3033
#define AVCONV_DATADIR
Definition: config.h:8
int id
Format-specific stream ID.
Definition: avformat.h:881
#define OPT_OFFSET
Definition: cmdutils.h:175
int vstats_version
Definition: ffmpeg_opt.c:113
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4469
int nb_max_frames
Definition: ffmpeg.h:170
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:253
int shortest
Definition: ffmpeg.h:562
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1419
static int opt_vstats(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2867
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: utils.c:2161
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:144
int channel_idx
Definition: ffmpeg.h:91
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:63
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:672
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
int nb_streams
Definition: ffmpeg.h:409
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1482
int sync_file_index
Definition: ffmpeg.h:85
AVProgram * av_new_program(AVFormatContext *s, int id)
Definition: utils.c:4568
AVDictionary * resample_opts
Definition: ffmpeg.h:510
int seek_timestamp
Definition: ffmpeg.h:101
uint32_t tag
Definition: movenc.c:1478
int * formats
Definition: ffmpeg.h:277
#define OPT_SPEC
Definition: cmdutils.h:176
int nb_input_files
Definition: ffmpeg.c:150
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:2765
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:168
int init_complex_filtergraph(FilterGraph *fg)
int print_stats
Definition: ffmpeg_opt.c:106
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Print help for all options matching specified flags.
Definition: cmdutils.c:177
AVCodec * dec
Definition: ffmpeg.h:305
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:218
const OptionDef options[]
Definition: ffmpeg_opt.c:3329
int top_field_first
Definition: ffmpeg.h:334
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1499
int nb_output_streams
Definition: ffmpeg.c:153
int file_index
Definition: ffmpeg.h:296
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array.
Definition: mem.c:198
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1537
int64_t filter_in_rescale_delta_last
Definition: ffmpeg.h:319
#define av_log(a,...)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:276
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:647
static int opt_video_codec(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:250
float quality_factor
Definition: avcodec.h:826
static int opt_qscale(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2994
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1370
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:2136
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: allcodecs.c:903
AVDictionary * format_opts
Definition: cmdutils.c:73
static OutputStream * new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:1937
int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:148
#define OPT_SUBTITLE
Definition: cmdutils.h:169
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
Definition: dump.c:563
uint64_t channel_layout
Definition: ffmpeg.h:274
int filter_complex_nbthreads
Definition: ffmpeg_opt.c:112
enum AVCodecID id
Definition: avcodec.h:3438
int rate_emu
Definition: ffmpeg.h:412
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:258
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
static int opt_profile(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3009
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:69
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1591
void check_filter_outputs(void)
enum AVPixelFormat hwaccel_pix_fmt
Definition: ffmpeg.h:374
FilterGraph ** filtergraphs
Definition: ffmpeg.c:157
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:481
static int open_files(OptionGroupList *l, const char *inout, int(*open_file)(OptionsContext *, const char *))
Definition: ffmpeg_opt.c:3219
static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:256
#define AV_OPT_FLAG_FILTERING_PARAM
a generic parameter which can be set by the user for filtering
Definition: opt.h:291
int64_t start_time
Definition: ffmpeg.h:99
static int opt_video_channel(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:232
int loop
Definition: ffmpeg.h:398
#define AVERROR(e)
Definition: error.h:43
int64_t last_mux_dts
Definition: ffmpeg.h:457
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:638
int ofile_idx
Definition: ffmpeg.h:92
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1189
char * url
input or output URL.
Definition: avformat.h:1447
int video_delay
Video only.
Definition: avcodec.h:3995
static int autorotate
Definition: ffplay.c:354
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
unsigned int nb_programs
Definition: avformat.h:1530
AudioChannelMap * audio_channel_maps
Definition: ffmpeg.h:140
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
int debug_ts
Definition: ffmpeg_opt.c:103
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3896
const char * arg
Definition: jacosubdec.c:66
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1613
const char * name
Definition: cmdutils.h:159
static int opt_bitrate(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2978
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Parse one given option.
Definition: cmdutils.c:350
AVChapter ** chapters
Definition: avformat.h:1581
Definition: graph2dot.c:48
static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
Parse a metadata specifier passed as &#39;arg&#39; parameter.
Definition: ffmpeg_opt.c:521
simple assert() macros that are a bit more flexible than ISO C assert().
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:45
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
const char * name
Name of the codec implementation.
Definition: avcodec.h:3431
static int opt_old2new(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2969
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: ffmpeg.c:637
int video_disable
Definition: ffmpeg.h:158
static int opt_sameq(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:223
int flags
Definition: cmdutils.h:160
static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
Definition: ffmpeg_opt.c:548
int force_fps
Definition: ffmpeg.h:479
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:947
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1268
#define FFMAX(a, b)
Definition: common.h:94
static void uninit_options(OptionsContext *o)
Definition: ffmpeg_opt.c:126
StreamMap * stream_maps
Definition: ffmpeg.h:138
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:83
#define fail()
Definition: checkasm.h:117
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:149
uint64_t limit_filesize
Definition: ffmpeg.h:152
AVCodec * audio_codec
Forced audio codec.
Definition: avformat.h:1828
const char * format
Definition: ffmpeg.h:102
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3199
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3918
#define pass
Definition: fft_template.c:595
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:638
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
Definition: mem.c:205
OutputFilter * filter
Definition: ffmpeg.h:502
int avformat_query_codec(const AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance)
Test if the given container can store a codec.
Definition: utils.c:4992
int ffmpeg_parse_options(int argc, char **argv)
Definition: ffmpeg_opt.c:3253
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: avcodec.h:724
AVRational frame_aspect_ratio
Definition: ffmpeg.h:484
static AVDictionary * strip_specifiers(AVDictionary *dict)
Definition: ffmpeg_opt.c:188
static int opt_abort_on(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:205
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1608
static const char * subtitle_codec_name
Definition: ffplay.c:344
static int subtitle_disable
Definition: ffplay.c:321
int file_index
Definition: ffmpeg.h:83
int nb_audio_channel_maps
Definition: ffmpeg.h:141
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1407
int nb_attachments
Definition: ffmpeg.h:146
AVDictionary * opts
Definition: movenc.c:50
OptionGroup * groups
Definition: cmdutils.h:332
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:118
static int opt_video_filters(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3021
int nb_output_files
Definition: ffmpeg.c:155
int rc_override_count
ratecontrol override, see RcOverride
Definition: avcodec.h:2399
size_t off
Definition: cmdutils.h:186
char * linklabel
Definition: ffmpeg.h:87
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:238
const AVClass * av_bsf_get_class(void)
Get the AVClass for AVBSFContext.
Definition: bsf.c:77
audio channel layout utility functions
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:895
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:842
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx)
#define FFMIN(a, b)
Definition: common.h:96
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition: avformat.h:1543
SpecifierOpt * audio_channels
Definition: ffmpeg.h:106
uint64_t * channel_layouts
Definition: ffmpeg.h:278
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:213
static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
Definition: ffmpeg_opt.c:697
#define VSYNC_AUTO
Definition: ffmpeg.h:49
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1471
int nb_audio_sample_rate
Definition: ffmpeg.h:109
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:156
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:556
static int opt_progress(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3311
int exit_on_error
Definition: ffmpeg_opt.c:104
int metadata_chapters_manual
Definition: ffmpeg.h:144
enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, const char *filename, const char *mime_type, enum AVMediaType type)
Guess the codec ID based upon muxer and filename.
Definition: format.c:87
struct OutputStream * ost
Definition: ffmpeg.h:261
int accurate_seek
Definition: ffmpeg.h:121
int width
picture width / height.
Definition: avcodec.h:1706
static int open_output_file(OptionsContext *o, const char *filename)
Definition: ffmpeg_opt.c:2084
char * apad
Definition: ffmpeg.h:511
int64_t nb_samples
Definition: ffmpeg.h:328
SpecifierOpt * audio_sample_rate
Definition: ffmpeg.h:108
char * sdp_filename
Definition: ffmpeg_opt.c:85
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:468
int64_t duration
Definition: ffmpeg.h:399
const char * name
Definition: avformat.h:507
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
Definition: avcodec.h:874
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:858
SpecifierOpt * dump_attachment
Definition: ffmpeg.h:126
A list of option groups that all have the same group type (e.g.
Definition: cmdutils.h:329
int copy_ts
Definition: ffmpeg_opt.c:100
#define OPT_EXIT
Definition: cmdutils.h:171
static AVCodec * find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
Definition: ffmpeg_opt.c:653
int nb_filtergraphs
Definition: ffmpeg.c:158
int qsv_init(AVCodecContext *s)
Definition: ffmpeg_qsv.c:71
int start_frame
Definition: avcodec.h:823
float frame_drop_threshold
Definition: ffmpeg_opt.c:94
SpecifierOpt * metadata_map
Definition: ffmpeg.h:195
#define s(width, name)
Definition: cbs_vp9.c:257
static int open_file(AVFormatContext *avf, unsigned fileno)
Definition: concatdec.c:317
#define AV_OPT_FLAG_BSF_PARAM
a generic parameter which can be set by the user for bit stream filtering
Definition: opt.h:290
#define OPT_INT64
Definition: cmdutils.h:170
#define AV_DICT_APPEND
If the entry already exists, append to it.
Definition: dict.h:80
int64_t max_frames
Definition: ffmpeg.h:468
#define AV_RL32
Definition: intreadwrite.h:146
char * specifier
stream/chapter/program/...
Definition: cmdutils.h:147
int audio_channels_mapped
Definition: ffmpeg.h:497
int n
Definition: avisynth_c.h:684
AVDictionary * metadata
Definition: avformat.h:938
enum AVCodecID codec_id
Definition: vaapi_decode.c:364
int height
Definition: ffmpeg.h:270
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
Opaque data information usually sparse.
Definition: avutil.h:205
static void init_options(OptionsContext *o)
Definition: ffmpeg_opt.c:158
const AVClass * swr_get_class(void)
Get the AVClass for SwrContext.
Definition: options.c:144
int opt_timelimit(void *optctx, const char *opt, const char *arg)
Limit the execution time.
Definition: cmdutils.c:1068
SpecifierOpt * frame_sizes
Definition: ffmpeg.h:112
int stream_idx
Definition: ffmpeg.h:91
#define is(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:269
if(ret< 0)
Definition: vf_mcdeint.c:279
int sample_rate
Definition: ffmpeg.h:273
HW acceleration through CUDA.
Definition: pixfmt.h:235
static void error(const char *err)
const AVCodecDescriptor * avcodec_descriptor_get_by_name(const char *name)
Definition: codec_desc.c:3214
int do_hex_dump
Definition: ffmpeg_opt.c:98
HWDevice * filter_hw_device
Definition: ffmpeg_opt.c:82
RcOverride * rc_override
Definition: avcodec.h:2400
#define FF_ARRAY_ELEMS(a)
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition: avformat.h:842
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:1185
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:136
AVCodecContext * enc
Definition: muxing.c:55
HWDevice * hw_device_get_by_name(const char *name)
Definition: ffmpeg_hw.c:42
int do_pkt_dump
Definition: ffmpeg_opt.c:99
uint8_t * str
Definition: cmdutils.h:149
Stream structure.
Definition: avformat.h:874
const AVClass * avfilter_get_class(void)
Definition: avfilter.c:1635
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1003
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:106
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:1311
int fix_sub_duration
Definition: ffmpeg.h:339
#define VSYNC_DROP
Definition: ffmpeg.h:54
int64_t recording_time
Definition: ffmpeg.h:408
int do_benchmark_all
Definition: ffmpeg_opt.c:97
Definition: ffmpeg.h:67
SpecifierOpt * frame_rates
Definition: ffmpeg.h:110
AVStream * st
Definition: ffmpeg.h:297
union SpecifierOpt::@22 u
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
int frame_size
Definition: mxfenc.c:2091
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:365
int file_idx
Definition: ffmpeg.h:91
int abort_on_flags
Definition: ffmpeg_opt.c:105
int ost_index
Definition: ffmpeg.h:557
struct InputStream * sync_ist
Definition: ffmpeg.h:451
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
Libavcodec external API header.
enum AVMediaType codec_type
Definition: avcodec.h:1541
double ts_scale
Definition: ffmpeg.h:330
int64_t recording_time
Definition: ffmpeg.h:150
int chapters_input_file
Definition: ffmpeg.h:148
int64_t stop_time
Definition: ffmpeg.h:151
static int intra_only
Definition: ffmpeg_opt.c:116
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
int stdin_interaction
Definition: ffmpeg_opt.c:108
int sample_rate
samples per second
Definition: avcodec.h:2189
AVIOContext * pb
I/O context.
Definition: avformat.h:1393
AVFifoBuffer * muxing_queue
Definition: ffmpeg.h:545
#define SET_DICT(type, meta, context, index)
int ist_index
Definition: ffmpeg.h:397
static int loop
Definition: ffplay.c:339
const char * graph_desc
Definition: ffmpeg.h:284
int guess_layout_max
Definition: ffmpeg.h:335
int64_t start_time
Definition: ffmpeg.h:406
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:196
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:279
main external API structure.
Definition: avcodec.h:1533
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:880
int rate_emu
Definition: ffmpeg.h:120
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition: utils.c:330
int * sample_rates
Definition: ffmpeg.h:279
int metadata_streams_manual
Definition: ffmpeg.h:143
const char * attachment_filename
Definition: ffmpeg.h:523
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Definition: avcodec.h:1558
a very simple circular buffer FIFO implementation
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect->pict fiel...
Definition: avcodec.h:767
AVRational time_base
Definition: ffmpeg.h:401
void assert_avoptions(AVDictionary *m)
Definition: ffmpeg.c:646
AVCodecContext * enc_ctx
Definition: ffmpeg.h:465
int audio_disable
Definition: ffmpeg.h:159
void * buf
Definition: avisynth_c.h:690
int64_t input_ts_offset
Definition: ffmpeg.h:118
float audio_drift_threshold
Definition: ffmpeg_opt.c:87
void show_help_default(const char *opt, const char *arg)
Per-fftool specific help handler.
Definition: ffmpeg_opt.c:3130
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
uint16_t * intra_matrix
custom intra quantization matrix
Definition: avcodec.h:2031
static int opt_map_channel(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:381
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
Get a file corresponding to a preset file.
Definition: cmdutils.c:2021
double value
Definition: eval.c:98
int * audio_channels_map
Definition: ffmpeg.h:496
int coded_height
Definition: avcodec.h:1721
#define VSYNC_PASSTHROUGH
Definition: ffmpeg.h:50
Describe the class of an AVClass context structure.
Definition: log.h:67
#define NTSC
Definition: bktr.c:67
OutputStream ** output_streams
Definition: ffmpeg.c:152
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:88
int index
Definition: gxfenc.c:89
static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3113
static char * get_ost_filters(OptionsContext *o, AVFormatContext *oc, OutputStream *ost)
Definition: ffmpeg_opt.c:1598
enum AVCodecID subtitle_codec
default subtitle codec
Definition: avformat.h:519
option
Definition: libkvazaar.c:282
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int file_index
Definition: ffmpeg.h:443
int metadata_global_manual
Definition: ffmpeg.h:142
#define ABORT_ON_FLAG_EMPTY_OUTPUT
Definition: ffmpeg.h:433
double rotate_override_value
Definition: ffmpeg.h:482
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: utils.c:2104
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Parse a string specifying a time and return its corresponding value as a number of microseconds...
Definition: cmdutils.c:165
void * grow_array(void *array, int elem_size, int *size, int new_size)
Realloc array to hold new_size elements of elem_size.
Definition: cmdutils.c:2156
AVCodecContext * dec_ctx
Definition: ffmpeg.h:304
#define OPT_STRING
Definition: cmdutils.h:164
char * disposition
Definition: ffmpeg.h:526
cl_device_type type
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
Definition: samplefmt.c:56
AVMediaType
Definition: avutil.h:199
static OutputStream * new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:1830
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1177
#define AVFMT_SEEK_TO_PTS
Seeking is based on PTS.
Definition: avformat.h:500
AVDictionary * decoder_opts
Definition: ffmpeg.h:332
const VDPAUPixFmtMap * map
int shortest
Definition: ffmpeg.h:155
#define MAX_STREAMS
Definition: ffmpeg.h:56
int autorotate
Definition: ffmpeg.h:337
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:716
#define snprintf
Definition: snprintf.h:34
int av_opt_eval_int(void *obj, const AVOption *o, const char *val, int *int_out)
int64_t ts_offset
Definition: ffmpeg.h:404
char * filters_script
filtergraph script associated to the -filter_script option
Definition: ffmpeg.h:505
int audio_volume
Definition: ffmpeg_opt.c:91
misc parsing utilities
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
Definition: avstring.c:93
uint16_t * inter_matrix
custom inter quantization matrix
Definition: avcodec.h:2038
static int opt_channel_layout(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3056
int end_frame
Definition: avcodec.h:824
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition: utils.c:2540
static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:244
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:708
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Parse a string and return its corresponding value as a double.
Definition: cmdutils.c:144
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:367
static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2860
char * name
unique name for this input/output in the list
Definition: avfilter.h:1005
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
Definition: avio.c:476
int nb_audio_channels
Definition: ffmpeg.h:107
#define OPT_TIME
Definition: cmdutils.h:179
int source_index
Definition: ffmpeg.h:445
static int init_complex_filters(void)
Definition: ffmpeg_opt.c:2072
AVDictionary * metadata
Definition: avformat.h:1274
int copy_prior_start
Definition: ffmpeg.h:525
SpecifierOpt * metadata
Definition: ffmpeg.h:167
static AVCodec * choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
Definition: ffmpeg_opt.c:682
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1599
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:76
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: allcodecs.c:908
#define flags(name, subs,...)
Definition: cbs_av1.c:610
static OutputStream * new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:1632
static int opt_attach(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:373
static void parse_matrix_coeffs(uint16_t *dest, const char *str)
Definition: ffmpeg_opt.c:1552
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
Definition: avformat.h:1456
static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:485
AVBufferRef * hw_device_ctx
Definition: ffmpeg_opt.c:81
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:891
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:105
#define OFFSET(x)
Definition: ffmpeg_opt.c:3328
static int opt_video_frames(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2883
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
Definition: avstring.c:184
int64_t start
Definition: avformat.h:1311
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1728
OSTFinished finished
Definition: ffmpeg.h:512
char * forced_keyframes
Definition: ffmpeg.h:491
int nb_frame_rates
Definition: ffmpeg.h:111
#define OPT_BOOL
Definition: cmdutils.h:162
A reference to a data buffer.
Definition: buffer.h:81
float dts_error_threshold
Definition: ffmpeg_opt.c:89
static AVStream * ost
Main libavformat public API header.
static uint8_t * get_line(AVIOContext *s)
Definition: ffmpeg_opt.c:1251
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
Definition: cmdutils.c:1081
preset
Definition: vf_curves.c:46
int
static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
Definition: ffmpeg_opt.c:1270
static uint8_t * read_file(const char *filename)
Definition: ffmpeg_opt.c:1570
uint64_t limit_filesize
Definition: ffmpeg.h:560
#define OPT_INT
Definition: cmdutils.h:167
static int opt_target(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2717
AVDictionary * codec_opts
Definition: cmdutils.c:73
AVIOContext * progress_avio
Definition: ffmpeg.c:143
AVDictionary * format_opts
Definition: cmdutils.h:319
static int opt_video_standard(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:238
SpecifierOpt * program
Definition: ffmpeg.h:227
int reinit_filters
Definition: ffmpeg.h:361
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465
int nb_frame_sizes
Definition: ffmpeg.h:113
OptionGroupList * groups
Definition: cmdutils.h:339
AVCodecParameters * ref_par
Definition: ffmpeg.h:466
OptionGroup * g
Definition: ffmpeg.h:96
#define VSYNC_CFR
Definition: ffmpeg.h:51
static int video_disable
Definition: ffplay.c:320
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: utils.c:3578
AVCodec * video_codec
Forced video codec.
Definition: avformat.h:1820
static double c[64]
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set that converts the value to a string and stores it...
Definition: dict.c:147
#define AVFMT_NOSTREAMS
Format does not require any streams.
Definition: avformat.h:474
AVStream * st
Definition: muxing.c:54
AVBufferRef * device_ref
Definition: ffmpeg.h:77
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:927
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
OptionGroup global_opts
Definition: cmdutils.h:337
const char ** attachments
Definition: ffmpeg.h:145
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poi...
Definition: opt.h:565
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1310
char * key
Definition: dict.h:86
int den
Denominator.
Definition: rational.h:60
struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1363
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: utils.c:4441
AVFormatContext * ctx
Definition: ffmpeg.h:394
int stream_index
Definition: ffmpeg.h:84
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:782
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:862
union OptionDef::@23 u
int nb_metadata_map
Definition: ffmpeg.h:196
int frame_bits_per_raw_sample
Definition: ffmpeg_opt.c:109
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition: hwcontext.c:97
enum AVCodecID id
Definition: avcodec.h:709
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:622
pixel format definitions
AVHWDeviceType
Definition: hwcontext.h:27
char * avfilter
Definition: ffmpeg.h:503
#define av_free(p)
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition: avformat.h:1882
char * value
Definition: dict.h:87
int eof_reached
true if eof reached
Definition: avio.h:239
AVCodec * subtitle_codec
Forced subtitle codec.
Definition: avformat.h:1836
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
int len
static int opt_timecode(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3045
static void dump_attachment(AVStream *st, const char *filename)
Definition: ffmpeg_opt.c:945
int channels
number of audio channels
Definition: avcodec.h:2190
AVCodec * data_codec
Forced data codec.
Definition: avformat.h:1844
OptGroup
Definition: ffmpeg_opt.c:3209
int top_field_first
Definition: ffmpeg.h:480
OutputFilter ** outputs
Definition: ffmpeg.h:291
static const struct PPFilter filters[]
Definition: postprocess.c:134
InputFile ** input_files
Definition: ffmpeg.c:149
int codec_info_nb_frames
Number of frames that have been demuxed during avformat_find_stream_info()
Definition: avformat.h:1089
SpecifierOpt * max_frames
Definition: ffmpeg.h:169
int disabled
Definition: ffmpeg.h:82
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
AVRational frame_rate
Definition: ffmpeg.h:271
#define PAL
Definition: bktr.c:65
AVFormatContext * ctx
Definition: ffmpeg.h:555
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: utils.c:540
static int show_hwaccels(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:172
int hw_device_init_from_string(const char *arg, HWDevice **dev)
Definition: ffmpeg_hw.c:92
static int opt_streamid(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:1965
void show_help_children(const AVClass *class, int flags)
Show help for all options with given flags in class and all its children.
Definition: cmdutils.c:206
static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, const OutputStream *ost, enum AVMediaType type)
Definition: ffmpeg_opt.c:1618
uint64_t layout
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3914
int thread_queue_size
Definition: ffmpeg.h:122
int channels
Audio only.
Definition: avcodec.h:4006
char * hwaccel_device
Definition: ffmpeg.h:366
AVDictionary * encoder_opts
Definition: ffmpeg.h:507
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
float max_error_rate
Definition: ffmpeg_opt.c:110
AVDictionary * codec_opts
Definition: cmdutils.h:318
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1466
static const AVBitStreamFilter *const bitstream_filters[]
Definition: bsf_list.c:1
int read_yesno(void)
Return a positive value if a line read from standard input starts with [yY], otherwise return 0...
Definition: cmdutils.c:2010
static const char * video_codec_name
Definition: ffplay.c:345
FILE * out
Definition: movenc.c:54
float dts_delta_threshold
Definition: ffmpeg_opt.c:88
char * videotoolbox_pixfmt
#define av_freep(p)
void INT64 INT64 count
Definition: avisynth_c.h:690
void INT64 start
Definition: avisynth_c.h:690
int sync_stream_index
Definition: ffmpeg.h:86
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
Definition: dict.h:70
static int input_stream_potentially_available
Definition: ffmpeg_opt.c:121
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
Definition: ffmpeg_opt.c:59
OutputFile ** output_files
Definition: ffmpeg.c:154
#define DEFAULT_PASS_LOGFILENAME_PREFIX
Definition: ffmpeg_opt.c:45
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:170
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1021
static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2901
const HWAccel hwaccels[]
Definition: ffmpeg_opt.c:69
static int no_file_overwrite
Definition: ffmpeg_opt.c:118
int format
Definition: ffmpeg.h:272
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3904
int64_t min_pts
Definition: ffmpeg.h:321
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2374
int discard
Definition: ffmpeg.h:298
static int opt_map(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:268
#define OPT_PERFILE
Definition: cmdutils.h:173
AVDictionary * sws_dict
Definition: cmdutils.h:321
#define OPT_INPUT
Definition: cmdutils.h:181
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:903
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:364
static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2889
#define MKTAG(a, b, c, d)
Definition: common.h:366
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:929
#define DECODING_FOR_OST
Definition: ffmpeg.h:301
int index
Definition: ffmpeg.h:444
static OutputStream * new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:1929
enum AVMediaType type
Definition: ffmpeg.h:267
This structure stores compressed data.
Definition: avcodec.h:1422
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: aviobuf.c:1214
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:449
const char program_name[]
program name, defined by the program for show_version().
Definition: ffmpeg.c:109
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVProgram ** programs
Definition: avformat.h:1531
#define AVFMT_NEEDNUMBER
Needs &#39;d&#39; in filename.
Definition: avformat.h:466
InputStream ** input_streams
Definition: ffmpeg.c:147
discard nothing
Definition: avcodec.h:797
int videotoolbox_init(AVCodecContext *s)
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:191
int subtitle_disable
Definition: ffmpeg.h:160
static int copy_unknown_streams
Definition: ffmpeg_opt.c:123
static OutputStream * new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:1903
static uint8_t tmp[11]
Definition: aes_ctr.c:26