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 static void (*program_exit)(int ret);
87 
88 void register_exit(void (*cb)(int ret))
89 {
90  program_exit = cb;
91 }
92 
94 {
97 }
98 
99 void exit_program(int ret)
100 {
101  if (program_exit)
102  program_exit(ret);
103 
104  exit(ret);
105 }
106 
107 double parse_number_or_die(const char *context, const char *numstr, int type,
108  double min, double max)
109 {
110  char *tail;
111  const char *error;
112  double d = av_strtod(numstr, &tail);
113  if (*tail)
114  error = "Expected number for %s but found: %s\n";
115  else if (d < min || d > max)
116  error = "The value for %s was %s which is not within %f - %f\n";
117  else if (type == OPT_INT64 && (int64_t)d != d)
118  error = "Expected int64 for %s but found %s\n";
119  else if (type == OPT_INT && (int)d != d)
120  error = "Expected int for %s but found %s\n";
121  else
122  return d;
123  av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
124  exit_program(1);
125  return 0;
126 }
127 
128 int64_t parse_time_or_die(const char *context, const char *timestr,
129  int is_duration)
130 {
131  int64_t us;
132  if (av_parse_time(&us, timestr, is_duration) < 0) {
133  av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
134  is_duration ? "duration" : "date", context, timestr);
135  exit_program(1);
136  }
137  return us;
138 }
139 
140 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
141  int rej_flags, int alt_flags)
142 {
143  const OptionDef *po;
144  int first;
145 
146  first = 1;
147  for (po = options; po->name; po++) {
148  char buf[128];
149 
150  if (((po->flags & req_flags) != req_flags) ||
151  (alt_flags && !(po->flags & alt_flags)) ||
152  (po->flags & rej_flags))
153  continue;
154 
155  if (first) {
156  printf("%s\n", msg);
157  first = 0;
158  }
159  av_strlcpy(buf, po->name, sizeof(buf));
160  if (po->argname) {
161  av_strlcat(buf, " ", sizeof(buf));
162  av_strlcat(buf, po->argname, sizeof(buf));
163  }
164  printf("-%-17s %s\n", buf, po->help);
165  }
166  printf("\n");
167 }
168 
169 void show_help_children(const AVClass *class, int flags)
170 {
171  void *iter = NULL;
172  const AVClass *child;
173  if (class->option) {
174  av_opt_show2(&class, NULL, flags, 0);
175  printf("\n");
176  }
177 
178  while (child = av_opt_child_class_iterate(class, &iter))
179  show_help_children(child, flags);
180 }
181 
182 static const OptionDef *find_option(const OptionDef *po, const char *name)
183 {
184  while (po->name) {
185  const char *end;
186  if (av_strstart(name, po->name, &end) && (!*end || *end == ':'))
187  break;
188  po++;
189  }
190  return po;
191 }
192 
193 /* _WIN32 means using the windows libc - cygwin doesn't define that
194  * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
195  * it doesn't provide the actual command line via GetCommandLineW(). */
196 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
197 #include <shellapi.h>
198 /* Will be leaked on exit */
199 static char** win32_argv_utf8 = NULL;
200 static int win32_argc = 0;
201 
202 /**
203  * Prepare command line arguments for executable.
204  * For Windows - perform wide-char to UTF-8 conversion.
205  * Input arguments should be main() function arguments.
206  * @param argc_ptr Arguments number (including executable)
207  * @param argv_ptr Arguments list.
208  */
209 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
210 {
211  char *argstr_flat;
212  wchar_t **argv_w;
213  int i, buffsize = 0, offset = 0;
214 
215  if (win32_argv_utf8) {
216  *argc_ptr = win32_argc;
217  *argv_ptr = win32_argv_utf8;
218  return;
219  }
220 
221  win32_argc = 0;
222  argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
223  if (win32_argc <= 0 || !argv_w)
224  return;
225 
226  /* determine the UTF-8 buffer size (including NULL-termination symbols) */
227  for (i = 0; i < win32_argc; i++)
228  buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
229  NULL, 0, NULL, NULL);
230 
231  win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
232  argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
233  if (!win32_argv_utf8) {
234  LocalFree(argv_w);
235  return;
236  }
237 
238  for (i = 0; i < win32_argc; i++) {
239  win32_argv_utf8[i] = &argstr_flat[offset];
240  offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
241  &argstr_flat[offset],
242  buffsize - offset, NULL, NULL);
243  }
244  win32_argv_utf8[i] = NULL;
245  LocalFree(argv_w);
246 
247  *argc_ptr = win32_argc;
248  *argv_ptr = win32_argv_utf8;
249 }
250 #else
251 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
252 {
253  /* nothing to do */
254 }
255 #endif /* HAVE_COMMANDLINETOARGVW */
256 
257 static int write_option(void *optctx, const OptionDef *po, const char *opt,
258  const char *arg)
259 {
260  /* new-style options contain an offset into optctx, old-style address of
261  * a global var*/
262  void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
263  (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
264  int *dstcount;
265 
266  if (po->flags & OPT_SPEC) {
267  SpecifierOpt **so = dst;
268  char *p = strchr(opt, ':');
269  char *str;
270 
271  dstcount = (int *)(so + 1);
272  *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
273  str = av_strdup(p ? p + 1 : "");
274  if (!str)
275  return AVERROR(ENOMEM);
276  (*so)[*dstcount - 1].specifier = str;
277  dst = &(*so)[*dstcount - 1].u;
278  }
279 
280  if (po->flags & OPT_STRING) {
281  char *str;
282  str = av_strdup(arg);
283  av_freep(dst);
284  if (!str)
285  return AVERROR(ENOMEM);
286  *(char **)dst = str;
287  } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
288  *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
289  } else if (po->flags & OPT_INT64) {
290  *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
291  } else if (po->flags & OPT_TIME) {
292  *(int64_t *)dst = parse_time_or_die(opt, arg, 1);
293  } else if (po->flags & OPT_FLOAT) {
294  *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
295  } else if (po->flags & OPT_DOUBLE) {
296  *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
297  } else if (po->u.func_arg) {
298  int ret = po->u.func_arg(optctx, opt, arg);
299  if (ret < 0) {
301  "Failed to set value '%s' for option '%s': %s\n",
302  arg, opt, av_err2str(ret));
303  return ret;
304  }
305  }
306  if (po->flags & OPT_EXIT)
307  exit_program(0);
308 
309  return 0;
310 }
311 
312 int parse_option(void *optctx, const char *opt, const char *arg,
313  const OptionDef *options)
314 {
315  static const OptionDef opt_avoptions = {
316  .name = "AVOption passthrough",
317  .flags = HAS_ARG,
318  .u.func_arg = opt_default,
319  };
320 
321  const OptionDef *po;
322  int ret;
323 
324  po = find_option(options, opt);
325  if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
326  /* handle 'no' bool option */
327  po = find_option(options, opt + 2);
328  if ((po->name && (po->flags & OPT_BOOL)))
329  arg = "0";
330  } else if (po->flags & OPT_BOOL)
331  arg = "1";
332 
333  if (!po->name)
334  po = &opt_avoptions;
335  if (!po->name) {
336  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
337  return AVERROR(EINVAL);
338  }
339  if (po->flags & HAS_ARG && !arg) {
340  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
341  return AVERROR(EINVAL);
342  }
343 
344  ret = write_option(optctx, po, opt, arg);
345  if (ret < 0)
346  return ret;
347 
348  return !!(po->flags & HAS_ARG);
349 }
350 
351 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
352  void (*parse_arg_function)(void *, const char*))
353 {
354  const char *opt;
355  int optindex, handleoptions = 1, ret;
356 
357  /* perform system-dependent conversions for arguments list */
358  prepare_app_arguments(&argc, &argv);
359 
360  /* parse options */
361  optindex = 1;
362  while (optindex < argc) {
363  opt = argv[optindex++];
364 
365  if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
366  if (opt[1] == '-' && opt[2] == '\0') {
367  handleoptions = 0;
368  continue;
369  }
370  opt++;
371 
372  if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
373  exit_program(1);
374  optindex += ret;
375  } else {
376  if (parse_arg_function)
377  parse_arg_function(optctx, opt);
378  }
379  }
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 void finish_group(OptionParseContext *octx, int group_idx,
609  const char *arg)
610 {
611  OptionGroupList *l = &octx->groups[group_idx];
612  OptionGroup *g;
613 
614  GROW_ARRAY(l->groups, l->nb_groups);
615  g = &l->groups[l->nb_groups - 1];
616 
617  *g = octx->cur_group;
618  g->arg = arg;
619  g->group_def = l->group_def;
620  g->sws_dict = sws_dict;
621  g->swr_opts = swr_opts;
622  g->codec_opts = codec_opts;
623  g->format_opts = format_opts;
624 
625  codec_opts = NULL;
626  format_opts = NULL;
627  sws_dict = NULL;
628  swr_opts = NULL;
629 
630  memset(&octx->cur_group, 0, sizeof(octx->cur_group));
631 }
632 
633 /*
634  * Add an option instance to currently parsed group.
635  */
636 static void add_opt(OptionParseContext *octx, const OptionDef *opt,
637  const char *key, const char *val)
638 {
639  int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
640  OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
641 
642  GROW_ARRAY(g->opts, g->nb_opts);
643  g->opts[g->nb_opts - 1].opt = opt;
644  g->opts[g->nb_opts - 1].key = key;
645  g->opts[g->nb_opts - 1].val = val;
646 }
647 
649  const OptionGroupDef *groups, int nb_groups)
650 {
651  static const OptionGroupDef global_group = { "global" };
652  int i;
653 
654  memset(octx, 0, sizeof(*octx));
655 
656  octx->nb_groups = nb_groups;
657  octx->groups = av_calloc(octx->nb_groups, sizeof(*octx->groups));
658  if (!octx->groups)
659  report_and_exit(AVERROR(ENOMEM));
660 
661  for (i = 0; i < octx->nb_groups; i++)
662  octx->groups[i].group_def = &groups[i];
663 
664  octx->global_opts.group_def = &global_group;
665  octx->global_opts.arg = "";
666 }
667 
669 {
670  int i, j;
671 
672  for (i = 0; i < octx->nb_groups; i++) {
673  OptionGroupList *l = &octx->groups[i];
674 
675  for (j = 0; j < l->nb_groups; j++) {
676  av_freep(&l->groups[j].opts);
679 
680  av_dict_free(&l->groups[j].sws_dict);
681  av_dict_free(&l->groups[j].swr_opts);
682  }
683  av_freep(&l->groups);
684  }
685  av_freep(&octx->groups);
686 
687  av_freep(&octx->cur_group.opts);
688  av_freep(&octx->global_opts.opts);
689 
690  uninit_opts();
691 }
692 
693 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
694  const OptionDef *options,
695  const OptionGroupDef *groups, int nb_groups)
696 {
697  int optindex = 1;
698  int dashdash = -2;
699 
700  /* perform system-dependent conversions for arguments list */
701  prepare_app_arguments(&argc, &argv);
702 
703  init_parse_context(octx, groups, nb_groups);
704  av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
705 
706  while (optindex < argc) {
707  const char *opt = argv[optindex++], *arg;
708  const OptionDef *po;
709  int ret;
710 
711  av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
712 
713  if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
714  dashdash = optindex;
715  continue;
716  }
717  /* unnamed group separators, e.g. output filename */
718  if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
719  finish_group(octx, 0, opt);
720  av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
721  continue;
722  }
723  opt++;
724 
725 #define GET_ARG(arg) \
726 do { \
727  arg = argv[optindex++]; \
728  if (!arg) { \
729  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
730  return AVERROR(EINVAL); \
731  } \
732 } while (0)
733 
734  /* named group separators, e.g. -i */
735  if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
736  GET_ARG(arg);
737  finish_group(octx, ret, arg);
738  av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
739  groups[ret].name, arg);
740  continue;
741  }
742 
743  /* normal options */
744  po = find_option(options, opt);
745  if (po->name) {
746  if (po->flags & OPT_EXIT) {
747  /* optional argument, e.g. -h */
748  arg = argv[optindex++];
749  } else if (po->flags & HAS_ARG) {
750  GET_ARG(arg);
751  } else {
752  arg = "1";
753  }
754 
755  add_opt(octx, po, opt, arg);
756  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
757  "argument '%s'.\n", po->name, po->help, arg);
758  continue;
759  }
760 
761  /* AVOptions */
762  if (argv[optindex]) {
763  ret = opt_default(NULL, opt, argv[optindex]);
764  if (ret >= 0) {
765  av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
766  "argument '%s'.\n", opt, argv[optindex]);
767  optindex++;
768  continue;
769  } else if (ret != AVERROR_OPTION_NOT_FOUND) {
770  av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
771  "with argument '%s'.\n", opt, argv[optindex]);
772  return ret;
773  }
774  }
775 
776  /* boolean -nofoo options */
777  if (opt[0] == 'n' && opt[1] == 'o' &&
778  (po = find_option(options, opt + 2)) &&
779  po->name && po->flags & OPT_BOOL) {
780  add_opt(octx, po, opt, "0");
781  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
782  "argument 0.\n", po->name, po->help);
783  continue;
784  }
785 
786  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
788  }
789 
790  if (octx->cur_group.nb_opts || codec_opts || format_opts)
791  av_log(NULL, AV_LOG_WARNING, "Trailing option(s) found in the "
792  "command: may be ignored.\n");
793 
794  av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
795 
796  return 0;
797 }
798 
799 void print_error(const char *filename, int err)
800 {
801  char errbuf[128];
802  const char *errbuf_ptr = errbuf;
803 
804  if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
805  errbuf_ptr = strerror(AVUNERROR(err));
806  av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
807 }
808 
809 int read_yesno(void)
810 {
811  int c = getchar();
812  int yesno = (av_toupper(c) == 'Y');
813 
814  while (c != '\n' && c != EOF)
815  c = getchar();
816 
817  return yesno;
818 }
819 
820 FILE *get_preset_file(char *filename, size_t filename_size,
821  const char *preset_name, int is_path,
822  const char *codec_name)
823 {
824  FILE *f = NULL;
825  int i;
826 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
827  char *datadir = NULL;
828 #endif
829  char *env_home = getenv_utf8("HOME");
830  char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR");
831  const char *base[3] = { env_ffmpeg_datadir,
832  env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */
833  FFMPEG_DATADIR, };
834 
835  if (is_path) {
836  av_strlcpy(filename, preset_name, filename_size);
837  f = fopen_utf8(filename, "r");
838  } else {
839 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
840  wchar_t *datadir_w = get_module_filename(NULL);
841  base[2] = NULL;
842 
843  if (wchartoutf8(datadir_w, &datadir))
844  datadir = NULL;
845  av_free(datadir_w);
846 
847  if (datadir)
848  {
849  char *ls;
850  for (ls = datadir; *ls; ls++)
851  if (*ls == '\\') *ls = '/';
852 
853  if (ls = strrchr(datadir, '/'))
854  {
855  ptrdiff_t datadir_len = ls - datadir;
856  size_t desired_size = datadir_len + strlen("/ffpresets") + 1;
857  char *new_datadir = av_realloc_array(
858  datadir, desired_size, sizeof *datadir);
859  if (new_datadir) {
860  datadir = new_datadir;
861  datadir[datadir_len] = 0;
862  strncat(datadir, "/ffpresets", desired_size - 1 - datadir_len);
863  base[2] = datadir;
864  }
865  }
866  }
867 #endif
868  for (i = 0; i < 3 && !f; i++) {
869  if (!base[i])
870  continue;
871  snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
872  i != 1 ? "" : "/.ffmpeg", preset_name);
873  f = fopen_utf8(filename, "r");
874  if (!f && codec_name) {
875  snprintf(filename, filename_size,
876  "%s%s/%s-%s.ffpreset",
877  base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
878  preset_name);
879  f = fopen_utf8(filename, "r");
880  }
881  }
882  }
883 
884 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
885  av_free(datadir);
886 #endif
887  freeenv_utf8(env_ffmpeg_datadir);
888  freeenv_utf8(env_home);
889  return f;
890 }
891 
892 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
893 {
894  int ret = avformat_match_stream_specifier(s, st, spec);
895  if (ret < 0)
896  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
897  return ret;
898 }
899 
901  AVFormatContext *s, AVStream *st, const AVCodec *codec)
902 {
903  AVDictionary *ret = NULL;
904  const AVDictionaryEntry *t = NULL;
905  int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
907  char prefix = 0;
908  const AVClass *cc = avcodec_get_class();
909 
910  if (!codec)
911  codec = s->oformat ? avcodec_find_encoder(codec_id)
913 
914  switch (st->codecpar->codec_type) {
915  case AVMEDIA_TYPE_VIDEO:
916  prefix = 'v';
918  break;
919  case AVMEDIA_TYPE_AUDIO:
920  prefix = 'a';
922  break;
924  prefix = 's';
926  break;
927  }
928 
929  while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) {
930  const AVClass *priv_class;
931  char *p = strchr(t->key, ':');
932 
933  /* check stream specification in opt name */
934  if (p)
935  switch (check_stream_specifier(s, st, p + 1)) {
936  case 1: *p = 0; break;
937  case 0: continue;
938  default: exit_program(1);
939  }
940 
941  if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
942  !codec ||
943  ((priv_class = codec->priv_class) &&
944  av_opt_find(&priv_class, t->key, NULL, flags,
946  av_dict_set(&ret, t->key, t->value, 0);
947  else if (t->key[0] == prefix &&
948  av_opt_find(&cc, t->key + 1, NULL, flags,
950  av_dict_set(&ret, t->key + 1, t->value, 0);
951 
952  if (p)
953  *p = ':';
954  }
955  return ret;
956 }
957 
960 {
961  int i;
962  AVDictionary **opts;
963 
964  if (!s->nb_streams)
965  return NULL;
966  opts = av_calloc(s->nb_streams, sizeof(*opts));
967  if (!opts)
968  report_and_exit(AVERROR(ENOMEM));
969  for (i = 0; i < s->nb_streams; i++)
970  opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
971  s, s->streams[i], NULL);
972  return opts;
973 }
974 
975 void *grow_array(void *array, int elem_size, int *size, int new_size)
976 {
977  if (new_size >= INT_MAX / elem_size) {
978  av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
979  exit_program(1);
980  }
981  if (*size < new_size) {
982  uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
983  if (!tmp)
984  report_and_exit(AVERROR(ENOMEM));
985  memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
986  *size = new_size;
987  return tmp;
988  }
989  return array;
990 }
991 
992 void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
993 {
994  void *new_elem;
995 
996  if (!(new_elem = av_mallocz(elem_size)) ||
997  av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
998  report_and_exit(AVERROR(ENOMEM));
999  return new_elem;
1000 }
1001 
1002 double get_rotation(int32_t *displaymatrix)
1003 {
1004  double theta = 0;
1005  if (displaymatrix)
1006  theta = -round(av_display_rotation_get((int32_t*) displaymatrix));
1007 
1008  theta -= 360*floor(theta/360 + 0.9/360);
1009 
1010  if (fabs(theta - 90*round(theta/90)) > 2)
1011  av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
1012  "If you want to help, upload a sample "
1013  "of this file to https://streams.videolan.org/upload/ "
1014  "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
1015 
1016  return theta;
1017 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
OPT_FLOAT
#define OPT_FLOAT
Definition: cmdutils.h:156
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:159
AVCodec
AVCodec.
Definition: codec.h:204
OptionGroup::group_def
const OptionGroupDef * group_def
Definition: cmdutils.h:251
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: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:171
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:236
init_parse_context
static void init_parse_context(OptionParseContext *octx, const OptionGroupDef *groups, int nb_groups)
Definition: cmdutils.c:648
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:197
avcodec_find_encoder
const AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: allcodecs.c:940
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:1129
OPT_INPUT
#define OPT_INPUT
Definition: cmdutils.h:166
AVOption
AVOption.
Definition: opt.h:251
HAS_ARG
#define HAS_ARG
Definition: cmdutils.h:149
OptionGroupList::groups
OptionGroup * groups
Definition: cmdutils.h:270
OptionDef::dst_ptr
void * dst_ptr
Definition: cmdutils.h:169
OptionGroupList::nb_groups
int nb_groups
Definition: cmdutils.h:271
format_opts
AVDictionary * format_opts
Definition: cmdutils.c:60
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:515
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
base
uint8_t base
Definition: vp3data.h:141
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:551
OptionGroup::swr_opts
AVDictionary * swr_opts
Definition: cmdutils.h:260
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:169
AVOption::flags
int flags
Definition: opt.h:280
max
#define max(a, b)
Definition: cuda_runtime.h:33
mathematics.h
AVDictionary
Definition: dict.c:31
hide_banner
int hide_banner
Definition: cmdutils.c:62
OptionDef
Definition: cmdutils.h:146
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:99
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:107
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:799
fopen_utf8.h
OptionGroupList
A list of option groups that all have the same group type (e.g.
Definition: cmdutils.h:267
report_and_exit
void report_and_exit(int ret)
Reports an error corresponding to the provided AVERROR code and calls exit_program() with the corresp...
Definition: cmdutils.c:93
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:274
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:229
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:276
OptionGroup::nb_opts
int nb_opts
Definition: cmdutils.h:255
OPT_STRING
#define OPT_STRING
Definition: cmdutils.h:152
OptionGroupList::group_def
const OptionGroupDef * group_def
Definition: cmdutils.h:268
OptionDef::help
const char * help
Definition: cmdutils.h:173
OptionGroupDef
Definition: cmdutils.h:235
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:892
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:257
check_options
static void check_options(const OptionDef *po)
Definition: cmdutils.c:465
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:41
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:155
s
#define s(width, name)
Definition: cbs_vp9.c:256
OptionDef::argname
const char * argname
Definition: cmdutils.h:174
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:693
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:231
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:388
parse_options
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
Definition: cmdutils.c:351
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:163
finish_group
static void finish_group(OptionParseContext *octx, int group_idx, const char *arg)
Definition: cmdutils.c:608
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:1216
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:258
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:275
Option::opt
const OptionDef * opt
Definition: cmdutils.h:230
prepare_app_arguments
static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
Definition: cmdutils.c:251
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:1230
getenv_utf8
static char * getenv_utf8(const char *varname)
Definition: getenv_utf8.h:67
OPT_INT64
#define OPT_INT64
Definition: cmdutils.h:158
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:257
OptionGroup::opts
Option * opts
Definition: cmdutils.h:254
OptionGroup
Definition: cmdutils.h:250
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:945
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: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:611
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:820
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
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:958
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:992
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:208
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:86
register_exit
void register_exit(void(*cb)(int ret))
Register a program-specific cleanup routine.
Definition: cmdutils.c:88
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:269
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
OPT_TIME
#define OPT_TIME
Definition: cmdutils.h:164
swr_opts
AVDictionary * swr_opts
Definition: cmdutils.c:59
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:900
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:167
OPT_OFFSET
#define OPT_OFFSET
Definition: cmdutils.h:162
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
OptionParseContext::groups
OptionGroupList * groups
Definition: cmdutils.h:277
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:259
version.h
SpecifierOpt
Definition: cmdutils.h:134
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:809
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:252
uninit_parse_context
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:668
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:161
avformat.h
dict.h
add_opt
static void add_opt(OptionParseContext *octx, const OptionDef *opt, const char *key, const char *val)
Definition: cmdutils.c:636
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:312
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:232
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:442
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: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:147
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:79
OptionGroupDef::sep
const char * sep
Option to be used as group separator.
Definition: cmdutils.h:242
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:71
cmdutils.h
OPT_BOOL
#define OPT_BOOL
Definition: cmdutils.h:150
d
d
Definition: ffmpeg_filter.c:156
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:128
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:975
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:278
find_option
static const OptionDef * find_option(const OptionDef *po, const char *name)
Definition: cmdutils.c:182
AVDictionaryEntry::value
char * value
Definition: dict.h:81
get_rotation
double get_rotation(int32_t *displaymatrix)
Definition: cmdutils.c:1002
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:140
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:281
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:170
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:148
OPT_DOUBLE
#define OPT_DOUBLE
Definition: cmdutils.h:165