FFmpegKit Android API  4.4
fftools_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 /*
23  * CHANGES 01.2021
24  * - NDK r22 incompatibility issues regarding INT64_MAX fixed
25  *
26  * CHANGES 01.2020
27  * - ffprobe support changes
28  * - (optindex < argc) validation in parse_options() method updated with (optindex >= argc) check
29  *
30  * CHANGES 12.2019
31  * - Concurrent execution support
32  * - log_callback_report method re-added to fix -report option issues
33  *
34  * CHANGES 08.2018
35  * --------------------------------------------------------
36  * - fftools_ prefix added to the file name and parent header
37  *
38  * CHANGES 07.2018
39  * --------------------------------------------------------
40  * - Unused headers removed
41  * - Parentheses placed around assignments in conditions to prevent -Wparentheses warning
42  * - exit_program updated with longjmp, disabling exit
43  * - longjmp_value added to store exit code
44  * - (optindex < argc) validation added before accessing argv[optindex] inside split_commandline()
45  * and parse_options()
46  * - All av_log_set_callback invocations updated to set ffmpegkit_log_callback_function from ffmpegkit.c. Unused
47  * log_callback_help and log_callback_help methods removed
48  * - (idx + 1 < argc) validation added in parse_loglevel()
49  */
50 
51 #include <string.h>
52 #include <stdint.h>
53 #include <stdlib.h>
54 #include <errno.h>
55 #include <math.h>
56 
57 #include "ffmpegkit_exception.h"
58 
59 /* Include only the enabled headers since some compilers (namely, Sun
60  Studio) will not omit unused inline functions and create undefined
61  references to libraries that are not being built. */
62 
63 #include "config.h"
64 #include "libavformat/avformat.h"
65 #include "libavfilter/avfilter.h"
66 #include "libavdevice/avdevice.h"
67 #include "libswscale/swscale.h"
68 #include "libswresample/swresample.h"
69 #include "libavutil/attributes.h"
70 #include "libavutil/avassert.h"
71 #include "libavutil/avstring.h"
72 #include "libavutil/bprint.h"
73 #include "libavutil/display.h"
74 #include "libavutil/mathematics.h"
75 #include "libavutil/imgutils.h"
76 #include "libavutil/libm.h"
77 #include "libavutil/parseutils.h"
78 #include "libavutil/pixdesc.h"
79 #include "libavutil/eval.h"
80 #include "libavutil/dict.h"
81 #include "libavutil/opt.h"
82 #include "libavutil/cpu.h"
83 #include "libavutil/ffversion.h"
84 #include "libavutil/version.h"
85 #include "fftools_cmdutils.h"
86 #if HAVE_SYS_RESOURCE_H
87 #include <sys/time.h>
88 #include <sys/resource.h>
89 #endif
90 #ifdef _WIN32
91 #include <windows.h>
92 #endif
93 
94 static int init_report(const char *env);
95 extern void ffmpegkit_log_callback_function(void *ptr, int level, const char* format, va_list vargs);
96 extern void (*report_callback)(int, float, float, int64_t, int, double, double);
97 
98 __thread char *program_name;
99 __thread int program_birth_year;
100 
101 __thread AVDictionary *sws_dict;
102 __thread AVDictionary *swr_opts;
103 __thread AVDictionary *format_opts, *codec_opts, *resample_opts;
104 
106 int report_file_level = AV_LOG_DEBUG;
107 __thread int hide_banner = 0;
108 __thread volatile int longjmp_value = 0;
109 
114 };
115 
116 void init_opts(void)
117 {
118  av_dict_set(&sws_dict, "flags", "bicubic", 0);
119 }
120 
121 void uninit_opts(void)
122 {
123  av_dict_free(&swr_opts);
124  av_dict_free(&sws_dict);
125  av_dict_free(&format_opts);
126  av_dict_free(&codec_opts);
127  av_dict_free(&resample_opts);
128 }
129 
130 void log_callback_report(void *ptr, int level, const char *fmt, va_list vl)
131 {
132  va_list vl2;
133  char line[1024];
134  static int print_prefix = 1;
135 
136  va_copy(vl2, vl);
137  if (report_callback == NULL) {
138  av_log_default_callback(ptr, level, fmt, vl);
139  } else {
140  ffmpegkit_log_callback_function(ptr, level, fmt, vl);
141  }
142  av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
143  va_end(vl2);
144  if (report_file_level >= level) {
145  fputs(line, report_file);
146  fflush(report_file);
147  }
148 }
149 
150 void init_dynload(void)
151 {
152 #if HAVE_SETDLLDIRECTORY && defined(_WIN32)
153  /* Calling SetDllDirectory with the empty string (but not NULL) removes the
154  * current working directory from the DLL search path as a security pre-caution. */
155  SetDllDirectory("");
156 #endif
157 }
158 
159 static void (*program_exit)(int ret);
160 
161 void register_exit(void (*cb)(int ret))
162 {
163  program_exit = cb;
164 }
165 
166 void exit_program(int ret)
167 {
168  if (program_exit)
169  program_exit(ret);
170 
171  // exit disabled and replaced with longjmp, exit value stored in longjmp_value
172  // exit(ret);
173  longjmp_value = ret;
174  longjmp(ex_buf__, ret);
175 }
176 
177 double parse_number_or_die(const char *context, const char *numstr, int type,
178  double min, double max)
179 {
180  char *tail;
181  const char *error;
182  double d = av_strtod(numstr, &tail);
183  if (*tail)
184  error = "Expected number for %s but found: %s\n";
185  else if (d < min || d > max)
186  error = "The value for %s was %s which is not within %f - %f\n";
187  else if (type == OPT_INT64 && (int64_t)d != d)
188  error = "Expected int64 for %s but found %s\n";
189  else if (type == OPT_INT && (int)d != d)
190  error = "Expected int for %s but found %s\n";
191  else
192  return d;
193  av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
194  exit_program(1);
195  return 0;
196 }
197 
198 int64_t parse_time_or_die(const char *context, const char *timestr,
199  int is_duration)
200 {
201  int64_t us;
202  if (av_parse_time(&us, timestr, is_duration) < 0) {
203  av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
204  is_duration ? "duration" : "date", context, timestr);
205  exit_program(1);
206  }
207  return us;
208 }
209 
210 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
211  int rej_flags, int alt_flags)
212 {
213  const OptionDef *po;
214  int first;
215 
216  first = 1;
217  for (po = options; po->name; po++) {
218  char buf[128];
219 
220  if (((po->flags & req_flags) != req_flags) ||
221  (alt_flags && !(po->flags & alt_flags)) ||
222  (po->flags & rej_flags))
223  continue;
224 
225  if (first) {
226  av_log(NULL, AV_LOG_STDERR, "%s\n", msg);
227  first = 0;
228  }
229  av_strlcpy(buf, po->name, sizeof(buf));
230  if (po->argname) {
231  av_strlcat(buf, " ", sizeof(buf));
232  av_strlcat(buf, po->argname, sizeof(buf));
233  }
234  av_log(NULL, AV_LOG_STDERR, "-%-17s %s\n", buf, po->help);
235  }
236  av_log(NULL, AV_LOG_STDERR, "\n");
237 }
238 
239 void show_help_children(const AVClass *class, int flags)
240 {
241  void *iter = NULL;
242  const AVClass *child;
243  if (class->option) {
244  av_opt_show2(&class, NULL, flags, 0);
245  av_log(NULL, AV_LOG_STDERR, "\n");
246  }
247 
248  while ((child = av_opt_child_class_iterate(class, &iter)))
249  show_help_children(child, flags);
250 }
251 
252 static const OptionDef *find_option(const OptionDef *po, const char *name)
253 {
254  const char *p = strchr(name, ':');
255  int len = p ? p - name : strlen(name);
256 
257  while (po->name) {
258  if (!strncmp(name, po->name, len) && strlen(po->name) == len)
259  break;
260  po++;
261  }
262  return po;
263 }
264 
265 /* _WIN32 means using the windows libc - cygwin doesn't define that
266  * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
267  * it doesn't provide the actual command line via GetCommandLineW(). */
268 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
269 #include <shellapi.h>
270 /* Will be leaked on exit */
271 static char** win32_argv_utf8 = NULL;
272 static int win32_argc = 0;
273 
281 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
282 {
283  char *argstr_flat;
284  wchar_t **argv_w;
285  int i, buffsize = 0, offset = 0;
286 
287  if (win32_argv_utf8) {
288  *argc_ptr = win32_argc;
289  *argv_ptr = win32_argv_utf8;
290  return;
291  }
292 
293  win32_argc = 0;
294  argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
295  if (win32_argc <= 0 || !argv_w)
296  return;
297 
298  /* determine the UTF-8 buffer size (including NULL-termination symbols) */
299  for (i = 0; i < win32_argc; i++)
300  buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
301  NULL, 0, NULL, NULL);
302 
303  win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
304  argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
305  if (!win32_argv_utf8) {
306  LocalFree(argv_w);
307  return;
308  }
309 
310  for (i = 0; i < win32_argc; i++) {
311  win32_argv_utf8[i] = &argstr_flat[offset];
312  offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
313  &argstr_flat[offset],
314  buffsize - offset, NULL, NULL);
315  }
316  win32_argv_utf8[i] = NULL;
317  LocalFree(argv_w);
318 
319  *argc_ptr = win32_argc;
320  *argv_ptr = win32_argv_utf8;
321 }
322 #else
323 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
324 {
325  /* nothing to do */
326 }
327 #endif /* HAVE_COMMANDLINETOARGVW */
328 
329 static int write_option(void *optctx, const OptionDef *po, const char *opt,
330  const char *arg)
331 {
332  /* new-style options contain an offset into optctx, old-style address of
333  * a global var*/
334  void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
335  (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
336  int *dstcount;
337 
338  if (po->flags & OPT_SPEC) {
339  SpecifierOpt **so = dst;
340  char *p = strchr(opt, ':');
341  char *str;
342 
343  dstcount = (int *)(so + 1);
344  *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
345  str = av_strdup(p ? p + 1 : "");
346  if (!str)
347  return AVERROR(ENOMEM);
348  (*so)[*dstcount - 1].specifier = str;
349  dst = &(*so)[*dstcount - 1].u;
350  }
351 
352  if (po->flags & OPT_STRING) {
353  char *str;
354  str = av_strdup(arg);
355  av_freep(dst);
356  if (!str)
357  return AVERROR(ENOMEM);
358  *(char **)dst = str;
359  } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
360  *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
361  } else if (po->flags & OPT_INT64) {
362  *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, (double)INT64_MAX);
363  } else if (po->flags & OPT_TIME) {
364  *(int64_t *)dst = parse_time_or_die(opt, arg, 1);
365  } else if (po->flags & OPT_FLOAT) {
366  *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
367  } else if (po->flags & OPT_DOUBLE) {
368  *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
369  } else if (po->u.func_arg) {
370  int ret = po->u.func_arg(optctx, opt, arg);
371  if (ret < 0) {
372  av_log(NULL, AV_LOG_ERROR,
373  "Failed to set value '%s' for option '%s': %s\n",
374  arg, opt, av_err2str(ret));
375  return ret;
376  }
377  }
378  if (po->flags & OPT_EXIT)
379  exit_program(0);
380 
381  return 0;
382 }
383 
384 int parse_option(void *optctx, const char *opt, const char *arg,
385  const OptionDef *options)
386 {
387  const OptionDef *po;
388  int ret;
389 
390  po = find_option(options, opt);
391  if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
392  /* handle 'no' bool option */
393  po = find_option(options, opt + 2);
394  if ((po->name && (po->flags & OPT_BOOL)))
395  arg = "0";
396  } else if (po->flags & OPT_BOOL)
397  arg = "1";
398 
399  if (!po->name)
400  po = find_option(options, "default");
401  if (!po->name) {
402  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
403  return AVERROR(EINVAL);
404  }
405  if (po->flags & HAS_ARG && !arg) {
406  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
407  return AVERROR(EINVAL);
408  }
409 
410  ret = write_option(optctx, po, opt, arg);
411  if (ret < 0)
412  return ret;
413 
414  return !!(po->flags & HAS_ARG);
415 }
416 
417 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
418  void (*parse_arg_function)(void *, const char*))
419 {
420  const char *opt;
421  int optindex, handleoptions = 1, ret;
422 
423  /* perform system-dependent conversions for arguments list */
424  prepare_app_arguments(&argc, &argv);
425 
426  /* parse options */
427  optindex = 1;
428  while (optindex < argc) {
429  opt = argv[optindex++];
430 
431  if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
432  if (opt[1] == '-' && opt[2] == '\0') {
433  handleoptions = 0;
434  continue;
435  }
436  opt++;
437  if (optindex >= argc) {
438  if ((ret = parse_option(optctx, opt, NULL, options)) < 0)
439  exit_program(1);
440  } else {
441  if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
442  exit_program(1);
443  }
444  optindex += ret;
445  } else {
446  if (parse_arg_function)
447  parse_arg_function(optctx, opt);
448  }
449  }
450 }
451 
452 int parse_optgroup(void *optctx, OptionGroup *g)
453 {
454  int i, ret;
455 
456  av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
457  g->group_def->name, g->arg);
458 
459  for (i = 0; i < g->nb_opts; i++) {
460  Option *o = &g->opts[i];
461 
462  if (g->group_def->flags &&
463  !(g->group_def->flags & o->opt->flags)) {
464  av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
465  "%s %s -- you are trying to apply an input option to an "
466  "output file or vice versa. Move this option before the "
467  "file it belongs to.\n", o->key, o->opt->help,
468  g->group_def->name, g->arg);
469  return AVERROR(EINVAL);
470  }
471 
472  av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
473  o->key, o->opt->help, o->val);
474 
475  ret = write_option(optctx, o->opt, o->key, o->val);
476  if (ret < 0)
477  return ret;
478  }
479 
480  av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
481 
482  return 0;
483 }
484 
485 int locate_option(int argc, char **argv, const OptionDef *options,
486  const char *optname)
487 {
488  const OptionDef *po;
489  int i;
490 
491  for (i = 1; i < argc; i++) {
492  const char *cur_opt = argv[i];
493 
494  if (*cur_opt++ != '-')
495  continue;
496 
497  po = find_option(options, cur_opt);
498  if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
499  po = find_option(options, cur_opt + 2);
500 
501  if ((!po->name && !strcmp(cur_opt, optname)) ||
502  (po->name && !strcmp(optname, po->name)))
503  return i;
504 
505  if (!po->name || po->flags & HAS_ARG)
506  i++;
507  }
508  return 0;
509 }
510 
511 static void dump_argument(const char *a)
512 {
513  const unsigned char *p;
514 
515  for (p = a; *p; p++)
516  if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
517  *p == '_' || (*p >= 'a' && *p <= 'z')))
518  break;
519  if (!*p) {
520  fputs(a, report_file);
521  return;
522  }
523  fputc('"', report_file);
524  for (p = a; *p; p++) {
525  if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
526  fprintf(report_file, "\\%c", *p);
527  else if (*p < ' ' || *p > '~')
528  fprintf(report_file, "\\x%02x", *p);
529  else
530  fputc(*p, report_file);
531  }
532  fputc('"', report_file);
533 }
534 
535 static void check_options(const OptionDef *po)
536 {
537  while (po->name) {
538  if (po->flags & OPT_PERFILE)
539  av_assert0(po->flags & (OPT_INPUT | OPT_OUTPUT));
540  po++;
541  }
542 }
543 
544 void parse_loglevel(int argc, char **argv, const OptionDef *options)
545 {
546  int idx = locate_option(argc, argv, options, "loglevel");
547  const char *env;
548 
549  check_options(options);
550 
551  if (!idx)
552  idx = locate_option(argc, argv, options, "v");
553  if (idx && (idx + 1 < argc) && argv[idx + 1])
554  opt_loglevel(NULL, "loglevel", argv[idx + 1]);
555  idx = locate_option(argc, argv, options, "report");
556  if ((env = getenv("FFREPORT")) || idx) {
557  init_report(env);
558  if (report_file) {
559  int i;
560  fprintf(report_file, "Command line:\n");
561  for (i = 0; i < argc; i++) {
562  dump_argument(argv[i]);
563  fputc(i < argc - 1 ? ' ' : '\n', report_file);
564  }
565  fflush(report_file);
566  }
567  }
568  idx = locate_option(argc, argv, options, "hide_banner");
569  if (idx)
570  hide_banner = 1;
571 }
572 
573 static const AVOption *opt_find(void *obj, const char *name, const char *unit,
574  int opt_flags, int search_flags)
575 {
576  const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
577  if(o && !o->flags)
578  return NULL;
579  return o;
580 }
581 
582 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
583 int opt_default(void *optctx, const char *opt, const char *arg)
584 {
585  const AVOption *o;
586  int consumed = 0;
587  char opt_stripped[128];
588  const char *p;
589  const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
590 #if CONFIG_AVRESAMPLE
591  const AVClass *rc = avresample_get_class();
592 #endif
593 #if CONFIG_SWSCALE
594  const AVClass *sc = sws_get_class();
595 #endif
596 #if CONFIG_SWRESAMPLE
597  const AVClass *swr_class = swr_get_class();
598 #endif
599 
600  if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
601  av_log_set_level(AV_LOG_DEBUG);
602 
603  if (!(p = strchr(opt, ':')))
604  p = opt + strlen(opt);
605  av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
606 
607  if ((o = opt_find(&cc, opt_stripped, NULL, 0,
608  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
609  ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
610  (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
611  av_dict_set(&codec_opts, opt, arg, FLAGS);
612  consumed = 1;
613  }
614  if ((o = opt_find(&fc, opt, NULL, 0,
615  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
616  av_dict_set(&format_opts, opt, arg, FLAGS);
617  if (consumed)
618  av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
619  consumed = 1;
620  }
621 #if CONFIG_SWSCALE
622  if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
623  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
624  struct SwsContext *sws = sws_alloc_context();
625  int ret = av_opt_set(sws, opt, arg, 0);
626  sws_freeContext(sws);
627  if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
628  !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
629  !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
630  av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
631  return AVERROR(EINVAL);
632  }
633  if (ret < 0) {
634  av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
635  return ret;
636  }
637 
638  av_dict_set(&sws_dict, opt, arg, FLAGS);
639 
640  consumed = 1;
641  }
642 #else
643  if (!consumed && !strcmp(opt, "sws_flags")) {
644  av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
645  consumed = 1;
646  }
647 #endif
648 #if CONFIG_SWRESAMPLE
649  if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
650  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
651  struct SwrContext *swr = swr_alloc();
652  int ret = av_opt_set(swr, opt, arg, 0);
653  swr_free(&swr);
654  if (ret < 0) {
655  av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
656  return ret;
657  }
658  av_dict_set(&swr_opts, opt, arg, FLAGS);
659  consumed = 1;
660  }
661 #endif
662 #if CONFIG_AVRESAMPLE
663  if ((o=opt_find(&rc, opt, NULL, 0,
664  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
665  av_dict_set(&resample_opts, opt, arg, FLAGS);
666  consumed = 1;
667  }
668 #endif
669 
670  if (consumed)
671  return 0;
672  return AVERROR_OPTION_NOT_FOUND;
673 }
674 
675 /*
676  * Check whether given option is a group separator.
677  *
678  * @return index of the group definition that matched or -1 if none
679  */
680 static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
681  const char *opt)
682 {
683  int i;
684 
685  for (i = 0; i < nb_groups; i++) {
686  const OptionGroupDef *p = &groups[i];
687  if (p->sep && !strcmp(p->sep, opt))
688  return i;
689  }
690 
691  return -1;
692 }
693 
694 /*
695  * Finish parsing an option group.
696  *
697  * @param group_idx which group definition should this group belong to
698  * @param arg argument of the group delimiting option
699  */
700 static void finish_group(OptionParseContext *octx, int group_idx,
701  const char *arg)
702 {
703  OptionGroupList *l = &octx->groups[group_idx];
704  OptionGroup *g;
705 
706  GROW_ARRAY(l->groups, l->nb_groups);
707  g = &l->groups[l->nb_groups - 1];
708 
709  *g = octx->cur_group;
710  g->arg = arg;
711  g->group_def = l->group_def;
712  g->sws_dict = sws_dict;
713  g->swr_opts = swr_opts;
714  g->codec_opts = codec_opts;
717 
718  codec_opts = NULL;
719  format_opts = NULL;
720  resample_opts = NULL;
721  sws_dict = NULL;
722  swr_opts = NULL;
723  init_opts();
724 
725  memset(&octx->cur_group, 0, sizeof(octx->cur_group));
726 }
727 
728 /*
729  * Add an option instance to currently parsed group.
730  */
731 static void add_opt(OptionParseContext *octx, const OptionDef *opt,
732  const char *key, const char *val)
733 {
734  int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
735  OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
736 
737  GROW_ARRAY(g->opts, g->nb_opts);
738  g->opts[g->nb_opts - 1].opt = opt;
739  g->opts[g->nb_opts - 1].key = key;
740  g->opts[g->nb_opts - 1].val = val;
741 }
742 
744  const OptionGroupDef *groups, int nb_groups)
745 {
746  static const OptionGroupDef global_group = { "global" };
747  int i;
748 
749  memset(octx, 0, sizeof(*octx));
750 
751  octx->nb_groups = nb_groups;
752  octx->groups = av_mallocz_array(octx->nb_groups, sizeof(*octx->groups));
753  if (!octx->groups)
754  exit_program(1);
755 
756  for (i = 0; i < octx->nb_groups; i++)
757  octx->groups[i].group_def = &groups[i];
758 
759  octx->global_opts.group_def = &global_group;
760  octx->global_opts.arg = "";
761 
762  init_opts();
763 }
764 
766 {
767  int i, j;
768 
769  for (i = 0; i < octx->nb_groups; i++) {
770  OptionGroupList *l = &octx->groups[i];
771 
772  for (j = 0; j < l->nb_groups; j++) {
773  av_freep(&l->groups[j].opts);
774  av_dict_free(&l->groups[j].codec_opts);
775  av_dict_free(&l->groups[j].format_opts);
776  av_dict_free(&l->groups[j].resample_opts);
777 
778  av_dict_free(&l->groups[j].sws_dict);
779  av_dict_free(&l->groups[j].swr_opts);
780  }
781  av_freep(&l->groups);
782  }
783  av_freep(&octx->groups);
784 
785  av_freep(&octx->cur_group.opts);
786  av_freep(&octx->global_opts.opts);
787 
788  uninit_opts();
789 }
790 
791 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
792  const OptionDef *options,
793  const OptionGroupDef *groups, int nb_groups)
794 {
795  int optindex = 1;
796  int dashdash = -2;
797 
798  /* perform system-dependent conversions for arguments list */
799  prepare_app_arguments(&argc, &argv);
800 
801  init_parse_context(octx, groups, nb_groups);
802  av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
803 
804  while (optindex < argc) {
805  const char *opt = argv[optindex++], *arg;
806  const OptionDef *po;
807  int ret;
808 
809  av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
810 
811  if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
812  dashdash = optindex;
813  continue;
814  }
815  /* unnamed group separators, e.g. output filename */
816  if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
817  finish_group(octx, 0, opt);
818  av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
819  continue;
820  }
821  opt++;
822 
823 #define GET_ARG(arg) \
824 do { \
825  if (optindex < argc) { \
826  arg = argv[optindex++]; \
827  } else { \
828  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
829  return AVERROR(EINVAL); \
830  } \
831 } while (0)
832 
833  /* named group separators, e.g. -i */
834  if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
835  GET_ARG(arg);
836  finish_group(octx, ret, arg);
837  av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
838  groups[ret].name, arg);
839  continue;
840  }
841 
842  /* normal options */
843  po = find_option(options, opt);
844  if (po->name) {
845  if (po->flags & OPT_EXIT) {
846  /* optional argument, e.g. -h */
847  if (optindex < argc) {
848  arg = argv[optindex++];
849  } else {
850  arg = NULL;
851  }
852  } else if (po->flags & HAS_ARG) {
853  GET_ARG(arg);
854  } else {
855  arg = "1";
856  }
857 
858  add_opt(octx, po, opt, arg);
859  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
860  "argument '%s'.\n", po->name, po->help, arg);
861  continue;
862  }
863 
864  /* AVOptions */
865  if ((optindex < argc) && argv[optindex]) {
866  ret = opt_default(NULL, opt, argv[optindex]);
867  if (ret >= 0) {
868  av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
869  "argument '%s'.\n", opt, argv[optindex]);
870  optindex++;
871  continue;
872  } else if (ret != AVERROR_OPTION_NOT_FOUND) {
873  av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
874  "with argument '%s'.\n", opt, argv[optindex]);
875  return ret;
876  }
877  }
878 
879  /* boolean -nofoo options */
880  if (opt[0] == 'n' && opt[1] == 'o' &&
881  (po = find_option(options, opt + 2)) &&
882  po->name && po->flags & OPT_BOOL) {
883  add_opt(octx, po, opt, "0");
884  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
885  "argument 0.\n", po->name, po->help);
886  continue;
887  }
888 
889  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
890  return AVERROR_OPTION_NOT_FOUND;
891  }
892 
894  av_log(NULL, AV_LOG_WARNING, "Trailing option(s) found in the "
895  "command: may be ignored.\n");
896 
897  av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
898 
899  return 0;
900 }
901 
902 int opt_cpuflags(void *optctx, const char *opt, const char *arg)
903 {
904  int ret;
905  unsigned flags = av_get_cpu_flags();
906 
907  if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
908  return ret;
909 
910  av_force_cpu_flags(flags);
911  return 0;
912 }
913 
914 int opt_loglevel(void *optctx, const char *opt, const char *arg)
915 {
916  const struct { const char *name; int level; } log_levels[] = {
917  { "quiet" , AV_LOG_QUIET },
918  { "panic" , AV_LOG_PANIC },
919  { "fatal" , AV_LOG_FATAL },
920  { "error" , AV_LOG_ERROR },
921  { "warning", AV_LOG_WARNING },
922  { "info" , AV_LOG_INFO },
923  { "verbose", AV_LOG_VERBOSE },
924  { "debug" , AV_LOG_DEBUG },
925  { "trace" , AV_LOG_TRACE },
926  };
927  const char *token;
928  char *tail;
929  int flags = av_log_get_flags();
930  int level = av_log_get_level();
931  int cmd, i = 0;
932 
933  av_assert0(arg);
934  while (*arg) {
935  token = arg;
936  if (*token == '+' || *token == '-') {
937  cmd = *token++;
938  } else {
939  cmd = 0;
940  }
941  if (!i && !cmd) {
942  flags = 0; /* missing relative prefix, build absolute value */
943  }
944  if (!strncmp(token, "repeat", 6)) {
945  if (cmd == '-') {
946  flags |= AV_LOG_SKIP_REPEATED;
947  } else {
948  flags &= ~AV_LOG_SKIP_REPEATED;
949  }
950  arg = token + 6;
951  } else if (!strncmp(token, "level", 5)) {
952  if (cmd == '-') {
953  flags &= ~AV_LOG_PRINT_LEVEL;
954  } else {
955  flags |= AV_LOG_PRINT_LEVEL;
956  }
957  arg = token + 5;
958  } else {
959  break;
960  }
961  i++;
962  }
963  if (!*arg) {
964  goto end;
965  } else if (*arg == '+') {
966  arg++;
967  } else if (!i) {
968  flags = av_log_get_flags(); /* level value without prefix, reset flags */
969  }
970 
971  for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
972  if (!strcmp(log_levels[i].name, arg)) {
973  level = log_levels[i].level;
974  goto end;
975  }
976  }
977 
978  level = strtol(arg, &tail, 10);
979  if (*tail) {
980  av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
981  "Possible levels are numbers or:\n", arg);
982  for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
983  av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
984  exit_program(1);
985  }
986 
987 end:
988  av_log_set_flags(flags);
989  av_log_set_level(level);
990  return 0;
991 }
992 
993 static void expand_filename_template(AVBPrint *bp, const char *template,
994  struct tm *tm)
995 {
996  int c;
997 
998  while ((c = *(template++))) {
999  if (c == '%') {
1000  if (!(c = *(template++)))
1001  break;
1002  switch (c) {
1003  case 'p':
1004  av_bprintf(bp, "%s", program_name);
1005  break;
1006  case 't':
1007  av_bprintf(bp, "%04d%02d%02d-%02d%02d%02d",
1008  tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1009  tm->tm_hour, tm->tm_min, tm->tm_sec);
1010  break;
1011  case '%':
1012  av_bprint_chars(bp, c, 1);
1013  break;
1014  }
1015  } else {
1016  av_bprint_chars(bp, c, 1);
1017  }
1018  }
1019 }
1020 
1021 static int init_report(const char *env)
1022 {
1023  char *filename_template = NULL;
1024  char *key, *val;
1025  int ret, count = 0;
1026  int prog_loglevel, envlevel = 0;
1027  time_t now;
1028  struct tm *tm;
1029  AVBPrint filename;
1030 
1031  if (report_file) /* already opened */
1032  return 0;
1033  time(&now);
1034  tm = localtime(&now);
1035 
1036  while (env && *env) {
1037  if ((ret = av_opt_get_key_value(&env, "=", ":", 0, &key, &val)) < 0) {
1038  if (count)
1039  av_log(NULL, AV_LOG_ERROR,
1040  "Failed to parse FFREPORT environment variable: %s\n",
1041  av_err2str(ret));
1042  break;
1043  }
1044  if (*env)
1045  env++;
1046  count++;
1047  if (!strcmp(key, "file")) {
1048  av_free(filename_template);
1049  filename_template = val;
1050  val = NULL;
1051  } else if (!strcmp(key, "level")) {
1052  char *tail;
1053  report_file_level = strtol(val, &tail, 10);
1054  if (*tail) {
1055  av_log(NULL, AV_LOG_FATAL, "Invalid report file level\n");
1056  exit_program(1);
1057  }
1058  envlevel = 1;
1059  } else {
1060  av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in FFREPORT\n", key);
1061  }
1062  av_free(val);
1063  av_free(key);
1064  }
1065 
1066  av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
1067  expand_filename_template(&filename,
1068  av_x_if_null(filename_template, "%p-%t.log"), tm);
1069  av_free(filename_template);
1070  if (!av_bprint_is_complete(&filename)) {
1071  av_log(NULL, AV_LOG_ERROR, "Out of memory building report file name\n");
1072  return AVERROR(ENOMEM);
1073  }
1074 
1075  prog_loglevel = av_log_get_level();
1076  if (!envlevel)
1077  report_file_level = FFMAX(report_file_level, prog_loglevel);
1078 
1079  report_file = fopen(filename.str, "w");
1080  if (!report_file) {
1081  int ret = AVERROR(errno);
1082  av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n",
1083  filename.str, strerror(errno));
1084  return ret;
1085  }
1086  av_log_set_callback(log_callback_report);
1087  av_log(NULL, AV_LOG_INFO,
1088  "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
1089  "Report written to \"%s\"\n"
1090  "Log level: %d\n",
1091  program_name,
1092  tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1093  tm->tm_hour, tm->tm_min, tm->tm_sec,
1094  filename.str, report_file_level);
1095  av_bprint_finalize(&filename, NULL);
1096  return 0;
1097 }
1098 
1099 int opt_report(void *optctx, const char *opt, const char *arg)
1100 {
1101  return init_report(NULL);
1102 }
1103 
1104 int opt_max_alloc(void *optctx, const char *opt, const char *arg)
1105 {
1106  char *tail;
1107  size_t max;
1108 
1109  max = strtol(arg, &tail, 10);
1110  if (*tail) {
1111  av_log(NULL, AV_LOG_FATAL, "Invalid max_alloc \"%s\".\n", arg);
1112  exit_program(1);
1113  }
1114  av_max_alloc(max);
1115  return 0;
1116 }
1117 
1118 int opt_timelimit(void *optctx, const char *opt, const char *arg)
1119 {
1120 #if HAVE_SETRLIMIT
1121  int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
1122  struct rlimit rl = { lim, lim + 1 };
1123  if (setrlimit(RLIMIT_CPU, &rl))
1124  perror("setrlimit");
1125 #else
1126  av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
1127 #endif
1128  return 0;
1129 }
1130 
1131 void print_error(const char *filename, int err)
1132 {
1133  char errbuf[128];
1134  const char *errbuf_ptr = errbuf;
1135 
1136  if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
1137  errbuf_ptr = strerror(AVUNERROR(err));
1138  av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
1139 }
1140 
1141 __thread int warned_cfg = 0;
1142 
1143 #define INDENT 1
1144 #define SHOW_VERSION 2
1145 #define SHOW_CONFIG 4
1146 #define SHOW_COPYRIGHT 8
1147 
1148 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1149  if (CONFIG_##LIBNAME) { \
1150  const char *indent = flags & INDENT? " " : ""; \
1151  if (flags & SHOW_VERSION) { \
1152  unsigned int version = libname##_version(); \
1153  av_log(NULL, level, \
1154  "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1155  indent, #libname, \
1156  LIB##LIBNAME##_VERSION_MAJOR, \
1157  LIB##LIBNAME##_VERSION_MINOR, \
1158  LIB##LIBNAME##_VERSION_MICRO, \
1159  AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\
1160  AV_VERSION_MICRO(version)); \
1161  } \
1162  if (flags & SHOW_CONFIG) { \
1163  const char *cfg = libname##_configuration(); \
1164  if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1165  if (!warned_cfg) { \
1166  av_log(NULL, level, \
1167  "%sWARNING: library configuration mismatch\n", \
1168  indent); \
1169  warned_cfg = 1; \
1170  } \
1171  av_log(NULL, level, "%s%-11s configuration: %s\n", \
1172  indent, #libname, cfg); \
1173  } \
1174  } \
1175  } \
1176 
1177 static void print_all_libs_info(int flags, int level)
1178 {
1179  PRINT_LIB_INFO(avutil, AVUTIL, flags, level);
1180  PRINT_LIB_INFO(avcodec, AVCODEC, flags, level);
1181  PRINT_LIB_INFO(avformat, AVFORMAT, flags, level);
1182  PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
1183  PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
1184  PRINT_LIB_INFO(swscale, SWSCALE, flags, level);
1185  PRINT_LIB_INFO(swresample, SWRESAMPLE, flags, level);
1186 }
1187 
1188 static void print_program_info(int flags, int level)
1189 {
1190  const char *indent = flags & INDENT? " " : "";
1191 
1192  av_log(NULL, level, "%s version " FFMPEG_VERSION, program_name);
1193  if (flags & SHOW_COPYRIGHT)
1194  av_log(NULL, level, " Copyright (c) %d-%d the FFmpeg developers",
1195  program_birth_year, CONFIG_THIS_YEAR);
1196  av_log(NULL, level, "\n");
1197  av_log(NULL, level, "%sbuilt with %s\n", indent, CC_IDENT);
1198 
1199  av_log(NULL, level, "%sconfiguration: " FFMPEG_CONFIGURATION "\n", indent);
1200 }
1201 
1202 static void print_buildconf(int flags, int level)
1203 {
1204  const char *indent = flags & INDENT ? " " : "";
1205  char str[] = { FFMPEG_CONFIGURATION };
1206  char *conflist, *remove_tilde, *splitconf;
1207 
1208  // Change all the ' --' strings to '~--' so that
1209  // they can be identified as tokens.
1210  while ((conflist = strstr(str, " --")) != NULL) {
1211  strncpy(conflist, "~--", 3);
1212  }
1213 
1214  // Compensate for the weirdness this would cause
1215  // when passing 'pkg-config --static'.
1216  while ((remove_tilde = strstr(str, "pkg-config~")) != NULL) {
1217  strncpy(remove_tilde, "pkg-config ", 11);
1218  }
1219 
1220  splitconf = strtok(str, "~");
1221  av_log(NULL, level, "\n%sconfiguration:\n", indent);
1222  while (splitconf != NULL) {
1223  av_log(NULL, level, "%s%s%s\n", indent, indent, splitconf);
1224  splitconf = strtok(NULL, "~");
1225  }
1226 }
1227 
1228 void show_banner(int argc, char **argv, const OptionDef *options)
1229 {
1230  int idx = locate_option(argc, argv, options, "version");
1231  if (hide_banner || idx)
1232  return;
1233 
1234  print_program_info (INDENT|SHOW_COPYRIGHT, AV_LOG_INFO);
1235  print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_INFO);
1236  print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_INFO);
1237 }
1238 
1239 int show_version(void *optctx, const char *opt, const char *arg)
1240 {
1241  print_program_info (SHOW_COPYRIGHT, AV_LOG_INFO);
1242  print_all_libs_info(SHOW_VERSION, AV_LOG_INFO);
1243 
1244  return 0;
1245 }
1246 
1247 int show_buildconf(void *optctx, const char *opt, const char *arg)
1248 {
1249  print_buildconf (INDENT|0, AV_LOG_INFO);
1250 
1251  return 0;
1252 }
1253 
1254 int show_license(void *optctx, const char *opt, const char *arg)
1255 {
1256 #if CONFIG_NONFREE
1257  av_log(NULL, AV_LOG_STDERR,
1258  "This version of %s has nonfree parts compiled in.\n"
1259  "Therefore it is not legally redistributable.\n",
1260  program_name );
1261 #elif CONFIG_GPLV3
1262  av_log(NULL, AV_LOG_STDERR,
1263  "%s is free software; you can redistribute it and/or modify\n"
1264  "it under the terms of the GNU General Public License as published by\n"
1265  "the Free Software Foundation; either version 3 of the License, or\n"
1266  "(at your option) any later version.\n"
1267  "\n"
1268  "%s is distributed in the hope that it will be useful,\n"
1269  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1270  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1271  "GNU General Public License for more details.\n"
1272  "\n"
1273  "You should have received a copy of the GNU General Public License\n"
1274  "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1276 #elif CONFIG_GPL
1277  av_log(NULL, AV_LOG_STDERR,
1278  "%s is free software; you can redistribute it and/or modify\n"
1279  "it under the terms of the GNU General Public License as published by\n"
1280  "the Free Software Foundation; either version 2 of the License, or\n"
1281  "(at your option) any later version.\n"
1282  "\n"
1283  "%s is distributed in the hope that it will be useful,\n"
1284  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1285  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1286  "GNU General Public License for more details.\n"
1287  "\n"
1288  "You should have received a copy of the GNU General Public License\n"
1289  "along with %s; if not, write to the Free Software\n"
1290  "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1292 #elif CONFIG_LGPLV3
1293  av_log(NULL, AV_LOG_STDERR,
1294  "%s is free software; you can redistribute it and/or modify\n"
1295  "it under the terms of the GNU Lesser General Public License as published by\n"
1296  "the Free Software Foundation; either version 3 of the License, or\n"
1297  "(at your option) any later version.\n"
1298  "\n"
1299  "%s is distributed in the hope that it will be useful,\n"
1300  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1301  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1302  "GNU Lesser General Public License for more details.\n"
1303  "\n"
1304  "You should have received a copy of the GNU Lesser General Public License\n"
1305  "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1307 #else
1308  av_log(NULL, AV_LOG_STDERR,
1309  "%s is free software; you can redistribute it and/or\n"
1310  "modify it under the terms of the GNU Lesser General Public\n"
1311  "License as published by the Free Software Foundation; either\n"
1312  "version 2.1 of the License, or (at your option) any later version.\n"
1313  "\n"
1314  "%s is distributed in the hope that it will be useful,\n"
1315  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1316  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1317  "Lesser General Public License for more details.\n"
1318  "\n"
1319  "You should have received a copy of the GNU Lesser General Public\n"
1320  "License along with %s; if not, write to the Free Software\n"
1321  "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1323 #endif
1324 
1325  return 0;
1326 }
1327 
1328 static int is_device(const AVClass *avclass)
1329 {
1330  if (!avclass)
1331  return 0;
1332  return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
1333 }
1334 
1335 static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only, int muxdemuxers)
1336 {
1337  void *ifmt_opaque = NULL;
1338  const AVInputFormat *ifmt = NULL;
1339  void *ofmt_opaque = NULL;
1340  const AVOutputFormat *ofmt = NULL;
1341  const char *last_name;
1342  int is_dev;
1343 
1344  av_log(NULL, AV_LOG_STDERR, "%s\n"
1345  " D. = Demuxing supported\n"
1346  " .E = Muxing supported\n"
1347  " --\n", device_only ? "Devices:" : "File formats:");
1348  last_name = "000";
1349  for (;;) {
1350  int decode = 0;
1351  int encode = 0;
1352  const char *name = NULL;
1353  const char *long_name = NULL;
1354 
1355  if (muxdemuxers !=SHOW_DEMUXERS) {
1356  ofmt_opaque = NULL;
1357  while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
1358  is_dev = is_device(ofmt->priv_class);
1359  if (!is_dev && device_only)
1360  continue;
1361  if ((!name || strcmp(ofmt->name, name) < 0) &&
1362  strcmp(ofmt->name, last_name) > 0) {
1363  name = ofmt->name;
1364  long_name = ofmt->long_name;
1365  encode = 1;
1366  }
1367  }
1368  }
1369  if (muxdemuxers != SHOW_MUXERS) {
1370  ifmt_opaque = NULL;
1371  while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
1372  is_dev = is_device(ifmt->priv_class);
1373  if (!is_dev && device_only)
1374  continue;
1375  if ((!name || strcmp(ifmt->name, name) < 0) &&
1376  strcmp(ifmt->name, last_name) > 0) {
1377  name = ifmt->name;
1378  long_name = ifmt->long_name;
1379  encode = 0;
1380  }
1381  if (name && strcmp(ifmt->name, name) == 0)
1382  decode = 1;
1383  }
1384  }
1385  if (!name)
1386  break;
1387  last_name = name;
1388 
1389  av_log(NULL, AV_LOG_STDERR, " %s%s %-15s %s\n",
1390  decode ? "D" : " ",
1391  encode ? "E" : " ",
1392  name,
1393  long_name ? long_name:" ");
1394  }
1395  return 0;
1396 }
1397 
1398 int show_formats(void *optctx, const char *opt, const char *arg)
1399 {
1400  return show_formats_devices(optctx, opt, arg, 0, SHOW_DEFAULT);
1401 }
1402 
1403 int show_muxers(void *optctx, const char *opt, const char *arg)
1404 {
1405  return show_formats_devices(optctx, opt, arg, 0, SHOW_MUXERS);
1406 }
1407 
1408 int show_demuxers(void *optctx, const char *opt, const char *arg)
1409 {
1410  return show_formats_devices(optctx, opt, arg, 0, SHOW_DEMUXERS);
1411 }
1412 
1413 int show_devices(void *optctx, const char *opt, const char *arg)
1414 {
1415  return show_formats_devices(optctx, opt, arg, 1, SHOW_DEFAULT);
1416 }
1417 
1418 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1419  if (codec->field) { \
1420  const type *p = codec->field; \
1421  \
1422  av_log(NULL, AV_LOG_STDERR, " Supported " list_name ":"); \
1423  while (*p != term) { \
1424  get_name(*p); \
1425  av_log(NULL, AV_LOG_STDERR, " %s", name); \
1426  p++; \
1427  } \
1428  av_log(NULL, AV_LOG_STDERR, "\n"); \
1429  } \
1430 
1431 static void print_codec(const AVCodec *c)
1432 {
1433  int encoder = av_codec_is_encoder(c);
1434 
1435  av_log(NULL, AV_LOG_STDERR, "%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
1436  c->long_name ? c->long_name : "");
1437 
1438  av_log(NULL, AV_LOG_STDERR, " General capabilities: ");
1439  if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
1440  av_log(NULL, AV_LOG_STDERR, "horizband ");
1441  if (c->capabilities & AV_CODEC_CAP_DR1)
1442  av_log(NULL, AV_LOG_STDERR, "dr1 ");
1443  if (c->capabilities & AV_CODEC_CAP_TRUNCATED)
1444  av_log(NULL, AV_LOG_STDERR, "trunc ");
1445  if (c->capabilities & AV_CODEC_CAP_DELAY)
1446  av_log(NULL, AV_LOG_STDERR, "delay ");
1447  if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
1448  av_log(NULL, AV_LOG_STDERR, "small ");
1449  if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
1450  av_log(NULL, AV_LOG_STDERR, "subframes ");
1451  if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
1452  av_log(NULL, AV_LOG_STDERR, "exp ");
1453  if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
1454  av_log(NULL, AV_LOG_STDERR, "chconf ");
1455  if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
1456  av_log(NULL, AV_LOG_STDERR, "paramchange ");
1457  if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
1458  av_log(NULL, AV_LOG_STDERR, "variable ");
1459  if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1460  AV_CODEC_CAP_SLICE_THREADS |
1461  AV_CODEC_CAP_AUTO_THREADS))
1462  av_log(NULL, AV_LOG_STDERR, "threads ");
1463  if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
1464  av_log(NULL, AV_LOG_STDERR, "avoidprobe ");
1465  if (c->capabilities & AV_CODEC_CAP_HARDWARE)
1466  av_log(NULL, AV_LOG_STDERR, "hardware ");
1467  if (c->capabilities & AV_CODEC_CAP_HYBRID)
1468  av_log(NULL, AV_LOG_STDERR, "hybrid ");
1469  if (!c->capabilities)
1470  av_log(NULL, AV_LOG_STDERR, "none");
1471  av_log(NULL, AV_LOG_STDERR, "\n");
1472 
1473  if (c->type == AVMEDIA_TYPE_VIDEO ||
1474  c->type == AVMEDIA_TYPE_AUDIO) {
1475  av_log(NULL, AV_LOG_STDERR, " Threading capabilities: ");
1476  switch (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1477  AV_CODEC_CAP_SLICE_THREADS |
1478  AV_CODEC_CAP_AUTO_THREADS)) {
1479  case AV_CODEC_CAP_FRAME_THREADS |
1480  AV_CODEC_CAP_SLICE_THREADS: av_log(NULL, AV_LOG_STDERR, "frame and slice"); break;
1481  case AV_CODEC_CAP_FRAME_THREADS: av_log(NULL, AV_LOG_STDERR, "frame"); break;
1482  case AV_CODEC_CAP_SLICE_THREADS: av_log(NULL, AV_LOG_STDERR, "slice"); break;
1483  case AV_CODEC_CAP_AUTO_THREADS : av_log(NULL, AV_LOG_STDERR, "auto"); break;
1484  default: av_log(NULL, AV_LOG_STDERR, "none"); break;
1485  }
1486  av_log(NULL, AV_LOG_STDERR, "\n");
1487  }
1488 
1489  if (avcodec_get_hw_config(c, 0)) {
1490  av_log(NULL, AV_LOG_STDERR, " Supported hardware devices: ");
1491  for (int i = 0;; i++) {
1492  const AVCodecHWConfig *config = avcodec_get_hw_config(c, i);
1493  if (!config)
1494  break;
1495  av_log(NULL, AV_LOG_STDERR, "%s ", av_hwdevice_get_type_name(config->device_type));
1496  }
1497  av_log(NULL, AV_LOG_STDERR, "\n");
1498  }
1499 
1500  if (c->supported_framerates) {
1501  const AVRational *fps = c->supported_framerates;
1502 
1503  av_log(NULL, AV_LOG_STDERR, " Supported framerates:");
1504  while (fps->num) {
1505  av_log(NULL, AV_LOG_STDERR, " %d/%d", fps->num, fps->den);
1506  fps++;
1507  }
1508  av_log(NULL, AV_LOG_STDERR, "\n");
1509  }
1510  PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
1511  AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
1512  PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
1514  PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
1515  AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
1516  PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts",
1517  0, GET_CH_LAYOUT_DESC);
1518 
1519  if (c->priv_class) {
1520  show_help_children(c->priv_class,
1521  AV_OPT_FLAG_ENCODING_PARAM |
1522  AV_OPT_FLAG_DECODING_PARAM);
1523  }
1524 }
1525 
1526 static char get_media_type_char(enum AVMediaType type)
1527 {
1528  switch (type) {
1529  case AVMEDIA_TYPE_VIDEO: return 'V';
1530  case AVMEDIA_TYPE_AUDIO: return 'A';
1531  case AVMEDIA_TYPE_DATA: return 'D';
1532  case AVMEDIA_TYPE_SUBTITLE: return 'S';
1533  case AVMEDIA_TYPE_ATTACHMENT:return 'T';
1534  default: return '?';
1535  }
1536 }
1537 
1538 static const AVCodec *next_codec_for_id(enum AVCodecID id, void **iter,
1539  int encoder)
1540 {
1541  const AVCodec *c;
1542  while ((c = av_codec_iterate(iter))) {
1543  if (c->id == id &&
1544  (encoder ? av_codec_is_encoder(c) : av_codec_is_decoder(c)))
1545  return c;
1546  }
1547  return NULL;
1548 }
1549 
1550 static int compare_codec_desc(const void *a, const void *b)
1551 {
1552  const AVCodecDescriptor * const *da = a;
1553  const AVCodecDescriptor * const *db = b;
1554 
1555  return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
1556  strcmp((*da)->name, (*db)->name);
1557 }
1558 
1559 static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
1560 {
1561  const AVCodecDescriptor *desc = NULL;
1562  const AVCodecDescriptor **codecs;
1563  unsigned nb_codecs = 0, i = 0;
1564 
1565  while ((desc = avcodec_descriptor_next(desc)))
1566  nb_codecs++;
1567  if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) {
1568  av_log(NULL, AV_LOG_ERROR, "Out of memory\n");
1569  exit_program(1);
1570  }
1571  desc = NULL;
1572  while ((desc = avcodec_descriptor_next(desc)))
1573  codecs[i++] = desc;
1574  av_assert0(i == nb_codecs);
1575  qsort(codecs, nb_codecs, sizeof(*codecs), compare_codec_desc);
1576  *rcodecs = codecs;
1577  return nb_codecs;
1578 }
1579 
1580 static void print_codecs_for_id(enum AVCodecID id, int encoder)
1581 {
1582  void *iter = NULL;
1583  const AVCodec *codec;
1584 
1585  av_log(NULL, AV_LOG_STDERR, " (%s: ", encoder ? "encoders" : "decoders");
1586 
1587  while ((codec = next_codec_for_id(id, &iter, encoder)))
1588  av_log(NULL, AV_LOG_STDERR, "%s ", codec->name);
1589 
1590  av_log(NULL, AV_LOG_STDERR, ")");
1591 }
1592 
1593 int show_codecs(void *optctx, const char *opt, const char *arg)
1594 {
1595  const AVCodecDescriptor **codecs;
1596  unsigned i, nb_codecs = get_codecs_sorted(&codecs);
1597 
1598  av_log(NULL, AV_LOG_STDERR, "Codecs:\n"
1599  " D..... = Decoding supported\n"
1600  " .E.... = Encoding supported\n"
1601  " ..V... = Video codec\n"
1602  " ..A... = Audio codec\n"
1603  " ..S... = Subtitle codec\n"
1604  " ...I.. = Intra frame-only codec\n"
1605  " ....L. = Lossy compression\n"
1606  " .....S = Lossless compression\n"
1607  " -------\n");
1608  for (i = 0; i < nb_codecs; i++) {
1609  const AVCodecDescriptor *desc = codecs[i];
1610  const AVCodec *codec;
1611  void *iter = NULL;
1612 
1613  if (strstr(desc->name, "_deprecated"))
1614  continue;
1615 
1616  av_log(NULL, AV_LOG_STDERR, " ");
1617  av_log(NULL, AV_LOG_STDERR, avcodec_find_decoder(desc->id) ? "D" : ".");
1618  av_log(NULL, AV_LOG_STDERR, avcodec_find_encoder(desc->id) ? "E" : ".");
1619 
1620  av_log(NULL, AV_LOG_STDERR, "%c", get_media_type_char(desc->type));
1621  av_log(NULL, AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
1622  av_log(NULL, AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSY) ? "L" : ".");
1623  av_log(NULL, AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSLESS) ? "S" : ".");
1624 
1625  av_log(NULL, AV_LOG_STDERR, " %-20s %s", desc->name, desc->long_name ? desc->long_name : "");
1626 
1627  /* print decoders/encoders when there's more than one or their
1628  * names are different from codec name */
1629  while ((codec = next_codec_for_id(desc->id, &iter, 0))) {
1630  if (strcmp(codec->name, desc->name)) {
1631  print_codecs_for_id(desc->id, 0);
1632  break;
1633  }
1634  }
1635  iter = NULL;
1636  while ((codec = next_codec_for_id(desc->id, &iter, 1))) {
1637  if (strcmp(codec->name, desc->name)) {
1638  print_codecs_for_id(desc->id, 1);
1639  break;
1640  }
1641  }
1642 
1643  av_log(NULL, AV_LOG_STDERR, "\n");
1644  }
1645  av_free(codecs);
1646  return 0;
1647 }
1648 
1649 static void print_codecs(int encoder)
1650 {
1651  const AVCodecDescriptor **codecs;
1652  unsigned i, nb_codecs = get_codecs_sorted(&codecs);
1653 
1654  av_log(NULL, AV_LOG_STDERR, "%s:\n"
1655  " V..... = Video\n"
1656  " A..... = Audio\n"
1657  " S..... = Subtitle\n"
1658  " .F.... = Frame-level multithreading\n"
1659  " ..S... = Slice-level multithreading\n"
1660  " ...X.. = Codec is experimental\n"
1661  " ....B. = Supports draw_horiz_band\n"
1662  " .....D = Supports direct rendering method 1\n"
1663  " ------\n",
1664  encoder ? "Encoders" : "Decoders");
1665  for (i = 0; i < nb_codecs; i++) {
1666  const AVCodecDescriptor *desc = codecs[i];
1667  const AVCodec *codec;
1668  void *iter = NULL;
1669 
1670  while ((codec = next_codec_for_id(desc->id, &iter, encoder))) {
1671  av_log(NULL, AV_LOG_STDERR, " %c", get_media_type_char(desc->type));
1672  av_log(NULL, AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? "F" : ".");
1673  av_log(NULL, AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? "S" : ".");
1674  av_log(NULL, AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ? "X" : ".");
1675  av_log(NULL, AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : ".");
1676  av_log(NULL, AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DR1) ? "D" : ".");
1677 
1678  av_log(NULL, AV_LOG_STDERR, " %-20s %s", codec->name, codec->long_name ? codec->long_name : "");
1679  if (strcmp(codec->name, desc->name))
1680  av_log(NULL, AV_LOG_STDERR, " (codec %s)", desc->name);
1681 
1682  av_log(NULL, AV_LOG_STDERR, "\n");
1683  }
1684  }
1685  av_free(codecs);
1686 }
1687 
1688 int show_decoders(void *optctx, const char *opt, const char *arg)
1689 {
1690  print_codecs(0);
1691  return 0;
1692 }
1693 
1694 int show_encoders(void *optctx, const char *opt, const char *arg)
1695 {
1696  print_codecs(1);
1697  return 0;
1698 }
1699 
1700 int show_bsfs(void *optctx, const char *opt, const char *arg)
1701 {
1702  const AVBitStreamFilter *bsf = NULL;
1703  void *opaque = NULL;
1704 
1705  av_log(NULL, AV_LOG_STDERR, "Bitstream filters:\n");
1706  while ((bsf = av_bsf_iterate(&opaque)))
1707  av_log(NULL, AV_LOG_STDERR, "%s\n", bsf->name);
1708  av_log(NULL, AV_LOG_STDERR, "\n");
1709  return 0;
1710 }
1711 
1712 int show_protocols(void *optctx, const char *opt, const char *arg)
1713 {
1714  void *opaque = NULL;
1715  const char *name;
1716 
1717  av_log(NULL, AV_LOG_STDERR, "Supported file protocols:\n"
1718  "Input:\n");
1719  while ((name = avio_enum_protocols(&opaque, 0)))
1720  av_log(NULL, AV_LOG_STDERR, " %s\n", name);
1721  av_log(NULL, AV_LOG_STDERR, "Output:\n");
1722  while ((name = avio_enum_protocols(&opaque, 1)))
1723  av_log(NULL, AV_LOG_STDERR, " %s\n", name);
1724  return 0;
1725 }
1726 
1727 int show_filters(void *optctx, const char *opt, const char *arg)
1728 {
1729 #if CONFIG_AVFILTER
1730  const AVFilter *filter = NULL;
1731  char descr[64], *descr_cur;
1732  void *opaque = NULL;
1733  int i, j;
1734  const AVFilterPad *pad;
1735 
1736  av_log(NULL, AV_LOG_STDERR, "Filters:\n"
1737  " T.. = Timeline support\n"
1738  " .S. = Slice threading\n"
1739  " ..C = Command support\n"
1740  " A = Audio input/output\n"
1741  " V = Video input/output\n"
1742  " N = Dynamic number and/or type of input/output\n"
1743  " | = Source or sink filter\n");
1744  while ((filter = av_filter_iterate(&opaque))) {
1745  descr_cur = descr;
1746  for (i = 0; i < 2; i++) {
1747  if (i) {
1748  *(descr_cur++) = '-';
1749  *(descr_cur++) = '>';
1750  }
1751  pad = i ? filter->outputs : filter->inputs;
1752  for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
1753  if (descr_cur >= descr + sizeof(descr) - 4)
1754  break;
1755  *(descr_cur++) = get_media_type_char(avfilter_pad_get_type(pad, j));
1756  }
1757  if (!j)
1758  *(descr_cur++) = ((!i && (filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
1759  ( i && (filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ? 'N' : '|';
1760  }
1761  *descr_cur = 0;
1762  av_log(NULL, AV_LOG_STDERR, " %c%c%c %-17s %-10s %s\n",
1763  filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ? 'T' : '.',
1764  filter->flags & AVFILTER_FLAG_SLICE_THREADS ? 'S' : '.',
1765  filter->process_command ? 'C' : '.',
1766  filter->name, descr, filter->description);
1767  }
1768 #else
1769  av_log(NULL, AV_LOG_STDERR, "No filters available: libavfilter disabled\n");
1770 #endif
1771  return 0;
1772 }
1773 
1774 int show_colors(void *optctx, const char *opt, const char *arg)
1775 {
1776  const char *name;
1777  const uint8_t *rgb;
1778  int i;
1779 
1780  av_log(NULL, AV_LOG_STDERR, "%-32s #RRGGBB\n", "name");
1781 
1782  for (i = 0; (name = av_get_known_color_name(i, &rgb)); i++)
1783  av_log(NULL, AV_LOG_STDERR, "%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1784 
1785  return 0;
1786 }
1787 
1788 int show_pix_fmts(void *optctx, const char *opt, const char *arg)
1789 {
1790  const AVPixFmtDescriptor *pix_desc = NULL;
1791 
1792  av_log(NULL, AV_LOG_STDERR, "Pixel formats:\n"
1793  "I.... = Supported Input format for conversion\n"
1794  ".O... = Supported Output format for conversion\n"
1795  "..H.. = Hardware accelerated format\n"
1796  "...P. = Paletted format\n"
1797  "....B = Bitstream format\n"
1798  "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1799  "-----\n");
1800 
1801 #if !CONFIG_SWSCALE
1802 # define sws_isSupportedInput(x) 0
1803 # define sws_isSupportedOutput(x) 0
1804 #endif
1805 
1806  while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
1807  enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
1808  av_log(NULL, AV_LOG_STDERR, "%c%c%c%c%c %-16s %d %2d\n",
1809  sws_isSupportedInput (pix_fmt) ? 'I' : '.',
1810  sws_isSupportedOutput(pix_fmt) ? 'O' : '.',
1811  pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ? 'H' : '.',
1812  pix_desc->flags & AV_PIX_FMT_FLAG_PAL ? 'P' : '.',
1813  pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ? 'B' : '.',
1814  pix_desc->name,
1815  pix_desc->nb_components,
1816  av_get_bits_per_pixel(pix_desc));
1817  }
1818  return 0;
1819 }
1820 
1821 int show_layouts(void *optctx, const char *opt, const char *arg)
1822 {
1823  int i = 0;
1824  uint64_t layout, j;
1825  const char *name, *descr;
1826 
1827  av_log(NULL, AV_LOG_STDERR, "Individual channels:\n"
1828  "NAME DESCRIPTION\n");
1829  for (i = 0; i < 63; i++) {
1830  name = av_get_channel_name((uint64_t)1 << i);
1831  if (!name)
1832  continue;
1833  descr = av_get_channel_description((uint64_t)1 << i);
1834  av_log(NULL, AV_LOG_STDERR, "%-14s %s\n", name, descr);
1835  }
1836  av_log(NULL, AV_LOG_STDERR, "\nStandard channel layouts:\n"
1837  "NAME DECOMPOSITION\n");
1838  for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
1839  if (name) {
1840  av_log(NULL, AV_LOG_STDERR, "%-14s ", name);
1841  for (j = 1; j; j <<= 1)
1842  if ((layout & j))
1843  av_log(NULL, AV_LOG_STDERR, "%s%s", (layout & (j - 1)) ? "+" : "", av_get_channel_name(j));
1844  av_log(NULL, AV_LOG_STDERR, "\n");
1845  }
1846  }
1847  return 0;
1848 }
1849 
1850 int show_sample_fmts(void *optctx, const char *opt, const char *arg)
1851 {
1852  int i;
1853  char fmt_str[128];
1854  for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
1855  av_log(NULL, AV_LOG_STDERR, "%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
1856  return 0;
1857 }
1858 
1859 static void show_help_codec(const char *name, int encoder)
1860 {
1861  const AVCodecDescriptor *desc;
1862  const AVCodec *codec;
1863 
1864  if (!name) {
1865  av_log(NULL, AV_LOG_ERROR, "No codec name specified.\n");
1866  return;
1867  }
1868 
1869  codec = encoder ? avcodec_find_encoder_by_name(name) :
1870  avcodec_find_decoder_by_name(name);
1871 
1872  if (codec)
1873  print_codec(codec);
1874  else if ((desc = avcodec_descriptor_get_by_name(name))) {
1875  void *iter = NULL;
1876  int printed = 0;
1877 
1878  while ((codec = next_codec_for_id(desc->id, &iter, encoder))) {
1879  printed = 1;
1880  print_codec(codec);
1881  }
1882 
1883  if (!printed) {
1884  av_log(NULL, AV_LOG_ERROR, "Codec '%s' is known to FFmpeg, "
1885  "but no %s for it are available. FFmpeg might need to be "
1886  "recompiled with additional external libraries.\n",
1887  name, encoder ? "encoders" : "decoders");
1888  }
1889  } else {
1890  av_log(NULL, AV_LOG_ERROR, "Codec '%s' is not recognized by FFmpeg.\n",
1891  name);
1892  }
1893 }
1894 
1895 static void show_help_demuxer(const char *name)
1896 {
1897  const AVInputFormat *fmt = av_find_input_format(name);
1898 
1899  if (!fmt) {
1900  av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
1901  return;
1902  }
1903 
1904  av_log(NULL, AV_LOG_STDERR, "Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
1905 
1906  if (fmt->extensions)
1907  av_log(NULL, AV_LOG_STDERR, " Common extensions: %s.\n", fmt->extensions);
1908 
1909  if (fmt->priv_class)
1910  show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
1911 }
1912 
1913 static void show_help_protocol(const char *name)
1914 {
1915  const AVClass *proto_class;
1916 
1917  if (!name) {
1918  av_log(NULL, AV_LOG_ERROR, "No protocol name specified.\n");
1919  return;
1920  }
1921 
1922  proto_class = avio_protocol_get_class(name);
1923  if (!proto_class) {
1924  av_log(NULL, AV_LOG_ERROR, "Unknown protocol '%s'.\n", name);
1925  return;
1926  }
1927 
1928  show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
1929 }
1930 
1931 static void show_help_muxer(const char *name)
1932 {
1933  const AVCodecDescriptor *desc;
1934  const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
1935 
1936  if (!fmt) {
1937  av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
1938  return;
1939  }
1940 
1941  av_log(NULL, AV_LOG_STDERR, "Muxer %s [%s]:\n", fmt->name, fmt->long_name);
1942 
1943  if (fmt->extensions)
1944  av_log(NULL, AV_LOG_STDERR, " Common extensions: %s.\n", fmt->extensions);
1945  if (fmt->mime_type)
1946  av_log(NULL, AV_LOG_STDERR, " Mime type: %s.\n", fmt->mime_type);
1947  if (fmt->video_codec != AV_CODEC_ID_NONE &&
1948  (desc = avcodec_descriptor_get(fmt->video_codec))) {
1949  av_log(NULL, AV_LOG_STDERR, " Default video codec: %s.\n", desc->name);
1950  }
1951  if (fmt->audio_codec != AV_CODEC_ID_NONE &&
1952  (desc = avcodec_descriptor_get(fmt->audio_codec))) {
1953  av_log(NULL, AV_LOG_STDERR, " Default audio codec: %s.\n", desc->name);
1954  }
1955  if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
1956  (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
1957  av_log(NULL, AV_LOG_STDERR, " Default subtitle codec: %s.\n", desc->name);
1958  }
1959 
1960  if (fmt->priv_class)
1961  show_help_children(fmt->priv_class, AV_OPT_FLAG_ENCODING_PARAM);
1962 }
1963 
1964 #if CONFIG_AVFILTER
1965 static void show_help_filter(const char *name)
1966 {
1967 #if CONFIG_AVFILTER
1968  const AVFilter *f = avfilter_get_by_name(name);
1969  int i, count;
1970 
1971  if (!name) {
1972  av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
1973  return;
1974  } else if (!f) {
1975  av_log(NULL, AV_LOG_ERROR, "Unknown filter '%s'.\n", name);
1976  return;
1977  }
1978 
1979  av_log(NULL, AV_LOG_STDERR, "Filter %s\n", f->name);
1980  if (f->description)
1981  av_log(NULL, AV_LOG_STDERR, " %s\n", f->description);
1982 
1983  if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
1984  av_log(NULL, AV_LOG_STDERR, " slice threading supported\n");
1985 
1986  av_log(NULL, AV_LOG_STDERR, " Inputs:\n");
1987  count = avfilter_pad_count(f->inputs);
1988  for (i = 0; i < count; i++) {
1989  av_log(NULL, AV_LOG_STDERR, " #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
1990  media_type_string(avfilter_pad_get_type(f->inputs, i)));
1991  }
1992  if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
1993  av_log(NULL, AV_LOG_STDERR, " dynamic (depending on the options)\n");
1994  else if (!count)
1995  av_log(NULL, AV_LOG_STDERR, " none (source filter)\n");
1996 
1997  av_log(NULL, AV_LOG_STDERR, " Outputs:\n");
1998  count = avfilter_pad_count(f->outputs);
1999  for (i = 0; i < count; i++) {
2000  av_log(NULL, AV_LOG_STDERR, " #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
2001  media_type_string(avfilter_pad_get_type(f->outputs, i)));
2002  }
2003  if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
2004  av_log(NULL, AV_LOG_STDERR, " dynamic (depending on the options)\n");
2005  else if (!count)
2006  av_log(NULL, AV_LOG_STDERR, " none (sink filter)\n");
2007 
2008  if (f->priv_class)
2009  show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
2010  AV_OPT_FLAG_AUDIO_PARAM);
2011  if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
2012  av_log(NULL, AV_LOG_STDERR, "This filter has support for timeline through the 'enable' option.\n");
2013 #else
2014  av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; "
2015  "can not to satisfy request\n");
2016 #endif
2017 }
2018 #endif
2019 
2020 static void show_help_bsf(const char *name)
2021 {
2022  const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
2023 
2024  if (!name) {
2025  av_log(NULL, AV_LOG_ERROR, "No bitstream filter name specified.\n");
2026  return;
2027  } else if (!bsf) {
2028  av_log(NULL, AV_LOG_ERROR, "Unknown bit stream filter '%s'.\n", name);
2029  return;
2030  }
2031 
2032  av_log(NULL, AV_LOG_STDERR, "Bit stream filter %s\n", bsf->name);
2033  PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
2034  AV_CODEC_ID_NONE, GET_CODEC_NAME);
2035  if (bsf->priv_class)
2036  show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
2037 }
2038 
2039 int show_help(void *optctx, const char *opt, const char *arg)
2040 {
2041  char *topic, *par;
2042 
2043  topic = av_strdup(arg ? arg : "");
2044  if (!topic)
2045  return AVERROR(ENOMEM);
2046  par = strchr(topic, '=');
2047  if (par)
2048  *par++ = 0;
2049 
2050  if (!*topic) {
2051  if (program_name && !strcmp(program_name, "ffmpeg")) {
2052  show_help_default_ffmpeg(topic, par);
2053  } else {
2054  show_help_default_ffprobe(topic, par);
2055  }
2056  } else if (!strcmp(topic, "decoder")) {
2057  show_help_codec(par, 0);
2058  } else if (!strcmp(topic, "encoder")) {
2059  show_help_codec(par, 1);
2060  } else if (!strcmp(topic, "demuxer")) {
2061  show_help_demuxer(par);
2062  } else if (!strcmp(topic, "muxer")) {
2063  show_help_muxer(par);
2064  } else if (!strcmp(topic, "protocol")) {
2065  show_help_protocol(par);
2066 #if CONFIG_AVFILTER
2067  } else if (!strcmp(topic, "filter")) {
2068  show_help_filter(par);
2069 #endif
2070  } else if (!strcmp(topic, "bsf")) {
2071  show_help_bsf(par);
2072  } else {
2073  if (program_name && !strcmp(program_name, "ffmpeg")) {
2074  show_help_default_ffmpeg(topic, par);
2075  } else {
2076  show_help_default_ffprobe(topic, par);
2077  }
2078  }
2079 
2080  av_freep(&topic);
2081  return 0;
2082 }
2083 
2084 int read_yesno(void)
2085 {
2086  int c = getchar();
2087  int yesno = (av_toupper(c) == 'Y');
2088 
2089  while (c != '\n' && c != EOF)
2090  c = getchar();
2091 
2092  return yesno;
2093 }
2094 
2095 FILE *get_preset_file(char *filename, size_t filename_size,
2096  const char *preset_name, int is_path,
2097  const char *codec_name)
2098 {
2099  FILE *f = NULL;
2100  int i;
2101  const char *base[3] = { getenv("FFMPEG_DATADIR"),
2102  getenv("HOME"),
2103  FFMPEG_DATADIR, };
2104 
2105  if (is_path) {
2106  av_strlcpy(filename, preset_name, filename_size);
2107  f = fopen(filename, "r");
2108  } else {
2109 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
2110  char datadir[MAX_PATH], *ls;
2111  base[2] = NULL;
2112 
2113  if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
2114  {
2115  for (ls = datadir; ls < datadir + strlen(datadir); ls++)
2116  if (*ls == '\\') *ls = '/';
2117 
2118  if (ls = strrchr(datadir, '/'))
2119  {
2120  *ls = 0;
2121  strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
2122  base[2] = datadir;
2123  }
2124  }
2125 #endif
2126  for (i = 0; i < 3 && !f; i++) {
2127  if (!base[i])
2128  continue;
2129  snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
2130  i != 1 ? "" : "/.ffmpeg", preset_name);
2131  f = fopen(filename, "r");
2132  if (!f && codec_name) {
2133  snprintf(filename, filename_size,
2134  "%s%s/%s-%s.ffpreset",
2135  base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
2136  preset_name);
2137  f = fopen(filename, "r");
2138  }
2139  }
2140  }
2141 
2142  return f;
2143 }
2144 
2145 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
2146 {
2147  int ret = avformat_match_stream_specifier(s, st, spec);
2148  if (ret < 0)
2149  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
2150  return ret;
2151 }
2152 
2153 AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
2154  AVFormatContext *s, AVStream *st, AVCodec *codec)
2155 {
2156  AVDictionary *ret = NULL;
2157  AVDictionaryEntry *t = NULL;
2158  int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
2159  : AV_OPT_FLAG_DECODING_PARAM;
2160  char prefix = 0;
2161  const AVClass *cc = avcodec_get_class();
2162 
2163  if (!codec)
2164  codec = s->oformat ? avcodec_find_encoder(codec_id)
2165  : avcodec_find_decoder(codec_id);
2166 
2167  switch (st->codecpar->codec_type) {
2168  case AVMEDIA_TYPE_VIDEO:
2169  prefix = 'v';
2170  flags |= AV_OPT_FLAG_VIDEO_PARAM;
2171  break;
2172  case AVMEDIA_TYPE_AUDIO:
2173  prefix = 'a';
2174  flags |= AV_OPT_FLAG_AUDIO_PARAM;
2175  break;
2176  case AVMEDIA_TYPE_SUBTITLE:
2177  prefix = 's';
2178  flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
2179  break;
2180  }
2181 
2182  while ((t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX))) {
2183  char *p = strchr(t->key, ':');
2184 
2185  /* check stream specification in opt name */
2186  if (p)
2187  switch (check_stream_specifier(s, st, p + 1)) {
2188  case 1: *p = 0; break;
2189  case 0: continue;
2190  default: exit_program(1);
2191  }
2192 
2193  if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
2194  !codec ||
2195  (codec->priv_class &&
2196  av_opt_find(&codec->priv_class, t->key, NULL, flags,
2197  AV_OPT_SEARCH_FAKE_OBJ)))
2198  av_dict_set(&ret, t->key, t->value, 0);
2199  else if (t->key[0] == prefix &&
2200  av_opt_find(&cc, t->key + 1, NULL, flags,
2201  AV_OPT_SEARCH_FAKE_OBJ))
2202  av_dict_set(&ret, t->key + 1, t->value, 0);
2203 
2204  if (p)
2205  *p = ':';
2206  }
2207  return ret;
2208 }
2209 
2210 AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
2211  AVDictionary *codec_opts)
2212 {
2213  int i;
2214  AVDictionary **opts;
2215 
2216  if (!s->nb_streams)
2217  return NULL;
2218  opts = av_mallocz_array(s->nb_streams, sizeof(*opts));
2219  if (!opts) {
2220  av_log(NULL, AV_LOG_ERROR,
2221  "Could not alloc memory for stream options.\n");
2222  return NULL;
2223  }
2224  for (i = 0; i < s->nb_streams; i++)
2225  opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
2226  s, s->streams[i], NULL);
2227  return opts;
2228 }
2229 
2230 void *grow_array(void *array, int elem_size, int *size, int new_size)
2231 {
2232  if (new_size >= INT_MAX / elem_size) {
2233  av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
2234  exit_program(1);
2235  }
2236  if (*size < new_size) {
2237  uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
2238  if (!tmp) {
2239  av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
2240  exit_program(1);
2241  }
2242  memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
2243  *size = new_size;
2244  return tmp;
2245  }
2246  return array;
2247 }
2248 
2249 double get_rotation(AVStream *st)
2250 {
2251  uint8_t* displaymatrix = av_stream_get_side_data(st,
2252  AV_PKT_DATA_DISPLAYMATRIX, NULL);
2253  double theta = 0;
2254  if (displaymatrix)
2255  theta = -av_display_rotation_get((int32_t*) displaymatrix);
2256 
2257  theta -= 360*floor(theta/360 + 0.9/360);
2258 
2259  if (fabs(theta - 90*round(theta/90)) > 2)
2260  av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
2261  "If you want to help, upload a sample "
2262  "of this file to https://streams.videolan.org/upload/ "
2263  "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
2264 
2265  return theta;
2266 }
2267 
2268 #if CONFIG_AVDEVICE
2269 static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
2270 {
2271  int ret, i;
2272  AVDeviceInfoList *device_list = NULL;
2273 
2274  if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
2275  return AVERROR(EINVAL);
2276 
2277  av_log(NULL, AV_LOG_STDERR, "Auto-detected sources for %s:\n", fmt->name);
2278  if (!fmt->get_device_list) {
2279  ret = AVERROR(ENOSYS);
2280  av_log(NULL, AV_LOG_STDERR, "Cannot list sources. Not implemented.\n");
2281  goto fail;
2282  }
2283 
2284  if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
2285  av_log(NULL, AV_LOG_STDERR, "Cannot list sources.\n");
2286  goto fail;
2287  }
2288 
2289  for (i = 0; i < device_list->nb_devices; i++) {
2290  av_log(NULL, AV_LOG_STDERR, "%s %s [%s]\n", device_list->default_device == i ? "*" : " ",
2291  device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2292  }
2293 
2294  fail:
2295  avdevice_free_list_devices(&device_list);
2296  return ret;
2297 }
2298 
2299 static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
2300 {
2301  int ret, i;
2302  AVDeviceInfoList *device_list = NULL;
2303 
2304  if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
2305  return AVERROR(EINVAL);
2306 
2307  av_log(NULL, AV_LOG_STDERR, "Auto-detected sinks for %s:\n", fmt->name);
2308  if (!fmt->get_device_list) {
2309  ret = AVERROR(ENOSYS);
2310  av_log(NULL, AV_LOG_STDERR, "Cannot list sinks. Not implemented.\n");
2311  goto fail;
2312  }
2313 
2314  if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
2315  av_log(NULL, AV_LOG_STDERR, "Cannot list sinks.\n");
2316  goto fail;
2317  }
2318 
2319  for (i = 0; i < device_list->nb_devices; i++) {
2320  av_log(NULL, AV_LOG_STDERR, "%s %s [%s]\n", device_list->default_device == i ? "*" : " ",
2321  device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2322  }
2323 
2324  fail:
2325  avdevice_free_list_devices(&device_list);
2326  return ret;
2327 }
2328 
2329 static int show_sinks_sources_parse_arg(const char *arg, char **dev, AVDictionary **opts)
2330 {
2331  int ret;
2332  if (arg) {
2333  char *opts_str = NULL;
2334  av_assert0(dev && opts);
2335  *dev = av_strdup(arg);
2336  if (!*dev)
2337  return AVERROR(ENOMEM);
2338  if ((opts_str = strchr(*dev, ','))) {
2339  *(opts_str++) = '\0';
2340  if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str, "=", ":", 0)) < 0)) {
2341  av_freep(dev);
2342  return ret;
2343  }
2344  }
2345  } else
2346  av_log(NULL, AV_LOG_STDERR, "\nDevice name is not provided.\n"
2347  "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
2348  return 0;
2349 }
2350 
2351 int show_sources(void *optctx, const char *opt, const char *arg)
2352 {
2353  AVInputFormat *fmt = NULL;
2354  char *dev = NULL;
2355  AVDictionary *opts = NULL;
2356  int ret = 0;
2357  int error_level = av_log_get_level();
2358 
2359  av_log_set_level(AV_LOG_WARNING);
2360 
2361  if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2362  goto fail;
2363 
2364  do {
2365  fmt = av_input_audio_device_next(fmt);
2366  if (fmt) {
2367  if (!strcmp(fmt->name, "lavfi"))
2368  continue; //it's pointless to probe lavfi
2369  if (dev && !av_match_name(dev, fmt->name))
2370  continue;
2371  print_device_sources(fmt, opts);
2372  }
2373  } while (fmt);
2374  do {
2375  fmt = av_input_video_device_next(fmt);
2376  if (fmt) {
2377  if (dev && !av_match_name(dev, fmt->name))
2378  continue;
2379  print_device_sources(fmt, opts);
2380  }
2381  } while (fmt);
2382  fail:
2383  av_dict_free(&opts);
2384  av_free(dev);
2385  av_log_set_level(error_level);
2386  return ret;
2387 }
2388 
2389 int show_sinks(void *optctx, const char *opt, const char *arg)
2390 {
2391  AVOutputFormat *fmt = NULL;
2392  char *dev = NULL;
2393  AVDictionary *opts = NULL;
2394  int ret = 0;
2395  int error_level = av_log_get_level();
2396 
2397  av_log_set_level(AV_LOG_WARNING);
2398 
2399  if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2400  goto fail;
2401 
2402  do {
2403  fmt = av_output_audio_device_next(fmt);
2404  if (fmt) {
2405  if (dev && !av_match_name(dev, fmt->name))
2406  continue;
2407  print_device_sinks(fmt, opts);
2408  }
2409  } while (fmt);
2410  do {
2411  fmt = av_output_video_device_next(fmt);
2412  if (fmt) {
2413  if (dev && !av_match_name(dev, fmt->name))
2414  continue;
2415  print_device_sinks(fmt, opts);
2416  }
2417  } while (fmt);
2418  fail:
2419  av_dict_free(&opts);
2420  av_free(dev);
2421  av_log_set_level(error_level);
2422  return ret;
2423 }
2424 
2425 #endif
__thread jmp_buf ex_buf__
void exit_program(int ret)
__thread AVDictionary * swr_opts
static int match_group_separator(const OptionGroupDef *groups, int nb_groups, const char *opt)
int show_decoders(void *optctx, const char *opt, const char *arg)
int opt_loglevel(void *optctx, const char *opt, const char *arg)
void show_help_children(const AVClass *class, int flags)
__thread AVDictionary * codec_opts
int opt_cpuflags(void *optctx, const char *opt, const char *arg)
void ffmpegkit_log_callback_function(void *ptr, int level, const char *format, va_list vargs)
Definition: ffmpegkit.c:442
static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
void init_dynload(void)
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
int show_help(void *optctx, const char *opt, const char *arg)
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
static const OptionDef * find_option(const OptionDef *po, const char *name)
__thread AVDictionary * format_opts
static void show_help_bsf(const char *name)
int opt_default(void *optctx, const char *opt, const char *arg)
void print_error(const char *filename, int err)
static void show_help_codec(const char *name, int encoder)
int show_filters(void *optctx, const char *opt, const char *arg)
static void show_help_demuxer(const char *name)
__thread volatile int longjmp_value
int show_sample_fmts(void *optctx, const char *opt, const char *arg)
#define SHOW_CONFIG
int read_yesno(void)
int report_file_level
static void print_codecs(int encoder)
show_muxdemuxers
@ SHOW_DEFAULT
@ SHOW_DEMUXERS
@ SHOW_MUXERS
#define SHOW_VERSION
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
int show_muxers(void *optctx, const char *opt, const char *arg)
int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
#define INDENT
static int compare_codec_desc(const void *a, const void *b)
int show_bsfs(void *optctx, const char *opt, const char *arg)
FILE * report_file
void * grow_array(void *array, int elem_size, int *size, int new_size)
static int write_option(void *optctx, const OptionDef *po, const char *opt, const char *arg)
static void print_all_libs_info(int flags, int level)
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
__thread AVDictionary * resample_opts
static void(* program_exit)(int ret)
static void init_parse_context(OptionParseContext *octx, const OptionGroupDef *groups, int nb_groups)
static void add_opt(OptionParseContext *octx, const OptionDef *opt, const char *key, const char *val)
__thread char * program_name
#define FLAGS
static void print_buildconf(int flags, int level)
#define PRINT_LIB_INFO(libname, LIBNAME, flags, level)
int show_layouts(void *optctx, const char *opt, const char *arg)
static void dump_argument(const char *a)
int show_encoders(void *optctx, const char *opt, const char *arg)
#define GET_ARG(arg)
static void finish_group(OptionParseContext *octx, int group_idx, const char *arg)
int show_version(void *optctx, const char *opt, const char *arg)
static void expand_filename_template(AVBPrint *bp, const char *template, struct tm *tm)
void parse_loglevel(int argc, char **argv, const OptionDef *options)
static void show_help_protocol(const char *name)
__thread int program_birth_year
__thread int warned_cfg
static const AVCodec * next_codec_for_id(enum AVCodecID id, void **iter, int encoder)
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
static char get_media_type_char(enum AVMediaType type)
void uninit_parse_context(OptionParseContext *octx)
__thread AVDictionary * sws_dict
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
double get_rotation(AVStream *st)
void show_banner(int argc, char **argv, const OptionDef *options)
static void show_help_muxer(const char *name)
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
int opt_timelimit(void *optctx, const char *opt, const char *arg)
int show_license(void *optctx, const char *opt, const char *arg)
int show_codecs(void *optctx, const char *opt, const char *arg)
int show_buildconf(void *optctx, const char *opt, const char *arg)
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
void register_exit(void(*cb)(int ret))
static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only, int muxdemuxers)
int show_devices(void *optctx, const char *opt, const char *arg)
void(* report_callback)(int, float, float, int64_t, int, double, double)
static void print_program_info(int flags, int level)
static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
#define SHOW_COPYRIGHT
void log_callback_report(void *ptr, int level, const char *fmt, va_list vl)
void uninit_opts(void)
static void print_codec(const AVCodec *c)
int show_formats(void *optctx, const char *opt, const char *arg)
__thread int hide_banner
#define sws_isSupportedOutput(x)
static int is_device(const AVClass *avclass)
int show_protocols(void *optctx, const char *opt, const char *arg)
int parse_optgroup(void *optctx, OptionGroup *g)
static const AVOption * opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
int opt_max_alloc(void *optctx, const char *opt, const char *arg)
static void check_options(const OptionDef *po)
int opt_report(void *optctx, const char *opt, const char *arg)
void init_opts(void)
int show_colors(void *optctx, const char *opt, const char *arg)
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
static int init_report(const char *env)
#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name)
int show_pix_fmts(void *optctx, const char *opt, const char *arg)
int show_demuxers(void *optctx, const char *opt, const char *arg)
#define sws_isSupportedInput(x)
static void print_codecs_for_id(enum AVCodecID id, int encoder)
#define GET_SAMPLE_RATE_NAME(rate)
#define OPT_SPEC
#define OPT_BOOL
#define media_type_string
#define OPT_INT64
#define OPT_PERFILE
#define GET_CODEC_NAME(id)
#define OPT_INT
#define OPT_FLOAT
#define AV_LOG_STDERR
#define OPT_INPUT
#define GET_PIX_FMT_NAME(pix_fmt)
#define OPT_DOUBLE
#define OPT_STRING
#define GET_CH_LAYOUT_DESC(ch_layout)
#define GROW_ARRAY(array, nb_elems)
#define GET_SAMPLE_FMT_NAME(sample_fmt)
#define OPT_EXIT
#define OPT_OUTPUT
#define OPT_TIME
void show_help_default_ffprobe(const char *opt, const char *arg)
void show_help_default_ffmpeg(const char *opt, const char *arg)
#define OPT_OFFSET
#define HAS_ARG
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
union OptionDef::@1 u
const char * name
const char * argname
const char * help
int(* func_arg)(void *, const char *, const char *)
const char * name
const char * sep
const OptionGroupDef * group_def
AVDictionary * codec_opts
AVDictionary * swr_opts
AVDictionary * sws_dict
const char * arg
AVDictionary * format_opts
AVDictionary * resample_opts
OptionGroup * groups
const OptionGroupDef * group_def
const char * key
const OptionDef * opt
const char * val
OptionGroupList * groups