FFmpeg  4.4.9
ffmpeg_opt.c
Go to the documentation of this file.
1 
2 /*
3  * ffmpeg option parsing
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdint.h>
23 
24 #include "ffmpeg.h"
25 #include "cmdutils.h"
26 
27 #include "libavformat/avformat.h"
28 
29 #include "libavcodec/avcodec.h"
30 
31 #include "libavfilter/avfilter.h"
32 
33 #include "libavutil/avassert.h"
34 #include "libavutil/avstring.h"
35 #include "libavutil/avutil.h"
37 #include "libavutil/intreadwrite.h"
38 #include "libavutil/fifo.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/opt.h"
41 #include "libavutil/parseutils.h"
42 #include "libavutil/pixdesc.h"
43 #include "libavutil/pixfmt.h"
44 
45 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
46 
47 #define 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[] = {"copyinkf", 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 = INT64_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  uint8_t buf[4] = { 0 };
828  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
829  tag = AV_RL32(buf);
830  }
831  st->codecpar->codec_tag = tag;
832  }
833 
834  ist->dec = choose_decoder(o, ic, st);
835  ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
836 
837  ist->reinit_filters = -1;
838  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
839 
840  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
842 
843  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
848 
849  if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
850  av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
851  discard_str);
852  exit_program(1);
853  }
854 
856 
857  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
858  if (!ist->dec_ctx) {
859  av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
860  exit_program(1);
861  }
862 
863  ret = avcodec_parameters_to_context(ist->dec_ctx, par);
864  if (ret < 0) {
865  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
866  exit_program(1);
867  }
868 
869  if (o->bitexact)
871 
872  switch (par->codec_type) {
873  case AVMEDIA_TYPE_VIDEO:
874  if(!ist->dec)
875  ist->dec = avcodec_find_decoder(par->codec_id);
876 
877  // avformat_find_stream_info() doesn't set this for us anymore.
878  ist->dec_ctx->framerate = st->avg_frame_rate;
879 
880  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
882  framerate) < 0) {
883  av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
884  framerate);
885  exit_program(1);
886  }
887 
888  ist->top_field_first = -1;
889  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
890 
891  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
892  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
893  hwaccel_output_format, ic, st);
894 
895  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
897  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
898  "with old commandlines. This behaviour is DEPRECATED and will be removed "
899  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
901  } else if (hwaccel_output_format) {
902  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
904  av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
905  "format: %s", hwaccel_output_format);
906  }
907  } else {
909  }
910 
911  if (hwaccel) {
912  // The NVDEC hwaccels use a CUDA device, so remap the name here.
913  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
914  hwaccel = "cuda";
915 
916  if (!strcmp(hwaccel, "none"))
917  ist->hwaccel_id = HWACCEL_NONE;
918  else if (!strcmp(hwaccel, "auto"))
919  ist->hwaccel_id = HWACCEL_AUTO;
920  else {
921  enum AVHWDeviceType type;
922  int i;
923  for (i = 0; hwaccels[i].name; i++) {
924  if (!strcmp(hwaccels[i].name, hwaccel)) {
925  ist->hwaccel_id = hwaccels[i].id;
926  break;
927  }
928  }
929 
930  if (!ist->hwaccel_id) {
932  if (type != AV_HWDEVICE_TYPE_NONE) {
934  ist->hwaccel_device_type = type;
935  }
936  }
937 
938  if (!ist->hwaccel_id) {
939  av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
940  hwaccel);
941  av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
943  while ((type = av_hwdevice_iterate_types(type)) !=
945  av_log(NULL, AV_LOG_FATAL, "%s ",
947  av_log(NULL, AV_LOG_FATAL, "\n");
948  exit_program(1);
949  }
950  }
951  }
952 
953  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
954  if (hwaccel_device) {
955  ist->hwaccel_device = av_strdup(hwaccel_device);
956  if (!ist->hwaccel_device)
957  exit_program(1);
958  }
959 
961 
962  break;
963  case AVMEDIA_TYPE_AUDIO:
964  ist->guess_layout_max = INT_MAX;
965  MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
967  break;
968  case AVMEDIA_TYPE_DATA:
969  case AVMEDIA_TYPE_SUBTITLE: {
970  char *canvas_size = NULL;
971  if(!ist->dec)
972  ist->dec = avcodec_find_decoder(par->codec_id);
973  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
974  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
975  if (canvas_size &&
976  av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
977  av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
978  exit_program(1);
979  }
980  break;
981  }
984  break;
985  default:
986  abort();
987  }
988 
989  ret = avcodec_parameters_from_context(par, ist->dec_ctx);
990  if (ret < 0) {
991  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
992  exit_program(1);
993  }
994  }
995 }
996 
997 static void assert_file_overwrite(const char *filename)
998 {
999  const char *proto_name = avio_find_protocol_name(filename);
1000 
1002  fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
1003  exit_program(1);
1004  }
1005 
1006  if (!file_overwrite) {
1007  if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
1009  fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", filename);
1010  fflush(stderr);
1011  term_exit();
1012  signal(SIGINT, SIG_DFL);
1013  if (!read_yesno()) {
1014  av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
1015  exit_program(1);
1016  }
1017  term_init();
1018  }
1019  else {
1020  av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
1021  exit_program(1);
1022  }
1023  }
1024  }
1025 
1026  if (proto_name && !strcmp(proto_name, "file")) {
1027  for (int i = 0; i < nb_input_files; i++) {
1028  InputFile *file = input_files[i];
1029  if (file->ctx->iformat->flags & AVFMT_NOFILE)
1030  continue;
1031  if (!strcmp(filename, file->ctx->url)) {
1032  av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
1033  av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
1034  exit_program(1);
1035  }
1036  }
1037  }
1038 }
1039 
1040 static int is_windows_reserved_device_name(const char *f)
1041 {
1042 #if HAVE_DOS_PATHS
1043  for (const char *p = f; p && *p; ) {
1044  char stem[6], *s;
1045  av_strlcpy(stem, p, sizeof(stem));
1046  if ((s = strchr(stem, '.')))
1047  *s = 0;
1048  if ((s = strpbrk(stem, "123456789")))
1049  *s = '1';
1050 
1051  if( !av_strcasecmp(stem, "AUX") ||
1052  !av_strcasecmp(stem, "CON") ||
1053  !av_strcasecmp(stem, "NUL") ||
1054  !av_strcasecmp(stem, "PRN") ||
1055  !av_strcasecmp(stem, "COM1") ||
1056  !av_strcasecmp(stem, "LPT1")
1057  )
1058  return 1;
1059 
1060  p = strchr(p, '/');
1061  if (p)
1062  p++;
1063  }
1064 #endif
1065  return 0;
1066 }
1067 
1068 static int safe_filename(const char *f, int allow_subdir)
1069 {
1070  const char *start = f;
1071 
1073  return 0;
1074 
1075  for (; *f; f++) {
1076  /* A-Za-z0-9_- */
1077  if (!((unsigned)((*f | 32) - 'a') < 26 ||
1078  (unsigned)(*f - '0') < 10 || *f == '_' || *f == '-')) {
1079  if (f == start)
1080  return 0;
1081  else if (allow_subdir && *f == '/')
1082  start = f + 1;
1083  else if (*f != '.')
1084  return 0;
1085  }
1086  }
1087  return 1;
1088 }
1089 
1090 static void dump_attachment(AVStream *st, const char *filename)
1091 {
1092  int ret;
1093  AVIOContext *out = NULL;
1094  AVDictionaryEntry *e;
1095 
1096  if (!st->codecpar->extradata_size) {
1097  av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
1098  nb_input_files - 1, st->index);
1099  return;
1100  }
1101  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0))) {
1102  filename = e->value;
1103  if (!safe_filename(filename, 0)) {
1104  av_log(NULL, AV_LOG_ERROR, "Filename %s is unsafe\n", filename);
1105  exit_program(1);
1106  }
1107  }
1108  if (!*filename) {
1109  av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
1110  "in stream #%d:%d.\n", nb_input_files - 1, st->index);
1111  exit_program(1);
1112  }
1113 
1114  assert_file_overwrite(filename);
1115 
1116  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1117  av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1118  filename);
1119  exit_program(1);
1120  }
1121 
1123  avio_flush(out);
1124  avio_close(out);
1125 }
1126 
1127 static int open_input_file(OptionsContext *o, const char *filename)
1128 {
1129  InputFile *f;
1130  AVFormatContext *ic;
1132  int err, i, ret;
1133  int64_t timestamp;
1134  AVDictionary *unused_opts = NULL;
1135  AVDictionaryEntry *e = NULL;
1136  char * video_codec_name = NULL;
1137  char * audio_codec_name = NULL;
1138  char *subtitle_codec_name = NULL;
1139  char * data_codec_name = NULL;
1140  int scan_all_pmts_set = 0;
1141 
1142  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
1143  o->stop_time = INT64_MAX;
1144  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1145  }
1146 
1147  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
1149  if (o->stop_time <= start_time) {
1150  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1151  exit_program(1);
1152  } else {
1154  }
1155  }
1156 
1157  if (o->format) {
1158  if (!(file_iformat = av_find_input_format(o->format))) {
1159  av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1160  exit_program(1);
1161  }
1162  }
1163 
1164  if (!strcmp(filename, "-"))
1165  filename = "pipe:";
1166 
1167  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1168  strcmp(filename, "/dev/stdin");
1169 
1170  /* get default parameters from command line */
1171  ic = avformat_alloc_context();
1172  if (!ic) {
1173  print_error(filename, AVERROR(ENOMEM));
1174  exit_program(1);
1175  }
1176  if (o->nb_audio_sample_rate) {
1177  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1178  }
1179  if (o->nb_audio_channels) {
1180  /* because we set audio_channels based on both the "ac" and
1181  * "channel_layout" options, we need to check that the specified
1182  * demuxer actually has the "channels" option before setting it */
1184  av_opt_find(&file_iformat->priv_class, "channels", NULL, 0,
1186  av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);
1187  }
1188  }
1189  if (o->nb_frame_rates) {
1190  /* set the format-level framerate option;
1191  * this is important for video grabbers, e.g. x11 */
1193  av_opt_find(&file_iformat->priv_class, "framerate", NULL, 0,
1195  av_dict_set(&o->g->format_opts, "framerate",
1196  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1197  }
1198  }
1199  if (o->nb_frame_sizes) {
1200  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1201  }
1202  if (o->nb_frame_pix_fmts)
1203  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1204 
1205  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1206  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1207  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1208  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1209 
1210  if (video_codec_name)
1212  if (audio_codec_name)
1214  if (subtitle_codec_name)
1216  if (data_codec_name)
1217  ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
1218 
1222  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1223 
1224  ic->flags |= AVFMT_FLAG_NONBLOCK;
1225  if (o->bitexact)
1226  ic->flags |= AVFMT_FLAG_BITEXACT;
1227  ic->interrupt_callback = int_cb;
1228 
1229  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1230  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1231  scan_all_pmts_set = 1;
1232  }
1233  /* open the input file with generic avformat function */
1234  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1235  if (err < 0) {
1236  print_error(filename, err);
1237  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1238  av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1239  exit_program(1);
1240  }
1241  if (scan_all_pmts_set)
1242  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1245 
1246  /* apply forced codec ids */
1247  for (i = 0; i < ic->nb_streams; i++)
1248  choose_decoder(o, ic, ic->streams[i]);
1249 
1250  if (find_stream_info) {
1252  int orig_nb_streams = ic->nb_streams;
1253 
1254  /* If not enough info to get the stream parameters, we decode the
1255  first frames to get it. (used in mpeg case for example) */
1256  ret = avformat_find_stream_info(ic, opts);
1257 
1258  for (i = 0; i < orig_nb_streams; i++)
1259  av_dict_free(&opts[i]);
1260  av_freep(&opts);
1261 
1262  if (ret < 0) {
1263  av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
1264  if (ic->nb_streams == 0) {
1265  avformat_close_input(&ic);
1266  exit_program(1);
1267  }
1268  }
1269  }
1270 
1272  av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1274  }
1275 
1276  if (o->start_time_eof != AV_NOPTS_VALUE) {
1277  if (o->start_time_eof >= 0) {
1278  av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1279  exit_program(1);
1280  }
1281  if (ic->duration > 0) {
1282  o->start_time = o->start_time_eof + ic->duration;
1283  if (o->start_time < 0) {
1284  av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
1286  }
1287  } else
1288  av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
1289  }
1290  timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
1291  /* add the stream start time */
1292  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1293  timestamp += ic->start_time;
1294 
1295  /* if seeking requested, we execute it */
1296  if (o->start_time != AV_NOPTS_VALUE) {
1297  int64_t seek_timestamp = timestamp;
1298 
1299  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1300  int dts_heuristic = 0;
1301  for (i=0; i<ic->nb_streams; i++) {
1302  const AVCodecParameters *par = ic->streams[i]->codecpar;
1303  if (par->video_delay) {
1304  dts_heuristic = 1;
1305  break;
1306  }
1307  }
1308  if (dts_heuristic) {
1309  seek_timestamp -= 3*AV_TIME_BASE / 23;
1310  }
1311  }
1312  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1313  if (ret < 0) {
1314  av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
1315  filename, (double)timestamp / AV_TIME_BASE);
1316  }
1317  }
1318 
1319  /* update the current parameters so that they match the one of the input stream */
1320  add_input_streams(o, ic);
1321 
1322  /* dump the file content */
1323  av_dump_format(ic, nb_input_files, filename, 0);
1324 
1326  f = av_mallocz(sizeof(*f));
1327  if (!f)
1328  exit_program(1);
1329  input_files[nb_input_files - 1] = f;
1330 
1331  f->ctx = ic;
1332  f->ist_index = nb_input_streams - ic->nb_streams;
1333  f->start_time = o->start_time;
1334  f->recording_time = o->recording_time;
1335  f->input_ts_offset = o->input_ts_offset;
1336  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1337  f->nb_streams = ic->nb_streams;
1338  f->rate_emu = o->rate_emu;
1339  f->accurate_seek = o->accurate_seek;
1340  f->loop = o->loop;
1341  f->duration = 0;
1342  f->time_base = (AVRational){ 1, 1 };
1343  f->pkt = av_packet_alloc();
1344  if (!f->pkt)
1345  exit_program(1);
1346 #if HAVE_THREADS
1347  f->thread_queue_size = o->thread_queue_size;
1348 #endif
1349 
1350  /* check if all codec options have been used */
1351  unused_opts = strip_specifiers(o->g->codec_opts);
1352  for (i = f->ist_index; i < nb_input_streams; i++) {
1353  e = NULL;
1354  while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e,
1356  av_dict_set(&unused_opts, e->key, NULL, 0);
1357  }
1358 
1359  e = NULL;
1360  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
1361  const AVClass *class = avcodec_get_class();
1362  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1364  const AVClass *fclass = avformat_get_class();
1365  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1367  if (!option || foption)
1368  continue;
1369 
1370 
1371  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1372  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
1373  "input file #%d (%s) is not a decoding option.\n", e->key,
1374  option->help ? option->help : "", nb_input_files - 1,
1375  filename);
1376  exit_program(1);
1377  }
1378 
1379  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
1380  "input file #%d (%s) has not been used for any stream. The most "
1381  "likely reason is either wrong type (e.g. a video option with "
1382  "no video streams) or that it is a private option of some decoder "
1383  "which was not actually used for any stream.\n", e->key,
1384  option->help ? option->help : "", nb_input_files - 1, filename);
1385  }
1386  av_dict_free(&unused_opts);
1387 
1388  for (i = 0; i < o->nb_dump_attachment; i++) {
1389  int j;
1390 
1391  for (j = 0; j < ic->nb_streams; j++) {
1392  AVStream *st = ic->streams[j];
1393 
1394  if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
1396  }
1397  }
1398 
1400 
1401  return 0;
1402 }
1403 
1405 {
1406  AVIOContext *line;
1407  uint8_t *buf;
1408  char c;
1409 
1410  if (avio_open_dyn_buf(&line) < 0) {
1411  av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
1412  exit_program(1);
1413  }
1414 
1415  while ((c = avio_r8(s)) && c != '\n')
1416  avio_w8(line, c);
1417  avio_w8(line, 0);
1418  avio_close_dyn_buf(line, &buf);
1419 
1420  return buf;
1421 }
1422 
1423 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
1424 {
1425  int i, ret = -1;
1426  char filename[1000];
1427  const char *base[3] = { getenv("AVCONV_DATADIR"),
1428  getenv("HOME"),
1430  };
1431 
1432  for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1433  if (!base[i])
1434  continue;
1435  if (codec_name) {
1436  snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
1437  i != 1 ? "" : "/.avconv", codec_name, preset_name);
1438  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1439  }
1440  if (ret < 0) {
1441  snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
1442  i != 1 ? "" : "/.avconv", preset_name);
1443  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1444  }
1445  }
1446  return ret;
1447 }
1448 
1450 {
1451  enum AVMediaType type = ost->st->codecpar->codec_type;
1452  char *codec_name = NULL;
1453 
1455  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
1456  if (!codec_name) {
1457  ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1458  NULL, ost->st->codecpar->codec_type);
1460  if (!ost->enc) {
1461  av_log(NULL, AV_LOG_FATAL, "Automatic encoder selection failed for "
1462  "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1463  "probably disabled. Please choose an encoder manually.\n",
1464  ost->file_index, ost->index, s->oformat->name,
1467  }
1468  } else if (!strcmp(codec_name, "copy"))
1469  ost->stream_copy = 1;
1470  else {
1471  ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
1472  ost->st->codecpar->codec_id = ost->enc->id;
1473  }
1474  ost->encoding_needed = !ost->stream_copy;
1475  } else {
1476  /* no encoding supported for other media types */
1477  ost->stream_copy = 1;
1478  ost->encoding_needed = 0;
1479  }
1480 
1481  return 0;
1482 }
1483 
1485 {
1486  OutputStream *ost;
1487  AVStream *st = avformat_new_stream(oc, NULL);
1488  int idx = oc->nb_streams - 1, ret = 0;
1489  const char *bsfs = NULL, *time_base = NULL;
1490  char *next, *codec_tag = NULL;
1491  double qscale = -1;
1492  int i;
1493 
1494  if (!st) {
1495  av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
1496  exit_program(1);
1497  }
1498 
1499  if (oc->nb_streams - 1 < o->nb_streamid_map)
1500  st->id = o->streamid_map[oc->nb_streams - 1];
1501 
1503  if (!(ost = av_mallocz(sizeof(*ost))))
1504  exit_program(1);
1506 
1507  ost->file_index = nb_output_files - 1;
1508  ost->index = idx;
1509  ost->st = st;
1510  ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
1511  st->codecpar->codec_type = type;
1512 
1513  ret = choose_encoder(o, oc, ost);
1514  if (ret < 0) {
1515  av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream "
1516  "%d:%d\n", ost->file_index, ost->index);
1517  exit_program(1);
1518  }
1519 
1520  ost->enc_ctx = avcodec_alloc_context3(ost->enc);
1521  if (!ost->enc_ctx) {
1522  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
1523  exit_program(1);
1524  }
1525  ost->enc_ctx->codec_type = type;
1526 
1527  ost->ref_par = avcodec_parameters_alloc();
1528  if (!ost->ref_par) {
1529  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n");
1530  exit_program(1);
1531  }
1532 
1533  if (ost->enc) {
1534  AVIOContext *s = NULL;
1535  char *buf = NULL, *arg = NULL, *preset = NULL;
1536 
1537  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
1538 
1540  ost->autoscale = 1;
1541  MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
1542  if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
1543  do {
1544  buf = get_line(s);
1545  if (!buf[0] || buf[0] == '#') {
1546  av_free(buf);
1547  continue;
1548  }
1549  if (!(arg = strchr(buf, '='))) {
1550  av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1551  exit_program(1);
1552  }
1553  *arg++ = 0;
1554  av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1555  av_free(buf);
1556  } while (!s->eof_reached);
1557  avio_closep(&s);
1558  }
1559  if (ret) {
1561  "Preset %s specified for stream %d:%d, but could not be opened.\n",
1562  preset, ost->file_index, ost->index);
1563  exit_program(1);
1564  }
1565  } else {
1566  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
1567  }
1568 
1569 
1570  if (o->bitexact)
1571  ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
1572 
1573  MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1574  if (time_base) {
1575  AVRational q;
1576  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1577  q.num <= 0 || q.den <= 0) {
1578  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1579  exit_program(1);
1580  }
1581  st->time_base = q;
1582  }
1583 
1584  MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
1585  if (time_base) {
1586  AVRational q;
1587  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1588  q.den <= 0) {
1589  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1590  exit_program(1);
1591  }
1592  ost->enc_timebase = q;
1593  }
1594 
1595  ost->max_frames = INT64_MAX;
1596  MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
1597  for (i = 0; i<o->nb_max_frames; i++) {
1598  char *p = o->max_frames[i].specifier;
1599  if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1600  av_log(NULL, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1601  break;
1602  }
1603  }
1604 
1605  ost->copy_prior_start = -1;
1606  MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
1607 
1608  MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1609  if (bsfs && *bsfs) {
1610  ret = av_bsf_list_parse_str(bsfs, &ost->bsf_ctx);
1611  if (ret < 0) {
1612  av_log(NULL, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
1613  exit_program(1);
1614  }
1615  }
1616 
1617  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1618  if (codec_tag) {
1619  uint32_t tag = strtol(codec_tag, &next, 0);
1620  if (*next) {
1621  uint8_t buf[4] = { 0 };
1622  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1623  tag = AV_RL32(buf);
1624  }
1625  ost->st->codecpar->codec_tag =
1626  ost->enc_ctx->codec_tag = tag;
1627  }
1628 
1629  MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1630  if (qscale >= 0) {
1631  ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1632  ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1633  }
1634 
1635  MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
1637 
1638  ost->max_muxing_queue_size = 128;
1639  MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
1640  ost->max_muxing_queue_size = FFMIN(ost->max_muxing_queue_size, INT_MAX / sizeof(ost->pkt));
1641  ost->max_muxing_queue_size *= sizeof(ost->pkt);
1642 
1643  ost->muxing_queue_data_size = 0;
1644 
1645  ost->muxing_queue_data_threshold = 50*1024*1024;
1646  MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ost->muxing_queue_data_threshold, oc, st);
1647 
1648  if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1649  ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1650 
1651  av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1652 
1653  av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1654  if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
1655  av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1656 
1657  av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0);
1658 
1659  ost->source_index = source_index;
1660  if (source_index >= 0) {
1661  ost->sync_ist = input_streams[source_index];
1662  input_streams[source_index]->discard = 0;
1663  input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
1664  }
1665  ost->last_mux_dts = AV_NOPTS_VALUE;
1666 
1667  ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket));
1668  if (!ost->muxing_queue)
1669  exit_program(1);
1670 
1671  return ost;
1672 }
1673 
1674 static void parse_matrix_coeffs(uint16_t *dest, const char *str)
1675 {
1676  int i;
1677  const char *p = str;
1678  for (i = 0;; i++) {
1679  dest[i] = atoi(p);
1680  if (i == 63)
1681  break;
1682  p = strchr(p, ',');
1683  if (!p) {
1684  av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1685  exit_program(1);
1686  }
1687  p++;
1688  }
1689 }
1690 
1691 /* read file contents into a string */
1692 static uint8_t *read_file(const char *filename)
1693 {
1694  AVIOContext *pb = NULL;
1695  AVIOContext *dyn_buf = NULL;
1696  int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1697  uint8_t buf[1024], *str;
1698 
1699  if (ret < 0) {
1700  av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1701  return NULL;
1702  }
1703 
1704  ret = avio_open_dyn_buf(&dyn_buf);
1705  if (ret < 0) {
1706  avio_closep(&pb);
1707  return NULL;
1708  }
1709  while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
1710  avio_write(dyn_buf, buf, ret);
1711  avio_w8(dyn_buf, 0);
1712  avio_closep(&pb);
1713 
1714  ret = avio_close_dyn_buf(dyn_buf, &str);
1715  if (ret < 0)
1716  return NULL;
1717  return str;
1718 }
1719 
1721  OutputStream *ost)
1722 {
1723  AVStream *st = ost->st;
1724 
1725  if (ost->filters_script && ost->filters) {
1726  av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
1727  "output stream #%d:%d.\n", nb_output_files, st->index);
1728  exit_program(1);
1729  }
1730 
1731  if (ost->filters_script)
1732  return read_file(ost->filters_script);
1733  else if (ost->filters)
1734  return av_strdup(ost->filters);
1735 
1737  "null" : "anull");
1738 }
1739 
1741  const OutputStream *ost, enum AVMediaType type)
1742 {
1743  if (ost->filters_script || ost->filters) {
1745  "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1746  "Filtering and streamcopy cannot be used together.\n",
1747  ost->filters ? "Filtergraph" : "Filtergraph script",
1748  ost->filters ? ost->filters : ost->filters_script,
1749  av_get_media_type_string(type), ost->file_index, ost->index);
1750  exit_program(1);
1751  }
1752 }
1753 
1755 {
1756  AVStream *st;
1757  OutputStream *ost;
1758  AVCodecContext *video_enc;
1759  char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL;
1760 
1761  ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
1762  st = ost->st;
1763  video_enc = ost->enc_ctx;
1764 
1765  MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
1766  if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
1767  av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
1768  exit_program(1);
1769  }
1770 
1771  MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
1772  if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
1773  av_log(NULL, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
1774  exit_program(1);
1775  }
1776 
1777  if (frame_rate && max_frame_rate) {
1778  av_log(NULL, AV_LOG_ERROR, "Only one of -fpsmax and -r can be set for a stream.\n");
1779  exit_program(1);
1780  }
1781 
1782  if ((frame_rate || max_frame_rate) &&
1784  av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r/-fpsmax can produce invalid output files\n");
1785 
1786  MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
1787  if (frame_aspect_ratio) {
1788  AVRational q;
1789  if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1790  q.num <= 0 || q.den <= 0) {
1791  av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
1792  exit_program(1);
1793  }
1794  ost->frame_aspect_ratio = q;
1795  }
1796 
1797  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1798  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1799 
1800  if (!ost->stream_copy) {
1801  const char *p = NULL;
1802  char *frame_size = NULL;
1803  char *frame_pix_fmt = NULL;
1804  char *intra_matrix = NULL, *inter_matrix = NULL;
1805  char *chroma_intra_matrix = NULL;
1806  int do_pass = 0;
1807  int i;
1808 
1810  if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1811  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1812  exit_program(1);
1813  }
1814 
1816  MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
1817  if (frame_pix_fmt && *frame_pix_fmt == '+') {
1818  ost->keep_pix_fmt = 1;
1819  if (!*++frame_pix_fmt)
1820  frame_pix_fmt = NULL;
1821  }
1822  if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1823  av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
1824  exit_program(1);
1825  }
1826  st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1827 
1828  if (intra_only)
1829  video_enc->gop_size = 0;
1830  MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
1831  if (intra_matrix) {
1832  if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
1833  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1834  exit_program(1);
1835  }
1836  parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
1837  }
1838  MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
1839  if (chroma_intra_matrix) {
1840  uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
1841  if (!p) {
1842  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1843  exit_program(1);
1844  }
1845  video_enc->chroma_intra_matrix = p;
1846  parse_matrix_coeffs(p, chroma_intra_matrix);
1847  }
1848  MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
1849  if (inter_matrix) {
1850  if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
1851  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
1852  exit_program(1);
1853  }
1854  parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
1855  }
1856 
1857  MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
1858  for (i = 0; p; i++) {
1859  int start, end, q;
1860  int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
1861  if (e != 3) {
1862  av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
1863  exit_program(1);
1864  }
1865  video_enc->rc_override =
1866  av_realloc_array(video_enc->rc_override,
1867  i + 1, sizeof(RcOverride));
1868  if (!video_enc->rc_override) {
1869  av_log(NULL, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
1870  exit_program(1);
1871  }
1872  video_enc->rc_override[i].start_frame = start;
1873  video_enc->rc_override[i].end_frame = end;
1874  if (q > 0) {
1875  video_enc->rc_override[i].qscale = q;
1876  video_enc->rc_override[i].quality_factor = 1.0;
1877  }
1878  else {
1879  video_enc->rc_override[i].qscale = 0;
1880  video_enc->rc_override[i].quality_factor = -q/100.0;
1881  }
1882  p = strchr(p, '/');
1883  if (p) p++;
1884  }
1885  video_enc->rc_override_count = i;
1886 
1887  if (do_psnr)
1888  video_enc->flags|= AV_CODEC_FLAG_PSNR;
1889 
1890  /* two pass mode */
1891  MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
1892  if (do_pass) {
1893  if (do_pass & 1) {
1894  video_enc->flags |= AV_CODEC_FLAG_PASS1;
1895  av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
1896  }
1897  if (do_pass & 2) {
1898  video_enc->flags |= AV_CODEC_FLAG_PASS2;
1899  av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
1900  }
1901  }
1902 
1903  MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
1904  if (ost->logfile_prefix &&
1905  !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
1906  exit_program(1);
1907 
1908  if (do_pass) {
1909  char logfilename[1024];
1910  FILE *f;
1911 
1912  snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
1913  ost->logfile_prefix ? ost->logfile_prefix :
1915  i);
1916  if (!strcmp(ost->enc->name, "libx264")) {
1917  av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
1918  } else {
1919  if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1920  char *logbuffer = read_file(logfilename);
1921 
1922  if (!logbuffer) {
1923  av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
1924  logfilename);
1925  exit_program(1);
1926  }
1927  video_enc->stats_in = logbuffer;
1928  }
1929  if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1930  f = av_fopen_utf8(logfilename, "wb");
1931  if (!f) {
1933  "Cannot write log file '%s' for pass-1 encoding: %s\n",
1934  logfilename, strerror(errno));
1935  exit_program(1);
1936  }
1937  ost->logfile = f;
1938  }
1939  }
1940  }
1941 
1942  MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
1943  if (ost->forced_keyframes)
1944  ost->forced_keyframes = av_strdup(ost->forced_keyframes);
1945 
1946  MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
1947 
1948  ost->top_field_first = -1;
1949  MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
1950 
1951 
1952  ost->avfilter = get_ost_filters(o, oc, ost);
1953  if (!ost->avfilter)
1954  exit_program(1);
1955 
1956  ost->last_frame = av_frame_alloc();
1957  if (!ost->last_frame)
1958  exit_program(1);
1959  } else {
1960  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
1961  }
1962 
1963  if (ost->stream_copy)
1965 
1966  return ost;
1967 }
1968 
1970 {
1971  int n;
1972  AVStream *st;
1973  OutputStream *ost;
1974  AVCodecContext *audio_enc;
1975 
1976  ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index);
1977  st = ost->st;
1978 
1979  audio_enc = ost->enc_ctx;
1980  audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1981 
1982  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1983  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1984 
1985  if (!ost->stream_copy) {
1986  char *sample_fmt = NULL;
1987  const char *apad = NULL;
1988 
1989  MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
1990 
1991  MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
1992  if (sample_fmt &&
1993  (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
1994  av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
1995  exit_program(1);
1996  }
1997 
1998  MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
1999 
2000  MATCH_PER_STREAM_OPT(apad, str, apad, oc, st);
2001  if (apad) {
2002  ost->apad = av_strdup(apad);
2003  if (!ost->apad)
2004  exit_program(1);
2005  }
2006 
2007  ost->avfilter = get_ost_filters(o, oc, ost);
2008  if (!ost->avfilter)
2009  exit_program(1);
2010 
2011  /* check for channel mapping for this audio stream */
2012  for (n = 0; n < o->nb_audio_channel_maps; n++) {
2014  if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
2015  (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
2016  InputStream *ist;
2017 
2018  if (map->channel_idx == -1) {
2019  ist = NULL;
2020  } else if (ost->source_index < 0) {
2021  av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
2022  ost->file_index, ost->st->index);
2023  continue;
2024  } else {
2025  ist = input_streams[ost->source_index];
2026  }
2027 
2028  if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
2029  if (av_reallocp_array(&ost->audio_channels_map,
2030  ost->audio_channels_mapped + 1,
2031  sizeof(*ost->audio_channels_map)
2032  ) < 0 )
2033  exit_program(1);
2034 
2035  ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
2036  }
2037  }
2038  }
2039  }
2040 
2041  if (ost->stream_copy)
2043 
2044  return ost;
2045 }
2046 
2048 {
2049  OutputStream *ost;
2050 
2051  ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
2052  if (!ost->stream_copy) {
2053  av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
2054  exit_program(1);
2055  }
2056 
2057  return ost;
2058 }
2059 
2061 {
2062  OutputStream *ost;
2063 
2064  ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
2065  if (!ost->stream_copy) {
2066  av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
2067  exit_program(1);
2068  }
2069 
2070  return ost;
2071 }
2072 
2074 {
2075  OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
2076  ost->stream_copy = 1;
2077  ost->finished = 1;
2078  return ost;
2079 }
2080 
2082 {
2083  AVStream *st;
2084  OutputStream *ost;
2085  AVCodecContext *subtitle_enc;
2086 
2087  ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
2088  st = ost->st;
2089  subtitle_enc = ost->enc_ctx;
2090 
2091  subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2092 
2093  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc, st);
2094 
2095  if (!ost->stream_copy) {
2096  char *frame_size = NULL;
2097 
2099  if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
2100  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
2101  exit_program(1);
2102  }
2103  }
2104 
2105  return ost;
2106 }
2107 
2108 /* arg format is "output-stream-index:streamid-value". */
2109 static int opt_streamid(void *optctx, const char *opt, const char *arg)
2110 {
2111  OptionsContext *o = optctx;
2112  int idx;
2113  char *p;
2114  char idx_str[16];
2115 
2116  av_strlcpy(idx_str, arg, sizeof(idx_str));
2117  p = strchr(idx_str, ':');
2118  if (!p) {
2120  "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
2121  arg, opt);
2122  exit_program(1);
2123  }
2124  *p++ = '\0';
2125  idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
2126  o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
2127  o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
2128  return 0;
2129 }
2130 
2132 {
2133  AVFormatContext *is = ifile->ctx;
2134  AVFormatContext *os = ofile->ctx;
2135  AVChapter **tmp;
2136  int i;
2137 
2138  tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
2139  if (!tmp)
2140  return AVERROR(ENOMEM);
2141  os->chapters = tmp;
2142 
2143  for (i = 0; i < is->nb_chapters; i++) {
2144  AVChapter *in_ch = is->chapters[i], *out_ch;
2145  int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2146  int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2147  AV_TIME_BASE_Q, in_ch->time_base);
2148  int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2149  av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
2150 
2151 
2152  if (in_ch->end < ts_off)
2153  continue;
2154  if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2155  break;
2156 
2157  out_ch = av_mallocz(sizeof(AVChapter));
2158  if (!out_ch)
2159  return AVERROR(ENOMEM);
2160 
2161  out_ch->id = in_ch->id;
2162  out_ch->time_base = in_ch->time_base;
2163  out_ch->start = FFMAX(0, in_ch->start - ts_off);
2164  out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2165 
2166  if (copy_metadata)
2167  av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2168 
2169  os->chapters[os->nb_chapters++] = out_ch;
2170  }
2171  return 0;
2172 }
2173 
2175  AVFormatContext *oc)
2176 {
2177  OutputStream *ost;
2178 
2179  switch (ofilter->type) {
2180  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
2181  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
2182  default:
2183  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported "
2184  "currently.\n");
2185  exit_program(1);
2186  }
2187 
2188  ost->source_index = -1;
2189  ost->filter = ofilter;
2190 
2191  ofilter->ost = ost;
2192  ofilter->format = -1;
2193 
2194  if (ost->stream_copy) {
2195  av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
2196  "which is fed from a complex filtergraph. Filtering and streamcopy "
2197  "cannot be used together.\n", ost->file_index, ost->index);
2198  exit_program(1);
2199  }
2200 
2201  if (ost->avfilter && (ost->filters || ost->filters_script)) {
2202  const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
2204  "%s '%s' was specified through the %s option "
2205  "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2206  "%s and -filter_complex cannot be used together for the same stream.\n",
2207  ost->filters ? "Filtergraph" : "Filtergraph script",
2208  ost->filters ? ost->filters : ost->filters_script,
2209  opt, ost->file_index, ost->index, opt);
2210  exit_program(1);
2211  }
2212 
2213  avfilter_inout_free(&ofilter->out_tmp);
2214 }
2215 
2216 static int init_complex_filters(void)
2217 {
2218  int i, ret = 0;
2219 
2220  for (i = 0; i < nb_filtergraphs; i++) {
2222  if (ret < 0)
2223  return ret;
2224  }
2225  return 0;
2226 }
2227 
2228 static int open_output_file(OptionsContext *o, const char *filename)
2229 {
2230  AVFormatContext *oc;
2231  int i, j, err;
2232  OutputFile *of;
2233  OutputStream *ost;
2234  InputStream *ist;
2235  AVDictionary *unused_opts = NULL;
2236  AVDictionaryEntry *e = NULL;
2237  int format_flags = 0;
2238 
2239  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
2240  o->stop_time = INT64_MAX;
2241  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2242  }
2243 
2244  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
2246  if (o->stop_time <= start_time) {
2247  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2248  exit_program(1);
2249  } else {
2251  }
2252  }
2253 
2255  of = av_mallocz(sizeof(*of));
2256  if (!of)
2257  exit_program(1);
2258  output_files[nb_output_files - 1] = of;
2259 
2261  of->recording_time = o->recording_time;
2262  of->start_time = o->start_time;
2263  of->limit_filesize = o->limit_filesize;
2264  of->shortest = o->shortest;
2265  av_dict_copy(&of->opts, o->g->format_opts, 0);
2266 
2267  if (!strcmp(filename, "-"))
2268  filename = "pipe:";
2269 
2270  err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2271  if (!oc) {
2272  print_error(filename, err);
2273  exit_program(1);
2274  }
2275 
2276  of->ctx = oc;
2277  if (o->recording_time != INT64_MAX)
2278  oc->duration = o->recording_time;
2279 
2280  oc->interrupt_callback = int_cb;
2281 
2282  e = av_dict_get(o->g->format_opts, "fflags", NULL, 0);
2283  if (e) {
2284  const AVOption *o = av_opt_find(oc, "fflags", NULL, 0, 0);
2285  av_opt_eval_flags(oc, o, e->value, &format_flags);
2286  }
2287  if (o->bitexact) {
2288  format_flags |= AVFMT_FLAG_BITEXACT;
2289  oc->flags |= AVFMT_FLAG_BITEXACT;
2290  }
2291 
2292  /* create streams for all unlabeled output pads */
2293  for (i = 0; i < nb_filtergraphs; i++) {
2294  FilterGraph *fg = filtergraphs[i];
2295  for (j = 0; j < fg->nb_outputs; j++) {
2296  OutputFilter *ofilter = fg->outputs[j];
2297 
2298  if (!ofilter->out_tmp || ofilter->out_tmp->name)
2299  continue;
2300 
2301  switch (ofilter->type) {
2302  case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break;
2303  case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break;
2304  case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
2305  }
2306  init_output_filter(ofilter, o, oc);
2307  }
2308  }
2309 
2310  if (!o->nb_stream_maps) {
2311  char *subtitle_codec_name = NULL;
2312  /* pick the "best" stream of each type */
2313 
2314  /* video: highest resolution */
2316  int best_score = 0, idx = -1;
2317  int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2318  for (i = 0; i < nb_input_streams; i++) {
2319  int score;
2320  ist = input_streams[i];
2321  score = ist->st->codecpar->width * ist->st->codecpar->height
2322  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
2323  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2324  if (ist->user_set_discard == AVDISCARD_ALL)
2325  continue;
2326  if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2327  score = 1;
2328  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2329  score > best_score) {
2330  if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2331  continue;
2332  best_score = score;
2333  idx = i;
2334  }
2335  }
2336  if (idx >= 0)
2337  new_video_stream(o, oc, idx);
2338  }
2339 
2340  /* audio: most channels */
2342  int best_score = 0, idx = -1;
2343  for (i = 0; i < nb_input_streams; i++) {
2344  int score;
2345  ist = input_streams[i];
2346  score = ist->st->codecpar->channels + 100000000*!!ist->st->codec_info_nb_frames
2347  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2348  if (ist->user_set_discard == AVDISCARD_ALL)
2349  continue;
2350  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2351  score > best_score) {
2352  best_score = score;
2353  idx = i;
2354  }
2355  }
2356  if (idx >= 0)
2357  new_audio_stream(o, oc, idx);
2358  }
2359 
2360  /* subtitles: pick first */
2361  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
2363  for (i = 0; i < nb_input_streams; i++)
2364  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2365  AVCodecDescriptor const *input_descriptor =
2366  avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id);
2367  AVCodecDescriptor const *output_descriptor = NULL;
2368  AVCodec const *output_codec =
2370  int input_props = 0, output_props = 0;
2371  if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2372  continue;
2373  if (output_codec)
2374  output_descriptor = avcodec_descriptor_get(output_codec->id);
2375  if (input_descriptor)
2376  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2377  if (output_descriptor)
2378  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2379  if (subtitle_codec_name ||
2380  input_props & output_props ||
2381  // Map dvb teletext which has neither property to any output subtitle encoder
2382  input_descriptor && output_descriptor &&
2383  (!input_descriptor->props ||
2384  !output_descriptor->props)) {
2385  new_subtitle_stream(o, oc, i);
2386  break;
2387  }
2388  }
2389  }
2390  /* Data only if codec id match */
2391  if (!o->data_disable ) {
2393  for (i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) {
2394  if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2395  continue;
2396  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2398  new_data_stream(o, oc, i);
2399  }
2400  }
2401  } else {
2402  for (i = 0; i < o->nb_stream_maps; i++) {
2403  StreamMap *map = &o->stream_maps[i];
2404 
2405  if (map->disabled)
2406  continue;
2407 
2408  if (map->linklabel) {
2409  FilterGraph *fg;
2410  OutputFilter *ofilter = NULL;
2411  int j, k;
2412 
2413  for (j = 0; j < nb_filtergraphs; j++) {
2414  fg = filtergraphs[j];
2415  for (k = 0; k < fg->nb_outputs; k++) {
2416  AVFilterInOut *out = fg->outputs[k]->out_tmp;
2417  if (out && !strcmp(out->name, map->linklabel)) {
2418  ofilter = fg->outputs[k];
2419  goto loop_end;
2420  }
2421  }
2422  }
2423 loop_end:
2424  if (!ofilter) {
2425  av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2426  "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2427  exit_program(1);
2428  }
2429  init_output_filter(ofilter, o, oc);
2430  } else {
2431  int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2432 
2433  ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
2434  if (ist->user_set_discard == AVDISCARD_ALL) {
2435  av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
2436  map->file_index, map->stream_index);
2437  exit_program(1);
2438  }
2440  continue;
2442  continue;
2444  continue;
2445  if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2446  continue;
2447 
2448  ost = NULL;
2449  switch (ist->st->codecpar->codec_type) {
2450  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2451  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2452  case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2453  case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2454  case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2455  case AVMEDIA_TYPE_UNKNOWN:
2456  if (copy_unknown_streams) {
2457  ost = new_unknown_stream (o, oc, src_idx);
2458  break;
2459  }
2460  default:
2462  "Cannot map stream #%d:%d - unsupported type.\n",
2463  map->file_index, map->stream_index);
2464  if (!ignore_unknown_streams) {
2466  "If you want unsupported types ignored instead "
2467  "of failing, please use the -ignore_unknown option\n"
2468  "If you want them copied, please use -copy_unknown\n");
2469  exit_program(1);
2470  }
2471  }
2472  if (ost)
2473  ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
2474  + map->sync_stream_index];
2475  }
2476  }
2477  }
2478 
2479  /* handle attached files */
2480  for (i = 0; i < o->nb_attachments; i++) {
2481  AVIOContext *pb;
2482  uint8_t *attachment;
2483  const char *p;
2484  int64_t len;
2485 
2486  if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
2487  av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
2488  o->attachments[i]);
2489  exit_program(1);
2490  }
2491  if ((len = avio_size(pb)) <= 0) {
2492  av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
2493  o->attachments[i]);
2494  exit_program(1);
2495  }
2496  if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
2497  !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
2498  av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
2499  o->attachments[i]);
2500  exit_program(1);
2501  }
2502  avio_read(pb, attachment, len);
2503  memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
2504 
2505  ost = new_attachment_stream(o, oc, -1);
2506  ost->stream_copy = 0;
2507  ost->attachment_filename = o->attachments[i];
2508  ost->st->codecpar->extradata = attachment;
2509  ost->st->codecpar->extradata_size = len;
2510 
2511  p = strrchr(o->attachments[i], '/');
2512  av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
2513  avio_closep(&pb);
2514  }
2515 
2516 #if FF_API_LAVF_AVCTX
2517  for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file
2518  AVDictionaryEntry *e;
2519  ost = output_streams[i];
2520 
2521  if ((ost->stream_copy || ost->attachment_filename)
2522  && (e = av_dict_get(o->g->codec_opts, "flags", NULL, AV_DICT_IGNORE_SUFFIX))
2523  && (!e->key[5] || check_stream_specifier(oc, ost->st, e->key+6)))
2524  if (av_opt_set(ost->st->codec, "flags", e->value, 0) < 0)
2525  exit_program(1);
2526  }
2527 #endif
2528 
2529  if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2530  av_dump_format(oc, nb_output_files - 1, oc->url, 1);
2531  av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
2532  exit_program(1);
2533  }
2534 
2535  /* check if all codec options have been used */
2536  unused_opts = strip_specifiers(o->g->codec_opts);
2537  for (i = of->ost_index; i < nb_output_streams; i++) {
2538  e = NULL;
2539  while ((e = av_dict_get(output_streams[i]->encoder_opts, "", e,
2541  av_dict_set(&unused_opts, e->key, NULL, 0);
2542  }
2543 
2544  e = NULL;
2545  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
2546  const AVClass *class = avcodec_get_class();
2547  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2549  const AVClass *fclass = avformat_get_class();
2550  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2552  if (!option || foption)
2553  continue;
2554 
2555 
2556  if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2557  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
2558  "output file #%d (%s) is not an encoding option.\n", e->key,
2559  option->help ? option->help : "", nb_output_files - 1,
2560  filename);
2561  exit_program(1);
2562  }
2563 
2564  // gop_timecode is injected by generic code but not always used
2565  if (!strcmp(e->key, "gop_timecode"))
2566  continue;
2567 
2568  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
2569  "output file #%d (%s) has not been used for any stream. The most "
2570  "likely reason is either wrong type (e.g. a video option with "
2571  "no video streams) or that it is a private option of some encoder "
2572  "which was not actually used for any stream.\n", e->key,
2573  option->help ? option->help : "", nb_output_files - 1, filename);
2574  }
2575  av_dict_free(&unused_opts);
2576 
2577  /* set the decoding_needed flags and create simple filtergraphs */
2578  for (i = of->ost_index; i < nb_output_streams; i++) {
2580 
2581  if (ost->encoding_needed && ost->source_index >= 0) {
2582  InputStream *ist = input_streams[ost->source_index];
2584 
2585  if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2587  err = init_simple_filtergraph(ist, ost);
2588  if (err < 0) {
2590  "Error initializing a simple filtergraph between streams "
2591  "%d:%d->%d:%d\n", ist->file_index, ost->source_index,
2592  nb_output_files - 1, ost->st->index);
2593  exit_program(1);
2594  }
2595  }
2596  }
2597 
2598  /* set the filter output constraints */
2599  if (ost->filter) {
2600  OutputFilter *f = ost->filter;
2601  int count;
2602  switch (ost->enc_ctx->codec_type) {
2603  case AVMEDIA_TYPE_VIDEO:
2604  f->frame_rate = ost->frame_rate;
2605  f->width = ost->enc_ctx->width;
2606  f->height = ost->enc_ctx->height;
2607  if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2608  f->format = ost->enc_ctx->pix_fmt;
2609  } else if (ost->enc->pix_fmts) {
2610  count = 0;
2611  while (ost->enc->pix_fmts[count] != AV_PIX_FMT_NONE)
2612  count++;
2613  f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2614  if (!f->formats)
2615  exit_program(1);
2616  memcpy(f->formats, ost->enc->pix_fmts, (count + 1) * sizeof(*f->formats));
2617  }
2618  break;
2619  case AVMEDIA_TYPE_AUDIO:
2620  if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2621  f->format = ost->enc_ctx->sample_fmt;
2622  } else if (ost->enc->sample_fmts) {
2623  count = 0;
2624  while (ost->enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
2625  count++;
2626  f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2627  if (!f->formats)
2628  exit_program(1);
2629  memcpy(f->formats, ost->enc->sample_fmts, (count + 1) * sizeof(*f->formats));
2630  }
2631  if (ost->enc_ctx->sample_rate) {
2632  f->sample_rate = ost->enc_ctx->sample_rate;
2633  } else if (ost->enc->supported_samplerates) {
2634  count = 0;
2635  while (ost->enc->supported_samplerates[count])
2636  count++;
2637  f->sample_rates = av_mallocz_array(count + 1, sizeof(*f->sample_rates));
2638  if (!f->sample_rates)
2639  exit_program(1);
2640  memcpy(f->sample_rates, ost->enc->supported_samplerates,
2641  (count + 1) * sizeof(*f->sample_rates));
2642  }
2643  if (ost->enc_ctx->channels) {
2644  f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels);
2645  } else if (ost->enc->channel_layouts) {
2646  count = 0;
2647  while (ost->enc->channel_layouts[count])
2648  count++;
2649  f->channel_layouts = av_mallocz_array(count + 1, sizeof(*f->channel_layouts));
2650  if (!f->channel_layouts)
2651  exit_program(1);
2652  memcpy(f->channel_layouts, ost->enc->channel_layouts,
2653  (count + 1) * sizeof(*f->channel_layouts));
2654  }
2655  break;
2656  }
2657  }
2658  }
2659 
2660  /* check filename in case of an image number is expected */
2661  if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2662  if (!av_filename_number_test(oc->url)) {
2663  print_error(oc->url, AVERROR(EINVAL));
2664  exit_program(1);
2665  }
2666  }
2667 
2670  "No input streams but output needs an input stream\n");
2671  exit_program(1);
2672  }
2673 
2674  if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2675  /* test if it already exists to avoid losing precious files */
2676  assert_file_overwrite(filename);
2677 
2678  /* open the file */
2679  if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2680  &oc->interrupt_callback,
2681  &of->opts)) < 0) {
2682  print_error(filename, err);
2683  exit_program(1);
2684  }
2685  } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
2686  assert_file_overwrite(filename);
2687 
2688  if (o->mux_preload) {
2689  av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2690  }
2691  oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2692 
2693  /* copy metadata */
2694  for (i = 0; i < o->nb_metadata_map; i++) {
2695  char *p;
2696  int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2697 
2698  if (in_file_index >= nb_input_files) {
2699  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
2700  exit_program(1);
2701  }
2702  copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc,
2703  in_file_index >= 0 ?
2704  input_files[in_file_index]->ctx : NULL, o);
2705  }
2706 
2707  /* copy chapters */
2708  if (o->chapters_input_file >= nb_input_files) {
2709  if (o->chapters_input_file == INT_MAX) {
2710  /* copy chapters from the first input file that has them*/
2711  o->chapters_input_file = -1;
2712  for (i = 0; i < nb_input_files; i++)
2713  if (input_files[i]->ctx->nb_chapters) {
2714  o->chapters_input_file = i;
2715  break;
2716  }
2717  } else {
2718  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2719  o->chapters_input_file);
2720  exit_program(1);
2721  }
2722  }
2723  if (o->chapters_input_file >= 0)
2726 
2727  /* copy global metadata by default */
2731  if(o->recording_time != INT64_MAX)
2732  av_dict_set(&oc->metadata, "duration", NULL, 0);
2733  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2734  av_dict_set(&oc->metadata, "company_name", NULL, 0);
2735  av_dict_set(&oc->metadata, "product_name", NULL, 0);
2736  av_dict_set(&oc->metadata, "product_version", NULL, 0);
2737  }
2738  if (!o->metadata_streams_manual)
2739  for (i = of->ost_index; i < nb_output_streams; i++) {
2740  InputStream *ist;
2741  if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
2742  continue;
2745  if (!output_streams[i]->stream_copy) {
2746  av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
2747  }
2748  }
2749 
2750  /* process manually set programs */
2751  for (i = 0; i < o->nb_program; i++) {
2752  const char *p = o->program[i].u.str;
2753  int progid = i+1;
2754  AVProgram *program;
2755 
2756  while(*p) {
2757  const char *p2 = av_get_token(&p, ":");
2758  const char *to_dealloc = p2;
2759  char *key;
2760  if (!p2)
2761  break;
2762 
2763  if(*p) p++;
2764 
2765  key = av_get_token(&p2, "=");
2766  if (!key || !*p2) {
2767  av_freep(&to_dealloc);
2768  av_freep(&key);
2769  break;
2770  }
2771  p2++;
2772 
2773  if (!strcmp(key, "program_num"))
2774  progid = strtol(p2, NULL, 0);
2775  av_freep(&to_dealloc);
2776  av_freep(&key);
2777  }
2778 
2779  program = av_new_program(oc, progid);
2780  if (!program)
2781  report_and_exit(AVERROR(ENOMEM));
2782 
2783  p = o->program[i].u.str;
2784  while(*p) {
2785  const char *p2 = av_get_token(&p, ":");
2786  const char *to_dealloc = p2;
2787  char *key;
2788  if (!p2)
2789  break;
2790  if(*p) p++;
2791 
2792  key = av_get_token(&p2, "=");
2793  if (!key) {
2795  "No '=' character in program string %s.\n",
2796  p2);
2797  exit_program(1);
2798  }
2799  if (!*p2)
2800  exit_program(1);
2801  p2++;
2802 
2803  if (!strcmp(key, "title")) {
2804  av_dict_set(&program->metadata, "title", p2, 0);
2805  } else if (!strcmp(key, "program_num")) {
2806  } else if (!strcmp(key, "st")) {
2807  int st_num = strtol(p2, NULL, 0);
2808  av_program_add_stream_index(oc, progid, st_num);
2809  } else {
2810  av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
2811  exit_program(1);
2812  }
2813  av_freep(&to_dealloc);
2814  av_freep(&key);
2815  }
2816  }
2817 
2818  /* process manually set metadata */
2819  for (i = 0; i < o->nb_metadata; i++) {
2820  AVDictionary **m;
2821  char type, *val;
2822  const char *stream_spec;
2823  int index = 0, j, ret = 0;
2824 
2825  val = strchr(o->metadata[i].u.str, '=');
2826  if (!val) {
2827  av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2828  o->metadata[i].u.str);
2829  exit_program(1);
2830  }
2831  *val++ = 0;
2832 
2833  parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
2834  if (type == 's') {
2835  for (j = 0; j < oc->nb_streams; j++) {
2837  if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2838  if (!strcmp(o->metadata[i].u.str, "rotate")) {
2839  char *tail;
2840  double theta = av_strtod(val, &tail);
2841  if (!*tail) {
2842  ost->rotate_overridden = 1;
2843  ost->rotate_override_value = theta;
2844  }
2845  } else {
2846  av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
2847  }
2848  } else if (ret < 0)
2849  exit_program(1);
2850  }
2851  }
2852  else {
2853  switch (type) {
2854  case 'g':
2855  m = &oc->metadata;
2856  break;
2857  case 'c':
2858  if (index < 0 || index >= oc->nb_chapters) {
2859  av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
2860  exit_program(1);
2861  }
2862  m = &oc->chapters[index]->metadata;
2863  break;
2864  case 'p':
2865  if (index < 0 || index >= oc->nb_programs) {
2866  av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
2867  exit_program(1);
2868  }
2869  m = &oc->programs[index]->metadata;
2870  break;
2871  default:
2872  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
2873  exit_program(1);
2874  }
2875  av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
2876  }
2877  }
2878 
2879  return 0;
2880 }
2881 
2882 static int opt_target(void *optctx, const char *opt, const char *arg)
2883 {
2884  OptionsContext *o = optctx;
2885  enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
2886  static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
2887 
2888  if (!strncmp(arg, "pal-", 4)) {
2889  norm = PAL;
2890  arg += 4;
2891  } else if (!strncmp(arg, "ntsc-", 5)) {
2892  norm = NTSC;
2893  arg += 5;
2894  } else if (!strncmp(arg, "film-", 5)) {
2895  norm = FILM;
2896  arg += 5;
2897  } else {
2898  /* Try to determine PAL/NTSC by peeking in the input files */
2899  if (nb_input_files) {
2900  int i, j;
2901  for (j = 0; j < nb_input_files; j++) {
2902  for (i = 0; i < input_files[j]->nb_streams; i++) {
2903  AVStream *st = input_files[j]->ctx->streams[i];
2904  int64_t fr;
2906  continue;
2907  fr = st->time_base.den * 1000LL / st->time_base.num;
2908  if (fr == 25000) {
2909  norm = PAL;
2910  break;
2911  } else if ((fr == 29970) || (fr == 23976)) {
2912  norm = NTSC;
2913  break;
2914  }
2915  }
2916  if (norm != UNKNOWN)
2917  break;
2918  }
2919  }
2920  if (norm != UNKNOWN)
2921  av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
2922  }
2923 
2924  if (norm == UNKNOWN) {
2925  av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
2926  av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
2927  av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
2928  exit_program(1);
2929  }
2930 
2931  if (!strcmp(arg, "vcd")) {
2932  opt_video_codec(o, "c:v", "mpeg1video");
2933  opt_audio_codec(o, "c:a", "mp2");
2934  parse_option(o, "f", "vcd", options);
2935 
2936  parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
2937  parse_option(o, "r", frame_rates[norm], options);
2938  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2939 
2940  opt_default(NULL, "b:v", "1150000");
2941  opt_default(NULL, "maxrate:v", "1150000");
2942  opt_default(NULL, "minrate:v", "1150000");
2943  opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
2944 
2945  opt_default(NULL, "b:a", "224000");
2946  parse_option(o, "ar", "44100", options);
2947  parse_option(o, "ac", "2", options);
2948 
2949  opt_default(NULL, "packetsize", "2324");
2950  opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
2951 
2952  /* We have to offset the PTS, so that it is consistent with the SCR.
2953  SCR starts at 36000, but the first two packs contain only padding
2954  and the first pack from the other stream, respectively, may also have
2955  been written before.
2956  So the real data starts at SCR 36000+3*1200. */
2957  o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
2958  } else if (!strcmp(arg, "svcd")) {
2959 
2960  opt_video_codec(o, "c:v", "mpeg2video");
2961  opt_audio_codec(o, "c:a", "mp2");
2962  parse_option(o, "f", "svcd", options);
2963 
2964  parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
2965  parse_option(o, "r", frame_rates[norm], options);
2966  parse_option(o, "pix_fmt", "yuv420p", options);
2967  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2968 
2969  opt_default(NULL, "b:v", "2040000");
2970  opt_default(NULL, "maxrate:v", "2516000");
2971  opt_default(NULL, "minrate:v", "0"); // 1145000;
2972  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2973  opt_default(NULL, "scan_offset", "1");
2974 
2975  opt_default(NULL, "b:a", "224000");
2976  parse_option(o, "ar", "44100", options);
2977 
2978  opt_default(NULL, "packetsize", "2324");
2979 
2980  } else if (!strcmp(arg, "dvd")) {
2981 
2982  opt_video_codec(o, "c:v", "mpeg2video");
2983  opt_audio_codec(o, "c:a", "ac3");
2984  parse_option(o, "f", "dvd", options);
2985 
2986  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2987  parse_option(o, "r", frame_rates[norm], options);
2988  parse_option(o, "pix_fmt", "yuv420p", options);
2989  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2990 
2991  opt_default(NULL, "b:v", "6000000");
2992  opt_default(NULL, "maxrate:v", "9000000");
2993  opt_default(NULL, "minrate:v", "0"); // 1500000;
2994  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2995 
2996  opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
2997  opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
2998 
2999  opt_default(NULL, "b:a", "448000");
3000  parse_option(o, "ar", "48000", options);
3001 
3002  } else if (!strncmp(arg, "dv", 2)) {
3003 
3004  parse_option(o, "f", "dv", options);
3005 
3006  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
3007  parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
3008  norm == PAL ? "yuv420p" : "yuv411p", options);
3009  parse_option(o, "r", frame_rates[norm], options);
3010 
3011  parse_option(o, "ar", "48000", options);
3012  parse_option(o, "ac", "2", options);
3013 
3014  } else {
3015  av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
3016  return AVERROR(EINVAL);
3017  }
3018 
3021 
3022  return 0;
3023 }
3024 
3025 static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
3026 {
3029  return 0;
3030 }
3031 
3032 static int opt_vstats(void *optctx, const char *opt, const char *arg)
3033 {
3034  char filename[40];
3035  time_t today2 = time(NULL);
3036  struct tm *today = localtime(&today2);
3037 
3038  if (!today) { // maybe tomorrow
3039  av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
3040  exit_program(1);
3041  }
3042 
3043  snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
3044  today->tm_sec);
3045  return opt_vstats_file(NULL, opt, filename);
3046 }
3047 
3048 static int opt_video_frames(void *optctx, const char *opt, const char *arg)
3049 {
3050  OptionsContext *o = optctx;
3051  return parse_option(o, "frames:v", arg, options);
3052 }
3053 
3054 static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
3055 {
3056  OptionsContext *o = optctx;
3057  return parse_option(o, "frames:a", arg, options);
3058 }
3059 
3060 static int opt_data_frames(void *optctx, const char *opt, const char *arg)
3061 {
3062  OptionsContext *o = optctx;
3063  return parse_option(o, "frames:d", arg, options);
3064 }
3065 
3066 static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
3067 {
3068  int ret;
3069  AVDictionary *cbak = codec_opts;
3070  AVDictionary *fbak = format_opts;
3071  codec_opts = NULL;
3072  format_opts = NULL;
3073 
3074  ret = opt_default(NULL, opt, arg);
3075 
3076  av_dict_copy(&o->g->codec_opts , codec_opts, 0);
3080  codec_opts = cbak;
3081  format_opts = fbak;
3082 
3083  return ret;
3084 }
3085 
3086 static int opt_preset(void *optctx, const char *opt, const char *arg)
3087 {
3088  OptionsContext *o = optctx;
3089  FILE *f=NULL;
3090  char filename[1000], line[1000], tmp_line[1000];
3091  const char *codec_name = NULL;
3092  int depth = o->depth;
3093 
3094  if (depth > 2) {
3095  av_log(NULL, AV_LOG_ERROR, "too deep recursion\n");
3096  return AVERROR(EINVAL);
3097  }
3098 
3099  tmp_line[0] = *opt;
3100  tmp_line[1] = 0;
3101  MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
3102 
3103  if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
3104  if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
3105  av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
3106  }else
3107  av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
3108  exit_program(1);
3109  }
3110 
3111  o->depth ++;
3112  while (fgets(line, sizeof(line), f)) {
3113  char *key = tmp_line, *value, *endptr;
3114 
3115  if (strcspn(line, "#\n\r") == 0)
3116  continue;
3117  av_strlcpy(tmp_line, line, sizeof(tmp_line));
3118  if (!av_strtok(key, "=", &value) ||
3119  !av_strtok(value, "\r\n", &endptr)) {
3120  av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
3121  exit_program(1);
3122  }
3123  av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
3124 
3125  if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
3126  else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
3127  else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
3128  else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
3129  else if (opt_default_new(o, key, value) < 0) {
3130  av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
3131  filename, line, key, value);
3132  exit_program(1);
3133  }
3134  }
3135 
3136  o->depth = depth;
3137  fclose(f);
3138 
3139  return 0;
3140 }
3141 
3142 static int opt_old2new(void *optctx, const char *opt, const char *arg)
3143 {
3144  OptionsContext *o = optctx;
3145  int ret;
3146  char *s = av_asprintf("%s:%c", opt + 1, *opt);
3147  if (!s)
3148  return AVERROR(ENOMEM);
3149  ret = parse_option(o, s, arg, options);
3150  av_free(s);
3151  return ret;
3152 }
3153 
3154 static int opt_bitrate(void *optctx, const char *opt, const char *arg)
3155 {
3156  OptionsContext *o = optctx;
3157 
3158  if(!strcmp(opt, "ab")){
3159  av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
3160  return 0;
3161  } else if(!strcmp(opt, "b")){
3162  av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
3163  av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
3164  return 0;
3165  }
3166  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3167  return 0;
3168 }
3169 
3170 static int opt_qscale(void *optctx, const char *opt, const char *arg)
3171 {
3172  OptionsContext *o = optctx;
3173  char *s;
3174  int ret;
3175  if(!strcmp(opt, "qscale")){
3176  av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
3177  return parse_option(o, "q:v", arg, options);
3178  }
3179  s = av_asprintf("q%s", opt + 6);
3180  if (!s)
3181  return AVERROR(ENOMEM);
3182  ret = parse_option(o, s, arg, options);
3183  av_free(s);
3184  return ret;
3185 }
3186 
3187 static int opt_profile(void *optctx, const char *opt, const char *arg)
3188 {
3189  OptionsContext *o = optctx;
3190  if(!strcmp(opt, "profile")){
3191  av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
3192  av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
3193  return 0;
3194  }
3195  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3196  return 0;
3197 }
3198 
3199 static int opt_video_filters(void *optctx, const char *opt, const char *arg)
3200 {
3201  OptionsContext *o = optctx;
3202  return parse_option(o, "filter:v", arg, options);
3203 }
3204 
3205 static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
3206 {
3207  OptionsContext *o = optctx;
3208  return parse_option(o, "filter:a", arg, options);
3209 }
3210 
3211 static int opt_vsync(void *optctx, const char *opt, const char *arg)
3212 {
3213  if (!av_strcasecmp(arg, "cfr")) video_sync_method = VSYNC_CFR;
3214  else if (!av_strcasecmp(arg, "vfr")) video_sync_method = VSYNC_VFR;
3215  else if (!av_strcasecmp(arg, "passthrough")) video_sync_method = VSYNC_PASSTHROUGH;
3216  else if (!av_strcasecmp(arg, "drop")) video_sync_method = VSYNC_DROP;
3217 
3220  return 0;
3221 }
3222 
3223 static int opt_timecode(void *optctx, const char *opt, const char *arg)
3224 {
3225  OptionsContext *o = optctx;
3226  int ret;
3227  char *tcr = av_asprintf("timecode=%s", arg);
3228  if (!tcr)
3229  return AVERROR(ENOMEM);
3230  ret = parse_option(o, "metadata:g", tcr, options);
3231  if (ret >= 0)
3232  ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
3233  av_free(tcr);
3234  return ret;
3235 }
3236 
3237 static int opt_channel_layout(void *optctx, const char *opt, const char *arg)
3238 {
3239  OptionsContext *o = optctx;
3240  char layout_str[32];
3241  char *stream_str;
3242  char *ac_str;
3243  int ret, channels, ac_str_size;
3244  uint64_t layout;
3245 
3247  if (!layout) {
3248  av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg);
3249  return AVERROR(EINVAL);
3250  }
3251  snprintf(layout_str, sizeof(layout_str), "%"PRIu64, layout);
3252  ret = opt_default_new(o, opt, layout_str);
3253  if (ret < 0)
3254  return ret;
3255 
3256  /* set 'ac' option based on channel layout */
3258  snprintf(layout_str, sizeof(layout_str), "%d", channels);
3259  stream_str = strchr(opt, ':');
3260  ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
3261  ac_str = av_mallocz(ac_str_size);
3262  if (!ac_str)
3263  return AVERROR(ENOMEM);
3264  av_strlcpy(ac_str, "ac", 3);
3265  if (stream_str)
3266  av_strlcat(ac_str, stream_str, ac_str_size);
3267  ret = parse_option(o, ac_str, layout_str, options);
3268  av_free(ac_str);
3269 
3270  return ret;
3271 }
3272 
3273 static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
3274 {
3275  OptionsContext *o = optctx;
3276  return parse_option(o, "q:a", arg, options);
3277 }
3278 
3279 static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
3280 {
3282  if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
3283  return AVERROR(ENOMEM);
3286  if (!filtergraphs[nb_filtergraphs - 1]->graph_desc)
3287  return AVERROR(ENOMEM);
3288 
3290 
3291  return 0;
3292 }
3293 
3294 static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
3295 {
3296  uint8_t *graph_desc = read_file(arg);
3297  if (!graph_desc)
3298  return AVERROR(EINVAL);
3299 
3301  if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
3302  return AVERROR(ENOMEM);
3304  filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc;
3305 
3307 
3308  return 0;
3309 }
3310 
3311 void show_help_default(const char *opt, const char *arg)
3312 {
3313  /* per-file options have at least one of those set */
3314  const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
3315  int show_advanced = 0, show_avoptions = 0;
3316 
3317  if (opt && *opt) {
3318  if (!strcmp(opt, "long"))
3319  show_advanced = 1;
3320  else if (!strcmp(opt, "full"))
3321  show_advanced = show_avoptions = 1;
3322  else
3323  av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
3324  }
3325 
3326  show_usage();
3327 
3328  printf("Getting help:\n"
3329  " -h -- print basic options\n"
3330  " -h long -- print more options\n"
3331  " -h full -- print all options (including all format and codec specific options, very long)\n"
3332  " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
3333  " See man %s for detailed description of the options.\n"
3334  "\n", program_name);
3335 
3336  show_help_options(options, "Print help / information / capabilities:",
3337  OPT_EXIT, 0, 0);
3338 
3339  show_help_options(options, "Global options (affect whole program "
3340  "instead of just one file):",
3341  0, per_file | OPT_EXIT | OPT_EXPERT, 0);
3342  if (show_advanced)
3343  show_help_options(options, "Advanced global options:", OPT_EXPERT,
3344  per_file | OPT_EXIT, 0);
3345 
3346  show_help_options(options, "Per-file main options:", 0,
3348  OPT_EXIT, per_file);
3349  if (show_advanced)
3350  show_help_options(options, "Advanced per-file options:",
3351  OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file);
3352 
3353  show_help_options(options, "Video options:",
3355  if (show_advanced)
3356  show_help_options(options, "Advanced Video options:",
3358 
3359  show_help_options(options, "Audio options:",
3361  if (show_advanced)
3362  show_help_options(options, "Advanced Audio options:",
3364  show_help_options(options, "Subtitle options:",
3365  OPT_SUBTITLE, 0, 0);
3366  printf("\n");
3367 
3368  if (show_avoptions) {
3372 #if CONFIG_SWSCALE
3374 #endif
3375 #if CONFIG_SWRESAMPLE
3377 #endif
3380  }
3381 }
3382 
3383 void show_usage(void)
3384 {
3385  av_log(NULL, AV_LOG_INFO, "Hyper fast Audio and Video encoder\n");
3386  av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
3387  av_log(NULL, AV_LOG_INFO, "\n");
3388 }
3389 
3390 enum OptGroup {
3391  GROUP_OUTFILE,
3392  GROUP_INFILE,
3393 };
3394 
3395 static const OptionGroupDef groups[] = {
3396  [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
3397  [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
3398 };
3399 
3400 static int open_files(OptionGroupList *l, const char *inout,
3401  int (*open_file)(OptionsContext*, const char*))
3402 {
3403  int i, ret;
3404 
3405  for (i = 0; i < l->nb_groups; i++) {
3406  OptionGroup *g = &l->groups[i];
3407  OptionsContext o;
3408 
3409  init_options(&o);
3410  o.g = g;
3411 
3412  ret = parse_optgroup(&o, g);
3413  if (ret < 0) {
3414  av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
3415  "%s.\n", inout, g->arg);
3416  uninit_options(&o);
3417  return ret;
3418  }
3419 
3420  av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
3421  ret = open_file(&o, g->arg);
3422  uninit_options(&o);
3423  if (ret < 0) {
3424  av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
3425  inout, g->arg);
3426  return ret;
3427  }
3428  av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
3429  }
3430 
3431  return 0;
3432 }
3433 
3434 int ffmpeg_parse_options(int argc, char **argv)
3435 {
3436  OptionParseContext octx;
3437  uint8_t error[128];
3438  int ret;
3439 
3440  memset(&octx, 0, sizeof(octx));
3441 
3442  /* split the commandline into an internal representation */
3443  ret = split_commandline(&octx, argc, argv, options, groups,
3444  FF_ARRAY_ELEMS(groups));
3445  if (ret < 0) {
3446  av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
3447  goto fail;
3448  }
3449 
3450  /* apply global options */
3451  ret = parse_optgroup(NULL, &octx.global_opts);
3452  if (ret < 0) {
3453  av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
3454  goto fail;
3455  }
3456 
3457  /* configure terminal and setup signal handlers */
3458  term_init();
3459 
3460  /* open input files */
3461  ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file);
3462  if (ret < 0) {
3463  av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
3464  goto fail;
3465  }
3466 
3467  /* create the complex filtergraphs */
3468  ret = init_complex_filters();
3469  if (ret < 0) {
3470  av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
3471  goto fail;
3472  }
3473 
3474  /* open output files */
3475  ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file);
3476  if (ret < 0) {
3477  av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
3478  goto fail;
3479  }
3480 
3482 
3483 fail:
3484  uninit_parse_context(&octx);
3485  if (ret < 0) {
3486  av_strerror(ret, error, sizeof(error));
3487  av_log(NULL, AV_LOG_FATAL, "%s\n", error);
3488  }
3489  return ret;
3490 }
3491 
3492 static int opt_progress(void *optctx, const char *opt, const char *arg)
3493 {
3494  AVIOContext *avio = NULL;
3495  int ret;
3496 
3497  if (!strcmp(arg, "-"))
3498  arg = "pipe:";
3499  ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
3500  if (ret < 0) {
3501  av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
3502  arg, av_err2str(ret));
3503  return ret;
3504  }
3505  progress_avio = avio;
3506  return 0;
3507 }
3508 
3509 #define OFFSET(x) offsetof(OptionsContext, x)
3510 const OptionDef options[] = {
3511  /* main options */
3513  { "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
3514  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
3515  "force format", "fmt" },
3516  { "y", OPT_BOOL, { &file_overwrite },
3517  "overwrite output files" },
3518  { "n", OPT_BOOL, { &no_file_overwrite },
3519  "never overwrite output files" },
3520  { "ignore_unknown", OPT_BOOL, { &ignore_unknown_streams },
3521  "Ignore unknown stream types" },
3522  { "copy_unknown", OPT_BOOL | OPT_EXPERT, { &copy_unknown_streams },
3523  "Copy unknown stream types" },
3524  { "c", HAS_ARG | OPT_STRING | OPT_SPEC |
3525  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3526  "codec name", "codec" },
3527  { "codec", HAS_ARG | OPT_STRING | OPT_SPEC |
3528  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3529  "codec name", "codec" },
3530  { "pre", HAS_ARG | OPT_STRING | OPT_SPEC |
3531  OPT_OUTPUT, { .off = OFFSET(presets) },
3532  "preset name", "preset" },
3533  { "map", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3534  OPT_OUTPUT, { .func_arg = opt_map },
3535  "set input stream mapping",
3536  "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
3537  { "map_channel", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map_channel },
3538  "map an audio channel from one stream to another", "file.stream.channel[:syncfile.syncstream]" },
3539  { "map_metadata", HAS_ARG | OPT_STRING | OPT_SPEC |
3540  OPT_OUTPUT, { .off = OFFSET(metadata_map) },
3541  "set metadata information of outfile from infile",
3542  "outfile[,metadata]:infile[,metadata]" },
3543  { "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
3544  OPT_OUTPUT, { .off = OFFSET(chapters_input_file) },
3545  "set chapters mapping", "input_file_index" },
3546  { "t", HAS_ARG | OPT_TIME | OPT_OFFSET |
3547  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) },
3548  "record or transcode \"duration\" seconds of audio/video",
3549  "duration" },
3550  { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) },
3551  "record or transcode stop time", "time_stop" },
3552  { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) },
3553  "set the limit file size in bytes", "limit_size" },
3554  { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |
3555  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(start_time) },
3556  "set the start time offset", "time_off" },
3557  { "sseof", HAS_ARG | OPT_TIME | OPT_OFFSET |
3558  OPT_INPUT, { .off = OFFSET(start_time_eof) },
3559  "set the start time offset relative to EOF", "time_off" },
3560  { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
3561  OPT_INPUT, { .off = OFFSET(seek_timestamp) },
3562  "enable/disable seeking by timestamp with -ss" },
3563  { "accurate_seek", OPT_BOOL | OPT_OFFSET | OPT_EXPERT |
3564  OPT_INPUT, { .off = OFFSET(accurate_seek) },
3565  "enable/disable accurate seeking with -ss" },
3566  { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET |
3567  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_ts_offset) },
3568  "set the input ts offset", "time_off" },
3569  { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC |
3570  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(ts_scale) },
3571  "set the input ts scale", "scale" },
3572  { "timestamp", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_recording_timestamp },
3573  "set the recording timestamp ('now' to set the current time)", "time" },
3574  { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(metadata) },
3575  "add metadata", "string=string" },
3576  { "program", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(program) },
3577  "add program with specified streams", "title=string:st=number..." },
3578  { "dframes", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3579  OPT_OUTPUT, { .func_arg = opt_data_frames },
3580  "set the number of data frames to output", "number" },
3581  { "benchmark", OPT_BOOL | OPT_EXPERT, { &do_benchmark },
3582  "add timings for benchmarking" },
3583  { "benchmark_all", OPT_BOOL | OPT_EXPERT, { &do_benchmark_all },
3584  "add timings for each task" },
3585  { "progress", HAS_ARG | OPT_EXPERT, { .func_arg = opt_progress },
3586  "write program-readable progress information", "url" },
3587  { "stdin", OPT_BOOL | OPT_EXPERT, { &stdin_interaction },
3588  "enable or disable interaction on standard input" },
3589  { "timelimit", HAS_ARG | OPT_EXPERT, { .func_arg = opt_timelimit },
3590  "set max runtime in seconds in CPU user time", "limit" },
3591  { "dump", OPT_BOOL | OPT_EXPERT, { &do_pkt_dump },
3592  "dump each input packet" },
3593  { "hex", OPT_BOOL | OPT_EXPERT, { &do_hex_dump },
3594  "when dumping packets, also dump the payload" },
3595  { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3596  OPT_INPUT, { .off = OFFSET(rate_emu) },
3597  "read input at native frame rate", "" },
3598  { "target", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_target },
3599  "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
3600  "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")", "type" },
3601  { "vsync", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vsync },
3602  "video sync method", "" },
3603  { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &frame_drop_threshold },
3604  "frame drop threshold", "" },
3605  { "async", HAS_ARG | OPT_INT | OPT_EXPERT, { &audio_sync_method },
3606  "audio sync method", "" },
3607  { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &audio_drift_threshold },
3608  "audio drift threshold", "threshold" },
3609  { "copyts", OPT_BOOL | OPT_EXPERT, { &copy_ts },
3610  "copy timestamps" },
3611  { "start_at_zero", OPT_BOOL | OPT_EXPERT, { &start_at_zero },
3612  "shift input timestamps to start at 0 when using copyts" },
3613  { "copytb", HAS_ARG | OPT_INT | OPT_EXPERT, { &copy_tb },
3614  "copy input stream time base when stream copying", "mode" },
3615  { "shortest", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3616  OPT_OUTPUT, { .off = OFFSET(shortest) },
3617  "finish encoding within shortest input" },
3618  { "bitexact", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3619  OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(bitexact) },
3620  "bitexact mode" },
3621  { "apad", OPT_STRING | HAS_ARG | OPT_SPEC |
3622  OPT_OUTPUT, { .off = OFFSET(apad) },
3623  "audio pad", "" },
3624  { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_delta_threshold },
3625  "timestamp discontinuity delta threshold", "threshold" },
3626  { "dts_error_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_error_threshold },
3627  "timestamp error delta threshold", "threshold" },
3628  { "xerror", OPT_BOOL | OPT_EXPERT, { &exit_on_error },
3629  "exit on error", "error" },
3630  { "abort_on", HAS_ARG | OPT_EXPERT, { .func_arg = opt_abort_on },
3631  "abort on the specified condition flags", "flags" },
3632  { "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3633  OPT_OUTPUT, { .off = OFFSET(copy_initial_nonkeyframes) },
3634  "copy initial non-keyframes" },
3635  { "copypriorss", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(copy_prior_start) },
3636  "copy or discard frames before start time" },
3637  { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(max_frames) },
3638  "set the number of frames to output", "number" },
3639  { "tag", OPT_STRING | HAS_ARG | OPT_SPEC |
3640  OPT_EXPERT | OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(codec_tags) },
3641  "force codec tag/fourcc", "fourcc/tag" },
3642  { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE |
3643  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(qscale) },
3644  "use fixed quality scale (VBR)", "q" },
3645  { "qscale", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3646  OPT_OUTPUT, { .func_arg = opt_qscale },
3647  "use fixed quality scale (VBR)", "q" },
3648  { "profile", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_profile },
3649  "set profile", "profile" },
3650  { "filter", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filters) },
3651  "set stream filtergraph", "filter_graph" },
3652  { "filter_threads", HAS_ARG | OPT_INT, { &filter_nbthreads },
3653  "number of non-complex filter threads" },
3654  { "filter_script", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filter_scripts) },
3655  "read stream filtergraph description from a file", "filename" },
3656  { "reinit_filter", HAS_ARG | OPT_INT | OPT_SPEC | OPT_INPUT, { .off = OFFSET(reinit_filters) },
3657  "reinit filtergraph on input parameter changes", "" },
3658  { "filter_complex", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3659  "create a complex filtergraph", "graph_description" },
3660  { "filter_complex_threads", HAS_ARG | OPT_INT, { &filter_complex_nbthreads },
3661  "number of threads for -filter_complex" },
3662  { "lavfi", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3663  "create a complex filtergraph", "graph_description" },
3664  { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script },
3665  "read complex filtergraph description from a file", "filename" },
3666  { "auto_conversion_filters", OPT_BOOL | OPT_EXPERT, { &auto_conversion_filters },
3667  "enable automatic conversion filters globally" },
3668  { "stats", OPT_BOOL, { &print_stats },
3669  "print progress report during encoding", },
3670  { "stats_period", HAS_ARG | OPT_EXPERT, { .func_arg = opt_stats_period },
3671  "set the period at which ffmpeg updates stats and -progress output", "time" },
3672  { "attach", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3673  OPT_OUTPUT, { .func_arg = opt_attach },
3674  "add an attachment to the output file", "filename" },
3675  { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC |
3676  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(dump_attachment) },
3677  "extract an attachment into a file", "filename" },
3678  { "stream_loop", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_INPUT |
3679  OPT_OFFSET, { .off = OFFSET(loop) }, "set number of times input stream shall be looped", "loop count" },
3680  { "debug_ts", OPT_BOOL | OPT_EXPERT, { &debug_ts },
3681  "print timestamp debugging info" },
3682  { "max_error_rate", HAS_ARG | OPT_FLOAT, { &max_error_rate },
3683  "ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.", "maximum error rate" },
3684  { "discard", OPT_STRING | HAS_ARG | OPT_SPEC |
3685  OPT_INPUT, { .off = OFFSET(discard) },
3686  "discard", "" },
3687  { "disposition", OPT_STRING | HAS_ARG | OPT_SPEC |
3688  OPT_OUTPUT, { .off = OFFSET(disposition) },
3689  "disposition", "" },
3690  { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
3691  { .off = OFFSET(thread_queue_size) },
3692  "set the maximum number of queued packets from the demuxer" },
3693  { "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3694  "read and decode the streams to fill missing information with heuristics" },
3695 
3696  /* video options */
3697  { "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },
3698  "set the number of video frames to output", "number" },
3699  { "r", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3700  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_rates) },
3701  "set frame rate (Hz value, fraction or abbreviation)", "rate" },
3702  { "fpsmax", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3703  OPT_OUTPUT, { .off = OFFSET(max_frame_rates) },
3704  "set max frame rate (Hz value, fraction or abbreviation)", "rate" },
3706  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_sizes) },
3707  "set frame size (WxH or abbreviation)", "size" },
3708  { "aspect", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3709  OPT_OUTPUT, { .off = OFFSET(frame_aspect_ratios) },
3710  "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
3711  { "pix_fmt", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3712  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_pix_fmts) },
3713  "set pixel format", "format" },
3714  { "bits_per_raw_sample", OPT_VIDEO | OPT_INT | HAS_ARG, { &frame_bits_per_raw_sample },
3715  "set the number of bits per raw sample", "number" },
3716  { "intra", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &intra_only },
3717  "deprecated use -g 1" },
3719  "disable video" },
3720  { "rc_override", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3721  OPT_OUTPUT, { .off = OFFSET(rc_overrides) },
3722  "rate control override for specific intervals", "override" },
3723  { "vcodec", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_INPUT |
3724  OPT_OUTPUT, { .func_arg = opt_video_codec },
3725  "force video codec ('copy' to copy stream)", "codec" },
3726  { "sameq", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_sameq },
3727  "Removed" },
3728  { "same_quant", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_sameq },
3729  "Removed" },
3730  { "timecode", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_timecode },
3731  "set initial TimeCode value.", "hh:mm:ss[:;.]ff" },
3732  { "pass", OPT_VIDEO | HAS_ARG | OPT_SPEC | OPT_INT | OPT_OUTPUT, { .off = OFFSET(pass) },
3733  "select the pass number (1 to 3)", "n" },
3734  { "passlogfile", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC |
3735  OPT_OUTPUT, { .off = OFFSET(passlogfiles) },
3736  "select two pass log file name prefix", "prefix" },
3737  { "deinterlace", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_deinterlace },
3738  "this option is deprecated, use the yadif filter instead" },
3739  { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr },
3740  "calculate PSNR of compressed frames" },
3741  { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats },
3742  "dump video coding statistics to file" },
3743  { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file },
3744  "dump video coding statistics to file", "file" },
3745  { "vstats_version", OPT_VIDEO | OPT_INT | HAS_ARG | OPT_EXPERT , { &vstats_version },
3746  "Version of the vstats format to use."},
3747  { "vf", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_filters },
3748  "set video filters", "filter_graph" },
3749  { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3750  OPT_OUTPUT, { .off = OFFSET(intra_matrices) },
3751  "specify intra matrix coeffs", "matrix" },
3752  { "inter_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3753  OPT_OUTPUT, { .off = OFFSET(inter_matrices) },
3754  "specify inter matrix coeffs", "matrix" },
3755  { "chroma_intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3756  OPT_OUTPUT, { .off = OFFSET(chroma_intra_matrices) },
3757  "specify intra matrix coeffs", "matrix" },
3758  { "top", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_INT| OPT_SPEC |
3759  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(top_field_first) },
3760  "top=1/bottom=0/auto=-1 field first", "" },
3761  { "vtag", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3762  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_old2new },
3763  "force video tag/fourcc", "fourcc/tag" },
3764  { "qphist", OPT_VIDEO | OPT_BOOL | OPT_EXPERT , { &qp_hist },
3765  "show QP histogram" },
3766  { "force_fps", OPT_VIDEO | OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3767  OPT_OUTPUT, { .off = OFFSET(force_fps) },
3768  "force the selected framerate, disable the best supported framerate selection" },
3769  { "streamid", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3770  OPT_OUTPUT, { .func_arg = opt_streamid },
3771  "set the value of an outfile streamid", "streamIndex:value" },
3772  { "force_key_frames", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3773  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(forced_key_frames) },
3774  "force key frames at specified timestamps", "timestamps" },
3775  { "ab", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3776  "audio bitrate (please use -b:a)", "bitrate" },
3777  { "b", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3778  "video bitrate (please use -b:v)", "bitrate" },
3779  { "hwaccel", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3780  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccels) },
3781  "use HW accelerated decoding", "hwaccel name" },
3782  { "hwaccel_device", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3783  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_devices) },
3784  "select a device for HW acceleration", "devicename" },
3785  { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3786  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) },
3787  "select output format used with HW accelerated decoding", "format" },
3788 #if CONFIG_VIDEOTOOLBOX
3789  { "videotoolbox_pixfmt", HAS_ARG | OPT_STRING | OPT_EXPERT, { &videotoolbox_pixfmt}, "" },
3790 #endif
3791  { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels },
3792  "show available HW acceleration methods" },
3793  { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC |
3794  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) },
3795  "automatically insert correct rotate filters" },
3796  { "autoscale", HAS_ARG | OPT_BOOL | OPT_SPEC |
3797  OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(autoscale) },
3798  "automatically insert a scale filter at the end of the filter graph" },
3799 
3800  /* audio options */
3801  { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },
3802  "set the number of audio frames to output", "number" },
3803  { "aq", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_qscale },
3804  "set audio quality (codec-specific)", "quality", },
3805  { "ar", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3806  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_sample_rate) },
3807  "set audio sampling rate (in Hz)", "rate" },
3808  { "ac", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3809  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_channels) },
3810  "set number of audio channels", "channels" },
3812  "disable audio" },
3813  { "acodec", OPT_AUDIO | HAS_ARG | OPT_PERFILE |
3814  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_audio_codec },
3815  "force audio codec ('copy' to copy stream)", "codec" },
3816  { "atag", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3817  OPT_OUTPUT, { .func_arg = opt_old2new },
3818  "force audio tag/fourcc", "fourcc/tag" },
3819  { "vol", OPT_AUDIO | HAS_ARG | OPT_INT, { &audio_volume },
3820  "change audio volume (256=normal)" , "volume" },
3821  { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3823  "set sample format", "format" },
3824  { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3825  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_channel_layout },
3826  "set channel layout", "layout" },
3827  { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters },
3828  "set audio filters", "filter_graph" },
3829  { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) },
3830  "set the maximum number of channels to try to guess the channel layout" },
3831 
3832  /* subtitle options */
3834  "disable subtitle" },
3835  { "scodec", OPT_SUBTITLE | HAS_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_subtitle_codec },
3836  "force subtitle codec ('copy' to copy stream)", "codec" },
3837  { "stag", OPT_SUBTITLE | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new }
3838  , "force subtitle tag/fourcc", "fourcc/tag" },
3839  { "fix_sub_duration", OPT_BOOL | OPT_EXPERT | OPT_SUBTITLE | OPT_SPEC | OPT_INPUT, { .off = OFFSET(fix_sub_duration) },
3840  "fix subtitles duration" },
3841  { "canvas_size", OPT_SUBTITLE | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_INPUT, { .off = OFFSET(canvas_sizes) },
3842  "set canvas size (WxH or abbreviation)", "size" },
3843 
3844  /* grab options */
3845  { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_video_channel },
3846  "deprecated, use -channel", "channel" },
3847  { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_video_standard },
3848  "deprecated, use -standard", "standard" },
3849  { "isync", OPT_BOOL | OPT_EXPERT, { &input_sync }, "this option is deprecated and does nothing", "" },
3850 
3851  /* muxer options */
3852  { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_max_delay) },
3853  "set the maximum demux-decode delay", "seconds" },
3854  { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_preload) },
3855  "set the initial demux-decode delay", "seconds" },
3856  { "sdp_file", HAS_ARG | OPT_EXPERT | OPT_OUTPUT, { .func_arg = opt_sdp_file },
3857  "specify a file in which to print sdp information", "file" },
3858 
3859  { "time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(time_bases) },
3860  "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)", "ratio" },
3861  { "enc_time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(enc_time_bases) },
3862  "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
3863  "two special values are defined - "
3864  "0 = use frame rate (video) or sample rate (audio),"
3865  "-1 = match source time base", "ratio" },
3866 
3868  "A comma-separated list of bitstream filters", "bitstream_filters" },
3869  { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3870  "deprecated", "audio bitstream_filters" },
3871  { "vbsf", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3872  "deprecated", "video bitstream_filters" },
3873 
3874  { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3875  "set the audio options to the indicated preset", "preset" },
3876  { "vpre", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3877  "set the video options to the indicated preset", "preset" },
3878  { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3879  "set the subtitle options to the indicated preset", "preset" },
3880  { "fpre", HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3881  "set options from indicated preset file", "filename" },
3882 
3883  { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) },
3884  "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" },
3885  { "muxing_queue_data_threshold", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(muxing_queue_data_threshold) },
3886  "set the threshold after which max_muxing_queue_size is taken into account", "bytes" },
3887 
3888  /* data codec support */
3889  { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec },
3890  "force data codec ('copy' to copy stream)", "codec" },
3891  { "dn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(data_disable) },
3892  "disable data" },
3893 
3894 #if CONFIG_VAAPI
3895  { "vaapi_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vaapi_device },
3896  "set VAAPI hardware device (DRM path or X11 display name)", "device" },
3897 #endif
3898 
3899 #if CONFIG_QSV
3900  { "qsv_device", HAS_ARG | OPT_STRING | OPT_EXPERT, { &qsv_device },
3901  "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
3902 #endif
3903 
3904  { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
3905  "initialise hardware device", "args" },
3906  { "filter_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_hw_device },
3907  "set hardware device used when filtering", "device" },
3908 
3909  { NULL, },
3910 };
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:457
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:208
#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:1154
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:349
#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:1441
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:645
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:230
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1186
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:252
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1396
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:1180
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:1209
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:636
#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:296
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:274
#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:139
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:209
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Parse one given option.
Definition: cmdutils.c:352
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:180
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:547
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:1090
void report_and_exit(int ret)
Reports an error corresponding to the provided AVERROR code and calls exit_program() with the corresp...
Definition: cmdutils.c:133
int read_yesno(void)
Return a positive value if a line read from standard input starts with [yY], otherwise return 0.
Definition: cmdutils.c:2040
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:2051
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:2187
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:2167
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:2101
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:2109
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:729
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:755
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:1077
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:168
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:416
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:147
const char program_name[]
program name, defined by the program for show_version().
Definition: ffmpeg.c:109
#define OPT_VIDEO
Definition: cmdutils.h:176
#define OPT_SPEC
Definition: cmdutils.h:186
#define OPT_BOOL
Definition: cmdutils.h:173
#define OPT_INT64
Definition: cmdutils.h:181
#define OPT_PERFILE
Definition: cmdutils.h:184
#define OPT_INT
Definition: cmdutils.h:178
#define OPT_FLOAT
Definition: cmdutils.h:179
#define OPT_INPUT
Definition: cmdutils.h:189
#define OPT_DOUBLE
Definition: cmdutils.h:188
#define OPT_STRING
Definition: cmdutils.h:175
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:630
#define OPT_AUDIO
Definition: cmdutils.h:177
#define OPT_DATA
Definition: cmdutils.h:183
#define OPT_SUBTITLE
Definition: cmdutils.h:180
#define OPT_EXPERT
Definition: cmdutils.h:174
#define OPT_EXIT
Definition: cmdutils.h:182
#define OPT_OUTPUT
Definition: cmdutils.h:190
#define OPT_TIME
Definition: cmdutils.h:187
#define CMDUTILS_COMMON_OPTIONS
Definition: cmdutils.h:223
#define OPT_OFFSET
Definition: cmdutils.h:185
#define HAS_ARG
Definition: cmdutils.h:172
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:330
#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:2136
InputFile ** input_files
Definition: ffmpeg.c:150
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:524
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:687
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:696
@ 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:1423
#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:3199
int debug_ts
Definition: ffmpeg_opt.c:166
static OutputStream * new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:1969
static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3054
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:2131
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:3060
char * sdp_filename
Definition: ffmpeg_opt.c:148
static int opt_qscale(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3170
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:3211
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:3279
static int input_sync
Definition: ffmpeg_opt.c:185
static char * get_ost_filters(OptionsContext *o, AVFormatContext *oc, OutputStream *ost)
Definition: ffmpeg_opt.c:1720
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:2216
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:1674
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:3066
static int opt_bitrate(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3154
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:3025
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:3142
static OutputStream * new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
Definition: ffmpeg_opt.c:1484
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:3383
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:1692
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:1754
static OutputStream * new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:2081
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:3237
static OutputStream * new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:2047
static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
Definition: ffmpeg_opt.c:1449
static int opt_video_standard(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:317
static int is_windows_reserved_device_name(const char *f)
Definition: ffmpeg_opt.c:1040
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:3223
void show_help_default(const char *opt, const char *arg)
Per-fftool specific help handler.
Definition: ffmpeg_opt.c:3311
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:2174
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:1090
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:3187
static int opt_preset(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3086
static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, const OutputStream *ost, enum AVMediaType type)
Definition: ffmpeg_opt.c:1740
static OutputStream * new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:2073
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:1127
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:1404
static int opt_target(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2882
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:2109
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:3273
int64_t stats_period
Definition: ffmpeg_opt.c:178
static void assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:997
#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:2228
static int opt_vstats(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3032
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:3048
static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3294
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:2060
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 safe_filename(const char *f, int allow_subdir)
Definition: ffmpeg_opt.c:1068
static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3205
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:1671
@ 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:497
#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:312
@ 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:567
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:4606
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:4508
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:5037
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:1664
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:199
#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:213
#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:143
#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
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
#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:475
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:67
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:83
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:1018
char * name
unique name for this input/output in the list
Definition: avfilter.h:1020
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:171
size_t off
Definition: cmdutils.h:194
const char * name
Definition: cmdutils.h:170
A list of option groups that all have the same group type (e.g.
Definition: cmdutils.h:337
OptionGroup * groups
Definition: cmdutils.h:340
AVDictionary * codec_opts
Definition: cmdutils.h:326
AVDictionary * swr_opts
Definition: cmdutils.h:330
AVDictionary * sws_dict
Definition: cmdutils.h:329
AVDictionary * format_opts
Definition: cmdutils.h:327
AVDictionary * resample_opts
Definition: cmdutils.h:328
OptionGroup global_opts
Definition: cmdutils.h:345
OptionGroupList * groups
Definition: cmdutils.h:347
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
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
int64_t limit_filesize
Definition: ffmpeg.h:154
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
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
int64_t limit_filesize
Definition: ffmpeg.h:582
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:160
char * specifier
stream/chapter/program/...
Definition: cmdutils.h:158
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:374
static AVStream * ost
const char * g
Definition: vf_curves.c:118
preset
Definition: vf_curves.c:47
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]