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"
36 #include "libswscale/version.h"
38 #include "libavutil/avassert.h"
39 #include "libavutil/avstring.h"
40 #include "libavutil/bprint.h"
42 #include "libavutil/display.h"
43 #include "libavutil/getenv_utf8.h"
44 #include "libavutil/mathematics.h"
45 #include "libavutil/imgutils.h"
46 #include "libavutil/libm.h"
47 #include "libavutil/parseutils.h"
48 #include "libavutil/eval.h"
49 #include "libavutil/dict.h"
50 #include "libavutil/opt.h"
51 #include "cmdutils.h"
52 #include "fopen_utf8.h"
53 #include "opt_common.h"
54 #ifdef _WIN32
55 #include <windows.h>
56 #include "compat/w32dlfcn.h"
57 #endif
58 
62 
63 int hide_banner = 0;
64 
65 void uninit_opts(void)
66 {
71 }
72 
73 void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
74 {
75  vfprintf(stdout, fmt, vl);
76 }
77 
78 void init_dynload(void)
79 {
80 #if HAVE_SETDLLDIRECTORY && defined(_WIN32)
81  /* Calling SetDllDirectory with the empty string (but not NULL) removes the
82  * current working directory from the DLL search path as a security pre-caution. */
83  SetDllDirectory("");
84 #endif
85 }
86 
87 int parse_number(const char *context, const char *numstr, enum OptionType type,
88  double min, double max, double *dst)
89 {
90  char *tail;
91  const char *error;
92  double d = av_strtod(numstr, &tail);
93  if (*tail)
94  error = "Expected number for %s but found: %s\n";
95  else if (d < min || d > max)
96  error = "The value for %s was %s which is not within %f - %f\n";
97  else if (type == OPT_TYPE_INT64 && (int64_t)d != d)
98  error = "Expected int64 for %s but found %s\n";
99  else if (type == OPT_TYPE_INT && (int)d != d)
100  error = "Expected int for %s but found %s\n";
101  else {
102  *dst = d;
103  return 0;
104  }
105 
106  av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
107  return AVERROR(EINVAL);
108 }
109 
110 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
111  int rej_flags)
112 {
113  const OptionDef *po;
114  int first;
115 
116  first = 1;
117  for (po = options; po->name; po++) {
118  char buf[128];
119 
120  if (((po->flags & req_flags) != req_flags) ||
121  (po->flags & rej_flags))
122  continue;
123 
124  if (first) {
125  printf("%s\n", msg);
126  first = 0;
127  }
128  av_strlcpy(buf, po->name, sizeof(buf));
129 
130  if (po->flags & OPT_FLAG_PERSTREAM)
131  av_strlcat(buf, "[:<stream_spec>]", sizeof(buf));
132  else if (po->flags & OPT_FLAG_SPEC)
133  av_strlcat(buf, "[:<spec>]", sizeof(buf));
134 
135  if (po->argname)
136  av_strlcatf(buf, sizeof(buf), " <%s>", po->argname);
137 
138  printf("-%-17s %s\n", buf, po->help);
139  }
140  printf("\n");
141 }
142 
143 void show_help_children(const AVClass *class, int flags)
144 {
145  void *iter = NULL;
146  const AVClass *child;
147  if (class->option) {
148  av_opt_show2(&class, NULL, flags, 0);
149  printf("\n");
150  }
151 
152  while (child = av_opt_child_class_iterate(class, &iter))
153  show_help_children(child, flags);
154 }
155 
156 static const OptionDef *find_option(const OptionDef *po, const char *name)
157 {
158  if (*name == '/')
159  name++;
160 
161  while (po->name) {
162  const char *end;
163  if (av_strstart(name, po->name, &end) && (!*end || *end == ':'))
164  break;
165  po++;
166  }
167  return po;
168 }
169 
170 /* _WIN32 means using the windows libc - cygwin doesn't define that
171  * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
172  * it doesn't provide the actual command line via GetCommandLineW(). */
173 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
174 #include <shellapi.h>
175 /* Will be leaked on exit */
176 static char** win32_argv_utf8 = NULL;
177 static int win32_argc = 0;
178 
179 /**
180  * Prepare command line arguments for executable.
181  * For Windows - perform wide-char to UTF-8 conversion.
182  * Input arguments should be main() function arguments.
183  * @param argc_ptr Arguments number (including executable)
184  * @param argv_ptr Arguments list.
185  */
186 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
187 {
188  char *argstr_flat;
189  wchar_t **argv_w;
190  int i, buffsize = 0, offset = 0;
191 
192  if (win32_argv_utf8) {
193  *argc_ptr = win32_argc;
194  *argv_ptr = win32_argv_utf8;
195  return;
196  }
197 
198  win32_argc = 0;
199  argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
200  if (win32_argc <= 0 || !argv_w)
201  return;
202 
203  /* determine the UTF-8 buffer size (including NULL-termination symbols) */
204  for (i = 0; i < win32_argc; i++)
205  buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
206  NULL, 0, NULL, NULL);
207 
208  win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
209  argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
210  if (!win32_argv_utf8) {
211  LocalFree(argv_w);
212  return;
213  }
214 
215  for (i = 0; i < win32_argc; i++) {
216  win32_argv_utf8[i] = &argstr_flat[offset];
217  offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
218  &argstr_flat[offset],
219  buffsize - offset, NULL, NULL);
220  }
221  win32_argv_utf8[i] = NULL;
222  LocalFree(argv_w);
223 
224  *argc_ptr = win32_argc;
225  *argv_ptr = win32_argv_utf8;
226 }
227 #else
228 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
229 {
230  /* nothing to do */
231 }
232 #endif /* HAVE_COMMANDLINETOARGVW */
233 
234 static int opt_has_arg(const OptionDef *o)
235 {
236  if (o->type == OPT_TYPE_BOOL)
237  return 0;
238  if (o->type == OPT_TYPE_FUNC)
239  return !!(o->flags & OPT_FUNC_ARG);
240  return 1;
241 }
242 
243 static int write_option(void *optctx, const OptionDef *po, const char *opt,
244  const char *arg, const OptionDef *defs)
245 {
246  /* new-style options contain an offset into optctx, old-style address of
247  * a global var*/
248  void *dst = po->flags & OPT_FLAG_OFFSET ?
249  (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
250  char *arg_allocated = NULL;
251 
252  SpecifierOptList *sol = NULL;
253  double num;
254  int ret = 0;
255 
256  if (*opt == '/') {
257  opt++;
258 
259  if (po->type == OPT_TYPE_BOOL) {
261  "Requested to load an argument from file for a bool option '%s'\n",
262  po->name);
263  return AVERROR(EINVAL);
264  }
265 
266  arg_allocated = file_read(arg);
267  if (!arg_allocated) {
269  "Error reading the value for option '%s' from file: %s\n",
270  opt, arg);
271  return AVERROR(EINVAL);
272  }
273 
274  arg = arg_allocated;
275  }
276 
277  if (po->flags & OPT_FLAG_SPEC) {
278  char *p = strchr(opt, ':');
279  char *str;
280 
281  sol = dst;
282  ret = GROW_ARRAY(sol->opt, sol->nb_opt);
283  if (ret < 0)
284  goto finish;
285 
286  str = av_strdup(p ? p + 1 : "");
287  if (!str) {
288  ret = AVERROR(ENOMEM);
289  goto finish;
290  }
291  sol->opt[sol->nb_opt - 1].specifier = str;
292  dst = &sol->opt[sol->nb_opt - 1].u;
293  }
294 
295  if (po->type == OPT_TYPE_STRING) {
296  char *str;
297  if (arg_allocated) {
298  str = arg_allocated;
299  arg_allocated = NULL;
300  } else
301  str = av_strdup(arg);
302  av_freep(dst);
303 
304  if (!str) {
305  ret = AVERROR(ENOMEM);
306  goto finish;
307  }
308 
309  *(char **)dst = str;
310  } else if (po->type == OPT_TYPE_BOOL || po->type == OPT_TYPE_INT) {
311  ret = parse_number(opt, arg, OPT_TYPE_INT64, INT_MIN, INT_MAX, &num);
312  if (ret < 0)
313  goto finish;
314 
315  *(int *)dst = num;
316  } else if (po->type == OPT_TYPE_INT64) {
317  ret = parse_number(opt, arg, OPT_TYPE_INT64, INT64_MIN, INT64_MAX, &num);
318  if (ret < 0)
319  goto finish;
320 
321  *(int64_t *)dst = num;
322  } else if (po->type == OPT_TYPE_TIME) {
323  ret = av_parse_time(dst, arg, 1);
324  if (ret < 0) {
325  av_log(NULL, AV_LOG_ERROR, "Invalid duration for option %s: %s\n",
326  opt, arg);
327  goto finish;
328  }
329  } else if (po->type == OPT_TYPE_FLOAT) {
331  if (ret < 0)
332  goto finish;
333 
334  *(float *)dst = num;
335  } else if (po->type == OPT_TYPE_DOUBLE) {
337  if (ret < 0)
338  goto finish;
339 
340  *(double *)dst = num;
341  } else {
342  av_assert0(po->type == OPT_TYPE_FUNC && po->u.func_arg);
343 
344  ret = po->u.func_arg(optctx, opt, arg);
345  if (ret < 0) {
347  "Failed to set value '%s' for option '%s': %s\n",
348  arg, opt, av_err2str(ret));
349  goto finish;
350  }
351  }
352  if (po->flags & OPT_EXIT) {
353  ret = AVERROR_EXIT;
354  goto finish;
355  }
356 
357  if (sol) {
358  sol->type = po->type;
359  sol->opt_canon = (po->flags & OPT_HAS_CANON) ?
360  find_option(defs, po->u1.name_canon) : po;
361  }
362 
363 finish:
364  av_freep(&arg_allocated);
365  return ret;
366 }
367 
368 int parse_option(void *optctx, const char *opt, const char *arg,
369  const OptionDef *options)
370 {
371  static const OptionDef opt_avoptions = {
372  .name = "AVOption passthrough",
373  .type = OPT_TYPE_FUNC,
374  .flags = OPT_FUNC_ARG,
375  .u.func_arg = opt_default,
376  };
377 
378  const OptionDef *po;
379  int ret;
380 
381  po = find_option(options, opt);
382  if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
383  /* handle 'no' bool option */
384  po = find_option(options, opt + 2);
385  if ((po->name && po->type == OPT_TYPE_BOOL))
386  arg = "0";
387  } else if (po->type == OPT_TYPE_BOOL)
388  arg = "1";
389 
390  if (!po->name)
391  po = &opt_avoptions;
392  if (!po->name) {
393  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
394  return AVERROR(EINVAL);
395  }
396  if (opt_has_arg(po) && !arg) {
397  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
398  return AVERROR(EINVAL);
399  }
400 
401  ret = write_option(optctx, po, opt, arg, options);
402  if (ret < 0)
403  return ret;
404 
405  return opt_has_arg(po);
406 }
407 
408 int parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
409  int (*parse_arg_function)(void *, const char*))
410 {
411  const char *opt;
412  int optindex, handleoptions = 1, ret;
413 
414  /* perform system-dependent conversions for arguments list */
415  prepare_app_arguments(&argc, &argv);
416 
417  /* parse options */
418  optindex = 1;
419  while (optindex < argc) {
420  opt = argv[optindex++];
421 
422  if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
423  if (opt[1] == '-' && opt[2] == '\0') {
424  handleoptions = 0;
425  continue;
426  }
427  opt++;
428 
429  if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
430  return ret;
431  optindex += ret;
432  } else {
433  if (parse_arg_function) {
434  ret = parse_arg_function(optctx, opt);
435  if (ret < 0)
436  return ret;
437  }
438  }
439  }
440 
441  return 0;
442 }
443 
444 int parse_optgroup(void *optctx, OptionGroup *g, const OptionDef *defs)
445 {
446  int i, ret;
447 
448  av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
449  g->group_def->name, g->arg);
450 
451  for (i = 0; i < g->nb_opts; i++) {
452  Option *o = &g->opts[i];
453 
454  if (g->group_def->flags &&
455  !(g->group_def->flags & o->opt->flags)) {
456  av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
457  "%s %s -- you are trying to apply an input option to an "
458  "output file or vice versa. Move this option before the "
459  "file it belongs to.\n", o->key, o->opt->help,
460  g->group_def->name, g->arg);
461  return AVERROR(EINVAL);
462  }
463 
464  av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
465  o->key, o->opt->help, o->val);
466 
467  ret = write_option(optctx, o->opt, o->key, o->val, defs);
468  if (ret < 0)
469  return ret;
470  }
471 
472  av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
473 
474  return 0;
475 }
476 
477 int locate_option(int argc, char **argv, const OptionDef *options,
478  const char *optname)
479 {
480  const OptionDef *po;
481  int i;
482 
483  for (i = 1; i < argc; i++) {
484  const char *cur_opt = argv[i];
485 
486  if (*cur_opt++ != '-')
487  continue;
488 
489  po = find_option(options, cur_opt);
490  if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
491  po = find_option(options, cur_opt + 2);
492 
493  if ((!po->name && !strcmp(cur_opt, optname)) ||
494  (po->name && !strcmp(optname, po->name)))
495  return i;
496 
497  if (!po->name || opt_has_arg(po))
498  i++;
499  }
500  return 0;
501 }
502 
503 static void dump_argument(FILE *report_file, const char *a)
504 {
505  const unsigned char *p;
506 
507  for (p = a; *p; p++)
508  if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
509  *p == '_' || (*p >= 'a' && *p <= 'z')))
510  break;
511  if (!*p) {
512  fputs(a, report_file);
513  return;
514  }
515  fputc('"', report_file);
516  for (p = a; *p; p++) {
517  if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
518  fprintf(report_file, "\\%c", *p);
519  else if (*p < ' ' || *p > '~')
520  fprintf(report_file, "\\x%02x", *p);
521  else
522  fputc(*p, report_file);
523  }
524  fputc('"', report_file);
525 }
526 
527 static void check_options(const OptionDef *po)
528 {
529  while (po->name) {
530  if (po->flags & OPT_PERFILE)
532 
533  if (po->type == OPT_TYPE_FUNC)
535 
536  // OPT_FUNC_ARG can only be ser for OPT_TYPE_FUNC
537  av_assert0((po->type == OPT_TYPE_FUNC) || !(po->flags & OPT_FUNC_ARG));
538 
539  po++;
540  }
541 }
542 
543 void parse_loglevel(int argc, char **argv, const OptionDef *options)
544 {
545  int idx = locate_option(argc, argv, options, "loglevel");
546  char *env;
547 
549 
550  if (!idx)
551  idx = locate_option(argc, argv, options, "v");
552  if (idx && argv[idx + 1])
553  opt_loglevel(NULL, "loglevel", argv[idx + 1]);
554  idx = locate_option(argc, argv, options, "report");
555  env = getenv_utf8("FFREPORT");
556  if (env || idx) {
557  FILE *report_file = NULL;
558  init_report(env, &report_file);
559  if (report_file) {
560  int i;
561  fprintf(report_file, "Command line:\n");
562  for (i = 0; i < argc; i++) {
563  dump_argument(report_file, argv[i]);
564  fputc(i < argc - 1 ? ' ' : '\n', report_file);
565  }
566  fflush(report_file);
567  }
568  }
569  freeenv_utf8(env);
570  idx = locate_option(argc, argv, options, "hide_banner");
571  if (idx)
572  hide_banner = 1;
573 }
574 
575 static const AVOption *opt_find(void *obj, const char *name, const char *unit,
576  int opt_flags, int search_flags)
577 {
578  const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
579  if(o && !o->flags)
580  return NULL;
581  return o;
582 }
583 
584 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
585 int opt_default(void *optctx, const char *opt, const char *arg)
586 {
587  const AVOption *o;
588  int consumed = 0;
589  char opt_stripped[128];
590  const char *p;
591  const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
592 #if CONFIG_SWSCALE
593  const AVClass *sc = sws_get_class();
594 #endif
595 #if CONFIG_SWRESAMPLE
596  const AVClass *swr_class = swr_get_class();
597 #endif
598 
599  if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
601 
602  if (!(p = strchr(opt, ':')))
603  p = opt + strlen(opt);
604  av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
605 
606  if ((o = opt_find(&cc, opt_stripped, NULL, 0,
608  ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
609  (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
610  av_dict_set(&codec_opts, opt, arg, FLAGS);
611  consumed = 1;
612  }
613  if ((o = opt_find(&fc, opt, NULL, 0,
615  av_dict_set(&format_opts, opt, arg, FLAGS);
616  if (consumed)
617  av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
618  consumed = 1;
619  }
620 #if CONFIG_SWSCALE
621  if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
623  if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
624  !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
625  !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
626  av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
627  return AVERROR(EINVAL);
628  }
629  av_dict_set(&sws_dict, opt, arg, FLAGS);
630 
631  consumed = 1;
632  }
633 #else
634  if (!consumed && !strcmp(opt, "sws_flags")) {
635  av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
636  consumed = 1;
637  }
638 #endif
639 #if CONFIG_SWRESAMPLE
640  if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
642  av_dict_set(&swr_opts, opt, arg, FLAGS);
643  consumed = 1;
644  }
645 #endif
646 
647  if (consumed)
648  return 0;
650 }
651 
652 /*
653  * Check whether given option is a group separator.
654  *
655  * @return index of the group definition that matched or -1 if none
656  */
657 static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
658  const char *opt)
659 {
660  int i;
661 
662  for (i = 0; i < nb_groups; i++) {
663  const OptionGroupDef *p = &groups[i];
664  if (p->sep && !strcmp(p->sep, opt))
665  return i;
666  }
667 
668  return -1;
669 }
670 
671 /*
672  * Finish parsing an option group.
673  *
674  * @param group_idx which group definition should this group belong to
675  * @param arg argument of the group delimiting option
676  */
677 static int finish_group(OptionParseContext *octx, int group_idx,
678  const char *arg)
679 {
680  OptionGroupList *l = &octx->groups[group_idx];
681  OptionGroup *g;
682  int ret;
683 
684  ret = GROW_ARRAY(l->groups, l->nb_groups);
685  if (ret < 0)
686  return ret;
687 
688  g = &l->groups[l->nb_groups - 1];
689 
690  *g = octx->cur_group;
691  g->arg = arg;
692  g->group_def = l->group_def;
693  g->sws_dict = sws_dict;
694  g->swr_opts = swr_opts;
695  g->codec_opts = codec_opts;
696  g->format_opts = format_opts;
697 
698  codec_opts = NULL;
699  format_opts = NULL;
700  sws_dict = NULL;
701  swr_opts = NULL;
702 
703  memset(&octx->cur_group, 0, sizeof(octx->cur_group));
704 
705  return ret;
706 }
707 
708 /*
709  * Add an option instance to currently parsed group.
710  */
711 static int add_opt(OptionParseContext *octx, const OptionDef *opt,
712  const char *key, const char *val)
713 {
714  int global = !(opt->flags & OPT_PERFILE);
715  OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
716  int ret;
717 
718  ret = GROW_ARRAY(g->opts, g->nb_opts);
719  if (ret < 0)
720  return ret;
721 
722  g->opts[g->nb_opts - 1].opt = opt;
723  g->opts[g->nb_opts - 1].key = key;
724  g->opts[g->nb_opts - 1].val = val;
725 
726  return 0;
727 }
728 
730  const OptionGroupDef *groups, int nb_groups)
731 {
732  static const OptionGroupDef global_group = { "global" };
733  int i;
734 
735  memset(octx, 0, sizeof(*octx));
736 
737  octx->groups = av_calloc(nb_groups, sizeof(*octx->groups));
738  if (!octx->groups)
739  return AVERROR(ENOMEM);
740  octx->nb_groups = nb_groups;
741 
742  for (i = 0; i < octx->nb_groups; i++)
743  octx->groups[i].group_def = &groups[i];
744 
745  octx->global_opts.group_def = &global_group;
746  octx->global_opts.arg = "";
747 
748  return 0;
749 }
750 
752 {
753  int i, j;
754 
755  for (i = 0; i < octx->nb_groups; i++) {
756  OptionGroupList *l = &octx->groups[i];
757 
758  for (j = 0; j < l->nb_groups; j++) {
759  av_freep(&l->groups[j].opts);
762 
763  av_dict_free(&l->groups[j].sws_dict);
764  av_dict_free(&l->groups[j].swr_opts);
765  }
766  av_freep(&l->groups);
767  }
768  av_freep(&octx->groups);
769 
770  av_freep(&octx->cur_group.opts);
771  av_freep(&octx->global_opts.opts);
772 
773  uninit_opts();
774 }
775 
776 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
777  const OptionDef *options,
778  const OptionGroupDef *groups, int nb_groups)
779 {
780  int ret;
781  int optindex = 1;
782  int dashdash = -2;
783 
784  /* perform system-dependent conversions for arguments list */
785  prepare_app_arguments(&argc, &argv);
786 
787  ret = init_parse_context(octx, groups, nb_groups);
788  if (ret < 0)
789  return ret;
790 
791  av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
792 
793  while (optindex < argc) {
794  const char *opt = argv[optindex++], *arg;
795  const OptionDef *po;
796  int ret, group_idx;
797 
798  av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
799 
800  if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
801  dashdash = optindex;
802  continue;
803  }
804  /* unnamed group separators, e.g. output filename */
805  if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
806  ret = finish_group(octx, 0, opt);
807  if (ret < 0)
808  return ret;
809 
810  av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
811  continue;
812  }
813  opt++;
814 
815 #define GET_ARG(arg) \
816 do { \
817  arg = argv[optindex++]; \
818  if (!arg) { \
819  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
820  return AVERROR(EINVAL); \
821  } \
822 } while (0)
823 
824  /* named group separators, e.g. -i */
825  group_idx = match_group_separator(groups, nb_groups, opt);
826  if (group_idx >= 0) {
827  GET_ARG(arg);
828  ret = finish_group(octx, group_idx, arg);
829  if (ret < 0)
830  return ret;
831 
832  av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
833  groups[group_idx].name, arg);
834  continue;
835  }
836 
837  /* normal options */
838  po = find_option(options, opt);
839  if (po->name) {
840  if (po->flags & OPT_EXIT) {
841  /* optional argument, e.g. -h */
842  arg = argv[optindex++];
843  } else if (opt_has_arg(po)) {
844  GET_ARG(arg);
845  } else {
846  arg = "1";
847  }
848 
849  ret = add_opt(octx, po, opt, arg);
850  if (ret < 0)
851  return ret;
852 
853  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
854  "argument '%s'.\n", po->name, po->help, arg);
855  continue;
856  }
857 
858  /* AVOptions */
859  if (argv[optindex]) {
860  ret = opt_default(NULL, opt, argv[optindex]);
861  if (ret >= 0) {
862  av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
863  "argument '%s'.\n", opt, argv[optindex]);
864  optindex++;
865  continue;
866  } else if (ret != AVERROR_OPTION_NOT_FOUND) {
867  av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
868  "with argument '%s'.\n", opt, argv[optindex]);
869  return ret;
870  }
871  }
872 
873  /* boolean -nofoo options */
874  if (opt[0] == 'n' && opt[1] == 'o' &&
875  (po = find_option(options, opt + 2)) &&
876  po->name && po->type == OPT_TYPE_BOOL) {
877  ret = add_opt(octx, po, opt, "0");
878  if (ret < 0)
879  return ret;
880 
881  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
882  "argument 0.\n", po->name, po->help);
883  continue;
884  }
885 
886  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
888  }
889 
890  if (octx->cur_group.nb_opts || codec_opts || format_opts)
891  av_log(NULL, AV_LOG_WARNING, "Trailing option(s) found in the "
892  "command: may be ignored.\n");
893 
894  av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
895 
896  return 0;
897 }
898 
899 int read_yesno(void)
900 {
901  int c = getchar();
902  int yesno = (av_toupper(c) == 'Y');
903 
904  while (c != '\n' && c != EOF)
905  c = getchar();
906 
907  return yesno;
908 }
909 
910 FILE *get_preset_file(char *filename, size_t filename_size,
911  const char *preset_name, int is_path,
912  const char *codec_name)
913 {
914  FILE *f = NULL;
915  int i;
916 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
917  char *datadir = NULL;
918 #endif
919  char *env_home = getenv_utf8("HOME");
920  char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR");
921  const char *base[3] = { env_ffmpeg_datadir,
922  env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */
923  FFMPEG_DATADIR, };
924 
925  if (is_path) {
926  av_strlcpy(filename, preset_name, filename_size);
927  f = fopen_utf8(filename, "r");
928  } else {
929 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
930  wchar_t *datadir_w = get_module_filename(NULL);
931  base[2] = NULL;
932 
933  if (wchartoutf8(datadir_w, &datadir))
934  datadir = NULL;
935  av_free(datadir_w);
936 
937  if (datadir)
938  {
939  char *ls;
940  for (ls = datadir; *ls; ls++)
941  if (*ls == '\\') *ls = '/';
942 
943  if (ls = strrchr(datadir, '/'))
944  {
945  ptrdiff_t datadir_len = ls - datadir;
946  size_t desired_size = datadir_len + strlen("/ffpresets") + 1;
947  char *new_datadir = av_realloc_array(
948  datadir, desired_size, sizeof *datadir);
949  if (new_datadir) {
950  datadir = new_datadir;
951  datadir[datadir_len] = 0;
952  strncat(datadir, "/ffpresets", desired_size - 1 - datadir_len);
953  base[2] = datadir;
954  }
955  }
956  }
957 #endif
958  for (i = 0; i < 3 && !f; i++) {
959  if (!base[i])
960  continue;
961  snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
962  i != 1 ? "" : "/.ffmpeg", preset_name);
963  f = fopen_utf8(filename, "r");
964  if (!f && codec_name) {
965  snprintf(filename, filename_size,
966  "%s%s/%s-%s.ffpreset",
967  base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
968  preset_name);
969  f = fopen_utf8(filename, "r");
970  }
971  }
972  }
973 
974 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
975  av_free(datadir);
976 #endif
977  freeenv_utf8(env_ffmpeg_datadir);
978  freeenv_utf8(env_home);
979  return f;
980 }
981 
982 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
983 {
984  int ret = avformat_match_stream_specifier(s, st, spec);
985  if (ret < 0)
986  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
987  return ret;
988 }
989 
991  AVFormatContext *s, AVStream *st, const AVCodec *codec,
992  AVDictionary **dst)
993 {
994  AVDictionary *ret = NULL;
995  const AVDictionaryEntry *t = NULL;
996  int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
998  char prefix = 0;
999  const AVClass *cc = avcodec_get_class();
1000 
1001  if (!codec)
1002  codec = s->oformat ? avcodec_find_encoder(codec_id)
1004 
1005  switch (st->codecpar->codec_type) {
1006  case AVMEDIA_TYPE_VIDEO:
1007  prefix = 'v';
1009  break;
1010  case AVMEDIA_TYPE_AUDIO:
1011  prefix = 'a';
1013  break;
1014  case AVMEDIA_TYPE_SUBTITLE:
1015  prefix = 's';
1017  break;
1018  }
1019 
1020  while (t = av_dict_iterate(opts, t)) {
1021  const AVClass *priv_class;
1022  char *p = strchr(t->key, ':');
1023 
1024  /* check stream specification in opt name */
1025  if (p) {
1026  int err = check_stream_specifier(s, st, p + 1);
1027  if (err < 0) {
1028  av_dict_free(&ret);
1029  return err;
1030  } else if (!err)
1031  continue;
1032 
1033  *p = 0;
1034  }
1035 
1036  if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
1037  !codec ||
1038  ((priv_class = codec->priv_class) &&
1039  av_opt_find(&priv_class, t->key, NULL, flags,
1041  av_dict_set(&ret, t->key, t->value, 0);
1042  else if (t->key[0] == prefix &&
1043  av_opt_find(&cc, t->key + 1, NULL, flags,
1045  av_dict_set(&ret, t->key + 1, t->value, 0);
1046 
1047  if (p)
1048  *p = ':';
1049  }
1050 
1051  *dst = ret;
1052  return 0;
1053 }
1054 
1057  AVDictionary ***dst)
1058 {
1059  int ret;
1060  AVDictionary **opts;
1061 
1062  *dst = NULL;
1063 
1064  if (!s->nb_streams)
1065  return 0;
1066 
1067  opts = av_calloc(s->nb_streams, sizeof(*opts));
1068  if (!opts)
1069  return AVERROR(ENOMEM);
1070 
1071  for (int i = 0; i < s->nb_streams; i++) {
1072  ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
1073  s, s->streams[i], NULL, &opts[i]);
1074  if (ret < 0)
1075  goto fail;
1076  }
1077  *dst = opts;
1078  return 0;
1079 fail:
1080  for (int i = 0; i < s->nb_streams; i++)
1081  av_dict_free(&opts[i]);
1082  av_freep(&opts);
1083  return ret;
1084 }
1085 
1086 int grow_array(void **array, int elem_size, int *size, int new_size)
1087 {
1088  if (new_size >= INT_MAX / elem_size) {
1089  av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
1090  return AVERROR(ERANGE);
1091  }
1092  if (*size < new_size) {
1093  uint8_t *tmp = av_realloc_array(*array, new_size, elem_size);
1094  if (!tmp)
1095  return AVERROR(ENOMEM);
1096  memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1097  *size = new_size;
1098  *array = tmp;
1099  return 0;
1100  }
1101  return 0;
1102 }
1103 
1104 void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
1105 {
1106  void *new_elem;
1107 
1108  if (!(new_elem = av_mallocz(elem_size)) ||
1109  av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
1110  return NULL;
1111  return new_elem;
1112 }
1113 
1114 double get_rotation(const int32_t *displaymatrix)
1115 {
1116  double theta = 0;
1117  if (displaymatrix)
1118  theta = -round(av_display_rotation_get(displaymatrix));
1119 
1120  theta -= 360*floor(theta/360 + 0.9/360);
1121 
1122  if (fabs(theta - 90*round(theta/90)) > 2)
1123  av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
1124  "If you want to help, upload a sample "
1125  "of this file to https://streams.videolan.org/upload/ "
1126  "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
1127 
1128  return theta;
1129 }
1130 
1131 /* read file contents into a string */
1132 char *file_read(const char *filename)
1133 {
1134  AVIOContext *pb = NULL;
1135  int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1136  AVBPrint bprint;
1137  char *str;
1138 
1139  if (ret < 0) {
1140  av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1141  return NULL;
1142  }
1143 
1145  ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
1146  avio_closep(&pb);
1147  if (ret < 0) {
1148  av_bprint_finalize(&bprint, NULL);
1149  return NULL;
1150  }
1151  ret = av_bprint_finalize(&bprint, &str);
1152  if (ret < 0)
1153  return NULL;
1154  return str;
1155 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:522
fopen_utf8
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: fopen_utf8.h:65
GET_ARG
#define GET_ARG(arg)
OPT_EXIT
#define OPT_EXIT
Definition: cmdutils.h:138
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:110
AVCodec
AVCodec.
Definition: codec.h:187
OptionGroup::group_def
const OptionGroupDef * group_def
Definition: cmdutils.h:272
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:204
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:1114
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:184
libm.h
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:2009
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
AVCodec::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: codec.h:212
va_copy.h
sws_dict
AVDictionary * sws_dict
Definition: cmdutils.c:59
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:196
avcodec_find_encoder
const AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: allcodecs.c:966
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
OPT_FLAG_OFFSET
#define OPT_FLAG_OFFSET
Definition: cmdutils.h:154
init_report
int init_report(const char *env, FILE **file)
Definition: opt_common.c:1143
OPT_INPUT
#define OPT_INPUT
Definition: cmdutils.h:168
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:87
AVOption
AVOption.
Definition: opt.h:346
OptionGroupList::groups
OptionGroup * groups
Definition: cmdutils.h:291
OptionDef::dst_ptr
void * dst_ptr
Definition: cmdutils.h:182
OptionGroupList::nb_groups
int nb_groups
Definition: cmdutils.h:292
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:496
format_opts
AVDictionary * format_opts
Definition: cmdutils.c:61
OptionDef::type
enum OptionType type
Definition: cmdutils.h:128
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:1086
FLAGS
#define FLAGS
Definition: cmdutils.c:584
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:464
OptionGroup::swr_opts
AVDictionary * swr_opts
Definition: cmdutils.h:281
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:143
AVOption::flags
int flags
A combination of AV_OPT_FLAG_*.
Definition: opt.h:389
max
#define max(a, b)
Definition: cuda_runtime.h:33
mathematics.h
AVDictionary
Definition: dict.c:34
finish_group
static int finish_group(OptionParseContext *octx, int group_idx, const char *arg)
Definition: cmdutils.c:677
hide_banner
int hide_banner
Definition: cmdutils.c:63
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
opt_has_arg
static int opt_has_arg(const OptionDef *o)
Definition: cmdutils.c:234
OptionDef
Definition: cmdutils.h:126
finish
static void finish(void)
Definition: movenc.c:342
fopen_utf8.h
OptionGroupList
A list of option groups that all have the same group type (e.g.
Definition: cmdutils.h:288
fail
#define fail()
Definition: checkasm.h:179
OptionParseContext
Definition: cmdutils.h:295
init_parse_context
static int init_parse_context(OptionParseContext *octx, const OptionGroupDef *groups, int nb_groups)
Definition: cmdutils.c:729
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:250
val
static double val(void *priv, double ch)
Definition: aeval.c:78
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:276
OptionGroupList::group_def
const OptionGroupDef * group_def
Definition: cmdutils.h:289
OptionDef::help
const char * help
Definition: cmdutils.h:186
OptionGroupDef
Definition: cmdutils.h:256
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:274
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:982
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_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:278
check_options
static void check_options(const OptionDef *po)
Definition: cmdutils.c:527
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:187
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:776
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:1250
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
g
const char * g
Definition: vf_curves.c:127
AVDictionaryEntry::key
char * key
Definition: dict.h:90
Option::key
const char * key
Definition: cmdutils.h:252
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
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
setup_find_stream_info_opts
int setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts, AVDictionary ***dst)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:1055
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:386
filter_codec_opts
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec, AVDictionary **dst)
Filter out options for given codec.
Definition: cmdutils.c:990
key
const char * key
Definition: hwcontext_opencl.c:189
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:1255
init_dynload
void init_dynload(void)
Initialize dynamic library loading.
Definition: cmdutils.c:78
opts
AVDictionary * opts
Definition: movenc.c:50
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:279
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
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:183
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:296
Option::opt
const OptionDef * opt
Definition: cmdutils.h:251
add_opt
static int add_opt(OptionParseContext *octx, const OptionDef *opt, const char *key, const char *val)
Definition: cmdutils.c:711
prepare_app_arguments
static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
Definition: cmdutils.c:228
swr_get_class
const AVClass * swr_get_class(void)
Get the AVClass for SwrContext.
Definition: options.c:142
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:1247
getenv_utf8
static char * getenv_utf8(const char *varname)
Definition: getenv_utf8.h:67
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:530
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
OptionGroup::opts
Option * opts
Definition: cmdutils.h:275
OptionGroup
Definition: cmdutils.h:271
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:269
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
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:971
file_read
char * file_read(const char *filename)
Definition: cmdutils.c:1132
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:477
codec_opts
AVDictionary * codec_opts
Definition: cmdutils.c:61
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:1950
f
f
Definition: af_crystalizer.c:121
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
OPT_TYPE_INT
@ OPT_TYPE_INT
Definition: cmdutils.h:84
avformat_match_stream_specifier
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
Definition: avformat.c:681
SpecifierOptList
Definition: cmdutils.h:117
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:240
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:121
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:910
uninit_opts
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents.
Definition: cmdutils.c:65
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")
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:1104
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:159
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:1626
OPT_DECODER
#define OPT_DECODER
Definition: cmdutils.h:179
OPT_TYPE_BOOL
@ OPT_TYPE_BOOL
Definition: cmdutils.h:82
OPT_HAS_CANON
#define OPT_HAS_CANON
Definition: cmdutils.h:176
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:255
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
swr_opts
AVDictionary * swr_opts
Definition: cmdutils.c:60
AV_OPT_FLAG_SUBTITLE_PARAM
#define AV_OPT_FLAG_SUBTITLE_PARAM
Definition: opt.h:276
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:408
av_toupper
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:227
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:275
OPT_FUNC_ARG
#define OPT_FUNC_ARG
Definition: cmdutils.h:136
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:254
OPT_OUTPUT
#define OPT_OUTPUT
Definition: cmdutils.h:169
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
OptionParseContext::groups
OptionGroupList * groups
Definition: cmdutils.h:298
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:543
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition: cmdutils.h:280
version.h
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:111
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:743
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:899
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:108
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:273
uninit_parse_context
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:751
log_callback_help
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
Definition: cmdutils.c:73
OPT_PERFILE
#define OPT_PERFILE
Definition: cmdutils.h:150
avformat.h
dict.h
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:313
OPT_FLAG_PERSTREAM
#define OPT_FLAG_PERSTREAM
Definition: cmdutils.h:163
parse_option
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Parse one given option.
Definition: cmdutils.c:368
channel_layout.h
opt_common.h
write_option
static int write_option(void *optctx, const OptionDef *po, const char *opt, const char *arg, const OptionDef *defs)
Definition: cmdutils.c:243
Option::val
const char * val
Definition: cmdutils.h:253
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:465
OptionDef::name_canon
const char * name_canon
Definition: cmdutils.h:192
parse_optgroup
int parse_optgroup(void *optctx, OptionGroup *g, const OptionDef *defs)
Parse an options group and write results into optctx.
Definition: cmdutils.c:444
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:585
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
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:273
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
OptionDef::name
const char * name
Definition: cmdutils.h:127
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:263
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:648
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
d
d
Definition: ffmpeg_filter.c:425
int32_t
int32_t
Definition: audioconvert.c:56
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
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:299
find_option
static const OptionDef * find_option(const OptionDef *po, const char *name)
Definition: cmdutils.c:156
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
snprintf
#define snprintf
Definition: snprintf.h:34
OptionParseContext::cur_group
OptionGroup cur_group
Definition: cmdutils.h:302
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:503
swscale.h
match_group_separator
static int match_group_separator(const OptionGroupDef *groups, int nb_groups, const char *opt)
Definition: cmdutils.c:657
w32dlfcn.h
OptionDef::func_arg
int(* func_arg)(void *, const char *, const char *)
Definition: cmdutils.h:183
opt_find
static const AVOption * opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Definition: cmdutils.c:575
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:129