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  SpecifierOptList *sol = NULL;
250  double num;
251  int ret = 0;
252 
253  if (*opt == '/') {
254  opt++;
255 
256  if (po->type == OPT_TYPE_BOOL) {
258  "Requested to load an argument from file for a bool option '%s'\n",
259  po->name);
260  return AVERROR(EINVAL);
261  }
262 
263  arg_allocated = file_read(arg);
264  if (!arg_allocated) {
266  "Error reading the value for option '%s' from file: %s\n",
267  opt, arg);
268  return AVERROR(EINVAL);
269  }
270 
271  arg = arg_allocated;
272  }
273 
274  if (po->flags & OPT_FLAG_SPEC) {
275  char *p = strchr(opt, ':');
276  char *str;
277 
278  sol = dst;
279  ret = GROW_ARRAY(sol->opt, sol->nb_opt);
280  if (ret < 0)
281  goto finish;
282 
283  str = av_strdup(p ? p + 1 : "");
284  if (!str) {
285  ret = AVERROR(ENOMEM);
286  goto finish;
287  }
288  sol->opt[sol->nb_opt - 1].specifier = str;
289  dst = &sol->opt[sol->nb_opt - 1].u;
290  }
291 
292  if (po->type == OPT_TYPE_STRING) {
293  char *str;
294  if (arg_allocated) {
295  str = arg_allocated;
296  arg_allocated = NULL;
297  } else
298  str = av_strdup(arg);
299  av_freep(dst);
300 
301  if (!str) {
302  ret = AVERROR(ENOMEM);
303  goto finish;
304  }
305 
306  *(char **)dst = str;
307  } else if (po->type == OPT_TYPE_BOOL || po->type == OPT_TYPE_INT) {
308  ret = parse_number(opt, arg, OPT_TYPE_INT64, INT_MIN, INT_MAX, &num);
309  if (ret < 0)
310  goto finish;
311 
312  *(int *)dst = num;
313  } else if (po->type == OPT_TYPE_INT64) {
314  ret = parse_number(opt, arg, OPT_TYPE_INT64, INT64_MIN, (double)INT64_MAX, &num);
315  if (ret < 0)
316  goto finish;
317 
318  *(int64_t *)dst = num;
319  } else if (po->type == OPT_TYPE_TIME) {
320  ret = av_parse_time(dst, arg, 1);
321  if (ret < 0) {
322  av_log(NULL, AV_LOG_ERROR, "Invalid duration for option %s: %s\n",
323  opt, arg);
324  goto finish;
325  }
326  } else if (po->type == OPT_TYPE_FLOAT) {
328  if (ret < 0)
329  goto finish;
330 
331  *(float *)dst = num;
332  } else if (po->type == OPT_TYPE_DOUBLE) {
334  if (ret < 0)
335  goto finish;
336 
337  *(double *)dst = num;
338  } else {
339  av_assert0(po->type == OPT_TYPE_FUNC && po->u.func_arg);
340 
341  ret = po->u.func_arg(optctx, opt, arg);
342  if (ret < 0) {
344  "Failed to set value '%s' for option '%s': %s\n",
345  arg, opt, av_err2str(ret));
346  goto finish;
347  }
348  }
349  if (po->flags & OPT_EXIT) {
350  ret = AVERROR_EXIT;
351  goto finish;
352  }
353 
354  if (sol) {
355  sol->type = po->type;
356  sol->opt_canon = (po->flags & OPT_HAS_CANON) ?
357  find_option(defs, po->u1.name_canon) : po;
358  }
359 
360 finish:
361  av_freep(&arg_allocated);
362  return ret;
363 }
364 
365 int parse_option(void *optctx, const char *opt, const char *arg,
366  const OptionDef *options)
367 {
368  static const OptionDef opt_avoptions = {
369  .name = "AVOption passthrough",
370  .type = OPT_TYPE_FUNC,
371  .flags = OPT_FUNC_ARG,
372  .u.func_arg = opt_default,
373  };
374 
375  const OptionDef *po;
376  int ret;
377 
378  po = find_option(options, opt);
379  if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
380  /* handle 'no' bool option */
381  po = find_option(options, opt + 2);
382  if ((po->name && po->type == OPT_TYPE_BOOL))
383  arg = "0";
384  } else if (po->type == OPT_TYPE_BOOL)
385  arg = "1";
386 
387  if (!po->name)
388  po = &opt_avoptions;
389  if (!po->name) {
390  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
391  return AVERROR(EINVAL);
392  }
393  if (opt_has_arg(po) && !arg) {
394  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
395  return AVERROR(EINVAL);
396  }
397 
398  ret = write_option(optctx, po, opt, arg, options);
399  if (ret < 0)
400  return ret;
401 
402  return opt_has_arg(po);
403 }
404 
405 int parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
406  int (*parse_arg_function)(void *, const char*))
407 {
408  const char *opt;
409  int optindex, handleoptions = 1, ret;
410 
411  /* perform system-dependent conversions for arguments list */
412  prepare_app_arguments(&argc, &argv);
413 
414  /* parse options */
415  optindex = 1;
416  while (optindex < argc) {
417  opt = argv[optindex++];
418 
419  if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
420  if (opt[1] == '-' && opt[2] == '\0') {
421  handleoptions = 0;
422  continue;
423  }
424  opt++;
425 
426  if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
427  return ret;
428  optindex += ret;
429  } else {
430  if (parse_arg_function) {
431  ret = parse_arg_function(optctx, opt);
432  if (ret < 0)
433  return ret;
434  }
435  }
436  }
437 
438  return 0;
439 }
440 
441 int parse_optgroup(void *optctx, OptionGroup *g, const OptionDef *defs)
442 {
443  int i, ret;
444 
445  av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
446  g->group_def->name, g->arg);
447 
448  for (i = 0; i < g->nb_opts; i++) {
449  Option *o = &g->opts[i];
450 
451  if (g->group_def->flags &&
452  !(g->group_def->flags & o->opt->flags)) {
453  av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
454  "%s %s -- you are trying to apply an input option to an "
455  "output file or vice versa. Move this option before the "
456  "file it belongs to.\n", o->key, o->opt->help,
457  g->group_def->name, g->arg);
458  return AVERROR(EINVAL);
459  }
460 
461  av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
462  o->key, o->opt->help, o->val);
463 
464  ret = write_option(optctx, o->opt, o->key, o->val, defs);
465  if (ret < 0)
466  return ret;
467  }
468 
469  av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
470 
471  return 0;
472 }
473 
474 int locate_option(int argc, char **argv, const OptionDef *options,
475  const char *optname)
476 {
477  const OptionDef *po;
478  int i;
479 
480  for (i = 1; i < argc; i++) {
481  const char *cur_opt = argv[i];
482 
483  if (*cur_opt++ != '-')
484  continue;
485 
486  po = find_option(options, cur_opt);
487  if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
488  po = find_option(options, cur_opt + 2);
489 
490  if ((!po->name && !strcmp(cur_opt, optname)) ||
491  (po->name && !strcmp(optname, po->name)))
492  return i;
493 
494  if (!po->name || opt_has_arg(po))
495  i++;
496  }
497  return 0;
498 }
499 
500 static void dump_argument(FILE *report_file, const char *a)
501 {
502  const unsigned char *p;
503 
504  for (p = a; *p; p++)
505  if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
506  *p == '_' || (*p >= 'a' && *p <= 'z')))
507  break;
508  if (!*p) {
509  fputs(a, report_file);
510  return;
511  }
512  fputc('"', report_file);
513  for (p = a; *p; p++) {
514  if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
515  fprintf(report_file, "\\%c", *p);
516  else if (*p < ' ' || *p > '~')
517  fprintf(report_file, "\\x%02x", *p);
518  else
519  fputc(*p, report_file);
520  }
521  fputc('"', report_file);
522 }
523 
524 static void check_options(const OptionDef *po)
525 {
526  while (po->name) {
527  if (po->flags & OPT_PERFILE)
529 
530  if (po->type == OPT_TYPE_FUNC)
532 
533  // OPT_FUNC_ARG can only be ser for OPT_TYPE_FUNC
534  av_assert0((po->type == OPT_TYPE_FUNC) || !(po->flags & OPT_FUNC_ARG));
535 
536  po++;
537  }
538 }
539 
540 void parse_loglevel(int argc, char **argv, const OptionDef *options)
541 {
542  int idx = locate_option(argc, argv, options, "loglevel");
543  char *env;
544 
546 
547  if (!idx)
548  idx = locate_option(argc, argv, options, "v");
549  if (idx && argv[idx + 1])
550  opt_loglevel(NULL, "loglevel", argv[idx + 1]);
551  idx = locate_option(argc, argv, options, "report");
552  env = getenv_utf8("FFREPORT");
553  if (env || idx) {
554  FILE *report_file = NULL;
555  init_report(env, &report_file);
556  if (report_file) {
557  int i;
558  fprintf(report_file, "Command line:\n");
559  for (i = 0; i < argc; i++) {
560  dump_argument(report_file, argv[i]);
561  fputc(i < argc - 1 ? ' ' : '\n', report_file);
562  }
563  fflush(report_file);
564  }
565  }
566  freeenv_utf8(env);
567  idx = locate_option(argc, argv, options, "hide_banner");
568  if (idx)
569  hide_banner = 1;
570 }
571 
572 static const AVOption *opt_find(void *obj, const char *name, const char *unit,
573  int opt_flags, int search_flags)
574 {
575  const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
576  if(o && !o->flags)
577  return NULL;
578  return o;
579 }
580 
581 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
582 int opt_default(void *optctx, const char *opt, const char *arg)
583 {
584  const AVOption *o;
585  int consumed = 0;
586  char opt_stripped[128];
587  const char *p;
588  const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
589 #if CONFIG_SWSCALE
590  const AVClass *sc = sws_get_class();
591 #endif
592 #if CONFIG_SWRESAMPLE
593  const AVClass *swr_class = swr_get_class();
594 #endif
595 
596  if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
598 
599  if (!(p = strchr(opt, ':')))
600  p = opt + strlen(opt);
601  av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
602 
603  if ((o = opt_find(&cc, opt_stripped, NULL, 0,
605  ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
606  (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
607  av_dict_set(&codec_opts, opt, arg, FLAGS);
608  consumed = 1;
609  }
610  if ((o = opt_find(&fc, opt, NULL, 0,
612  av_dict_set(&format_opts, opt, arg, FLAGS);
613  if (consumed)
614  av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
615  consumed = 1;
616  }
617 #if CONFIG_SWSCALE
618  if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
620  if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
621  !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
622  !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
623  av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
624  return AVERROR(EINVAL);
625  }
626  av_dict_set(&sws_dict, opt, arg, FLAGS);
627 
628  consumed = 1;
629  }
630 #else
631  if (!consumed && !strcmp(opt, "sws_flags")) {
632  av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
633  consumed = 1;
634  }
635 #endif
636 #if CONFIG_SWRESAMPLE
637  if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
639  av_dict_set(&swr_opts, opt, arg, FLAGS);
640  consumed = 1;
641  }
642 #endif
643 
644  if (consumed)
645  return 0;
647 }
648 
649 /*
650  * Check whether given option is a group separator.
651  *
652  * @return index of the group definition that matched or -1 if none
653  */
654 static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
655  const char *opt)
656 {
657  int i;
658 
659  for (i = 0; i < nb_groups; i++) {
660  const OptionGroupDef *p = &groups[i];
661  if (p->sep && !strcmp(p->sep, opt))
662  return i;
663  }
664 
665  return -1;
666 }
667 
668 /*
669  * Finish parsing an option group.
670  *
671  * @param group_idx which group definition should this group belong to
672  * @param arg argument of the group delimiting option
673  */
674 static int finish_group(OptionParseContext *octx, int group_idx,
675  const char *arg)
676 {
677  OptionGroupList *l = &octx->groups[group_idx];
678  OptionGroup *g;
679  int ret;
680 
681  ret = GROW_ARRAY(l->groups, l->nb_groups);
682  if (ret < 0)
683  return ret;
684 
685  g = &l->groups[l->nb_groups - 1];
686 
687  *g = octx->cur_group;
688  g->arg = arg;
689  g->group_def = l->group_def;
690  g->sws_dict = sws_dict;
691  g->swr_opts = swr_opts;
692  g->codec_opts = codec_opts;
693  g->format_opts = format_opts;
694 
695  codec_opts = NULL;
696  format_opts = NULL;
697  sws_dict = NULL;
698  swr_opts = NULL;
699 
700  memset(&octx->cur_group, 0, sizeof(octx->cur_group));
701 
702  return ret;
703 }
704 
705 /*
706  * Add an option instance to currently parsed group.
707  */
708 static int add_opt(OptionParseContext *octx, const OptionDef *opt,
709  const char *key, const char *val)
710 {
711  int global = !(opt->flags & OPT_PERFILE);
712  OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
713  int ret;
714 
715  ret = GROW_ARRAY(g->opts, g->nb_opts);
716  if (ret < 0)
717  return ret;
718 
719  g->opts[g->nb_opts - 1].opt = opt;
720  g->opts[g->nb_opts - 1].key = key;
721  g->opts[g->nb_opts - 1].val = val;
722 
723  return 0;
724 }
725 
727  const OptionGroupDef *groups, int nb_groups)
728 {
729  static const OptionGroupDef global_group = { "global" };
730  int i;
731 
732  memset(octx, 0, sizeof(*octx));
733 
734  octx->groups = av_calloc(nb_groups, sizeof(*octx->groups));
735  if (!octx->groups)
736  return AVERROR(ENOMEM);
737  octx->nb_groups = nb_groups;
738 
739  for (i = 0; i < octx->nb_groups; i++)
740  octx->groups[i].group_def = &groups[i];
741 
742  octx->global_opts.group_def = &global_group;
743  octx->global_opts.arg = "";
744 
745  return 0;
746 }
747 
749 {
750  int i, j;
751 
752  for (i = 0; i < octx->nb_groups; i++) {
753  OptionGroupList *l = &octx->groups[i];
754 
755  for (j = 0; j < l->nb_groups; j++) {
756  av_freep(&l->groups[j].opts);
759 
760  av_dict_free(&l->groups[j].sws_dict);
761  av_dict_free(&l->groups[j].swr_opts);
762  }
763  av_freep(&l->groups);
764  }
765  av_freep(&octx->groups);
766 
767  av_freep(&octx->cur_group.opts);
768  av_freep(&octx->global_opts.opts);
769 
770  uninit_opts();
771 }
772 
773 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
774  const OptionDef *options,
775  const OptionGroupDef *groups, int nb_groups)
776 {
777  int ret;
778  int optindex = 1;
779  int dashdash = -2;
780 
781  /* perform system-dependent conversions for arguments list */
782  prepare_app_arguments(&argc, &argv);
783 
784  ret = init_parse_context(octx, groups, nb_groups);
785  if (ret < 0)
786  return ret;
787 
788  av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
789 
790  while (optindex < argc) {
791  const char *opt = argv[optindex++], *arg;
792  const OptionDef *po;
793  int ret, group_idx;
794 
795  av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
796 
797  if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
798  dashdash = optindex;
799  continue;
800  }
801  /* unnamed group separators, e.g. output filename */
802  if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
803  ret = finish_group(octx, 0, opt);
804  if (ret < 0)
805  return ret;
806 
807  av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
808  continue;
809  }
810  opt++;
811 
812 #define GET_ARG(arg) \
813 do { \
814  arg = argv[optindex++]; \
815  if (!arg) { \
816  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
817  return AVERROR(EINVAL); \
818  } \
819 } while (0)
820 
821  /* named group separators, e.g. -i */
822  group_idx = match_group_separator(groups, nb_groups, opt);
823  if (group_idx >= 0) {
824  GET_ARG(arg);
825  ret = finish_group(octx, group_idx, arg);
826  if (ret < 0)
827  return ret;
828 
829  av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
830  groups[group_idx].name, arg);
831  continue;
832  }
833 
834  /* normal options */
835  po = find_option(options, opt);
836  if (po->name) {
837  if (po->flags & OPT_EXIT) {
838  /* optional argument, e.g. -h */
839  arg = argv[optindex++];
840  } else if (opt_has_arg(po)) {
841  GET_ARG(arg);
842  } else {
843  arg = "1";
844  }
845 
846  ret = add_opt(octx, po, opt, arg);
847  if (ret < 0)
848  return ret;
849 
850  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
851  "argument '%s'.\n", po->name, po->help, arg);
852  continue;
853  }
854 
855  /* AVOptions */
856  if (argv[optindex]) {
857  ret = opt_default(NULL, opt, argv[optindex]);
858  if (ret >= 0) {
859  av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
860  "argument '%s'.\n", opt, argv[optindex]);
861  optindex++;
862  continue;
863  } else if (ret != AVERROR_OPTION_NOT_FOUND) {
864  av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
865  "with argument '%s'.\n", opt, argv[optindex]);
866  return ret;
867  }
868  }
869 
870  /* boolean -nofoo options */
871  if (opt[0] == 'n' && opt[1] == 'o' &&
872  (po = find_option(options, opt + 2)) &&
873  po->name && po->type == OPT_TYPE_BOOL) {
874  ret = add_opt(octx, po, opt, "0");
875  if (ret < 0)
876  return ret;
877 
878  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
879  "argument 0.\n", po->name, po->help);
880  continue;
881  }
882 
883  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
885  }
886 
887  if (octx->cur_group.nb_opts || codec_opts || format_opts)
888  av_log(NULL, AV_LOG_WARNING, "Trailing option(s) found in the "
889  "command: may be ignored.\n");
890 
891  av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
892 
893  return 0;
894 }
895 
896 int read_yesno(void)
897 {
898  int c = getchar();
899  int yesno = (av_toupper(c) == 'Y');
900 
901  while (c != '\n' && c != EOF)
902  c = getchar();
903 
904  return yesno;
905 }
906 
907 FILE *get_preset_file(char *filename, size_t filename_size,
908  const char *preset_name, int is_path,
909  const char *codec_name)
910 {
911  FILE *f = NULL;
912  int i;
913 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
914  char *datadir = NULL;
915 #endif
916  char *env_home = getenv_utf8("HOME");
917  char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR");
918  const char *base[3] = { env_ffmpeg_datadir,
919  env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */
920  FFMPEG_DATADIR, };
921 
922  if (is_path) {
923  av_strlcpy(filename, preset_name, filename_size);
924  f = fopen_utf8(filename, "r");
925  } else {
926 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
927  wchar_t *datadir_w = get_module_filename(NULL);
928  base[2] = NULL;
929 
930  if (wchartoutf8(datadir_w, &datadir))
931  datadir = NULL;
932  av_free(datadir_w);
933 
934  if (datadir)
935  {
936  char *ls;
937  for (ls = datadir; *ls; ls++)
938  if (*ls == '\\') *ls = '/';
939 
940  if (ls = strrchr(datadir, '/'))
941  {
942  ptrdiff_t datadir_len = ls - datadir;
943  size_t desired_size = datadir_len + strlen("/ffpresets") + 1;
944  char *new_datadir = av_realloc_array(
945  datadir, desired_size, sizeof *datadir);
946  if (new_datadir) {
947  datadir = new_datadir;
948  datadir[datadir_len] = 0;
949  strncat(datadir, "/ffpresets", desired_size - 1 - datadir_len);
950  base[2] = datadir;
951  }
952  }
953  }
954 #endif
955  for (i = 0; i < 3 && !f; i++) {
956  if (!base[i])
957  continue;
958  snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
959  i != 1 ? "" : "/.ffmpeg", preset_name);
960  f = fopen_utf8(filename, "r");
961  if (!f && codec_name) {
962  snprintf(filename, filename_size,
963  "%s%s/%s-%s.ffpreset",
964  base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
965  preset_name);
966  f = fopen_utf8(filename, "r");
967  }
968  }
969  }
970 
971 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
972  av_free(datadir);
973 #endif
974  freeenv_utf8(env_ffmpeg_datadir);
975  freeenv_utf8(env_home);
976  return f;
977 }
978 
979 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
980 {
981  int ret = avformat_match_stream_specifier(s, st, spec);
982  if (ret < 0)
983  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
984  return ret;
985 }
986 
988  AVFormatContext *s, AVStream *st, const AVCodec *codec,
989  AVDictionary **dst)
990 {
991  AVDictionary *ret = NULL;
992  const AVDictionaryEntry *t = NULL;
993  int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
995  char prefix = 0;
996  const AVClass *cc = avcodec_get_class();
997 
998  switch (st->codecpar->codec_type) {
999  case AVMEDIA_TYPE_VIDEO:
1000  prefix = 'v';
1002  break;
1003  case AVMEDIA_TYPE_AUDIO:
1004  prefix = 'a';
1006  break;
1007  case AVMEDIA_TYPE_SUBTITLE:
1008  prefix = 's';
1010  break;
1011  }
1012 
1013  while (t = av_dict_iterate(opts, t)) {
1014  const AVClass *priv_class;
1015  char *p = strchr(t->key, ':');
1016 
1017  /* check stream specification in opt name */
1018  if (p) {
1019  int err = check_stream_specifier(s, st, p + 1);
1020  if (err < 0) {
1021  av_dict_free(&ret);
1022  return err;
1023  } else if (!err)
1024  continue;
1025 
1026  *p = 0;
1027  }
1028 
1029  if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
1030  !codec ||
1031  ((priv_class = codec->priv_class) &&
1032  av_opt_find(&priv_class, t->key, NULL, flags,
1034  av_dict_set(&ret, t->key, t->value, 0);
1035  else if (t->key[0] == prefix &&
1036  av_opt_find(&cc, t->key + 1, NULL, flags,
1038  av_dict_set(&ret, t->key + 1, t->value, 0);
1039 
1040  if (p)
1041  *p = ':';
1042  }
1043 
1044  *dst = ret;
1045  return 0;
1046 }
1047 
1050  AVDictionary ***dst)
1051 {
1052  int ret;
1053  AVDictionary **opts;
1054 
1055  *dst = NULL;
1056 
1057  if (!s->nb_streams)
1058  return 0;
1059 
1060  opts = av_calloc(s->nb_streams, sizeof(*opts));
1061  if (!opts)
1062  return AVERROR(ENOMEM);
1063 
1064  for (int i = 0; i < s->nb_streams; i++) {
1065  ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
1066  s, s->streams[i], NULL, &opts[i]);
1067  if (ret < 0)
1068  goto fail;
1069  }
1070  *dst = opts;
1071  return 0;
1072 fail:
1073  for (int i = 0; i < s->nb_streams; i++)
1074  av_dict_free(&opts[i]);
1075  av_freep(&opts);
1076  return ret;
1077 }
1078 
1079 int grow_array(void **array, int elem_size, int *size, int new_size)
1080 {
1081  if (new_size >= INT_MAX / elem_size) {
1082  av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
1083  return AVERROR(ERANGE);
1084  }
1085  if (*size < new_size) {
1086  uint8_t *tmp = av_realloc_array(*array, new_size, elem_size);
1087  if (!tmp)
1088  return AVERROR(ENOMEM);
1089  memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1090  *size = new_size;
1091  *array = tmp;
1092  return 0;
1093  }
1094  return 0;
1095 }
1096 
1097 void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
1098 {
1099  void *new_elem;
1100 
1101  if (!(new_elem = av_mallocz(elem_size)) ||
1102  av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
1103  return NULL;
1104  return new_elem;
1105 }
1106 
1107 double get_rotation(const int32_t *displaymatrix)
1108 {
1109  double theta = 0;
1110  if (displaymatrix)
1111  theta = -round(av_display_rotation_get(displaymatrix));
1112 
1113  theta -= 360*floor(theta/360 + 0.9/360);
1114 
1115  if (fabs(theta - 90*round(theta/90)) > 2)
1116  av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
1117  "If you want to help, upload a sample "
1118  "of this file to https://streams.videolan.org/upload/ "
1119  "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
1120 
1121  return theta;
1122 }
1123 
1124 /* read file contents into a string */
1125 char *file_read(const char *filename)
1126 {
1127  AVIOContext *pb = NULL;
1128  int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1129  AVBPrint bprint;
1130  char *str;
1131 
1132  if (ret < 0) {
1133  av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1134  return NULL;
1135  }
1136 
1138  ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
1139  avio_closep(&pb);
1140  if (ret < 0) {
1141  av_bprint_finalize(&bprint, NULL);
1142  return NULL;
1143  }
1144  ret = av_bprint_finalize(&bprint, &str);
1145  if (ret < 0)
1146  return NULL;
1147  return str;
1148 }
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:522
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: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:107
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: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:1107
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:2011
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:56
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: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:84
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:497
format_opts
AVDictionary * format_opts
Definition: cmdutils.c:58
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:1079
FLAGS
#define FLAGS
Definition: cmdutils.c:581
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:140
AVOption::flags
int flags
A combination of AV_OPT_FLAG_*.
Definition: opt.h:389
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:674
hide_banner
int hide_banner
Definition: cmdutils.c:60
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:231
OptionDef
Definition: cmdutils.h:126
finish
static void finish(void)
Definition: movenc.c:373
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:726
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:979
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:524
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:773
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: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:1048
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:387
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:987
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:75
opts
AVDictionary * opts
Definition: movenc.c:51
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:186
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:708
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
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
file_read
char * file_read(const char *filename)
Definition: cmdutils.c:1125
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:474
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:1952
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:907
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")
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:1097
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:1628
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: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
swr_opts
AVDictionary * swr_opts
Definition: cmdutils.c:57
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:405
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:256
OPT_OUTPUT
#define OPT_OUTPUT
Definition: cmdutils.h:169
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
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:540
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition: cmdutils.h:280
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:896
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:273
uninit_parse_context
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:748
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: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:315
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:365
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:240
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:441
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:582
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:273
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
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: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
d
d
Definition: ffmpeg_filter.c:424
int32_t
int32_t
Definition: audioconvert.c:56
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: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
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:500
swscale.h
match_group_separator
static int match_group_separator(const OptionGroupDef *groups, int nb_groups, const char *opt)
Definition: cmdutils.c:654
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:572
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