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