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