FFmpeg
cmdutils.c
Go to the documentation of this file.
1 /*
2  * Various utilities for command line tools
3  * Copyright (c) 2000-2003 Fabrice Bellard
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 <string.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <math.h>
27 
28 /* Include only the enabled headers since some compilers (namely, Sun
29  Studio) will not omit unused inline functions and create undefined
30  references to libraries that are not being built. */
31 
32 #include "config.h"
33 #include "compat/va_copy.h"
34 #include "libavformat/avformat.h"
35 #include "libswscale/swscale.h"
37 #include "libavutil/avassert.h"
38 #include "libavutil/avstring.h"
39 #include "libavutil/bprint.h"
40 #include "libavutil/display.h"
41 #include "libavutil/getenv_utf8.h"
42 #include "libavutil/libm.h"
43 #include "libavutil/mem.h"
44 #include "libavutil/parseutils.h"
45 #include "libavutil/eval.h"
46 #include "libavutil/dict.h"
47 #include "libavutil/opt.h"
48 #include "cmdutils.h"
49 #include "fopen_utf8.h"
50 #include "opt_common.h"
51 #ifdef _WIN32
52 #include <windows.h>
53 #include "compat/w32dlfcn.h"
54 #endif
55 
59 
60 int hide_banner = 0;
61 
62 void uninit_opts(void)
63 {
68 }
69 
70 void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
71 {
72  vfprintf(stdout, fmt, vl);
73 }
74 
75 void init_dynload(void)
76 {
77 #if HAVE_SETDLLDIRECTORY && defined(_WIN32)
78  /* Calling SetDllDirectory with the empty string (but not NULL) removes the
79  * current working directory from the DLL search path as a security pre-caution. */
80  SetDllDirectory("");
81 #endif
82 }
83 
84 int parse_number(const char *context, const char *numstr, enum OptionType type,
85  double min, double max, double *dst)
86 {
87  char *tail;
88  const char *error;
89  double d = av_strtod(numstr, &tail);
90  if (*tail)
91  error = "Expected number for %s but found: %s\n";
92  else if (d < min || d > max)
93  error = "The value for %s was %s which is not within %f - %f\n";
94  else if (type == OPT_TYPE_INT64 && (int64_t)d != d)
95  error = "Expected int64 for %s but found %s\n";
96  else if (type == OPT_TYPE_INT && (int)d != d)
97  error = "Expected int for %s but found %s\n";
98  else {
99  *dst = d;
100  return 0;
101  }
102 
103  av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
104  return AVERROR(EINVAL);
105 }
106 
107 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
108  int rej_flags)
109 {
110  const OptionDef *po;
111  int first;
112 
113  first = 1;
114  for (po = options; po->name; po++) {
115  char buf[128];
116 
117  if (((po->flags & req_flags) != req_flags) ||
118  (po->flags & rej_flags))
119  continue;
120 
121  if (first) {
122  printf("%s\n", msg);
123  first = 0;
124  }
125  av_strlcpy(buf, po->name, sizeof(buf));
126 
127  if (po->flags & OPT_FLAG_PERSTREAM)
128  av_strlcat(buf, "[:<stream_spec>]", sizeof(buf));
129  else if (po->flags & OPT_FLAG_SPEC)
130  av_strlcat(buf, "[:<spec>]", sizeof(buf));
131 
132  if (po->argname)
133  av_strlcatf(buf, sizeof(buf), " <%s>", po->argname);
134 
135  printf("-%-17s %s\n", buf, po->help);
136  }
137  printf("\n");
138 }
139 
140 void show_help_children(const AVClass *class, int flags)
141 {
142  void *iter = NULL;
143  const AVClass *child;
144  if (class->option) {
145  av_opt_show2(&class, NULL, flags, 0);
146  printf("\n");
147  }
148 
149  while (child = av_opt_child_class_iterate(class, &iter))
150  show_help_children(child, flags);
151 }
152 
153 static const OptionDef *find_option(const OptionDef *po, const char *name)
154 {
155  if (*name == '/')
156  name++;
157 
158  while (po->name) {
159  const char *end;
160  if (av_strstart(name, po->name, &end) && (!*end || *end == ':'))
161  break;
162  po++;
163  }
164  return po;
165 }
166 
167 /* _WIN32 means using the windows libc - cygwin doesn't define that
168  * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
169  * it doesn't provide the actual command line via GetCommandLineW(). */
170 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
171 #include <shellapi.h>
172 /* Will be leaked on exit */
173 static char** win32_argv_utf8 = NULL;
174 static int win32_argc = 0;
175 
176 /**
177  * Prepare command line arguments for executable.
178  * For Windows - perform wide-char to UTF-8 conversion.
179  * Input arguments should be main() function arguments.
180  * @param argc_ptr Arguments number (including executable)
181  * @param argv_ptr Arguments list.
182  */
183 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
184 {
185  char *argstr_flat;
186  wchar_t **argv_w;
187  int i, buffsize = 0, offset = 0;
188 
189  if (win32_argv_utf8) {
190  *argc_ptr = win32_argc;
191  *argv_ptr = win32_argv_utf8;
192  return;
193  }
194 
195  win32_argc = 0;
196  argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
197  if (win32_argc <= 0 || !argv_w)
198  return;
199 
200  /* determine the UTF-8 buffer size (including NULL-termination symbols) */
201  for (i = 0; i < win32_argc; i++)
202  buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
203  NULL, 0, NULL, NULL);
204 
205  win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
206  argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
207  if (!win32_argv_utf8) {
208  LocalFree(argv_w);
209  return;
210  }
211 
212  for (i = 0; i < win32_argc; i++) {
213  win32_argv_utf8[i] = &argstr_flat[offset];
214  offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
215  &argstr_flat[offset],
216  buffsize - offset, NULL, NULL);
217  }
218  win32_argv_utf8[i] = NULL;
219  LocalFree(argv_w);
220 
221  *argc_ptr = win32_argc;
222  *argv_ptr = win32_argv_utf8;
223 }
224 #else
225 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
226 {
227  /* nothing to do */
228 }
229 #endif /* HAVE_COMMANDLINETOARGVW */
230 
231 static int opt_has_arg(const OptionDef *o)
232 {
233  if (o->type == OPT_TYPE_BOOL)
234  return 0;
235  if (o->type == OPT_TYPE_FUNC)
236  return !!(o->flags & OPT_FUNC_ARG);
237  return 1;
238 }
239 
240 static int write_option(void *optctx, const OptionDef *po, const char *opt,
241  const char *arg, const OptionDef *defs)
242 {
243  /* new-style options contain an offset into optctx, old-style address of
244  * a global var*/
245  void *dst = po->flags & OPT_FLAG_OFFSET ?
246  (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
247  char *arg_allocated = NULL;
248 
249  enum OptionType so_type = po->type;
250 
251  SpecifierOptList *sol = NULL;
252  double num;
253  int ret = 0;
254 
255  if (*opt == '/') {
256  opt++;
257 
258  if (po->type == OPT_TYPE_BOOL) {
260  "Requested to load an argument from file for a bool option '%s'\n",
261  po->name);
262  return AVERROR(EINVAL);
263  }
264 
265  arg_allocated = file_read(arg);
266  if (!arg_allocated) {
268  "Error reading the value for option '%s' from file: %s\n",
269  opt, arg);
270  return AVERROR(EINVAL);
271  }
272 
273  arg = arg_allocated;
274  }
275 
276  if (po->flags & OPT_FLAG_SPEC) {
277  char *p = strchr(opt, ':');
278  char *str;
279 
280  sol = dst;
281  ret = GROW_ARRAY(sol->opt, sol->nb_opt);
282  if (ret < 0)
283  goto finish;
284 
285  str = av_strdup(p ? p + 1 : "");
286  if (!str) {
287  ret = AVERROR(ENOMEM);
288  goto finish;
289  }
290  sol->opt[sol->nb_opt - 1].specifier = str;
291 
292  if (po->flags & OPT_FLAG_PERSTREAM) {
293  ret = stream_specifier_parse(&sol->opt[sol->nb_opt - 1].stream_spec,
294  str, 0, NULL);
295  if (ret < 0)
296  goto finish;
297  }
298 
299  dst = &sol->opt[sol->nb_opt - 1].u;
300  }
301 
302  if (po->type == OPT_TYPE_STRING) {
303  char *str;
304  if (arg_allocated) {
305  str = arg_allocated;
306  arg_allocated = NULL;
307  } else
308  str = av_strdup(arg);
309  av_freep(dst);
310 
311  if (!str) {
312  ret = AVERROR(ENOMEM);
313  goto finish;
314  }
315 
316  *(char **)dst = str;
317  } else if (po->type == OPT_TYPE_BOOL || po->type == OPT_TYPE_INT) {
318  ret = parse_number(opt, arg, OPT_TYPE_INT64, INT_MIN, INT_MAX, &num);
319  if (ret < 0)
320  goto finish;
321 
322  *(int *)dst = num;
323  so_type = OPT_TYPE_INT;
324  } else if (po->type == OPT_TYPE_INT64) {
325  ret = parse_number(opt, arg, OPT_TYPE_INT64, INT64_MIN, (double)INT64_MAX, &num);
326  if (ret < 0)
327  goto finish;
328 
329  *(int64_t *)dst = num;
330  } else if (po->type == OPT_TYPE_TIME) {
331  ret = av_parse_time(dst, arg, 1);
332  if (ret < 0) {
333  av_log(NULL, AV_LOG_ERROR, "Invalid duration for option %s: %s\n",
334  opt, arg);
335  goto finish;
336  }
337  so_type = OPT_TYPE_INT64;
338  } else if (po->type == OPT_TYPE_FLOAT) {
340  if (ret < 0)
341  goto finish;
342 
343  *(float *)dst = num;
344  } else if (po->type == OPT_TYPE_DOUBLE) {
346  if (ret < 0)
347  goto finish;
348 
349  *(double *)dst = num;
350  } else {
351  av_assert0(po->type == OPT_TYPE_FUNC && po->u.func_arg);
352 
353  ret = po->u.func_arg(optctx, opt, arg);
354  if (ret < 0) {
356  "Failed to set value '%s' for option '%s': %s\n",
357  arg, opt, av_err2str(ret));
358  goto finish;
359  }
360  }
361  if (po->flags & OPT_EXIT) {
362  ret = AVERROR_EXIT;
363  goto finish;
364  }
365 
366  if (sol) {
367  sol->type = so_type;
368  sol->opt_canon = (po->flags & OPT_HAS_CANON) ?
369  find_option(defs, po->u1.name_canon) : po;
370  }
371 
372 finish:
373  av_freep(&arg_allocated);
374  return ret;
375 }
376 
377 int parse_option(void *optctx, const char *opt, const char *arg,
378  const OptionDef *options)
379 {
380  static const OptionDef opt_avoptions = {
381  .name = "AVOption passthrough",
382  .type = OPT_TYPE_FUNC,
383  .flags = OPT_FUNC_ARG,
384  .u.func_arg = opt_default,
385  };
386 
387  const OptionDef *po;
388  int ret;
389 
390  po = find_option(options, opt);
391  if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
392  /* handle 'no' bool option */
393  po = find_option(options, opt + 2);
394  if ((po->name && po->type == OPT_TYPE_BOOL))
395  arg = "0";
396  } else if (po->type == OPT_TYPE_BOOL)
397  arg = "1";
398 
399  if (!po->name)
400  po = &opt_avoptions;
401  if (!po->name) {
402  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
403  return AVERROR(EINVAL);
404  }
405  if (opt_has_arg(po) && !arg) {
406  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
407  return AVERROR(EINVAL);
408  }
409 
410  ret = write_option(optctx, po, opt, arg, options);
411  if (ret < 0)
412  return ret;
413 
414  return opt_has_arg(po);
415 }
416 
417 int parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
418  int (*parse_arg_function)(void *, const char*))
419 {
420  const char *opt;
421  int optindex, handleoptions = 1, ret;
422 
423  /* perform system-dependent conversions for arguments list */
424  prepare_app_arguments(&argc, &argv);
425 
426  /* parse options */
427  optindex = 1;
428  while (optindex < argc) {
429  opt = argv[optindex++];
430 
431  if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
432  if (opt[1] == '-' && opt[2] == '\0') {
433  handleoptions = 0;
434  continue;
435  }
436  opt++;
437 
438  if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
439  return ret;
440  optindex += ret;
441  } else {
442  if (parse_arg_function) {
443  ret = parse_arg_function(optctx, opt);
444  if (ret < 0)
445  return ret;
446  }
447  }
448  }
449 
450  return 0;
451 }
452 
453 int parse_optgroup(void *optctx, OptionGroup *g, const OptionDef *defs)
454 {
455  int i, ret;
456 
457  av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
458  g->group_def->name, g->arg);
459 
460  for (i = 0; i < g->nb_opts; i++) {
461  Option *o = &g->opts[i];
462 
463  if (g->group_def->flags &&
464  !(g->group_def->flags & o->opt->flags)) {
465  av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
466  "%s %s -- you are trying to apply an input option to an "
467  "output file or vice versa. Move this option before the "
468  "file it belongs to.\n", o->key, o->opt->help,
469  g->group_def->name, g->arg);
470  return AVERROR(EINVAL);
471  }
472 
473  av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
474  o->key, o->opt->help, o->val);
475 
476  ret = write_option(optctx, o->opt, o->key, o->val, defs);
477  if (ret < 0)
478  return ret;
479  }
480 
481  av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
482 
483  return 0;
484 }
485 
486 int locate_option(int argc, char **argv, const OptionDef *options,
487  const char *optname)
488 {
489  const OptionDef *po;
490  int i;
491 
492  for (i = 1; i < argc; i++) {
493  const char *cur_opt = argv[i];
494 
495  if (*cur_opt++ != '-')
496  continue;
497 
498  po = find_option(options, cur_opt);
499  if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
500  po = find_option(options, cur_opt + 2);
501 
502  if ((!po->name && !strcmp(cur_opt, optname)) ||
503  (po->name && !strcmp(optname, po->name)))
504  return i;
505 
506  if (!po->name || opt_has_arg(po))
507  i++;
508  }
509  return 0;
510 }
511 
512 static void dump_argument(FILE *report_file, const char *a)
513 {
514  const unsigned char *p;
515 
516  for (p = a; *p; p++)
517  if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
518  *p == '_' || (*p >= 'a' && *p <= 'z')))
519  break;
520  if (!*p) {
521  fputs(a, report_file);
522  return;
523  }
524  fputc('"', report_file);
525  for (p = a; *p; p++) {
526  if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
527  fprintf(report_file, "\\%c", *p);
528  else if (*p < ' ' || *p > '~')
529  fprintf(report_file, "\\x%02x", *p);
530  else
531  fputc(*p, report_file);
532  }
533  fputc('"', report_file);
534 }
535 
536 static void check_options(const OptionDef *po)
537 {
538  while (po->name) {
539  if (po->flags & OPT_PERFILE)
541 
542  if (po->type == OPT_TYPE_FUNC)
544 
545  // OPT_FUNC_ARG can only be ser for OPT_TYPE_FUNC
546  av_assert0((po->type == OPT_TYPE_FUNC) || !(po->flags & OPT_FUNC_ARG));
547 
548  po++;
549  }
550 }
551 
552 void parse_loglevel(int argc, char **argv, const OptionDef *options)
553 {
554  int idx = locate_option(argc, argv, options, "loglevel");
555  char *env;
556 
558 
559  if (!idx)
560  idx = locate_option(argc, argv, options, "v");
561  if (idx && argv[idx + 1])
562  opt_loglevel(NULL, "loglevel", argv[idx + 1]);
563  idx = locate_option(argc, argv, options, "report");
564  env = getenv_utf8("FFREPORT");
565  if (env || idx) {
566  FILE *report_file = NULL;
567  init_report(env, &report_file);
568  if (report_file) {
569  int i;
570  fprintf(report_file, "Command line:\n");
571  for (i = 0; i < argc; i++) {
572  dump_argument(report_file, argv[i]);
573  fputc(i < argc - 1 ? ' ' : '\n', report_file);
574  }
575  fflush(report_file);
576  }
577  }
578  freeenv_utf8(env);
579  idx = locate_option(argc, argv, options, "hide_banner");
580  if (idx)
581  hide_banner = 1;
582 }
583 
584 static const AVOption *opt_find(void *obj, const char *name, const char *unit,
585  int opt_flags, int search_flags)
586 {
587  const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
588  if(o && !o->flags)
589  return NULL;
590  return o;
591 }
592 
593 #define FLAGS ((o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0)
594 int opt_default(void *optctx, const char *opt, const char *arg)
595 {
596  const AVOption *o;
597  int consumed = 0;
598  char opt_stripped[128];
599  const char *p;
600  const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
601 #if CONFIG_SWSCALE
602  const AVClass *sc = sws_get_class();
603 #endif
604 #if CONFIG_SWRESAMPLE
605  const AVClass *swr_class = swr_get_class();
606 #endif
607 
608  if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
610 
611  if (!(p = strchr(opt, ':')))
612  p = opt + strlen(opt);
613  av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
614 
615  if ((o = opt_find(&cc, opt_stripped, NULL, 0,
617  ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
618  (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
619  av_dict_set(&codec_opts, opt, arg, FLAGS);
620  consumed = 1;
621  }
622  if ((o = opt_find(&fc, opt, NULL, 0,
624  av_dict_set(&format_opts, opt, arg, FLAGS);
625  if (consumed)
626  av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
627  consumed = 1;
628  }
629 #if CONFIG_SWSCALE
630  if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
632  if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
633  !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
634  !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
635  av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
636  return AVERROR(EINVAL);
637  }
638  av_dict_set(&sws_dict, opt, arg, FLAGS);
639 
640  consumed = 1;
641  }
642 #else
643  if (!consumed && !strcmp(opt, "sws_flags")) {
644  av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
645  consumed = 1;
646  }
647 #endif
648 #if CONFIG_SWRESAMPLE
649  if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
651  av_dict_set(&swr_opts, opt, arg, FLAGS);
652  consumed = 1;
653  }
654 #endif
655 
656  if (consumed)
657  return 0;
659 }
660 
661 /*
662  * Check whether given option is a group separator.
663  *
664  * @return index of the group definition that matched or -1 if none
665  */
666 static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
667  const char *opt)
668 {
669  int i;
670 
671  for (i = 0; i < nb_groups; i++) {
672  const OptionGroupDef *p = &groups[i];
673  if (p->sep && !strcmp(p->sep, opt))
674  return i;
675  }
676 
677  return -1;
678 }
679 
680 /*
681  * Finish parsing an option group.
682  *
683  * @param group_idx which group definition should this group belong to
684  * @param arg argument of the group delimiting option
685  */
686 static int finish_group(OptionParseContext *octx, int group_idx,
687  const char *arg)
688 {
689  OptionGroupList *l = &octx->groups[group_idx];
690  OptionGroup *g;
691  int ret;
692 
693  ret = GROW_ARRAY(l->groups, l->nb_groups);
694  if (ret < 0)
695  return ret;
696 
697  g = &l->groups[l->nb_groups - 1];
698 
699  *g = octx->cur_group;
700  g->arg = arg;
701  g->group_def = l->group_def;
702  g->sws_dict = sws_dict;
703  g->swr_opts = swr_opts;
704  g->codec_opts = codec_opts;
705  g->format_opts = format_opts;
706 
707  codec_opts = NULL;
708  format_opts = NULL;
709  sws_dict = NULL;
710  swr_opts = NULL;
711 
712  memset(&octx->cur_group, 0, sizeof(octx->cur_group));
713 
714  return ret;
715 }
716 
717 /*
718  * Add an option instance to currently parsed group.
719  */
720 static int add_opt(OptionParseContext *octx, const OptionDef *opt,
721  const char *key, const char *val)
722 {
723  int global = !(opt->flags & OPT_PERFILE);
724  OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
725  int ret;
726 
727  ret = GROW_ARRAY(g->opts, g->nb_opts);
728  if (ret < 0)
729  return ret;
730 
731  g->opts[g->nb_opts - 1].opt = opt;
732  g->opts[g->nb_opts - 1].key = key;
733  g->opts[g->nb_opts - 1].val = val;
734 
735  return 0;
736 }
737 
739  const OptionGroupDef *groups, int nb_groups)
740 {
741  static const OptionGroupDef global_group = { "global" };
742  int i;
743 
744  memset(octx, 0, sizeof(*octx));
745 
746  octx->groups = av_calloc(nb_groups, sizeof(*octx->groups));
747  if (!octx->groups)
748  return AVERROR(ENOMEM);
749  octx->nb_groups = nb_groups;
750 
751  for (i = 0; i < octx->nb_groups; i++)
752  octx->groups[i].group_def = &groups[i];
753 
754  octx->global_opts.group_def = &global_group;
755  octx->global_opts.arg = "";
756 
757  return 0;
758 }
759 
761 {
762  int i, j;
763 
764  for (i = 0; i < octx->nb_groups; i++) {
765  OptionGroupList *l = &octx->groups[i];
766 
767  for (j = 0; j < l->nb_groups; j++) {
768  av_freep(&l->groups[j].opts);
771 
772  av_dict_free(&l->groups[j].sws_dict);
773  av_dict_free(&l->groups[j].swr_opts);
774  }
775  av_freep(&l->groups);
776  }
777  av_freep(&octx->groups);
778 
779  av_freep(&octx->cur_group.opts);
780  av_freep(&octx->global_opts.opts);
781 
782  uninit_opts();
783 }
784 
785 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
786  const OptionDef *options,
787  const OptionGroupDef *groups, int nb_groups)
788 {
789  int ret;
790  int optindex = 1;
791  int dashdash = -2;
792 
793  /* perform system-dependent conversions for arguments list */
794  prepare_app_arguments(&argc, &argv);
795 
796  ret = init_parse_context(octx, groups, nb_groups);
797  if (ret < 0)
798  return ret;
799 
800  av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
801 
802  while (optindex < argc) {
803  const char *opt = argv[optindex++], *arg;
804  const OptionDef *po;
805  int group_idx;
806 
807  av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
808 
809  if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
810  dashdash = optindex;
811  continue;
812  }
813  /* unnamed group separators, e.g. output filename */
814  if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
815  ret = finish_group(octx, 0, opt);
816  if (ret < 0)
817  return ret;
818 
819  av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
820  continue;
821  }
822  opt++;
823 
824 #define GET_ARG(arg) \
825 do { \
826  arg = argv[optindex++]; \
827  if (!arg) { \
828  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
829  return AVERROR(EINVAL); \
830  } \
831 } while (0)
832 
833  /* named group separators, e.g. -i */
834  group_idx = match_group_separator(groups, nb_groups, opt);
835  if (group_idx >= 0) {
836  GET_ARG(arg);
837  ret = finish_group(octx, group_idx, arg);
838  if (ret < 0)
839  return ret;
840 
841  av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
842  groups[group_idx].name, arg);
843  continue;
844  }
845 
846  /* normal options */
847  po = find_option(options, opt);
848  if (po->name) {
849  if (po->flags & OPT_EXIT) {
850  /* optional argument, e.g. -h */
851  arg = argv[optindex++];
852  } else if (opt_has_arg(po)) {
853  GET_ARG(arg);
854  } else {
855  arg = "1";
856  }
857 
858  ret = add_opt(octx, po, opt, arg);
859  if (ret < 0)
860  return ret;
861 
862  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
863  "argument '%s'.\n", po->name, po->help, arg);
864  continue;
865  }
866 
867  /* AVOptions */
868  if (argv[optindex]) {
869  ret = opt_default(NULL, opt, argv[optindex]);
870  if (ret >= 0) {
871  av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
872  "argument '%s'.\n", opt, argv[optindex]);
873  optindex++;
874  continue;
875  } else if (ret != AVERROR_OPTION_NOT_FOUND) {
876  av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
877  "with argument '%s'.\n", opt, argv[optindex]);
878  return ret;
879  }
880  }
881 
882  /* boolean -nofoo options */
883  if (opt[0] == 'n' && opt[1] == 'o' &&
884  (po = find_option(options, opt + 2)) &&
885  po->name && po->type == OPT_TYPE_BOOL) {
886  ret = add_opt(octx, po, opt, "0");
887  if (ret < 0)
888  return ret;
889 
890  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
891  "argument 0.\n", po->name, po->help);
892  continue;
893  }
894 
895  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
897  }
898 
899  if (octx->cur_group.nb_opts || codec_opts || format_opts)
900  av_log(NULL, AV_LOG_WARNING, "Trailing option(s) found in the "
901  "command: may be ignored.\n");
902 
903  av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
904 
905  return 0;
906 }
907 
908 int read_yesno(void)
909 {
910  int c = getchar();
911  int yesno = (av_toupper(c) == 'Y');
912 
913  while (c != '\n' && c != EOF)
914  c = getchar();
915 
916  return yesno;
917 }
918 
919 FILE *get_preset_file(char *filename, size_t filename_size,
920  const char *preset_name, int is_path,
921  const char *codec_name)
922 {
923  FILE *f = NULL;
924  int i;
925 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
926  char *datadir = NULL;
927 #endif
928  char *env_home = getenv_utf8("HOME");
929  char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR");
930  const char *base[3] = { env_ffmpeg_datadir,
931  env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */
932  FFMPEG_DATADIR, };
933 
934  if (is_path) {
935  av_strlcpy(filename, preset_name, filename_size);
936  f = fopen_utf8(filename, "r");
937  } else {
938 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
939  wchar_t *datadir_w = get_module_filename(NULL);
940  base[2] = NULL;
941 
942  if (wchartoutf8(datadir_w, &datadir))
943  datadir = NULL;
944  av_free(datadir_w);
945 
946  if (datadir)
947  {
948  char *ls;
949  for (ls = datadir; *ls; ls++)
950  if (*ls == '\\') *ls = '/';
951 
952  if (ls = strrchr(datadir, '/'))
953  {
954  ptrdiff_t datadir_len = ls - datadir;
955  size_t desired_size = datadir_len + strlen("/ffpresets") + 1;
956  char *new_datadir = av_realloc_array(
957  datadir, desired_size, sizeof *datadir);
958  if (new_datadir) {
959  datadir = new_datadir;
960  datadir[datadir_len] = 0;
961  strncat(datadir, "/ffpresets", desired_size - 1 - datadir_len);
962  base[2] = datadir;
963  }
964  }
965  }
966 #endif
967  for (i = 0; i < 3 && !f; i++) {
968  if (!base[i])
969  continue;
970  snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
971  i != 1 ? "" : "/.ffmpeg", preset_name);
972  f = fopen_utf8(filename, "r");
973  if (!f && codec_name) {
974  snprintf(filename, filename_size,
975  "%s%s/%s-%s.ffpreset",
976  base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
977  preset_name);
978  f = fopen_utf8(filename, "r");
979  }
980  }
981  }
982 
983 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
984  av_free(datadir);
985 #endif
986  freeenv_utf8(env_ffmpeg_datadir);
987  freeenv_utf8(env_home);
988  return f;
989 }
990 
992 {
993  return (c >= '0' && c <= '9') ||
994  (c >= 'A' && c <= 'Z') ||
995  (c >= 'a' && c <= 'z');
996 }
997 
999 {
1000  av_freep(&ss->meta_key);
1001  av_freep(&ss->meta_val);
1002  av_freep(&ss->remainder);
1003 
1004  memset(ss, 0, sizeof(*ss));
1005 }
1006 
1008  int allow_remainder, void *logctx)
1009 {
1010  char *endptr;
1011  int ret;
1012 
1013  memset(ss, 0, sizeof(*ss));
1014 
1015  ss->idx = -1;
1016  ss->media_type = AVMEDIA_TYPE_UNKNOWN;
1017  ss->stream_list = STREAM_LIST_ALL;
1018 
1019  av_log(logctx, AV_LOG_TRACE, "Parsing stream specifier: %s\n", spec);
1020 
1021  while (*spec) {
1022  if (*spec <= '9' && *spec >= '0') { /* opt:index */
1023  ss->idx = strtol(spec, &endptr, 0);
1024 
1025  av_assert0(endptr > spec);
1026  spec = endptr;
1027 
1028  av_log(logctx, AV_LOG_TRACE,
1029  "Parsed index: %d; remainder: %s\n", ss->idx, spec);
1030 
1031  // this terminates the specifier
1032  break;
1033  } else if ((*spec == 'v' || *spec == 'a' || *spec == 's' ||
1034  *spec == 'd' || *spec == 't' || *spec == 'V') &&
1035  !cmdutils_isalnum(*(spec + 1))) { /* opt:[vasdtV] */
1036  if (ss->media_type != AVMEDIA_TYPE_UNKNOWN) {
1037  av_log(logctx, AV_LOG_ERROR, "Stream type specified multiple times\n");
1038  ret = AVERROR(EINVAL);
1039  goto fail;
1040  }
1041 
1042  switch (*spec++) {
1043  case 'v': ss->media_type = AVMEDIA_TYPE_VIDEO; break;
1044  case 'a': ss->media_type = AVMEDIA_TYPE_AUDIO; break;
1045  case 's': ss->media_type = AVMEDIA_TYPE_SUBTITLE; break;
1046  case 'd': ss->media_type = AVMEDIA_TYPE_DATA; break;
1047  case 't': ss->media_type = AVMEDIA_TYPE_ATTACHMENT; break;
1048  case 'V': ss->media_type = AVMEDIA_TYPE_VIDEO;
1049  ss->no_apic = 1; break;
1050  default: av_assert0(0);
1051  }
1052 
1053  av_log(logctx, AV_LOG_TRACE, "Parsed media type: %s; remainder: %s\n",
1054  av_get_media_type_string(ss->media_type), spec);
1055  } else if (*spec == 'g' && *(spec + 1) == ':') {
1056  if (ss->stream_list != STREAM_LIST_ALL)
1057  goto multiple_stream_lists;
1058 
1059  spec += 2;
1060  if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) {
1061  ss->stream_list = STREAM_LIST_GROUP_ID;
1062 
1063  spec += 1 + (*spec == 'i');
1064  } else
1065  ss->stream_list = STREAM_LIST_GROUP_IDX;
1066 
1067  ss->list_id = strtol(spec, &endptr, 0);
1068  if (spec == endptr) {
1069  av_log(logctx, AV_LOG_ERROR, "Expected stream group idx/ID, got: %s\n", spec);
1070  ret = AVERROR(EINVAL);
1071  goto fail;
1072  }
1073  spec = endptr;
1074 
1075  av_log(logctx, AV_LOG_TRACE, "Parsed stream group %s: %"PRId64"; remainder: %s\n",
1076  ss->stream_list == STREAM_LIST_GROUP_ID ? "ID" : "index", ss->list_id, spec);
1077  } else if (*spec == 'p' && *(spec + 1) == ':') {
1078  if (ss->stream_list != STREAM_LIST_ALL)
1079  goto multiple_stream_lists;
1080 
1081  ss->stream_list = STREAM_LIST_PROGRAM;
1082 
1083  spec += 2;
1084  ss->list_id = strtol(spec, &endptr, 0);
1085  if (spec == endptr) {
1086  av_log(logctx, AV_LOG_ERROR, "Expected program ID, got: %s\n", spec);
1087  ret = AVERROR(EINVAL);
1088  goto fail;
1089  }
1090  spec = endptr;
1091 
1092  av_log(logctx, AV_LOG_TRACE,
1093  "Parsed program ID: %"PRId64"; remainder: %s\n", ss->list_id, spec);
1094  } else if (!strncmp(spec, "disp:", 5)) {
1095  const AVClass *st_class = av_stream_get_class();
1096  const AVOption *o = av_opt_find(&st_class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ);
1097  char *disp = NULL;
1098  size_t len;
1099 
1100  av_assert0(o);
1101 
1102  if (ss->disposition) {
1103  av_log(logctx, AV_LOG_ERROR, "Multiple disposition specifiers\n");
1104  ret = AVERROR(EINVAL);
1105  goto fail;
1106  }
1107 
1108  spec += 5;
1109 
1110  for (len = 0; cmdutils_isalnum(spec[len]) ||
1111  spec[len] == '_' || spec[len] == '+'; len++)
1112  continue;
1113 
1114  disp = av_strndup(spec, len);
1115  if (!disp) {
1116  ret = AVERROR(ENOMEM);
1117  goto fail;
1118  }
1119 
1120  ret = av_opt_eval_flags(&st_class, o, disp, &ss->disposition);
1121  av_freep(&disp);
1122  if (ret < 0) {
1123  av_log(logctx, AV_LOG_ERROR, "Invalid disposition specifier\n");
1124  goto fail;
1125  }
1126 
1127  spec += len;
1128 
1129  av_log(logctx, AV_LOG_TRACE,
1130  "Parsed disposition: 0x%x; remainder: %s\n", ss->disposition, spec);
1131  } else if (*spec == '#' ||
1132  (*spec == 'i' && *(spec + 1) == ':')) {
1133  if (ss->stream_list != STREAM_LIST_ALL)
1134  goto multiple_stream_lists;
1135 
1136  ss->stream_list = STREAM_LIST_STREAM_ID;
1137 
1138  spec += 1 + (*spec == 'i');
1139  ss->list_id = strtol(spec, &endptr, 0);
1140  if (spec == endptr) {
1141  av_log(logctx, AV_LOG_ERROR, "Expected stream ID, got: %s\n", spec);
1142  ret = AVERROR(EINVAL);
1143  goto fail;
1144  }
1145  spec = endptr;
1146 
1147  av_log(logctx, AV_LOG_TRACE,
1148  "Parsed stream ID: %"PRId64"; remainder: %s\n", ss->list_id, spec);
1149 
1150  // this terminates the specifier
1151  break;
1152  } else if (*spec == 'm' && *(spec + 1) == ':') {
1153  av_assert0(!ss->meta_key && !ss->meta_val);
1154 
1155  spec += 2;
1156  ss->meta_key = av_get_token(&spec, ":");
1157  if (!ss->meta_key) {
1158  ret = AVERROR(ENOMEM);
1159  goto fail;
1160  }
1161  if (*spec == ':') {
1162  spec++;
1163  ss->meta_val = av_get_token(&spec, ":");
1164  if (!ss->meta_val) {
1165  ret = AVERROR(ENOMEM);
1166  goto fail;
1167  }
1168  }
1169 
1170  av_log(logctx, AV_LOG_TRACE,
1171  "Parsed metadata: %s:%s; remainder: %s", ss->meta_key,
1172  ss->meta_val ? ss->meta_val : "<any value>", spec);
1173 
1174  // this terminates the specifier
1175  break;
1176  } else if (*spec == 'u' && (*(spec + 1) == '\0' || *(spec + 1) == ':')) {
1177  ss->usable_only = 1;
1178  spec++;
1179  av_log(logctx, AV_LOG_ERROR, "Parsed 'usable only'\n");
1180 
1181  // this terminates the specifier
1182  break;
1183  } else
1184  break;
1185 
1186  if (*spec == ':')
1187  spec++;
1188  }
1189 
1190  if (*spec) {
1191  if (!allow_remainder) {
1192  av_log(logctx, AV_LOG_ERROR,
1193  "Trailing garbage at the end of a stream specifier: %s\n",
1194  spec);
1195  ret = AVERROR(EINVAL);
1196  goto fail;
1197  }
1198 
1199  if (*spec == ':')
1200  spec++;
1201 
1202  ss->remainder = av_strdup(spec);
1203  if (!ss->remainder) {
1204  ret = AVERROR(EINVAL);
1205  goto fail;
1206  }
1207  }
1208 
1209  return 0;
1210 
1211 multiple_stream_lists:
1212  av_log(logctx, AV_LOG_ERROR,
1213  "Cannot combine multiple program/group designators in a "
1214  "single stream specifier");
1215  ret = AVERROR(EINVAL);
1216 
1217 fail:
1219  return ret;
1220 }
1221 
1223  const AVFormatContext *s, const AVStream *st,
1224  void *logctx)
1225 {
1226  const AVStreamGroup *g = NULL;
1227  const AVProgram *p = NULL;
1228  int start_stream = 0, nb_streams;
1229  int nb_matched = 0;
1230 
1231  switch (ss->stream_list) {
1232  case STREAM_LIST_STREAM_ID:
1233  // <n-th> stream with given ID makes no sense and should be impossible to request
1234  av_assert0(ss->idx < 0);
1235  // return early if we know for sure the stream does not match
1236  if (st->id != ss->list_id)
1237  return 0;
1238  start_stream = st->index;
1239  nb_streams = st->index + 1;
1240  break;
1241  case STREAM_LIST_ALL:
1242  start_stream = ss->idx >= 0 ? 0 : st->index;
1243  nb_streams = st->index + 1;
1244  break;
1245  case STREAM_LIST_PROGRAM:
1246  for (unsigned i = 0; i < s->nb_programs; i++) {
1247  if (s->programs[i]->id == ss->list_id) {
1248  p = s->programs[i];
1249  break;
1250  }
1251  }
1252  if (!p) {
1253  av_log(logctx, AV_LOG_WARNING, "No program with ID %"PRId64" exists,"
1254  " stream specifier can never match\n", ss->list_id);
1255  return 0;
1256  }
1258  break;
1259  case STREAM_LIST_GROUP_ID:
1260  for (unsigned i = 0; i < s->nb_stream_groups; i++) {
1261  if (ss->list_id == s->stream_groups[i]->id) {
1262  g = s->stream_groups[i];
1263  break;
1264  }
1265  }
1266  // fall-through
1267  case STREAM_LIST_GROUP_IDX:
1268  if (ss->stream_list == STREAM_LIST_GROUP_IDX &&
1269  ss->list_id >= 0 && ss->list_id < s->nb_stream_groups)
1270  g = s->stream_groups[ss->list_id];
1271 
1272  if (!g) {
1273  av_log(logctx, AV_LOG_WARNING, "No stream group with group %s %"
1274  PRId64" exists, stream specifier can never match\n",
1275  ss->stream_list == STREAM_LIST_GROUP_ID ? "ID" : "index",
1276  ss->list_id);
1277  return 0;
1278  }
1279  nb_streams = g->nb_streams;
1280  break;
1281  default: av_assert0(0);
1282  }
1283 
1284  for (int i = start_stream; i < nb_streams; i++) {
1285  const AVStream *candidate = s->streams[g ? g->streams[i]->index :
1286  p ? p->stream_index[i] : i];
1287 
1288  if (ss->media_type != AVMEDIA_TYPE_UNKNOWN &&
1289  (ss->media_type != candidate->codecpar->codec_type ||
1290  (ss->no_apic && (candidate->disposition & AV_DISPOSITION_ATTACHED_PIC))))
1291  continue;
1292 
1293  if (ss->meta_key) {
1294  const AVDictionaryEntry *tag = av_dict_get(candidate->metadata,
1295  ss->meta_key, NULL, 0);
1296 
1297  if (!tag)
1298  continue;
1299  if (ss->meta_val && strcmp(tag->value, ss->meta_val))
1300  continue;
1301  }
1302 
1303  if (ss->usable_only) {
1304  const AVCodecParameters *par = candidate->codecpar;
1305 
1306  switch (par->codec_type) {
1307  case AVMEDIA_TYPE_AUDIO:
1308  if (!par->sample_rate || !par->ch_layout.nb_channels ||
1309  par->format == AV_SAMPLE_FMT_NONE)
1310  continue;
1311  break;
1312  case AVMEDIA_TYPE_VIDEO:
1313  if (!par->width || !par->height || par->format == AV_PIX_FMT_NONE)
1314  continue;
1315  break;
1316  case AVMEDIA_TYPE_UNKNOWN:
1317  continue;
1318  }
1319  }
1320 
1321  if (ss->disposition &&
1322  (candidate->disposition & ss->disposition) != ss->disposition)
1323  continue;
1324 
1325  if (st == candidate)
1326  return ss->idx < 0 || ss->idx == nb_matched;
1327 
1328  nb_matched++;
1329  }
1330 
1331  return 0;
1332 }
1333 
1334 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
1335 {
1337  int ret;
1338 
1339  ret = stream_specifier_parse(&ss, spec, 0, NULL);
1340  if (ret < 0)
1341  return ret;
1342 
1343  ret = stream_specifier_match(&ss, s, st, NULL);
1345  return ret;
1346 }
1347 
1349  AVFormatContext *s, AVStream *st, const AVCodec *codec,
1350  AVDictionary **dst, AVDictionary **opts_used)
1351 {
1352  AVDictionary *ret = NULL;
1353  const AVDictionaryEntry *t = NULL;
1354  int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
1356  char prefix = 0;
1357  const AVClass *cc = avcodec_get_class();
1358 
1359  switch (st->codecpar->codec_type) {
1360  case AVMEDIA_TYPE_VIDEO:
1361  prefix = 'v';
1363  break;
1364  case AVMEDIA_TYPE_AUDIO:
1365  prefix = 'a';
1367  break;
1368  case AVMEDIA_TYPE_SUBTITLE:
1369  prefix = 's';
1371  break;
1372  }
1373 
1374  while (t = av_dict_iterate(opts, t)) {
1375  const AVClass *priv_class;
1376  char *p = strchr(t->key, ':');
1377  int used = 0;
1378 
1379  /* check stream specification in opt name */
1380  if (p) {
1381  int err = check_stream_specifier(s, st, p + 1);
1382  if (err < 0) {
1383  av_dict_free(&ret);
1384  return err;
1385  } else if (!err)
1386  continue;
1387 
1388  *p = 0;
1389  }
1390 
1391  if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
1392  !codec ||
1393  ((priv_class = codec->priv_class) &&
1394  av_opt_find(&priv_class, t->key, NULL, flags,
1396  av_dict_set(&ret, t->key, t->value, 0);
1397  used = 1;
1398  } else if (t->key[0] == prefix &&
1399  av_opt_find(&cc, t->key + 1, NULL, flags,
1401  av_dict_set(&ret, t->key + 1, t->value, 0);
1402  used = 1;
1403  }
1404 
1405  if (p)
1406  *p = ':';
1407 
1408  if (used && opts_used)
1409  av_dict_set(opts_used, t->key, "", 0);
1410  }
1411 
1412  *dst = ret;
1413  return 0;
1414 }
1415 
1417  AVDictionary *local_codec_opts,
1418  AVDictionary ***dst)
1419 {
1420  int ret;
1421  AVDictionary **opts;
1422 
1423  *dst = NULL;
1424 
1425  if (!s->nb_streams)
1426  return 0;
1427 
1428  opts = av_calloc(s->nb_streams, sizeof(*opts));
1429  if (!opts)
1430  return AVERROR(ENOMEM);
1431 
1432  for (int i = 0; i < s->nb_streams; i++) {
1433  ret = filter_codec_opts(local_codec_opts, s->streams[i]->codecpar->codec_id,
1434  s, s->streams[i], NULL, &opts[i], NULL);
1435  if (ret < 0)
1436  goto fail;
1437  }
1438  *dst = opts;
1439  return 0;
1440 fail:
1441  for (int i = 0; i < s->nb_streams; i++)
1442  av_dict_free(&opts[i]);
1443  av_freep(&opts);
1444  return ret;
1445 }
1446 
1447 int grow_array(void **array, int elem_size, int *size, int new_size)
1448 {
1449  if (new_size >= INT_MAX / elem_size) {
1450  av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
1451  return AVERROR(ERANGE);
1452  }
1453  if (*size < new_size) {
1454  uint8_t *tmp = av_realloc_array(*array, new_size, elem_size);
1455  if (!tmp)
1456  return AVERROR(ENOMEM);
1457  memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1458  *size = new_size;
1459  *array = tmp;
1460  return 0;
1461  }
1462  return 0;
1463 }
1464 
1465 void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
1466 {
1467  void *new_elem;
1468 
1469  if (!(new_elem = av_mallocz(elem_size)) ||
1470  av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
1471  return NULL;
1472  return new_elem;
1473 }
1474 
1475 double get_rotation(const int32_t *displaymatrix)
1476 {
1477  double theta = 0;
1478  if (displaymatrix)
1479  theta = -round(av_display_rotation_get(displaymatrix));
1480 
1481  theta -= 360*floor(theta/360 + 0.9/360);
1482 
1483  if (fabs(theta - 90*round(theta/90)) > 2)
1484  av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
1485  "If you want to help, upload a sample "
1486  "of this file to https://streams.videolan.org/upload/ "
1487  "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
1488 
1489  return theta;
1490 }
1491 
1492 /* read file contents into a string */
1493 char *file_read(const char *filename)
1494 {
1495  AVIOContext *pb = NULL;
1496  int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1497  AVBPrint bprint;
1498  char *str;
1499 
1500  if (ret < 0) {
1501  av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1502  return NULL;
1503  }
1504 
1506  ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
1507  avio_closep(&pb);
1508  if (ret < 0) {
1509  av_bprint_finalize(&bprint, NULL);
1510  return NULL;
1511  }
1512  ret = av_bprint_finalize(&bprint, &str);
1513  if (ret < 0)
1514  return NULL;
1515  return str;
1516 }
1517 
1519 {
1520  const AVDictionaryEntry *t = NULL;
1521 
1522  while ((t = av_dict_iterate(b, t))) {
1524  }
1525 }
1526 
1528 {
1529  const AVDictionaryEntry *t = av_dict_iterate(m, NULL);
1530  if (t) {
1531  av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
1532  return AVERROR_OPTION_NOT_FOUND;
1533  }
1534 
1535  return 0;
1536 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:605
fopen_utf8
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: fopen_utf8.h:66
GET_ARG
#define GET_ARG(arg)
OPT_EXIT
#define OPT_EXIT
Definition: cmdutils.h:203
show_help_options
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags)
Print help for all options matching specified flags.
Definition: cmdutils.c:107
AVCodec
AVCodec.
Definition: codec.h:187
OptionGroup::group_def
const OptionGroupDef * group_def
Definition: cmdutils.h:337
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
level
uint8_t level
Definition: svq3.c:205
INFINITY
#define INFINITY
Definition: mathematics.h:118
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
get_rotation
double get_rotation(const int32_t *displaymatrix)
Definition: cmdutils.c:1475
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
OptionDef::off
size_t off
Definition: cmdutils.h:249
libm.h
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1216
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: cmdutils.c:1527
av_opt_child_class_iterate
const AVClass * av_opt_child_class_iterate(const AVClass *parent, void **iter)
Iterate over potential AVOptions-enabled children of parent.
Definition: opt.c:2016
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
AVCodec::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: codec.h:221
va_copy.h
AV_DISPOSITION_ATTACHED_PIC
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition: avformat.h:674
stream_specifier_parse
int stream_specifier_parse(StreamSpecifier *ss, const char *spec, int allow_remainder, void *logctx)
Parse a stream specifier string into a form suitable for matching.
Definition: cmdutils.c:1007
sws_dict
AVDictionary * sws_dict
Definition: cmdutils.c:56
int64_t
long long int64_t
Definition: coverity.c:34
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:197
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
OPT_FLAG_OFFSET
#define OPT_FLAG_OFFSET
Definition: cmdutils.h:219
init_report
int init_report(const char *env, FILE **file)
Definition: opt_common.c:1151
OPT_INPUT
#define OPT_INPUT
Definition: cmdutils.h:233
parse_number
int parse_number(const char *context, const char *numstr, enum OptionType type, double min, double max, double *dst)
Parse a string and return its corresponding value as a double.
Definition: cmdutils.c:84
StreamSpecifier
Definition: cmdutils.h:113
AVOption
AVOption.
Definition: opt.h:429
OptionGroupList::groups
OptionGroup * groups
Definition: cmdutils.h:356
b
#define b
Definition: input.c:41
OptionDef::dst_ptr
void * dst_ptr
Definition: cmdutils.h:247
OptionGroupList::nb_groups
int nb_groups
Definition: cmdutils.h:357
avio_open
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: avio.c:497
format_opts
AVDictionary * format_opts
Definition: cmdutils.c:58
OptionDef::type
enum OptionType type
Definition: cmdutils.h:193
grow_array
int 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:1447
FLAGS
#define FLAGS
Definition: cmdutils.c:593
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
base
uint8_t base
Definition: vp3data.h:128
freeenv_utf8
static void freeenv_utf8(char *var)
Definition: getenv_utf8.h:72
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:472
OptionGroup::swr_opts
AVDictionary * swr_opts
Definition: cmdutils.h:346
show_help_children
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:140
AVOption::flags
int flags
A combination of AV_OPT_FLAG_*.
Definition: opt.h:472
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVDictionary
Definition: dict.c:34
finish_group
static int finish_group(OptionParseContext *octx, int group_idx, const char *arg)
Definition: cmdutils.c:686
hide_banner
int hide_banner
Definition: cmdutils.c:60
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:321
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
STREAM_LIST_GROUP_ID
@ STREAM_LIST_GROUP_ID
Definition: cmdutils.h:109
opt_has_arg
static int opt_has_arg(const OptionDef *o)
Definition: cmdutils.c:231
OptionDef
Definition: cmdutils.h:191
stream_specifier_uninit
void stream_specifier_uninit(StreamSpecifier *ss)
Definition: cmdutils.c:998
finish
static void finish(void)
Definition: movenc.c:374
fopen_utf8.h
OptionGroupList
A list of option groups that all have the same group type (e.g.
Definition: cmdutils.h:353
fail
#define fail()
Definition: checkasm.h:188
OptionParseContext
Definition: cmdutils.h:360
init_parse_context
static int init_parse_context(OptionParseContext *octx, const OptionGroupDef *groups, int nb_groups)
Definition: cmdutils.c:738
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:63
Option
An option extracted from the commandline.
Definition: cmdutils.h:315
val
static double val(void *priv, double ch)
Definition: aeval.c:77
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
sws_get_class
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
Definition: options.c:97
OPT_TYPE_FLOAT
@ OPT_TYPE_FLOAT
Definition: cmdutils.h:86
OptionGroup::nb_opts
int nb_opts
Definition: cmdutils.h:341
OptionGroupList::group_def
const OptionGroupDef * group_def
Definition: cmdutils.h:354
ss
#define ss(width, name, subs,...)
Definition: cbs_vp9.c:202
OptionDef::help
const char * help
Definition: cmdutils.h:251
OptionGroupDef
Definition: cmdutils.h:321
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:357
check_stream_specifier
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:1334
first
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
Definition: rate_distortion.txt:12
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:343
check_options
static void check_options(const OptionDef *po)
Definition: cmdutils.c:536
av_dict_get
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:62
class
#define class
Definition: math.h:25
report_file
static FILE * report_file
Definition: opt_common.c:72
s
#define s(width, name)
Definition: cbs_vp9.c:198
OptionDef::argname
const char * argname
Definition: cmdutils.h:252
split_commandline
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:785
avio_read_to_bprint
int avio_read_to_bprint(AVIOContext *h, struct AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
Definition: aviobuf.c:1251
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
g
const char * g
Definition: vf_curves.c:128
AVDictionaryEntry::key
char * key
Definition: dict.h:90
Option::key
const char * key
Definition: cmdutils.h:317
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
OPT_TYPE_DOUBLE
@ OPT_TYPE_DOUBLE
Definition: cmdutils.h:87
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
nb_streams
static int nb_streams
Definition: ffprobe.c:384
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:394
key
const char * key
Definition: hwcontext_opencl.c:189
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
arg
const char * arg
Definition: jacosubdec.c:67
if
if(ret)
Definition: filter_design.txt:179
context
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Definition: writing_filters.txt:91
AVFormatContext
Format I/O context.
Definition: avformat.h:1287
init_dynload
void init_dynload(void)
Initialize dynamic library loading.
Definition: cmdutils.c:75
opts
AVDictionary * opts
Definition: movenc.c:51
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:344
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
STREAM_LIST_PROGRAM
@ STREAM_LIST_PROGRAM
Definition: cmdutils.h:108
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
avcodec_get_class
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:184
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
OptionParseContext::global_opts
OptionGroup global_opts
Definition: cmdutils.h:361
Option::opt
const OptionDef * opt
Definition: cmdutils.h:316
add_opt
static int add_opt(OptionParseContext *octx, const OptionDef *opt, const char *key, const char *val)
Definition: cmdutils.c:720
prepare_app_arguments
static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
Definition: cmdutils.c:225
swr_get_class
const AVClass * swr_get_class(void)
Get the AVClass for SwrContext.
Definition: options.c:143
filter_codec_opts
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec, AVDictionary **dst, AVDictionary **opts_used)
Filter out options for given codec.
Definition: cmdutils.c:1348
parseutils.h
opt_loglevel
int opt_loglevel(void *optctx, const char *opt, const char *arg)
Set the libav* libraries log level.
Definition: opt_common.c:1255
STREAM_LIST_STREAM_ID
@ STREAM_LIST_STREAM_ID
Definition: cmdutils.h:107
getenv_utf8
static char * getenv_utf8(const char *varname)
Definition: getenv_utf8.h:67
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1215
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:828
AV_OPT_SEARCH_FAKE_OBJ
#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:613
av_parse_time
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Definition: parseutils.c:589
stream_specifier_match
unsigned stream_specifier_match(const StreamSpecifier *ss, const AVFormatContext *s, const AVStream *st, void *logctx)
Definition: cmdutils.c:1222
STREAM_LIST_GROUP_IDX
@ STREAM_LIST_GROUP_IDX
Definition: cmdutils.h:110
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
OptionGroup::opts
Option * opts
Definition: cmdutils.h:340
OptionGroup
Definition: cmdutils.h:336
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:352
swresample.h
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
file_read
char * file_read(const char *filename)
Definition: cmdutils.c:1493
locate_option
int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
Return index of option opt in argv or 0 if not found.
Definition: cmdutils.c:486
codec_opts
AVDictionary * codec_opts
Definition: cmdutils.c:58
options
const OptionDef options[]
eval.h
av_opt_find
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:1957
f
f
Definition: af_crystalizer.c:122
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
OPT_TYPE_INT
@ OPT_TYPE_INT
Definition: cmdutils.h:84
SpecifierOptList
Definition: cmdutils.h:179
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:240
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
get_preset_file
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:919
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
uninit_opts
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents.
Definition: cmdutils.c:62
size
int size
Definition: twinvq_data.h:10344
OPT_TYPE_INT64
@ OPT_TYPE_INT64
Definition: cmdutils.h:85
printf
printf("static const uint8_t my_array[100] = {\n")
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
OptionType
OptionType
Definition: cmdutils.h:80
allocate_array_elem
void * allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
Atomically add a new element to an array of pointers, i.e.
Definition: cmdutils.c:1465
getenv_utf8.h
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
OPT_FLAG_SPEC
#define OPT_FLAG_SPEC
Definition: cmdutils.h:224
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
av_strstart
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:36
OPT_TYPE_FUNC
@ OPT_TYPE_FUNC
Definition: cmdutils.h:81
av_opt_show2
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition: opt.c:1632
OPT_DECODER
#define OPT_DECODER
Definition: cmdutils.h:244
OPT_TYPE_BOOL
@ OPT_TYPE_BOOL
Definition: cmdutils.h:82
OPT_HAS_CANON
#define OPT_HAS_CANON
Definition: cmdutils.h:241
OptionDef::u1
union OptionDef::@2 u1
av_log_set_level
void av_log_set_level(int level)
Set the log level.
Definition: log.c:447
bprint.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
OPT_TYPE_TIME
@ OPT_TYPE_TIME
Definition: cmdutils.h:88
setup_find_stream_info_opts
int setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *local_codec_opts, AVDictionary ***dst)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:1416
swr_opts
AVDictionary * swr_opts
Definition: cmdutils.c:57
AVCodecParameters::height
int height
Definition: codec_par.h:135
AV_OPT_FLAG_SUBTITLE_PARAM
#define AV_OPT_FLAG_SUBTITLE_PARAM
Definition: opt.h:359
display.h
parse_options
int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, int(*parse_arg_function)(void *, const char *))
Definition: cmdutils.c:417
av_toupper
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:227
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:358
OPT_FUNC_ARG
#define OPT_FUNC_ARG
Definition: cmdutils.h:201
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1211
OPT_OUTPUT
#define OPT_OUTPUT
Definition: cmdutils.h:234
len
int len
Definition: vorbis_enc_data.h:426
cmdutils_isalnum
int cmdutils_isalnum(char c)
Definition: cmdutils.c:991
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
OptionParseContext::groups
OptionGroupList * groups
Definition: cmdutils.h:363
OptionDef::u
union OptionDef::@1 u
parse_loglevel
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
Definition: cmdutils.c:552
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition: cmdutils.h:345
av_opt_eval_flags
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:817
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:111
tag
uint32_t tag
Definition: movenc.c:1879
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:760
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
read_yesno
int read_yesno(void)
Return a positive value if a line read from standard input starts with [yY], otherwise return 0.
Definition: cmdutils.c:908
av_strtod
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:107
av_strlcat
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:95
OptionGroup::arg
const char * arg
Definition: cmdutils.h:338
uninit_parse_context
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:760
log_callback_help
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
Definition: cmdutils.c:70
OPT_PERFILE
#define OPT_PERFILE
Definition: cmdutils.h:215
avformat.h
dict.h
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: cmdutils.c:1518
AV_DICT_MATCH_CASE
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:74
av_dynarray_add_nofree
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:315
AVStreamGroup
Definition: avformat.h:1121
av_get_media_type_string
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:28
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:754
OPT_FLAG_PERSTREAM
#define OPT_FLAG_PERSTREAM
Definition: cmdutils.h:228
parse_option
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Parse one given option.
Definition: cmdutils.c:377
opt_common.h
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
av_get_token
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:143
write_option
static int write_option(void *optctx, const OptionDef *po, const char *opt, const char *arg, const OptionDef *defs)
Definition: cmdutils.c:240
Option::val
const char * val
Definition: cmdutils.h:318
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:532
OptionDef::name_canon
const char * name_canon
Definition: cmdutils.h:257
parse_optgroup
int parse_optgroup(void *optctx, OptionGroup *g, const OptionDef *defs)
Parse an options group and write results into optctx.
Definition: cmdutils.c:453
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:617
opt_default
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:594
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:356
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
AVCodecParameters::format
int format
Definition: codec_par.h:92
OptionDef::name
const char * name
Definition: cmdutils.h:192
STREAM_LIST_ALL
@ STREAM_LIST_ALL
Definition: cmdutils.h:106
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:89
OPT_TYPE_STRING
@ OPT_TYPE_STRING
Definition: cmdutils.h:83
OptionGroupDef::sep
const char * sep
Option to be used as group separator.
Definition: cmdutils.h:328
avio_closep
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: avio.c:649
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
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:88
cmdutils.h
int32_t
int32_t
Definition: audioconvert.c:56
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_strlcpy
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:85
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
OptionParseContext::nb_groups
int nb_groups
Definition: cmdutils.h:364
find_option
static const OptionDef * find_option(const OptionDef *po, const char *name)
Definition: cmdutils.c:153
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
av_stream_get_class
const AVClass * av_stream_get_class(void)
Get the AVClass for AVStream.
Definition: options.c:246
av_strndup
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
Definition: mem.c:284
snprintf
#define snprintf
Definition: snprintf.h:34
OptionParseContext::cur_group
OptionGroup cur_group
Definition: cmdutils.h:367
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:44
dump_argument
static void dump_argument(FILE *report_file, const char *a)
Definition: cmdutils.c:512
swscale.h
match_group_separator
static int match_group_separator(const OptionGroupDef *groups, int nb_groups, const char *opt)
Definition: cmdutils.c:666
w32dlfcn.h
OptionDef::func_arg
int(* func_arg)(void *, const char *, const char *)
Definition: cmdutils.h:248
opt_find
static const AVOption * opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Definition: cmdutils.c:584
av_display_rotation_get
double av_display_rotation_get(const int32_t matrix[9])
Extract the rotation component of the transformation matrix.
Definition: display.c:35
min
float min
Definition: vorbis_enc_data.h:429
OptionDef::flags
int flags
Definition: cmdutils.h:194