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