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