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