FFmpeg  2.8.15
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 "libavfilter/avfilter.h"
36 #include "libavdevice/avdevice.h"
38 #include "libswscale/swscale.h"
41 #include "libavutil/avassert.h"
42 #include "libavutil/avstring.h"
43 #include "libavutil/bprint.h"
44 #include "libavutil/display.h"
45 #include "libavutil/mathematics.h"
46 #include "libavutil/imgutils.h"
47 #include "libavutil/libm.h"
48 #include "libavutil/parseutils.h"
49 #include "libavutil/pixdesc.h"
50 #include "libavutil/eval.h"
51 #include "libavutil/dict.h"
52 #include "libavutil/opt.h"
53 #include "libavutil/cpu.h"
54 #include "libavutil/ffversion.h"
55 #include "cmdutils.h"
56 #if CONFIG_NETWORK
57 #include "libavformat/network.h"
58 #endif
59 #if HAVE_SYS_RESOURCE_H
60 #include <sys/time.h>
61 #include <sys/resource.h>
62 #endif
63 #if HAVE_SETDLLDIRECTORY
64 #include <windows.h>
65 #endif
66 
67 static int init_report(const char *env);
68 
72 
73 static FILE *report_file;
75 int hide_banner = 0;
76 
77 void init_opts(void)
78 {
79  av_dict_set(&sws_dict, "flags", "bicubic", 0);
80 }
81 
82 void uninit_opts(void)
83 {
84  av_dict_free(&swr_opts);
85  av_dict_free(&sws_dict);
86  av_dict_free(&format_opts);
87  av_dict_free(&codec_opts);
88  av_dict_free(&resample_opts);
89 }
90 
91 void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
92 {
93  vfprintf(stdout, fmt, vl);
94 }
95 
96 static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl)
97 {
98  va_list vl2;
99  char line[1024];
100  static int print_prefix = 1;
101 
102  va_copy(vl2, vl);
103  av_log_default_callback(ptr, level, fmt, vl);
104  av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
105  va_end(vl2);
106  if (report_file_level >= level) {
107  fputs(line, report_file);
108  fflush(report_file);
109  }
110 }
111 
112 void init_dynload(void)
113 {
114 #if HAVE_SETDLLDIRECTORY
115  /* Calling SetDllDirectory with the empty string (but not NULL) removes the
116  * current working directory from the DLL search path as a security pre-caution. */
117  SetDllDirectory("");
118 #endif
119 }
120 
121 static void (*program_exit)(int ret);
122 
123 void register_exit(void (*cb)(int ret))
124 {
125  program_exit = cb;
126 }
127 
128 void exit_program(int ret)
129 {
130  if (program_exit)
131  program_exit(ret);
132 
133  exit(ret);
134 }
135 
136 double parse_number_or_die(const char *context, const char *numstr, int type,
137  double min, double max)
138 {
139  char *tail;
140  const char *error;
141  double d = av_strtod(numstr, &tail);
142  if (*tail)
143  error = "Expected number for %s but found: %s\n";
144  else if (d < min || d > max)
145  error = "The value for %s was %s which is not within %f - %f\n";
146  else if (type == OPT_INT64 && (int64_t)d != d)
147  error = "Expected int64 for %s but found %s\n";
148  else if (type == OPT_INT && (int)d != d)
149  error = "Expected int for %s but found %s\n";
150  else
151  return d;
152  av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
153  exit_program(1);
154  return 0;
155 }
156 
157 int64_t parse_time_or_die(const char *context, const char *timestr,
158  int is_duration)
159 {
160  int64_t us;
161  if (av_parse_time(&us, timestr, is_duration) < 0) {
162  av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
163  is_duration ? "duration" : "date", context, timestr);
164  exit_program(1);
165  }
166  return us;
167 }
168 
169 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
170  int rej_flags, int alt_flags)
171 {
172  const OptionDef *po;
173  int first;
174 
175  first = 1;
176  for (po = options; po->name; po++) {
177  char buf[64];
178 
179  if (((po->flags & req_flags) != req_flags) ||
180  (alt_flags && !(po->flags & alt_flags)) ||
181  (po->flags & rej_flags))
182  continue;
183 
184  if (first) {
185  printf("%s\n", msg);
186  first = 0;
187  }
188  av_strlcpy(buf, po->name, sizeof(buf));
189  if (po->argname) {
190  av_strlcat(buf, " ", sizeof(buf));
191  av_strlcat(buf, po->argname, sizeof(buf));
192  }
193  printf("-%-17s %s\n", buf, po->help);
194  }
195  printf("\n");
196 }
197 
198 void show_help_children(const AVClass *class, int flags)
199 {
200  const AVClass *child = NULL;
201  if (class->option) {
202  av_opt_show2(&class, NULL, flags, 0);
203  printf("\n");
204  }
205 
206  while (child = av_opt_child_class_next(class, child))
207  show_help_children(child, flags);
208 }
209 
210 static const OptionDef *find_option(const OptionDef *po, const char *name)
211 {
212  const char *p = strchr(name, ':');
213  int len = p ? p - name : strlen(name);
214 
215  while (po->name) {
216  if (!strncmp(name, po->name, len) && strlen(po->name) == len)
217  break;
218  po++;
219  }
220  return po;
221 }
222 
223 /* _WIN32 means using the windows libc - cygwin doesn't define that
224  * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
225  * it doesn't provide the actual command line via GetCommandLineW(). */
226 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
227 #include <windows.h>
228 #include <shellapi.h>
229 /* Will be leaked on exit */
230 static char** win32_argv_utf8 = NULL;
231 static int win32_argc = 0;
232 
233 /**
234  * Prepare command line arguments for executable.
235  * For Windows - perform wide-char to UTF-8 conversion.
236  * Input arguments should be main() function arguments.
237  * @param argc_ptr Arguments number (including executable)
238  * @param argv_ptr Arguments list.
239  */
240 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
241 {
242  char *argstr_flat;
243  wchar_t **argv_w;
244  int i, buffsize = 0, offset = 0;
245 
246  if (win32_argv_utf8) {
247  *argc_ptr = win32_argc;
248  *argv_ptr = win32_argv_utf8;
249  return;
250  }
251 
252  win32_argc = 0;
253  argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
254  if (win32_argc <= 0 || !argv_w)
255  return;
256 
257  /* determine the UTF-8 buffer size (including NULL-termination symbols) */
258  for (i = 0; i < win32_argc; i++)
259  buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
260  NULL, 0, NULL, NULL);
261 
262  win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
263  argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
264  if (!win32_argv_utf8) {
265  LocalFree(argv_w);
266  return;
267  }
268 
269  for (i = 0; i < win32_argc; i++) {
270  win32_argv_utf8[i] = &argstr_flat[offset];
271  offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
272  &argstr_flat[offset],
273  buffsize - offset, NULL, NULL);
274  }
275  win32_argv_utf8[i] = NULL;
276  LocalFree(argv_w);
277 
278  *argc_ptr = win32_argc;
279  *argv_ptr = win32_argv_utf8;
280 }
281 #else
282 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
283 {
284  /* nothing to do */
285 }
286 #endif /* HAVE_COMMANDLINETOARGVW */
287 
288 static int write_option(void *optctx, const OptionDef *po, const char *opt,
289  const char *arg)
290 {
291  /* new-style options contain an offset into optctx, old-style address of
292  * a global var*/
293  void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
294  (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
295  int *dstcount;
296 
297  if (po->flags & OPT_SPEC) {
298  SpecifierOpt **so = dst;
299  char *p = strchr(opt, ':');
300  char *str;
301 
302  dstcount = (int *)(so + 1);
303  *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
304  str = av_strdup(p ? p + 1 : "");
305  if (!str)
306  return AVERROR(ENOMEM);
307  (*so)[*dstcount - 1].specifier = str;
308  dst = &(*so)[*dstcount - 1].u;
309  }
310 
311  if (po->flags & OPT_STRING) {
312  char *str;
313  str = av_strdup(arg);
314  av_freep(dst);
315  if (!str)
316  return AVERROR(ENOMEM);
317  *(char **)dst = str;
318  } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
319  *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
320  } else if (po->flags & OPT_INT64) {
321  *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
322  } else if (po->flags & OPT_TIME) {
323  *(int64_t *)dst = parse_time_or_die(opt, arg, 1);
324  } else if (po->flags & OPT_FLOAT) {
325  *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
326  } else if (po->flags & OPT_DOUBLE) {
327  *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
328  } else if (po->u.func_arg) {
329  int ret = po->u.func_arg(optctx, opt, arg);
330  if (ret < 0) {
332  "Failed to set value '%s' for option '%s': %s\n",
333  arg, opt, av_err2str(ret));
334  return ret;
335  }
336  }
337  if (po->flags & OPT_EXIT)
338  exit_program(0);
339 
340  return 0;
341 }
342 
343 int parse_option(void *optctx, const char *opt, const char *arg,
344  const OptionDef *options)
345 {
346  const OptionDef *po;
347  int ret;
348 
349  po = find_option(options, opt);
350  if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
351  /* handle 'no' bool option */
352  po = find_option(options, opt + 2);
353  if ((po->name && (po->flags & OPT_BOOL)))
354  arg = "0";
355  } else if (po->flags & OPT_BOOL)
356  arg = "1";
357 
358  if (!po->name)
359  po = find_option(options, "default");
360  if (!po->name) {
361  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
362  return AVERROR(EINVAL);
363  }
364  if (po->flags & HAS_ARG && !arg) {
365  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
366  return AVERROR(EINVAL);
367  }
368 
369  ret = write_option(optctx, po, opt, arg);
370  if (ret < 0)
371  return ret;
372 
373  return !!(po->flags & HAS_ARG);
374 }
375 
376 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
377  void (*parse_arg_function)(void *, const char*))
378 {
379  const char *opt;
380  int optindex, handleoptions = 1, ret;
381 
382  /* perform system-dependent conversions for arguments list */
383  prepare_app_arguments(&argc, &argv);
384 
385  /* parse options */
386  optindex = 1;
387  while (optindex < argc) {
388  opt = argv[optindex++];
389 
390  if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
391  if (opt[1] == '-' && opt[2] == '\0') {
392  handleoptions = 0;
393  continue;
394  }
395  opt++;
396 
397  if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
398  exit_program(1);
399  optindex += ret;
400  } else {
401  if (parse_arg_function)
402  parse_arg_function(optctx, opt);
403  }
404  }
405 }
406 
407 int parse_optgroup(void *optctx, OptionGroup *g)
408 {
409  int i, ret;
410 
411  av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
412  g->group_def->name, g->arg);
413 
414  for (i = 0; i < g->nb_opts; i++) {
415  Option *o = &g->opts[i];
416 
417  if (g->group_def->flags &&
418  !(g->group_def->flags & o->opt->flags)) {
419  av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
420  "%s %s -- you are trying to apply an input option to an "
421  "output file or vice versa. Move this option before the "
422  "file it belongs to.\n", o->key, o->opt->help,
423  g->group_def->name, g->arg);
424  return AVERROR(EINVAL);
425  }
426 
427  av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
428  o->key, o->opt->help, o->val);
429 
430  ret = write_option(optctx, o->opt, o->key, o->val);
431  if (ret < 0)
432  return ret;
433  }
434 
435  av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
436 
437  return 0;
438 }
439 
440 int locate_option(int argc, char **argv, const OptionDef *options,
441  const char *optname)
442 {
443  const OptionDef *po;
444  int i;
445 
446  for (i = 1; i < argc; i++) {
447  const char *cur_opt = argv[i];
448 
449  if (*cur_opt++ != '-')
450  continue;
451 
452  po = find_option(options, cur_opt);
453  if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
454  po = find_option(options, cur_opt + 2);
455 
456  if ((!po->name && !strcmp(cur_opt, optname)) ||
457  (po->name && !strcmp(optname, po->name)))
458  return i;
459 
460  if (!po->name || po->flags & HAS_ARG)
461  i++;
462  }
463  return 0;
464 }
465 
466 static void dump_argument(const char *a)
467 {
468  const unsigned char *p;
469 
470  for (p = a; *p; p++)
471  if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
472  *p == '_' || (*p >= 'a' && *p <= 'z')))
473  break;
474  if (!*p) {
475  fputs(a, report_file);
476  return;
477  }
478  fputc('"', report_file);
479  for (p = a; *p; p++) {
480  if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
481  fprintf(report_file, "\\%c", *p);
482  else if (*p < ' ' || *p > '~')
483  fprintf(report_file, "\\x%02x", *p);
484  else
485  fputc(*p, report_file);
486  }
487  fputc('"', report_file);
488 }
489 
490 static void check_options(const OptionDef *po)
491 {
492  while (po->name) {
493  if (po->flags & OPT_PERFILE)
495  po++;
496  }
497 }
498 
499 void parse_loglevel(int argc, char **argv, const OptionDef *options)
500 {
501  int idx = locate_option(argc, argv, options, "loglevel");
502  const char *env;
503 
504  check_options(options);
505 
506  if (!idx)
507  idx = locate_option(argc, argv, options, "v");
508  if (idx && argv[idx + 1])
509  opt_loglevel(NULL, "loglevel", argv[idx + 1]);
510  idx = locate_option(argc, argv, options, "report");
511  if ((env = getenv("FFREPORT")) || idx) {
512  init_report(env);
513  if (report_file) {
514  int i;
515  fprintf(report_file, "Command line:\n");
516  for (i = 0; i < argc; i++) {
517  dump_argument(argv[i]);
518  fputc(i < argc - 1 ? ' ' : '\n', report_file);
519  }
520  fflush(report_file);
521  }
522  }
523  idx = locate_option(argc, argv, options, "hide_banner");
524  if (idx)
525  hide_banner = 1;
526 }
527 
528 static const AVOption *opt_find(void *obj, const char *name, const char *unit,
529  int opt_flags, int search_flags)
530 {
531  const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
532  if(o && !o->flags)
533  return NULL;
534  return o;
535 }
536 
537 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
538 int opt_default(void *optctx, const char *opt, const char *arg)
539 {
540  const AVOption *o;
541  int consumed = 0;
542  char opt_stripped[128];
543  const char *p;
544  const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
545 #if CONFIG_AVRESAMPLE
546  const AVClass *rc = avresample_get_class();
547 #endif
548  const AVClass *sc, *swr_class;
549 
550  if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
552 
553  if (!(p = strchr(opt, ':')))
554  p = opt + strlen(opt);
555  av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
556 
557  if ((o = opt_find(&cc, opt_stripped, NULL, 0,
559  ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
560  (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
561  av_dict_set(&codec_opts, opt, arg, FLAGS);
562  consumed = 1;
563  }
564  if ((o = opt_find(&fc, opt, NULL, 0,
566  av_dict_set(&format_opts, opt, arg, FLAGS);
567  if (consumed)
568  av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
569  consumed = 1;
570  }
571 #if CONFIG_SWSCALE
572  sc = sws_get_class();
573  if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
575  struct SwsContext *sws = sws_alloc_context();
576  int ret = av_opt_set(sws, opt, arg, 0);
577  sws_freeContext(sws);
578  if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
579  !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
580  !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
581  av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
582  return AVERROR(EINVAL);
583  }
584  if (ret < 0) {
585  av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
586  return ret;
587  }
588 
589  av_dict_set(&sws_dict, opt, arg, FLAGS);
590 
591  consumed = 1;
592  }
593 #else
594  if (!consumed && !strcmp(opt, "sws_flags")) {
595  av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
596  consumed = 1;
597  }
598 #endif
599 #if CONFIG_SWRESAMPLE
600  swr_class = swr_get_class();
601  if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
603  struct SwrContext *swr = swr_alloc();
604  int ret = av_opt_set(swr, opt, arg, 0);
605  swr_free(&swr);
606  if (ret < 0) {
607  av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
608  return ret;
609  }
610  av_dict_set(&swr_opts, opt, arg, FLAGS);
611  consumed = 1;
612  }
613 #endif
614 #if CONFIG_AVRESAMPLE
615  if ((o=opt_find(&rc, opt, NULL, 0,
617  av_dict_set(&resample_opts, opt, arg, FLAGS);
618  consumed = 1;
619  }
620 #endif
621 
622  if (consumed)
623  return 0;
625 }
626 
627 /*
628  * Check whether given option is a group separator.
629  *
630  * @return index of the group definition that matched or -1 if none
631  */
632 static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
633  const char *opt)
634 {
635  int i;
636 
637  for (i = 0; i < nb_groups; i++) {
638  const OptionGroupDef *p = &groups[i];
639  if (p->sep && !strcmp(p->sep, opt))
640  return i;
641  }
642 
643  return -1;
644 }
645 
646 /*
647  * Finish parsing an option group.
648  *
649  * @param group_idx which group definition should this group belong to
650  * @param arg argument of the group delimiting option
651  */
652 static void finish_group(OptionParseContext *octx, int group_idx,
653  const char *arg)
654 {
655  OptionGroupList *l = &octx->groups[group_idx];
656  OptionGroup *g;
657 
658  GROW_ARRAY(l->groups, l->nb_groups);
659  g = &l->groups[l->nb_groups - 1];
660 
661  *g = octx->cur_group;
662  g->arg = arg;
663  g->group_def = l->group_def;
664  g->sws_dict = sws_dict;
665  g->swr_opts = swr_opts;
666  g->codec_opts = codec_opts;
669 
670  codec_opts = NULL;
671  format_opts = NULL;
672  resample_opts = NULL;
673  sws_dict = NULL;
674  swr_opts = NULL;
675  init_opts();
676 
677  memset(&octx->cur_group, 0, sizeof(octx->cur_group));
678 }
679 
680 /*
681  * Add an option instance to currently parsed group.
682  */
683 static void add_opt(OptionParseContext *octx, const OptionDef *opt,
684  const char *key, const char *val)
685 {
686  int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
687  OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
688 
689  GROW_ARRAY(g->opts, g->nb_opts);
690  g->opts[g->nb_opts - 1].opt = opt;
691  g->opts[g->nb_opts - 1].key = key;
692  g->opts[g->nb_opts - 1].val = val;
693 }
694 
696  const OptionGroupDef *groups, int nb_groups)
697 {
698  static const OptionGroupDef global_group = { "global" };
699  int i;
700 
701  memset(octx, 0, sizeof(*octx));
702 
703  octx->nb_groups = nb_groups;
704  octx->groups = av_mallocz_array(octx->nb_groups, sizeof(*octx->groups));
705  if (!octx->groups)
706  exit_program(1);
707 
708  for (i = 0; i < octx->nb_groups; i++)
709  octx->groups[i].group_def = &groups[i];
710 
711  octx->global_opts.group_def = &global_group;
712  octx->global_opts.arg = "";
713 
714  init_opts();
715 }
716 
718 {
719  int i, j;
720 
721  for (i = 0; i < octx->nb_groups; i++) {
722  OptionGroupList *l = &octx->groups[i];
723 
724  for (j = 0; j < l->nb_groups; j++) {
725  av_freep(&l->groups[j].opts);
729 
730  av_dict_free(&l->groups[j].sws_dict);
731  av_dict_free(&l->groups[j].swr_opts);
732  }
733  av_freep(&l->groups);
734  }
735  av_freep(&octx->groups);
736 
737  av_freep(&octx->cur_group.opts);
738  av_freep(&octx->global_opts.opts);
739 
740  uninit_opts();
741 }
742 
743 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
744  const OptionDef *options,
745  const OptionGroupDef *groups, int nb_groups)
746 {
747  int optindex = 1;
748  int dashdash = -2;
749 
750  /* perform system-dependent conversions for arguments list */
751  prepare_app_arguments(&argc, &argv);
752 
753  init_parse_context(octx, groups, nb_groups);
754  av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
755 
756  while (optindex < argc) {
757  const char *opt = argv[optindex++], *arg;
758  const OptionDef *po;
759  int ret;
760 
761  av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
762 
763  if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
764  dashdash = optindex;
765  continue;
766  }
767  /* unnamed group separators, e.g. output filename */
768  if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
769  finish_group(octx, 0, opt);
770  av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
771  continue;
772  }
773  opt++;
774 
775 #define GET_ARG(arg) \
776 do { \
777  arg = argv[optindex++]; \
778  if (!arg) { \
779  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
780  return AVERROR(EINVAL); \
781  } \
782 } while (0)
783 
784  /* named group separators, e.g. -i */
785  if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
786  GET_ARG(arg);
787  finish_group(octx, ret, arg);
788  av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
789  groups[ret].name, arg);
790  continue;
791  }
792 
793  /* normal options */
794  po = find_option(options, opt);
795  if (po->name) {
796  if (po->flags & OPT_EXIT) {
797  /* optional argument, e.g. -h */
798  arg = argv[optindex++];
799  } else if (po->flags & HAS_ARG) {
800  GET_ARG(arg);
801  } else {
802  arg = "1";
803  }
804 
805  add_opt(octx, po, opt, arg);
806  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
807  "argument '%s'.\n", po->name, po->help, arg);
808  continue;
809  }
810 
811  /* AVOptions */
812  if (argv[optindex]) {
813  ret = opt_default(NULL, opt, argv[optindex]);
814  if (ret >= 0) {
815  av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
816  "argument '%s'.\n", opt, argv[optindex]);
817  optindex++;
818  continue;
819  } else if (ret != AVERROR_OPTION_NOT_FOUND) {
820  av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
821  "with argument '%s'.\n", opt, argv[optindex]);
822  return ret;
823  }
824  }
825 
826  /* boolean -nofoo options */
827  if (opt[0] == 'n' && opt[1] == 'o' &&
828  (po = find_option(options, opt + 2)) &&
829  po->name && po->flags & OPT_BOOL) {
830  add_opt(octx, po, opt, "0");
831  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
832  "argument 0.\n", po->name, po->help);
833  continue;
834  }
835 
836  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
838  }
839 
840  if (octx->cur_group.nb_opts || codec_opts || format_opts || resample_opts)
841  av_log(NULL, AV_LOG_WARNING, "Trailing options were found on the "
842  "commandline.\n");
843 
844  av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
845 
846  return 0;
847 }
848 
849 int opt_cpuflags(void *optctx, const char *opt, const char *arg)
850 {
851  int ret;
852  unsigned flags = av_get_cpu_flags();
853 
854  if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
855  return ret;
856 
857  av_force_cpu_flags(flags);
858  return 0;
859 }
860 
861 int opt_loglevel(void *optctx, const char *opt, const char *arg)
862 {
863  const struct { const char *name; int level; } log_levels[] = {
864  { "quiet" , AV_LOG_QUIET },
865  { "panic" , AV_LOG_PANIC },
866  { "fatal" , AV_LOG_FATAL },
867  { "error" , AV_LOG_ERROR },
868  { "warning", AV_LOG_WARNING },
869  { "info" , AV_LOG_INFO },
870  { "verbose", AV_LOG_VERBOSE },
871  { "debug" , AV_LOG_DEBUG },
872  { "trace" , AV_LOG_TRACE },
873  };
874  char *tail;
875  int level;
876  int flags;
877  int i;
878 
879  flags = av_log_get_flags();
880  tail = strstr(arg, "repeat");
881  if (tail)
882  flags &= ~AV_LOG_SKIP_REPEATED;
883  else
884  flags |= AV_LOG_SKIP_REPEATED;
885 
886  av_log_set_flags(flags);
887  if (tail == arg)
888  arg += 6 + (arg[6]=='+');
889  if(tail && !*arg)
890  return 0;
891 
892  for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
893  if (!strcmp(log_levels[i].name, arg)) {
894  av_log_set_level(log_levels[i].level);
895  return 0;
896  }
897  }
898 
899  level = strtol(arg, &tail, 10);
900  if (*tail) {
901  av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
902  "Possible levels are numbers or:\n", arg);
903  for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
904  av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
905  exit_program(1);
906  }
907  av_log_set_level(level);
908  return 0;
909 }
910 
911 static void expand_filename_template(AVBPrint *bp, const char *template,
912  struct tm *tm)
913 {
914  int c;
915 
916  while ((c = *(template++))) {
917  if (c == '%') {
918  if (!(c = *(template++)))
919  break;
920  switch (c) {
921  case 'p':
922  av_bprintf(bp, "%s", program_name);
923  break;
924  case 't':
925  av_bprintf(bp, "%04d%02d%02d-%02d%02d%02d",
926  tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
927  tm->tm_hour, tm->tm_min, tm->tm_sec);
928  break;
929  case '%':
930  av_bprint_chars(bp, c, 1);
931  break;
932  }
933  } else {
934  av_bprint_chars(bp, c, 1);
935  }
936  }
937 }
938 
939 static int init_report(const char *env)
940 {
941  char *filename_template = NULL;
942  char *key, *val;
943  int ret, count = 0;
944  time_t now;
945  struct tm *tm;
946  AVBPrint filename;
947 
948  if (report_file) /* already opened */
949  return 0;
950  time(&now);
951  tm = localtime(&now);
952 
953  while (env && *env) {
954  if ((ret = av_opt_get_key_value(&env, "=", ":", 0, &key, &val)) < 0) {
955  if (count)
957  "Failed to parse FFREPORT environment variable: %s\n",
958  av_err2str(ret));
959  break;
960  }
961  if (*env)
962  env++;
963  count++;
964  if (!strcmp(key, "file")) {
965  av_free(filename_template);
966  filename_template = val;
967  val = NULL;
968  } else if (!strcmp(key, "level")) {
969  char *tail;
970  report_file_level = strtol(val, &tail, 10);
971  if (*tail) {
972  av_log(NULL, AV_LOG_FATAL, "Invalid report file level\n");
973  exit_program(1);
974  }
975  } else {
976  av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in FFREPORT\n", key);
977  }
978  av_free(val);
979  av_free(key);
980  }
981 
982  av_bprint_init(&filename, 0, 1);
983  expand_filename_template(&filename,
984  av_x_if_null(filename_template, "%p-%t.log"), tm);
985  av_free(filename_template);
986  if (!av_bprint_is_complete(&filename)) {
987  av_log(NULL, AV_LOG_ERROR, "Out of memory building report file name\n");
988  return AVERROR(ENOMEM);
989  }
990 
991  report_file = fopen(filename.str, "w");
992  if (!report_file) {
993  int ret = AVERROR(errno);
994  av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n",
995  filename.str, strerror(errno));
996  return ret;
997  }
1000  "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
1001  "Report written to \"%s\"\n",
1002  program_name,
1003  tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1004  tm->tm_hour, tm->tm_min, tm->tm_sec,
1005  filename.str);
1006  av_bprint_finalize(&filename, NULL);
1007  return 0;
1008 }
1009 
1010 int opt_report(const char *opt)
1011 {
1012  return init_report(NULL);
1013 }
1014 
1015 int opt_max_alloc(void *optctx, const char *opt, const char *arg)
1016 {
1017  char *tail;
1018  size_t max;
1019 
1020  max = strtol(arg, &tail, 10);
1021  if (*tail) {
1022  av_log(NULL, AV_LOG_FATAL, "Invalid max_alloc \"%s\".\n", arg);
1023  exit_program(1);
1024  }
1025  av_max_alloc(max);
1026  return 0;
1027 }
1028 
1029 int opt_timelimit(void *optctx, const char *opt, const char *arg)
1030 {
1031 #if HAVE_SETRLIMIT
1032  int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
1033  struct rlimit rl = { lim, lim + 1 };
1034  if (setrlimit(RLIMIT_CPU, &rl))
1035  perror("setrlimit");
1036 #else
1037  av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
1038 #endif
1039  return 0;
1040 }
1041 
1042 void print_error(const char *filename, int err)
1043 {
1044  char errbuf[128];
1045  const char *errbuf_ptr = errbuf;
1046 
1047  if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
1048  errbuf_ptr = strerror(AVUNERROR(err));
1049  av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
1050 }
1051 
1052 static int warned_cfg = 0;
1053 
1054 #define INDENT 1
1055 #define SHOW_VERSION 2
1056 #define SHOW_CONFIG 0
1057 #define SHOW_COPYRIGHT 8
1058 
1059 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1060  if (CONFIG_##LIBNAME) { \
1061  const char *indent = flags & INDENT? " " : ""; \
1062  if (flags & SHOW_VERSION) { \
1063  unsigned int version = libname##_version(); \
1064  av_log(NULL, level, \
1065  "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1066  indent, #libname, \
1067  LIB##LIBNAME##_VERSION_MAJOR, \
1068  LIB##LIBNAME##_VERSION_MINOR, \
1069  LIB##LIBNAME##_VERSION_MICRO, \
1070  version >> 16, version >> 8 & 0xff, version & 0xff); \
1071  } \
1072  if (flags & SHOW_CONFIG) { \
1073  const char *cfg = libname##_configuration(); \
1074  if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1075  if (!warned_cfg) { \
1076  av_log(NULL, level, \
1077  "%sWARNING: library configuration mismatch\n", \
1078  indent); \
1079  warned_cfg = 1; \
1080  } \
1081  av_log(NULL, level, "%s%-11s configuration: %s\n", \
1082  indent, #libname, cfg); \
1083  } \
1084  } \
1085  } \
1086 
1087 static void print_all_libs_info(int flags, int level)
1088 {
1089  PRINT_LIB_INFO(avutil, AVUTIL, flags, level);
1090  PRINT_LIB_INFO(avcodec, AVCODEC, flags, level);
1091  PRINT_LIB_INFO(avformat, AVFORMAT, flags, level);
1092  PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
1093  PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
1094  PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level);
1095  PRINT_LIB_INFO(swscale, SWSCALE, flags, level);
1096  PRINT_LIB_INFO(swresample,SWRESAMPLE, flags, level);
1097  PRINT_LIB_INFO(postproc, POSTPROC, flags, level);
1098 }
1099 
1100 static void print_program_info(int flags, int level)
1101 {
1102  const char *indent = flags & INDENT? " " : "";
1103 
1104  av_log(NULL, level, "%s version " FFMPEG_VERSION, program_name);
1105  if (flags & SHOW_COPYRIGHT)
1106  av_log(NULL, level, " Copyright (c) %d-%d the FFmpeg developers",
1108  av_log(NULL, level, "\n");
1109  av_log(NULL, level, "%sbuilt with %s\n", indent, CC_IDENT);
1110 
1111  av_log(NULL, level, "%sconfiguration: " FFMPEG_CONFIGURATION "\n", indent);
1112 }
1113 
1114 static void print_buildconf(int flags, int level)
1115 {
1116  const char *indent = flags & INDENT ? " " : "";
1117  char str[] = { FFMPEG_CONFIGURATION };
1118  char *conflist, *remove_tilde, *splitconf;
1119 
1120  // Change all the ' --' strings to '~--' so that
1121  // they can be identified as tokens.
1122  while ((conflist = strstr(str, " --")) != NULL) {
1123  strncpy(conflist, "~--", 3);
1124  }
1125 
1126  // Compensate for the weirdness this would cause
1127  // when passing 'pkg-config --static'.
1128  while ((remove_tilde = strstr(str, "pkg-config~")) != NULL) {
1129  strncpy(remove_tilde, "pkg-config ", 11);
1130  }
1131 
1132  splitconf = strtok(str, "~");
1133  av_log(NULL, level, "\n%sconfiguration:\n", indent);
1134  while (splitconf != NULL) {
1135  av_log(NULL, level, "%s%s%s\n", indent, indent, splitconf);
1136  splitconf = strtok(NULL, "~");
1137  }
1138 }
1139 
1140 void show_banner(int argc, char **argv, const OptionDef *options)
1141 {
1142  int idx = locate_option(argc, argv, options, "version");
1143  if (hide_banner || idx)
1144  return;
1145 
1149 }
1150 
1151 int show_version(void *optctx, const char *opt, const char *arg)
1152 {
1156 
1157  return 0;
1158 }
1159 
1160 int show_buildconf(void *optctx, const char *opt, const char *arg)
1161 {
1164 
1165  return 0;
1166 }
1167 
1168 int show_license(void *optctx, const char *opt, const char *arg)
1169 {
1170 #if CONFIG_NONFREE
1171  printf(
1172  "This version of %s has nonfree parts compiled in.\n"
1173  "Therefore it is not legally redistributable.\n",
1174  program_name );
1175 #elif CONFIG_GPLV3
1176  printf(
1177  "%s is free software; you can redistribute it and/or modify\n"
1178  "it under the terms of the GNU General Public License as published by\n"
1179  "the Free Software Foundation; either version 3 of the License, or\n"
1180  "(at your option) any later version.\n"
1181  "\n"
1182  "%s is distributed in the hope that it will be useful,\n"
1183  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1184  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1185  "GNU General Public License for more details.\n"
1186  "\n"
1187  "You should have received a copy of the GNU General Public License\n"
1188  "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1190 #elif CONFIG_GPL
1191  printf(
1192  "%s is free software; you can redistribute it and/or modify\n"
1193  "it under the terms of the GNU General Public License as published by\n"
1194  "the Free Software Foundation; either version 2 of the License, or\n"
1195  "(at your option) any later version.\n"
1196  "\n"
1197  "%s is distributed in the hope that it will be useful,\n"
1198  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1199  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1200  "GNU General Public License for more details.\n"
1201  "\n"
1202  "You should have received a copy of the GNU General Public License\n"
1203  "along with %s; if not, write to the Free Software\n"
1204  "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1206 #elif CONFIG_LGPLV3
1207  printf(
1208  "%s is free software; you can redistribute it and/or modify\n"
1209  "it under the terms of the GNU Lesser General Public License as published by\n"
1210  "the Free Software Foundation; either version 3 of the License, or\n"
1211  "(at your option) any later version.\n"
1212  "\n"
1213  "%s is distributed in the hope that it will be useful,\n"
1214  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1215  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1216  "GNU Lesser General Public License for more details.\n"
1217  "\n"
1218  "You should have received a copy of the GNU Lesser General Public License\n"
1219  "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1221 #else
1222  printf(
1223  "%s is free software; you can redistribute it and/or\n"
1224  "modify it under the terms of the GNU Lesser General Public\n"
1225  "License as published by the Free Software Foundation; either\n"
1226  "version 2.1 of the License, or (at your option) any later version.\n"
1227  "\n"
1228  "%s is distributed in the hope that it will be useful,\n"
1229  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1230  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1231  "Lesser General Public License for more details.\n"
1232  "\n"
1233  "You should have received a copy of the GNU Lesser General Public\n"
1234  "License along with %s; if not, write to the Free Software\n"
1235  "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1237 #endif
1238 
1239  return 0;
1240 }
1241 
1242 static int is_device(const AVClass *avclass)
1243 {
1244  if (!avclass)
1245  return 0;
1246  return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
1247 }
1248 
1249 static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only)
1250 {
1251  AVInputFormat *ifmt = NULL;
1252  AVOutputFormat *ofmt = NULL;
1253  const char *last_name;
1254  int is_dev;
1255 
1256  printf("%s\n"
1257  " D. = Demuxing supported\n"
1258  " .E = Muxing supported\n"
1259  " --\n", device_only ? "Devices:" : "File formats:");
1260  last_name = "000";
1261  for (;;) {
1262  int decode = 0;
1263  int encode = 0;
1264  const char *name = NULL;
1265  const char *long_name = NULL;
1266 
1267  while ((ofmt = av_oformat_next(ofmt))) {
1268  is_dev = is_device(ofmt->priv_class);
1269  if (!is_dev && device_only)
1270  continue;
1271  if ((!name || strcmp(ofmt->name, name) < 0) &&
1272  strcmp(ofmt->name, last_name) > 0) {
1273  name = ofmt->name;
1274  long_name = ofmt->long_name;
1275  encode = 1;
1276  }
1277  }
1278  while ((ifmt = av_iformat_next(ifmt))) {
1279  is_dev = is_device(ifmt->priv_class);
1280  if (!is_dev && device_only)
1281  continue;
1282  if ((!name || strcmp(ifmt->name, name) < 0) &&
1283  strcmp(ifmt->name, last_name) > 0) {
1284  name = ifmt->name;
1285  long_name = ifmt->long_name;
1286  encode = 0;
1287  }
1288  if (name && strcmp(ifmt->name, name) == 0)
1289  decode = 1;
1290  }
1291  if (!name)
1292  break;
1293  last_name = name;
1294 
1295  printf(" %s%s %-15s %s\n",
1296  decode ? "D" : " ",
1297  encode ? "E" : " ",
1298  name,
1299  long_name ? long_name:" ");
1300  }
1301  return 0;
1302 }
1303 
1304 int show_formats(void *optctx, const char *opt, const char *arg)
1305 {
1306  return show_formats_devices(optctx, opt, arg, 0);
1307 }
1308 
1309 int show_devices(void *optctx, const char *opt, const char *arg)
1310 {
1311  return show_formats_devices(optctx, opt, arg, 1);
1312 }
1313 
1314 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1315  if (codec->field) { \
1316  const type *p = codec->field; \
1317  \
1318  printf(" Supported " list_name ":"); \
1319  while (*p != term) { \
1320  get_name(*p); \
1321  printf(" %s", name); \
1322  p++; \
1323  } \
1324  printf("\n"); \
1325  } \
1326 
1327 static void print_codec(const AVCodec *c)
1328 {
1329  int encoder = av_codec_is_encoder(c);
1330 
1331  printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
1332  c->long_name ? c->long_name : "");
1333 
1334  if (c->type == AVMEDIA_TYPE_VIDEO ||
1335  c->type == AVMEDIA_TYPE_AUDIO) {
1336  printf(" Threading capabilities: ");
1340  AV_CODEC_CAP_SLICE_THREADS: printf("frame and slice"); break;
1341  case AV_CODEC_CAP_FRAME_THREADS: printf("frame"); break;
1342  case AV_CODEC_CAP_SLICE_THREADS: printf("slice"); break;
1343  default: printf("no"); break;
1344  }
1345  printf("\n");
1346  }
1347 
1348  if (c->supported_framerates) {
1349  const AVRational *fps = c->supported_framerates;
1350 
1351  printf(" Supported framerates:");
1352  while (fps->num) {
1353  printf(" %d/%d", fps->num, fps->den);
1354  fps++;
1355  }
1356  printf("\n");
1357  }
1358  PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
1360  PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
1362  PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
1364  PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts",
1365  0, GET_CH_LAYOUT_DESC);
1366 
1367  if (c->priv_class) {
1371  }
1372 }
1373 
1375 {
1376  switch (type) {
1377  case AVMEDIA_TYPE_VIDEO: return 'V';
1378  case AVMEDIA_TYPE_AUDIO: return 'A';
1379  case AVMEDIA_TYPE_DATA: return 'D';
1380  case AVMEDIA_TYPE_SUBTITLE: return 'S';
1381  case AVMEDIA_TYPE_ATTACHMENT:return 'T';
1382  default: return '?';
1383  }
1384 }
1385 
1386 static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev,
1387  int encoder)
1388 {
1389  while ((prev = av_codec_next(prev))) {
1390  if (prev->id == id &&
1391  (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev)))
1392  return prev;
1393  }
1394  return NULL;
1395 }
1396 
1397 static int compare_codec_desc(const void *a, const void *b)
1398 {
1399  const AVCodecDescriptor * const *da = a;
1400  const AVCodecDescriptor * const *db = b;
1401 
1402  return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1403  strcmp((*da)->name, (*db)->name);
1404 }
1405 
1406 static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
1407 {
1408  const AVCodecDescriptor *desc = NULL;
1409  const AVCodecDescriptor **codecs;
1410  unsigned nb_codecs = 0, i = 0;
1411 
1412  while ((desc = avcodec_descriptor_next(desc)))
1413  nb_codecs++;
1414  if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) {
1415  av_log(NULL, AV_LOG_ERROR, "Out of memory\n");
1416  exit_program(1);
1417  }
1418  desc = NULL;
1419  while ((desc = avcodec_descriptor_next(desc)))
1420  codecs[i++] = desc;
1421  av_assert0(i == nb_codecs);
1422  qsort(codecs, nb_codecs, sizeof(*codecs), compare_codec_desc);
1423  *rcodecs = codecs;
1424  return nb_codecs;
1425 }
1426 
1427 static void print_codecs_for_id(enum AVCodecID id, int encoder)
1428 {
1429  const AVCodec *codec = NULL;
1430 
1431  printf(" (%s: ", encoder ? "encoders" : "decoders");
1432 
1433  while ((codec = next_codec_for_id(id, codec, encoder)))
1434  printf("%s ", codec->name);
1435 
1436  printf(")");
1437 }
1438 
1439 int show_codecs(void *optctx, const char *opt, const char *arg)
1440 {
1441  const AVCodecDescriptor **codecs;
1442  unsigned i, nb_codecs = get_codecs_sorted(&codecs);
1443 
1444  printf("Codecs:\n"
1445  " D..... = Decoding supported\n"
1446  " .E.... = Encoding supported\n"
1447  " ..V... = Video codec\n"
1448  " ..A... = Audio codec\n"
1449  " ..S... = Subtitle codec\n"
1450  " ...I.. = Intra frame-only codec\n"
1451  " ....L. = Lossy compression\n"
1452  " .....S = Lossless compression\n"
1453  " -------\n");
1454  for (i = 0; i < nb_codecs; i++) {
1455  const AVCodecDescriptor *desc = codecs[i];
1456  const AVCodec *codec = NULL;
1457 
1458  if (strstr(desc->name, "_deprecated"))
1459  continue;
1460 
1461  printf(" ");
1462  printf(avcodec_find_decoder(desc->id) ? "D" : ".");
1463  printf(avcodec_find_encoder(desc->id) ? "E" : ".");
1464 
1465  printf("%c", get_media_type_char(desc->type));
1466  printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
1467  printf((desc->props & AV_CODEC_PROP_LOSSY) ? "L" : ".");
1468  printf((desc->props & AV_CODEC_PROP_LOSSLESS) ? "S" : ".");
1469 
1470  printf(" %-20s %s", desc->name, desc->long_name ? desc->long_name : "");
1471 
1472  /* print decoders/encoders when there's more than one or their
1473  * names are different from codec name */
1474  while ((codec = next_codec_for_id(desc->id, codec, 0))) {
1475  if (strcmp(codec->name, desc->name)) {
1476  print_codecs_for_id(desc->id, 0);
1477  break;
1478  }
1479  }
1480  codec = NULL;
1481  while ((codec = next_codec_for_id(desc->id, codec, 1))) {
1482  if (strcmp(codec->name, desc->name)) {
1483  print_codecs_for_id(desc->id, 1);
1484  break;
1485  }
1486  }
1487 
1488  printf("\n");
1489  }
1490  av_free(codecs);
1491  return 0;
1492 }
1493 
1494 static void print_codecs(int encoder)
1495 {
1496  const AVCodecDescriptor **codecs;
1497  unsigned i, nb_codecs = get_codecs_sorted(&codecs);
1498 
1499  printf("%s:\n"
1500  " V..... = Video\n"
1501  " A..... = Audio\n"
1502  " S..... = Subtitle\n"
1503  " .F.... = Frame-level multithreading\n"
1504  " ..S... = Slice-level multithreading\n"
1505  " ...X.. = Codec is experimental\n"
1506  " ....B. = Supports draw_horiz_band\n"
1507  " .....D = Supports direct rendering method 1\n"
1508  " ------\n",
1509  encoder ? "Encoders" : "Decoders");
1510  for (i = 0; i < nb_codecs; i++) {
1511  const AVCodecDescriptor *desc = codecs[i];
1512  const AVCodec *codec = NULL;
1513 
1514  while ((codec = next_codec_for_id(desc->id, codec, encoder))) {
1515  printf(" %c", get_media_type_char(desc->type));
1516  printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? "F" : ".");
1517  printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? "S" : ".");
1518  printf((codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ? "X" : ".");
1519  printf((codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : ".");
1520  printf((codec->capabilities & AV_CODEC_CAP_DR1) ? "D" : ".");
1521 
1522  printf(" %-20s %s", codec->name, codec->long_name ? codec->long_name : "");
1523  if (strcmp(codec->name, desc->name))
1524  printf(" (codec %s)", desc->name);
1525 
1526  printf("\n");
1527  }
1528  }
1529  av_free(codecs);
1530 }
1531 
1532 int show_decoders(void *optctx, const char *opt, const char *arg)
1533 {
1534  print_codecs(0);
1535  return 0;
1536 }
1537 
1538 int show_encoders(void *optctx, const char *opt, const char *arg)
1539 {
1540  print_codecs(1);
1541  return 0;
1542 }
1543 
1544 int show_bsfs(void *optctx, const char *opt, const char *arg)
1545 {
1546  AVBitStreamFilter *bsf = NULL;
1547 
1548  printf("Bitstream filters:\n");
1549  while ((bsf = av_bitstream_filter_next(bsf)))
1550  printf("%s\n", bsf->name);
1551  printf("\n");
1552  return 0;
1553 }
1554 
1555 int show_protocols(void *optctx, const char *opt, const char *arg)
1556 {
1557  void *opaque = NULL;
1558  const char *name;
1559 
1560  printf("Supported file protocols:\n"
1561  "Input:\n");
1562  while ((name = avio_enum_protocols(&opaque, 0)))
1563  printf(" %s\n", name);
1564  printf("Output:\n");
1565  while ((name = avio_enum_protocols(&opaque, 1)))
1566  printf(" %s\n", name);
1567  return 0;
1568 }
1569 
1570 int show_filters(void *optctx, const char *opt, const char *arg)
1571 {
1572 #if CONFIG_AVFILTER
1573  const AVFilter *filter = NULL;
1574  char descr[64], *descr_cur;
1575  int i, j;
1576  const AVFilterPad *pad;
1577 
1578  printf("Filters:\n"
1579  " T.. = Timeline support\n"
1580  " .S. = Slice threading\n"
1581  " ..C = Command support\n"
1582  " A = Audio input/output\n"
1583  " V = Video input/output\n"
1584  " N = Dynamic number and/or type of input/output\n"
1585  " | = Source or sink filter\n");
1586  while ((filter = avfilter_next(filter))) {
1587  descr_cur = descr;
1588  for (i = 0; i < 2; i++) {
1589  if (i) {
1590  *(descr_cur++) = '-';
1591  *(descr_cur++) = '>';
1592  }
1593  pad = i ? filter->outputs : filter->inputs;
1594  for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
1595  if (descr_cur >= descr + sizeof(descr) - 4)
1596  break;
1597  *(descr_cur++) = get_media_type_char(avfilter_pad_get_type(pad, j));
1598  }
1599  if (!j)
1600  *(descr_cur++) = ((!i && (filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
1601  ( i && (filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ? 'N' : '|';
1602  }
1603  *descr_cur = 0;
1604  printf(" %c%c%c %-16s %-10s %s\n",
1605  filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ? 'T' : '.',
1606  filter->flags & AVFILTER_FLAG_SLICE_THREADS ? 'S' : '.',
1607  filter->process_command ? 'C' : '.',
1608  filter->name, descr, filter->description);
1609  }
1610 #else
1611  printf("No filters available: libavfilter disabled\n");
1612 #endif
1613  return 0;
1614 }
1615 
1616 int show_colors(void *optctx, const char *opt, const char *arg)
1617 {
1618  const char *name;
1619  const uint8_t *rgb;
1620  int i;
1621 
1622  printf("%-32s #RRGGBB\n", "name");
1623 
1624  for (i = 0; name = av_get_known_color_name(i, &rgb); i++)
1625  printf("%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1626 
1627  return 0;
1628 }
1629 
1630 int show_pix_fmts(void *optctx, const char *opt, const char *arg)
1631 {
1632  const AVPixFmtDescriptor *pix_desc = NULL;
1633 
1634  printf("Pixel formats:\n"
1635  "I.... = Supported Input format for conversion\n"
1636  ".O... = Supported Output format for conversion\n"
1637  "..H.. = Hardware accelerated format\n"
1638  "...P. = Paletted format\n"
1639  "....B = Bitstream format\n"
1640  "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1641  "-----\n");
1642 
1643 #if !CONFIG_SWSCALE
1644 # define sws_isSupportedInput(x) 0
1645 # define sws_isSupportedOutput(x) 0
1646 #endif
1647 
1648  while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
1649  enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
1650  printf("%c%c%c%c%c %-16s %d %2d\n",
1651  sws_isSupportedInput (pix_fmt) ? 'I' : '.',
1652  sws_isSupportedOutput(pix_fmt) ? 'O' : '.',
1653  pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ? 'H' : '.',
1654  pix_desc->flags & AV_PIX_FMT_FLAG_PAL ? 'P' : '.',
1655  pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ? 'B' : '.',
1656  pix_desc->name,
1657  pix_desc->nb_components,
1658  av_get_bits_per_pixel(pix_desc));
1659  }
1660  return 0;
1661 }
1662 
1663 int show_layouts(void *optctx, const char *opt, const char *arg)
1664 {
1665  int i = 0;
1666  uint64_t layout, j;
1667  const char *name, *descr;
1668 
1669  printf("Individual channels:\n"
1670  "NAME DESCRIPTION\n");
1671  for (i = 0; i < 63; i++) {
1672  name = av_get_channel_name((uint64_t)1 << i);
1673  if (!name)
1674  continue;
1675  descr = av_get_channel_description((uint64_t)1 << i);
1676  printf("%-14s %s\n", name, descr);
1677  }
1678  printf("\nStandard channel layouts:\n"
1679  "NAME DECOMPOSITION\n");
1680  for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
1681  if (name) {
1682  printf("%-14s ", name);
1683  for (j = 1; j; j <<= 1)
1684  if ((layout & j))
1685  printf("%s%s", (layout & (j - 1)) ? "+" : "", av_get_channel_name(j));
1686  printf("\n");
1687  }
1688  }
1689  return 0;
1690 }
1691 
1692 int show_sample_fmts(void *optctx, const char *opt, const char *arg)
1693 {
1694  int i;
1695  char fmt_str[128];
1696  for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
1697  printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
1698  return 0;
1699 }
1700 
1701 static void show_help_codec(const char *name, int encoder)
1702 {
1703  const AVCodecDescriptor *desc;
1704  const AVCodec *codec;
1705 
1706  if (!name) {
1707  av_log(NULL, AV_LOG_ERROR, "No codec name specified.\n");
1708  return;
1709  }
1710 
1711  codec = encoder ? avcodec_find_encoder_by_name(name) :
1713 
1714  if (codec)
1715  print_codec(codec);
1716  else if ((desc = avcodec_descriptor_get_by_name(name))) {
1717  int printed = 0;
1718 
1719  while ((codec = next_codec_for_id(desc->id, codec, encoder))) {
1720  printed = 1;
1721  print_codec(codec);
1722  }
1723 
1724  if (!printed) {
1725  av_log(NULL, AV_LOG_ERROR, "Codec '%s' is known to FFmpeg, "
1726  "but no %s for it are available. FFmpeg might need to be "
1727  "recompiled with additional external libraries.\n",
1728  name, encoder ? "encoders" : "decoders");
1729  }
1730  } else {
1731  av_log(NULL, AV_LOG_ERROR, "Codec '%s' is not recognized by FFmpeg.\n",
1732  name);
1733  }
1734 }
1735 
1736 static void show_help_demuxer(const char *name)
1737 {
1738  const AVInputFormat *fmt = av_find_input_format(name);
1739 
1740  if (!fmt) {
1741  av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
1742  return;
1743  }
1744 
1745  printf("Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
1746 
1747  if (fmt->extensions)
1748  printf(" Common extensions: %s.\n", fmt->extensions);
1749 
1750  if (fmt->priv_class)
1752 }
1753 
1754 static void show_help_muxer(const char *name)
1755 {
1756  const AVCodecDescriptor *desc;
1757  const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
1758 
1759  if (!fmt) {
1760  av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
1761  return;
1762  }
1763 
1764  printf("Muxer %s [%s]:\n", fmt->name, fmt->long_name);
1765 
1766  if (fmt->extensions)
1767  printf(" Common extensions: %s.\n", fmt->extensions);
1768  if (fmt->mime_type)
1769  printf(" Mime type: %s.\n", fmt->mime_type);
1770  if (fmt->video_codec != AV_CODEC_ID_NONE &&
1771  (desc = avcodec_descriptor_get(fmt->video_codec))) {
1772  printf(" Default video codec: %s.\n", desc->name);
1773  }
1774  if (fmt->audio_codec != AV_CODEC_ID_NONE &&
1775  (desc = avcodec_descriptor_get(fmt->audio_codec))) {
1776  printf(" Default audio codec: %s.\n", desc->name);
1777  }
1778  if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
1779  (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
1780  printf(" Default subtitle codec: %s.\n", desc->name);
1781  }
1782 
1783  if (fmt->priv_class)
1785 }
1786 
1787 #if CONFIG_AVFILTER
1788 static void show_help_filter(const char *name)
1789 {
1790 #if CONFIG_AVFILTER
1791  const AVFilter *f = avfilter_get_by_name(name);
1792  int i, count;
1793 
1794  if (!name) {
1795  av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
1796  return;
1797  } else if (!f) {
1798  av_log(NULL, AV_LOG_ERROR, "Unknown filter '%s'.\n", name);
1799  return;
1800  }
1801 
1802  printf("Filter %s\n", f->name);
1803  if (f->description)
1804  printf(" %s\n", f->description);
1805 
1807  printf(" slice threading supported\n");
1808 
1809  printf(" Inputs:\n");
1810  count = avfilter_pad_count(f->inputs);
1811  for (i = 0; i < count; i++) {
1812  printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
1814  }
1816  printf(" dynamic (depending on the options)\n");
1817  else if (!count)
1818  printf(" none (source filter)\n");
1819 
1820  printf(" Outputs:\n");
1821  count = avfilter_pad_count(f->outputs);
1822  for (i = 0; i < count; i++) {
1823  printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
1825  }
1827  printf(" dynamic (depending on the options)\n");
1828  else if (!count)
1829  printf(" none (sink filter)\n");
1830 
1831  if (f->priv_class)
1835  printf("This filter has support for timeline through the 'enable' option.\n");
1836 #else
1837  av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; "
1838  "can not to satisfy request\n");
1839 #endif
1840 }
1841 #endif
1842 
1843 int show_help(void *optctx, const char *opt, const char *arg)
1844 {
1845  char *topic, *par;
1847 
1848  topic = av_strdup(arg ? arg : "");
1849  if (!topic)
1850  return AVERROR(ENOMEM);
1851  par = strchr(topic, '=');
1852  if (par)
1853  *par++ = 0;
1854 
1855  if (!*topic) {
1856  show_help_default(topic, par);
1857  } else if (!strcmp(topic, "decoder")) {
1858  show_help_codec(par, 0);
1859  } else if (!strcmp(topic, "encoder")) {
1860  show_help_codec(par, 1);
1861  } else if (!strcmp(topic, "demuxer")) {
1862  show_help_demuxer(par);
1863  } else if (!strcmp(topic, "muxer")) {
1864  show_help_muxer(par);
1865 #if CONFIG_AVFILTER
1866  } else if (!strcmp(topic, "filter")) {
1867  show_help_filter(par);
1868 #endif
1869  } else {
1870  show_help_default(topic, par);
1871  }
1872 
1873  av_freep(&topic);
1874  return 0;
1875 }
1876 
1877 int read_yesno(void)
1878 {
1879  int c = getchar();
1880  int yesno = (av_toupper(c) == 'Y');
1881 
1882  while (c != '\n' && c != EOF)
1883  c = getchar();
1884 
1885  return yesno;
1886 }
1887 
1888 FILE *get_preset_file(char *filename, size_t filename_size,
1889  const char *preset_name, int is_path,
1890  const char *codec_name)
1891 {
1892  FILE *f = NULL;
1893  int i;
1894  const char *base[3] = { getenv("FFMPEG_DATADIR"),
1895  getenv("HOME"),
1896  FFMPEG_DATADIR, };
1897 
1898  if (is_path) {
1899  av_strlcpy(filename, preset_name, filename_size);
1900  f = fopen(filename, "r");
1901  } else {
1902 #ifdef _WIN32
1903  char datadir[MAX_PATH], *ls;
1904  base[2] = NULL;
1905 
1906  if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
1907  {
1908  for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1909  if (*ls == '\\') *ls = '/';
1910 
1911  if (ls = strrchr(datadir, '/'))
1912  {
1913  *ls = 0;
1914  strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
1915  base[2] = datadir;
1916  }
1917  }
1918 #endif
1919  for (i = 0; i < 3 && !f; i++) {
1920  if (!base[i])
1921  continue;
1922  snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
1923  i != 1 ? "" : "/.ffmpeg", preset_name);
1924  f = fopen(filename, "r");
1925  if (!f && codec_name) {
1926  snprintf(filename, filename_size,
1927  "%s%s/%s-%s.ffpreset",
1928  base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
1929  preset_name);
1930  f = fopen(filename, "r");
1931  }
1932  }
1933  }
1934 
1935  return f;
1936 }
1937 
1938 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
1939 {
1940  int ret = avformat_match_stream_specifier(s, st, spec);
1941  if (ret < 0)
1942  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
1943  return ret;
1944 }
1945 
1947  AVFormatContext *s, AVStream *st, AVCodec *codec)
1948 {
1949  AVDictionary *ret = NULL;
1950  AVDictionaryEntry *t = NULL;
1953  char prefix = 0;
1954  const AVClass *cc = avcodec_get_class();
1955 
1956  if (!codec)
1957  codec = s->oformat ? avcodec_find_encoder(codec_id)
1958  : avcodec_find_decoder(codec_id);
1959 
1960  switch (st->codec->codec_type) {
1961  case AVMEDIA_TYPE_VIDEO:
1962  prefix = 'v';
1963  flags |= AV_OPT_FLAG_VIDEO_PARAM;
1964  break;
1965  case AVMEDIA_TYPE_AUDIO:
1966  prefix = 'a';
1967  flags |= AV_OPT_FLAG_AUDIO_PARAM;
1968  break;
1969  case AVMEDIA_TYPE_SUBTITLE:
1970  prefix = 's';
1971  flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
1972  break;
1973  }
1974 
1975  while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) {
1976  char *p = strchr(t->key, ':');
1977 
1978  /* check stream specification in opt name */
1979  if (p)
1980  switch (check_stream_specifier(s, st, p + 1)) {
1981  case 1: *p = 0; break;
1982  case 0: continue;
1983  default: exit_program(1);
1984  }
1985 
1986  if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
1987  !codec ||
1988  (codec->priv_class &&
1989  av_opt_find(&codec->priv_class, t->key, NULL, flags,
1991  av_dict_set(&ret, t->key, t->value, 0);
1992  else if (t->key[0] == prefix &&
1993  av_opt_find(&cc, t->key + 1, NULL, flags,
1995  av_dict_set(&ret, t->key + 1, t->value, 0);
1996 
1997  if (p)
1998  *p = ':';
1999  }
2000  return ret;
2001 }
2002 
2004  AVDictionary *codec_opts)
2005 {
2006  int i;
2007  AVDictionary **opts;
2008 
2009  if (!s->nb_streams)
2010  return NULL;
2011  opts = av_mallocz_array(s->nb_streams, sizeof(*opts));
2012  if (!opts) {
2014  "Could not alloc memory for stream options.\n");
2015  return NULL;
2016  }
2017  for (i = 0; i < s->nb_streams; i++)
2018  opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codec->codec_id,
2019  s, s->streams[i], NULL);
2020  return opts;
2021 }
2022 
2023 void *grow_array(void *array, int elem_size, int *size, int new_size)
2024 {
2025  if (new_size >= INT_MAX / elem_size) {
2026  av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
2027  exit_program(1);
2028  }
2029  if (*size < new_size) {
2030  uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
2031  if (!tmp) {
2032  av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
2033  exit_program(1);
2034  }
2035  memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
2036  *size = new_size;
2037  return tmp;
2038  }
2039  return array;
2040 }
2041 
2043 {
2044  AVDictionaryEntry *rotate_tag = av_dict_get(st->metadata, "rotate", NULL, 0);
2045  uint8_t* displaymatrix = av_stream_get_side_data(st,
2047  double theta = 0;
2048 
2049  if (rotate_tag && *rotate_tag->value && strcmp(rotate_tag->value, "0")) {
2050  char *tail;
2051  theta = av_strtod(rotate_tag->value, &tail);
2052  if (*tail)
2053  theta = 0;
2054  }
2055  if (displaymatrix && !theta)
2056  theta = -av_display_rotation_get((int32_t*) displaymatrix);
2057 
2058  theta -= 360*floor(theta/360 + 0.9/360);
2059 
2060  if (fabs(theta - 90*round(theta/90)) > 2)
2061  av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
2062  "If you want to help, upload a sample "
2063  "of this file to ftp://upload.ffmpeg.org/incoming/ "
2064  "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
2065 
2066  return theta;
2067 }
2068 
2069 #if CONFIG_AVDEVICE
2071 {
2072  int ret, i;
2073  AVDeviceInfoList *device_list = NULL;
2074 
2075  if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
2076  return AVERROR(EINVAL);
2077 
2078  printf("Auto-detected sources for %s:\n", fmt->name);
2079  if (!fmt->get_device_list) {
2080  ret = AVERROR(ENOSYS);
2081  printf("Cannot list sources. Not implemented.\n");
2082  goto fail;
2083  }
2084 
2085  if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
2086  printf("Cannot list sources.\n");
2087  goto fail;
2088  }
2089 
2090  for (i = 0; i < device_list->nb_devices; i++) {
2091  printf("%s %s [%s]\n", device_list->default_device == i ? "*" : " ",
2092  device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2093  }
2094 
2095  fail:
2096  avdevice_free_list_devices(&device_list);
2097  return ret;
2098 }
2099 
2101 {
2102  int ret, i;
2103  AVDeviceInfoList *device_list = NULL;
2104 
2105  if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
2106  return AVERROR(EINVAL);
2107 
2108  printf("Auto-detected sinks for %s:\n", fmt->name);
2109  if (!fmt->get_device_list) {
2110  ret = AVERROR(ENOSYS);
2111  printf("Cannot list sinks. Not implemented.\n");
2112  goto fail;
2113  }
2114 
2115  if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
2116  printf("Cannot list sinks.\n");
2117  goto fail;
2118  }
2119 
2120  for (i = 0; i < device_list->nb_devices; i++) {
2121  printf("%s %s [%s]\n", device_list->default_device == i ? "*" : " ",
2122  device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2123  }
2124 
2125  fail:
2126  avdevice_free_list_devices(&device_list);
2127  return ret;
2128 }
2129 
2130 static int show_sinks_sources_parse_arg(const char *arg, char **dev, AVDictionary **opts)
2131 {
2132  int ret;
2133  if (arg) {
2134  char *opts_str = NULL;
2135  av_assert0(dev && opts);
2136  *dev = av_strdup(arg);
2137  if (!*dev)
2138  return AVERROR(ENOMEM);
2139  if ((opts_str = strchr(*dev, ','))) {
2140  *(opts_str++) = '\0';
2141  if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str, "=", ":", 0)) < 0)) {
2142  av_freep(dev);
2143  return ret;
2144  }
2145  }
2146  } else
2147  printf("\nDevice name is not provided.\n"
2148  "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
2149  return 0;
2150 }
2151 
2152 int show_sources(void *optctx, const char *opt, const char *arg)
2153 {
2154  AVInputFormat *fmt = NULL;
2155  char *dev = NULL;
2156  AVDictionary *opts = NULL;
2157  int ret = 0;
2158  int error_level = av_log_get_level();
2159 
2161 
2162  if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2163  goto fail;
2164 
2165  do {
2166  fmt = av_input_audio_device_next(fmt);
2167  if (fmt) {
2168  if (!strcmp(fmt->name, "lavfi"))
2169  continue; //it's pointless to probe lavfi
2170  if (dev && !av_match_name(dev, fmt->name))
2171  continue;
2172  print_device_sources(fmt, opts);
2173  }
2174  } while (fmt);
2175  do {
2176  fmt = av_input_video_device_next(fmt);
2177  if (fmt) {
2178  if (dev && !av_match_name(dev, fmt->name))
2179  continue;
2180  print_device_sources(fmt, opts);
2181  }
2182  } while (fmt);
2183  fail:
2184  av_dict_free(&opts);
2185  av_free(dev);
2186  av_log_set_level(error_level);
2187  return ret;
2188 }
2189 
2190 int show_sinks(void *optctx, const char *opt, const char *arg)
2191 {
2192  AVOutputFormat *fmt = NULL;
2193  char *dev = NULL;
2194  AVDictionary *opts = NULL;
2195  int ret = 0;
2196  int error_level = av_log_get_level();
2197 
2199 
2200  if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2201  goto fail;
2202 
2203  do {
2204  fmt = av_output_audio_device_next(fmt);
2205  if (fmt) {
2206  if (dev && !av_match_name(dev, fmt->name))
2207  continue;
2208  print_device_sinks(fmt, opts);
2209  }
2210  } while (fmt);
2211  do {
2212  fmt = av_output_video_device_next(fmt);
2213  if (fmt) {
2214  if (dev && !av_match_name(dev, fmt->name))
2215  continue;
2216  print_device_sinks(fmt, opts);
2217  }
2218  } while (fmt);
2219  fail:
2220  av_dict_free(&opts);
2221  av_free(dev);
2222  av_log_set_level(error_level);
2223  return ret;
2224 }
2225 
2226 #endif
AVOutputFormat * av_output_audio_device_next(AVOutputFormat *d)
Audio output devices iterator.
Definition: avdevice.c:115
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:115
void init_dynload(void)
Initialize dynamic library loading.
Definition: cmdutils.c:112
int parse_optgroup(void *optctx, OptionGroup *g)
Parse an options group and write results into optctx.
Definition: cmdutils.c:407
#define NULL
Definition: coverity.c:32
int sws_isSupportedOutput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported output format, 0 otherwise.
Definition: utils.c:237
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
Definition: avcodec.h:596
const char const char void * val
Definition: avisynth_c.h:634
static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
Definition: cmdutils.c:2100
AVDictionary * resample_opts
Definition: cmdutils.h:284
const char * s
Definition: avisynth_c.h:631
int show_sinks(void *optctx, const char *opt, const char *arg)
Print a listing containing autodetected sinks of the output device.
Definition: cmdutils.c:2190
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:73
static enum AVPixelFormat pix_fmt
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
static void show_help_filter(const char *name)
Definition: cmdutils.c:1788
AVDictionary * swr_opts
Definition: cmdutils.h:286
int show_decoders(void *optctx, const char *opt, const char *arg)
Print a listing containing all the decoders supported by the program.
Definition: cmdutils.c:1532
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:3009
const char * name
< group name
Definition: cmdutils.h:262
static void finish_group(OptionParseContext *octx, int group_idx, const char *arg)
Definition: cmdutils.c:652
#define FLAGS
Definition: cmdutils.c:537
AVOption.
Definition: opt.h:255
int show_license(void *optctx, const char *opt, const char *arg)
Print the license of the program to stdout.
Definition: cmdutils.c:1168
#define AV_CODEC_PROP_LOSSY
Codec supports lossy compression.
Definition: avcodec.h:602
#define AV_OPT_FLAG_SUBTITLE_PARAM
Definition: opt.h:292
double get_rotation(AVStream *st)
Definition: cmdutils.c:2042
const char * fmt
Definition: avisynth_c.h:632
char * device_description
human friendly name
Definition: avdevice.h:453
int(* func_arg)(void *, const char *, const char *)
Definition: cmdutils.h:190
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
char * av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt)
Generate a string corresponding to the sample format with sample_fmt, or a header if sample_fmt is ne...
Definition: samplefmt.c:91
Main libavfilter public API header.
const char * g
Definition: vf_curves.c:108
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:558
void av_log_set_level(int level)
Set the log level.
Definition: log.c:382
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:743
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:2081
const AVClass * av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
Iterate over potential AVOptions-enabled children of parent.
Definition: opt.c:1540
int opt_loglevel(void *optctx, const char *opt, const char *arg)
Set the libav* libraries log level.
Definition: cmdutils.c:861
enum AVCodecID video_codec
default video codec
Definition: avformat.h:536
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:1938
#define INDENT
Definition: cmdutils.c:1054
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:431
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:1009
char * device_name
device name, format depends on device
Definition: avdevice.h:452
int num
numerator
Definition: rational.h:44
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:290
const char * b
Definition: vf_curves.c:109
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
Definition: cmdutils.c:1140
static int is_device(const AVClass *avclass)
Definition: cmdutils.c:1242
int show_protocols(void *optctx, const char *opt, const char *arg)
Print a listing containing all the protocols supported by the program.
Definition: cmdutils.c:1555
uint8_t * av_stream_get_side_data(AVStream *stream, enum AVPacketSideDataType type, int *size)
Get side information from stream.
Definition: utils.c:4569
const char * arg
Definition: cmdutils.h:277
const char * sep
Option to be used as group separator.
Definition: cmdutils.h:267
#define GET_CH_LAYOUT_DESC(ch_layout)
Definition: cmdutils.h:589
static const AVOption * opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Definition: cmdutils.c:528
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:912
enum AVMediaType type
Definition: avcodec.h:3495
int show_devices(void *optctx, const char *opt, const char *arg)
Print a listing containing all the devices supported by the program.
Definition: cmdutils.c:1309
int show_formats(void *optctx, const char *opt, const char *arg)
Print a listing containing all the formats supported by the program (including devices).
Definition: cmdutils.c:1304
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
Definition: options.c:97
#define OPT_DOUBLE
Definition: cmdutils.h:185
static void check_options(const OptionDef *po)
Definition: cmdutils.c:490
#define OPT_FLOAT
Definition: cmdutils.h:173
AVCodec.
Definition: avcodec.h:3482
void av_max_alloc(size_t max)
Set the maximum size that may me allocated in one block.
Definition: mem.c:73
int show_pix_fmts(void *optctx, const char *opt, const char *arg)
Print a listing containing all the pixel formats supported by the program.
Definition: cmdutils.c:1630
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Filter out options for given codec.
Definition: cmdutils.c:1946
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:717
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:179
int av_get_standard_channel_layout(unsigned index, uint64_t *layout, const char **name)
Get the value and name of a standard channel layout.
const AVCodecDescriptor * avcodec_descriptor_next(const AVCodecDescriptor *prev)
Iterate over all codec descriptors known to libavcodec.
Definition: codec_desc.c:2945
Format I/O context.
Definition: avformat.h:1285
const AVClass * avresample_get_class(void)
Get the AVClass for AVAudioResampleContext.
Definition: options.c:110
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:267
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:174
#define AV_LOG_QUIET
Print no output.
Definition: log.h:158
static int warned_cfg
Definition: cmdutils.c:1052
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int show_codecs(void *optctx, const char *opt, const char *arg)
Print a listing containing all the codecs supported by the program.
Definition: cmdutils.c:1439
supported_samplerates
Public dictionary API.
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:97
static void dump_argument(const char *a)
Definition: cmdutils.c:466
void register_exit(void(*cb)(int ret))
Register a program-specific cleanup routine.
Definition: cmdutils.c:123
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
Definition: cmdutils.c:91
uint8_t
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
Definition: options.c:148
Opaque data information usually continuous.
Definition: avutil.h:195
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:538
#define OPT_OUTPUT
Definition: cmdutils.h:187
AVOptions.
#define HAS_ARG
Definition: cmdutils.h:166
#define AV_LOG_PANIC
Something went really wrong and we will crash now.
Definition: log.h:163
#define va_copy(dst, src)
Definition: va_copy.h:28
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:202
static const OptionGroupDef groups[]
Definition: ffmpeg_opt.c:2885
static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
Definition: cmdutils.c:1406
AVS_FilterInfo AVS_Value child
Definition: avisynth_c.h:594
#define AV_CODEC_PROP_LOSSLESS
Codec supports lossless compression.
Definition: avcodec.h:606
int opt_max_alloc(void *optctx, const char *opt, const char *arg)
Definition: cmdutils.c:1015
#define media_type_string
Definition: cmdutils.h:570
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: avcodec.h:1279
int nb_opts
Definition: cmdutils.h:280
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: utils.c:4319
#define OPT_OFFSET
Definition: cmdutils.h:180
static void init_parse_context(OptionParseContext *octx, const OptionGroupDef *groups, int nb_groups)
Definition: cmdutils.c:695
#define AV_IS_INPUT_DEVICE(category)
Definition: log.h:50
int show_buildconf(void *optctx, const char *opt, const char *arg)
Print the build configuration of the program to stdout.
Definition: cmdutils.c:1160
void init_opts(void)
Initialize the cmdutils option system, in particular allocate the *_opts contexts.
Definition: cmdutils.c:77
int hide_banner
Definition: cmdutils.c:75
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1353
int flags
A combination of AVFILTER_FLAG_*.
Definition: avfilter.h:513
const char * name
Definition: avcodec.h:5384
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:665
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:39
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
Definition: cmdutils.c:376
#define OPT_SPEC
Definition: cmdutils.h:181
const AVFilter * avfilter_next(const AVFilter *prev)
Iterate over all registered filters.
Definition: avfilter.c:526
static void print_all_libs_info(int flags, int level)
Definition: cmdutils.c:1087
AVInputFormat * av_input_video_device_next(AVInputFormat *d)
Video input devices iterator.
Definition: avdevice.c:109
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:134
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:499
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:437
external API header
ptrdiff_t size
Definition: opengl_enc.c:101
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:169
int(* process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags)
Make the filter instance process a command.
Definition: avfilter.h:615
int show_sources(void *optctx, const char *opt, const char *arg)
Print a listing containing autodetected sources of the input device.
Definition: cmdutils.c:2152
const OptionDef options[]
Definition: ffserver.c:3810
static void print_codecs(int encoder)
Definition: cmdutils.c:1494
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:440
#define av_log(a,...)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:285
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1304
const char * name
Definition: pixdesc.h:70
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:2003
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:3014
AVDictionary * format_opts
Definition: cmdutils.c:71
int show_help(void *optctx, const char *opt, const char *arg)
Generic -h handler common to all fftools.
Definition: cmdutils.c:1843
A filter pad used for either input or output.
Definition: internal.h:63
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:300
Main libavdevice API header.
int flags
Option flags that must be set on each option that is applied to this group.
Definition: cmdutils.h:272
void avdevice_free_list_devices(AVDeviceInfoList **device_list)
Convenient function to free result of avdevice_list_devices().
Definition: avdevice.c:250
libswresample public header
enum AVCodecID id
Definition: avcodec.h:3496
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:102
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, char *line, int line_size, int *print_prefix)
Format a line of log the same way as the default callback.
Definition: log.c:284
#define AV_OPT_FLAG_FILTERING_PARAM
a generic parameter which can be set by the user for filtering
Definition: opt.h:302
#define AVERROR(e)
Definition: error.h:43
const char * long_name
Descriptive name for the format, meant to be more human-readable than name.
Definition: avformat.h:531
int show_sample_fmts(void *optctx, const char *opt, const char *arg)
Print a listing containing all the sample formats supported by the program.
Definition: cmdutils.c:1692
AVCodec * av_codec_next(const AVCodec *c)
If c is NULL, returns the first registered codec, if c is non-NULL, returns the next registered codec...
Definition: utils.c:154
The libswresample context.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
int capabilities
Codec capabilities.
Definition: avcodec.h:3501
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:442
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:199
const char * arg
Definition: jacosubdec.c:66
#define SHOW_COPYRIGHT
Definition: cmdutils.c:1057
static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only)
Definition: cmdutils.c:1249
const char * name
Definition: cmdutils.h:164
static void show_help_muxer(const char *name)
Definition: cmdutils.c:1754
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Parse one given option.
Definition: cmdutils.c:343
Definition: graph2dot.c:48
#define AV_LOG_SKIP_REPEATED
Skip repeated messages, this requires the user app to use av_log() instead of (f)printf as the 2 woul...
Definition: log.h:342
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:123
simple assert() macros that are a bit more flexible than ISO C assert().
#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name)
Definition: cmdutils.c:1314
int av_log_get_level(void)
Get the current log level.
Definition: log.c:377
const char * name
Name of the codec implementation.
Definition: avcodec.h:3489
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
Definition: avstring.c:342
static av_always_inline av_const double round(double x)
Definition: libm.h:162
AVClassCategory category
Category used for visualization (like color) This is only set if the category is equal for all object...
Definition: log.h:130
int avdevice_list_input_sources(AVInputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:228
int flags
Definition: cmdutils.h:165
const char * long_name
A more descriptive name for this codec.
Definition: avcodec.h:578
const char * val
Definition: cmdutils.h:257
enum AVCodecID codec_id
Definition: mov_chan.c:433
AVDeviceInfo ** devices
list of autodetected devices
Definition: avdevice.h:460
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
GLsizei count
Definition: opengl_enc.c:109
int show_filters(void *optctx, const char *opt, const char *arg)
Print a listing containing all the filters supported by the program.
Definition: cmdutils.c:1570
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:83
#define fail()
Definition: checkasm.h:57
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:920
void av_log_default_callback(void *ptr, int level, const char *fmt, va_list vl)
Default logging callback.
Definition: log.c:293
int av_parse_cpu_caps(unsigned *flags, const char *s)
Parse CPU caps from a string and update the given AV_CPU_* flags based on that.
Definition: cpu.c:178
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2935
AVDictionary * sws_dict
Definition: cmdutils.c:69
static const OptionDef * find_option(const OptionDef *po, const char *name)
Definition: cmdutils.c:210
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:873
const char * av_get_known_color_name(int color_idx, const uint8_t **rgbp)
Get the name of a color from the internal table of hard-coded named colors.
Definition: parseutils.c:428
int opt_report(const char *opt)
Definition: cmdutils.c:1010
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: avcodec.h:582
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:487
const int program_birth_year
program birth year, defined by the program for show_banner()
Definition: ffmpeg.c:113
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:1482
#define AV_IS_OUTPUT_DEVICE(category)
Definition: log.h:55
AVBitStreamFilter * av_bitstream_filter_next(const AVBitStreamFilter *f)
If f is NULL, return the first registered bitstream filter, if f is non-NULL, return the next registe...
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1341
OptionGroup * groups
Definition: cmdutils.h:296
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:2148
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:164
static const uint16_t fc[]
Definition: dcaenc.h:41
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:851
size_t off
Definition: cmdutils.h:191
int show_colors(void *optctx, const char *opt, const char *arg)
Print a listing containing all the color names and values recognized by the program.
Definition: cmdutils.c:1616
static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl)
Definition: cmdutils.c:96
external API header
#define FFMIN(a, b)
Definition: common.h:92
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition: log.c:397
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:611
int show_bsfs(void *optctx, const char *opt, const char *arg)
Print a listing containing all the bit stream filters supported by the program.
Definition: cmdutils.c:1544
int avdevice_list_output_sinks(AVOutputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
Definition: avdevice.c:239
static void print_codecs_for_id(enum AVCodecID id, int encoder)
Definition: cmdutils.c:1427
static int init_report(const char *env)
Definition: cmdutils.c:939
const char * avio_enum_protocols(void **opaque, int output)
Iterate through names of available protocols.
Definition: avio.c:87
const char * name
Definition: avformat.h:525
#define GET_PIX_FMT_NAME(pix_fmt)
Definition: cmdutils.h:575
int32_t
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
const OptionGroupDef * group_def
Definition: cmdutils.h:294
A list of option groups that all have the same group type (e.g.
Definition: cmdutils.h:293
#define OPT_EXIT
Definition: cmdutils.h:176
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:2249
void show_help_default(const char *opt, const char *arg)
Per-fftool specific help handler.
Definition: ffmpeg_opt.c:2805
AVDictionary * resample_opts
Definition: cmdutils.c:71
#define OPT_INT64
Definition: cmdutils.h:175
AVDictionary * metadata
Definition: avformat.h:928
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
Definition: format.c:98
static int show_sinks_sources_parse_arg(const char *arg, char **dev, AVDictionary **opts)
Definition: cmdutils.c:2130
#define CONFIG_THIS_YEAR
Definition: config.h:6
Opaque data information usually sparse.
Definition: avutil.h:197
const AVClass * swr_get_class(void)
Get the AVClass for SwrContext.
Definition: options.c:143
int opt_timelimit(void *optctx, const char *opt, const char *arg)
Limit the execution time.
Definition: cmdutils.c:1029
AVOutputFormat * av_output_video_device_next(AVOutputFormat *d)
Video output devices iterator.
Definition: avdevice.c:121
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:553
AVOutputFormat * av_oformat_next(const AVOutputFormat *f)
If f is NULL, returns the first registered output format, if f is non-NULL, returns the next register...
Definition: format.c:53
void * dst_ptr
Definition: cmdutils.h:189
const AVCodecDescriptor * avcodec_descriptor_get_by_name(const char *name)
Definition: codec_desc.c:2954
#define GET_SAMPLE_FMT_NAME(sample_fmt)
Definition: cmdutils.h:578
#define FF_ARRAY_ELEMS(a)
int flags
Definition: opt.h:284
int(* get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list)
Returns device list with it properties.
Definition: avformat.h:614
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:128
const AVFilterPad * inputs
List of inputs, terminated by a zeroed element.
Definition: avfilter.h:490
const char * long_name
Descriptive name for the format, meant to be more human-readable than name.
Definition: avformat.h:647
#define INFINITY
Definition: math.h:27
Stream structure.
Definition: avformat.h:854
static char get_media_type_char(enum AVMediaType type)
Definition: cmdutils.c:1374
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:924
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:93
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
Definition: dict.c:176
#define GET_SAMPLE_RATE_NAME(rate)
Definition: cmdutils.h:581
external API header
const char * long_name
Descriptive name for the codec, meant to be more human readable than name.
Definition: avcodec.h:3494
const AVClass * priv_class
A class for the private data, used to declare filter private AVOptions.
Definition: avfilter.h:508
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
static const AVCodec * next_codec_for_id(enum AVCodecID id, const AVCodec *prev, int encoder)
Definition: cmdutils.c:1386
enum AVMediaType codec_type
Definition: avcodec.h:1520
const AVRational * supported_framerates
array of supported framerates, or NULL if any, array is terminated by {0,0}
Definition: avcodec.h:3502
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
enum AVCodecID codec_id
Definition: avcodec.h:1529
static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
Definition: cmdutils.c:2070
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition: opt.c:1166
const char * help
Definition: cmdutils.h:193
uint8_t flags
Definition: pixdesc.h:90
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:291
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:3028
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
int av_log_get_flags(void)
Definition: log.c:392
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
Definition: swresample.c:140
void * buf
Definition: avisynth_c.h:553
GLint GLenum type
Definition: opengl_enc.c:105
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:69
Replacements for frequently missing libm functions.
#define SHOW_VERSION
Definition: cmdutils.c:1055
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:1888
const OptionGroupDef * group_def
Definition: cmdutils.h:276
#define PRINT_LIB_INFO(libname, LIBNAME, flags, level)
Definition: cmdutils.c:1059
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:221
enum AVCodecID subtitle_codec
default subtitle codec
Definition: avformat.h:537
rational number numerator/denominator
Definition: rational.h:43
static void expand_filename_template(AVBPrint *bp, const char *template, struct tm *tm)
Definition: cmdutils.c:911
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:286
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:157
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:2023
const char * argname
Definition: cmdutils.h:194
#define OPT_STRING
Definition: cmdutils.h:169
AVMediaType
Definition: avutil.h:191
const char * name
Filter name.
Definition: avfilter.h:474
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:574
#define snprintf
Definition: snprintf.h:34
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
Definition: avfilter.c:1004
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:76
static void print_codec(const AVCodec *c)
Definition: cmdutils.c:1327
misc parsing utilities
int default_device
index of default device or -1 if no default
Definition: avdevice.h:462
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition: pixdesc.h:119
struct SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
Definition: utils.c:1036
List of devices.
Definition: avdevice.h:459
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:93
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:245
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:566
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:136
#define OPT_TIME
Definition: cmdutils.h:184
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:260
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:3033
static int flags
Definition: cpu.c:47
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:3508
uint8_t level
Definition: svq3.c:150
static int match_group_separator(const OptionGroupDef *groups, int nb_groups, const char *opt)
Definition: cmdutils.c:632
static int swscale(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
Definition: swscale.c:318
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:68
enum AVMediaType type
Definition: avcodec.h:568
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:521
const char * extensions
If extensions are defined, then no probe is done.
Definition: avformat.h:661
#define OPT_BOOL
Definition: cmdutils.h:167
An option extracted from the commandline.
Definition: cmdutils.h:254
static FILE * report_file
Definition: cmdutils.c:73
Main libavformat public API header.
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:1042
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
#define OPT_INT
Definition: cmdutils.h:172
AVDictionary * codec_opts
Definition: cmdutils.c:71
AVDictionary * format_opts
Definition: cmdutils.h:283
#define class
Definition: math.h:25
OptionGroupList * groups
Definition: cmdutils.h:303
#define CC_IDENT
Definition: config.h:9
#define AVFILTER_FLAG_SUPPORT_TIMELINE
Handy mask to test whether the filter supports or no the timeline feature (internally or generically)...
Definition: avfilter.h:464
static double c[64]
static void(* program_exit)(int ret)
Definition: cmdutils.c:121
OptionGroup global_opts
Definition: cmdutils.h:301
static void print_buildconf(int flags, int level)
Definition: cmdutils.c:1114
AVInputFormat * av_input_audio_device_next(AVInputFormat *d)
Audio input devices iterator.
Definition: avdevice.c:103
#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 poi...
Definition: opt.h:620
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:208
char * key
Definition: dict.h:87
int den
denominator
Definition: rational.h:45
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
Definition: cmdutils.c:82
double av_display_rotation_get(const int32_t matrix[9])
The display transformation matrix specifies an affine transformation that should be applied to video ...
Definition: display.c:34
const char * key
Definition: cmdutils.h:256
#define FFMPEG_CONFIGURATION
Definition: config.h:4
#define AVUNERROR(e)
Definition: error.h:44
enum AVCodecID id
Definition: avcodec.h:567
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:572
const OptionDef * opt
Definition: cmdutils.h:255
#define av_free(p)
const char * description
A description of the filter.
Definition: avfilter.h:481
const char * av_get_channel_name(uint64_t channel)
Get the name of a given channel.
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
char * value
Definition: dict.h:88
static int report_file_level
Definition: cmdutils.c:74
#define FFMPEG_DATADIR
Definition: config.h:7
#define FFMPEG_VERSION
Definition: ffversion.h:3
#define SHOW_CONFIG
Definition: cmdutils.c:1056
int len
int av_opt_get_key_value(const char **ropts, const char *key_val_sep, const char *pairs_sep, unsigned flags, char **rkey, char **rval)
Extract a key-value pair from the beginning of a string.
Definition: opt.c:1358
enum AVCodecID audio_codec
default audio codec
Definition: avformat.h:535
static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
Definition: cmdutils.c:282
int(* get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list)
Returns device list with it properties.
Definition: avformat.h:766
static int write_option(void *optctx, const OptionDef *po, const char *opt, const char *arg)
Definition: cmdutils.c:288
void av_log_set_flags(int arg)
Definition: log.c:387
AVDictionary * swr_opts
Definition: cmdutils.c:70
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:198
uint64_t layout
int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported input format, 0 otherwise.
Definition: utils.c:231
int show_layouts(void *optctx, const char *opt, const char *arg)
Print a listing containing all the standard channel layouts supported by the program.
Definition: cmdutils.c:1663
#define GET_ARG(arg)
OptionGroup cur_group
Definition: cmdutils.h:307
int avfilter_pad_count(const AVFilterPad *pads)
Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
Definition: avfilter.c:542
int opt_cpuflags(void *optctx, const char *opt, const char *arg)
Override the cpuflags.
Definition: cmdutils.c:849
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:228
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
AVDictionary * codec_opts
Definition: cmdutils.h:282
Option * opts
Definition: cmdutils.h:279
int read_yesno(void)
Return a positive value if a line read from standard input starts with [yY], otherwise return 0...
Definition: cmdutils.c:1877
const AVFilterPad * outputs
List of outputs, terminated by a zeroed element.
Definition: avfilter.h:498
union OptionDef::@1 u
#define av_freep(p)
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:640
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
Definition: dict.h:72
static void show_help_demuxer(const char *name)
Definition: cmdutils.c:1736
const char * av_get_channel_description(uint64_t channel)
Get the description of a given channel.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:170
int show_version(void *optctx, const char *opt, const char *arg)
Print the version of the program to stdout.
Definition: cmdutils.c:1151
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition: cpu.c:49
#define OPT_PERFILE
Definition: cmdutils.h:178
AVDictionary * sws_dict
Definition: cmdutils.h:285
#define OPT_INPUT
Definition: cmdutils.h:186
const char * extensions
comma-separated filename extensions
Definition: avformat.h:533
const char * mime_type
Definition: avformat.h:532
int nb_devices
number of autodetected devices
Definition: avdevice.h:461
float min
static void print_program_info(int flags, int level)
Definition: cmdutils.c:1100
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:369
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:252
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:857
const char program_name[]
program name, defined by the program for show_version().
Definition: ffmpeg.c:112
AVInputFormat * av_iformat_next(const AVInputFormat *f)
If f is NULL, returns the first registered input format, if f is non-NULL, returns the next registere...
Definition: format.c:45
static void show_help_codec(const char *name, int encoder)
Definition: cmdutils.c:1701
static int compare_codec_desc(const void *a, const void *b)
Definition: cmdutils.c:1397
int show_encoders(void *optctx, const char *opt, const char *arg)
Print a listing containing all the encoders supported by the program.
Definition: cmdutils.c:1538
simple arithmetic expression evaluator
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:2136
const char * name
Definition: opengl_enc.c:103
static void add_opt(OptionParseContext *octx, const OptionDef *opt, const char *key, const char *val)
Definition: cmdutils.c:683
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:140