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