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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <string.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <math.h>
26 
27 /* Include only the enabled headers since some compilers (namely, Sun
28  Studio) will not omit unused inline functions and create undefined
29  references to libraries that are not being built. */
30 
31 #include "config.h"
32 #include "libavformat/avformat.h"
33 #include "libavfilter/avfilter.h"
34 #include "libavdevice/avdevice.h"
36 #include "libswscale/swscale.h"
37 #include "libavutil/avassert.h"
38 #include "libavutil/avstring.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/imgutils.h"
41 #include "libavutil/parseutils.h"
42 #include "libavutil/pixdesc.h"
43 #include "libavutil/eval.h"
44 #include "libavutil/dict.h"
45 #include "libavutil/opt.h"
46 #include "cmdutils.h"
47 #include "version.h"
48 #if CONFIG_NETWORK
49 #include "libavformat/network.h"
50 #endif
51 #if HAVE_SYS_RESOURCE_H
52 #include <sys/time.h>
53 #include <sys/resource.h>
54 #endif
55 
58 
59 static const int this_year = 2014;
60 
61 void init_opts(void)
62 {
63 #if CONFIG_SWSCALE
64  sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC,
65  NULL, NULL, NULL);
66 #endif
67 }
68 
69 void uninit_opts(void)
70 {
71 #if CONFIG_SWSCALE
72  sws_freeContext(sws_opts);
73  sws_opts = NULL;
74 #endif
75  av_dict_free(&format_opts);
76  av_dict_free(&codec_opts);
77 }
78 
79 void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
80 {
81  vfprintf(stdout, fmt, vl);
82 }
83 
84 double parse_number_or_die(const char *context, const char *numstr, int type,
85  double min, double max)
86 {
87  char *tail;
88  const char *error;
89  double d = av_strtod(numstr, &tail);
90  if (*tail)
91  error = "Expected number for %s but found: %s\n";
92  else if (d < min || d > max)
93  error = "The value for %s was %s which is not within %f - %f\n";
94  else if (type == OPT_INT64 && (int64_t)d != d)
95  error = "Expected int64 for %s but found %s\n";
96  else if (type == OPT_INT && (int)d != d)
97  error = "Expected int for %s but found %s\n";
98  else
99  return d;
100  av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
101  exit(1);
102  return 0;
103 }
104 
105 int64_t parse_time_or_die(const char *context, const char *timestr,
106  int is_duration)
107 {
108  int64_t us;
109  if (av_parse_time(&us, timestr, is_duration) < 0) {
110  av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
111  is_duration ? "duration" : "date", context, timestr);
112  exit(1);
113  }
114  return us;
115 }
116 
117 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
118  int rej_flags, int alt_flags)
119 {
120  const OptionDef *po;
121  int first;
122 
123  first = 1;
124  for (po = options; po->name != NULL; po++) {
125  char buf[64];
126 
127  if (((po->flags & req_flags) != req_flags) ||
128  (alt_flags && !(po->flags & alt_flags)) ||
129  (po->flags & rej_flags))
130  continue;
131 
132  if (first) {
133  printf("%s\n", msg);
134  first = 0;
135  }
136  av_strlcpy(buf, po->name, sizeof(buf));
137  if (po->argname) {
138  av_strlcat(buf, " ", sizeof(buf));
139  av_strlcat(buf, po->argname, sizeof(buf));
140  }
141  printf("-%-17s %s\n", buf, po->help);
142  }
143  printf("\n");
144 }
145 
146 void show_help_children(const AVClass *class, int flags)
147 {
148  const AVClass *child = NULL;
149  av_opt_show2(&class, NULL, flags, 0);
150  printf("\n");
151 
152  while (child = av_opt_child_class_next(class, child))
153  show_help_children(child, flags);
154 }
155 
156 static const OptionDef *find_option(const OptionDef *po, const char *name)
157 {
158  const char *p = strchr(name, ':');
159  int len = p ? p - name : strlen(name);
160 
161  while (po->name != NULL) {
162  if (!strncmp(name, po->name, len) && strlen(po->name) == len)
163  break;
164  po++;
165  }
166  return po;
167 }
168 
169 #if HAVE_COMMANDLINETOARGVW
170 #include <windows.h>
171 #include <shellapi.h>
172 /* Will be leaked on exit */
173 static char** win32_argv_utf8 = NULL;
174 static int win32_argc = 0;
175 
183 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
184 {
185  char *argstr_flat;
186  wchar_t **argv_w;
187  int i, buffsize = 0, offset = 0;
188 
189  if (win32_argv_utf8) {
190  *argc_ptr = win32_argc;
191  *argv_ptr = win32_argv_utf8;
192  return;
193  }
194 
195  win32_argc = 0;
196  argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
197  if (win32_argc <= 0 || !argv_w)
198  return;
199 
200  /* determine the UTF-8 buffer size (including NULL-termination symbols) */
201  for (i = 0; i < win32_argc; i++)
202  buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
203  NULL, 0, NULL, NULL);
204 
205  win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
206  argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
207  if (win32_argv_utf8 == NULL) {
208  LocalFree(argv_w);
209  return;
210  }
211 
212  for (i = 0; i < win32_argc; i++) {
213  win32_argv_utf8[i] = &argstr_flat[offset];
214  offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
215  &argstr_flat[offset],
216  buffsize - offset, NULL, NULL);
217  }
218  win32_argv_utf8[i] = NULL;
219  LocalFree(argv_w);
220 
221  *argc_ptr = win32_argc;
222  *argv_ptr = win32_argv_utf8;
223 }
224 #else
225 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
226 {
227  /* nothing to do */
228 }
229 #endif /* HAVE_COMMANDLINETOARGVW */
230 
231 static int write_option(void *optctx, const OptionDef *po, const char *opt,
232  const char *arg)
233 {
234  /* new-style options contain an offset into optctx, old-style address of
235  * a global var*/
236  void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
237  (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
238  int *dstcount;
239 
240  if (po->flags & OPT_SPEC) {
241  SpecifierOpt **so = dst;
242  char *p = strchr(opt, ':');
243 
244  dstcount = (int *)(so + 1);
245  *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
246  (*so)[*dstcount - 1].specifier = av_strdup(p ? p + 1 : "");
247  dst = &(*so)[*dstcount - 1].u;
248  }
249 
250  if (po->flags & OPT_STRING) {
251  char *str;
252  str = av_strdup(arg);
253  av_freep(dst);
254  *(char **)dst = str;
255  } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
256  *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
257  } else if (po->flags & OPT_INT64) {
258  *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
259  } else if (po->flags & OPT_TIME) {
260  *(int64_t *)dst = parse_time_or_die(opt, arg, 1);
261  } else if (po->flags & OPT_FLOAT) {
262  *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
263  } else if (po->flags & OPT_DOUBLE) {
264  *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
265  } else if (po->u.func_arg) {
266  int ret = po->u.func_arg(optctx, opt, arg);
267  if (ret < 0) {
269  "Failed to set value '%s' for option '%s'\n", arg, opt);
270  return ret;
271  }
272  }
273  if (po->flags & OPT_EXIT)
274  exit(0);
275 
276  return 0;
277 }
278 
279 int parse_option(void *optctx, const char *opt, const char *arg,
280  const OptionDef *options)
281 {
282  const OptionDef *po;
283  int ret;
284 
285  po = find_option(options, opt);
286  if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
287  /* handle 'no' bool option */
288  po = find_option(options, opt + 2);
289  if ((po->name && (po->flags & OPT_BOOL)))
290  arg = "0";
291  } else if (po->flags & OPT_BOOL)
292  arg = "1";
293 
294  if (!po->name)
295  po = find_option(options, "default");
296  if (!po->name) {
297  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
298  return AVERROR(EINVAL);
299  }
300  if (po->flags & HAS_ARG && !arg) {
301  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
302  return AVERROR(EINVAL);
303  }
304 
305  ret = write_option(optctx, po, opt, arg);
306  if (ret < 0)
307  return ret;
308 
309  return !!(po->flags & HAS_ARG);
310 }
311 
312 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
313  void (*parse_arg_function)(void *, const char*))
314 {
315  const char *opt;
316  int optindex, handleoptions = 1, ret;
317 
318  /* perform system-dependent conversions for arguments list */
319  prepare_app_arguments(&argc, &argv);
320 
321  /* parse options */
322  optindex = 1;
323  while (optindex < argc) {
324  opt = argv[optindex++];
325 
326  if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
327  if (opt[1] == '-' && opt[2] == '\0') {
328  handleoptions = 0;
329  continue;
330  }
331  opt++;
332 
333  if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
334  exit(1);
335  optindex += ret;
336  } else {
337  if (parse_arg_function)
338  parse_arg_function(optctx, opt);
339  }
340  }
341 }
342 
343 int parse_optgroup(void *optctx, OptionGroup *g)
344 {
345  int i, ret;
346 
347  av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
348  g->group_def->name, g->arg);
349 
350  for (i = 0; i < g->nb_opts; i++) {
351  Option *o = &g->opts[i];
352 
353  av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
354  o->key, o->opt->help, o->val);
355 
356  ret = write_option(optctx, o->opt, o->key, o->val);
357  if (ret < 0)
358  return ret;
359  }
360 
361  av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
362 
363  return 0;
364 }
365 
366 int locate_option(int argc, char **argv, const OptionDef *options,
367  const char *optname)
368 {
369  const OptionDef *po;
370  int i;
371 
372  for (i = 1; i < argc; i++) {
373  const char *cur_opt = argv[i];
374 
375  if (*cur_opt++ != '-')
376  continue;
377 
378  po = find_option(options, cur_opt);
379  if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
380  po = find_option(options, cur_opt + 2);
381 
382  if ((!po->name && !strcmp(cur_opt, optname)) ||
383  (po->name && !strcmp(optname, po->name)))
384  return i;
385 
386  if (!po || po->flags & HAS_ARG)
387  i++;
388  }
389  return 0;
390 }
391 
392 void parse_loglevel(int argc, char **argv, const OptionDef *options)
393 {
394  int idx = locate_option(argc, argv, options, "loglevel");
395  if (!idx)
396  idx = locate_option(argc, argv, options, "v");
397  if (idx && argv[idx + 1])
398  opt_loglevel(NULL, "loglevel", argv[idx + 1]);
399 }
400 
401 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
402 int opt_default(void *optctx, const char *opt, const char *arg)
403 {
404  const AVOption *o;
405  char opt_stripped[128];
406  const char *p;
407  const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
408 #if CONFIG_SWSCALE
409  const AVClass *sc = sws_get_class();
410 #endif
411 
412  if (!(p = strchr(opt, ':')))
413  p = opt + strlen(opt);
414  av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
415 
416  if ((o = av_opt_find(&cc, opt_stripped, NULL, 0,
418  ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
419  (o = av_opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ))))
420  av_dict_set(&codec_opts, opt, arg, FLAGS);
421  else if ((o = av_opt_find(&fc, opt, NULL, 0,
423  av_dict_set(&format_opts, opt, arg, FLAGS);
424 #if CONFIG_SWSCALE
425  else if ((o = av_opt_find(&sc, opt, NULL, 0,
427  // XXX we only support sws_flags, not arbitrary sws options
428  int ret = av_opt_set(sws_opts, opt, arg, 0);
429  if (ret < 0) {
430  av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
431  return ret;
432  }
433  }
434 #endif
435 
436  if (o)
437  return 0;
439 }
440 
441 /*
442  * Check whether given option is a group separator.
443  *
444  * @return index of the group definition that matched or -1 if none
445  */
446 static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
447  const char *opt)
448 {
449  int i;
450 
451  for (i = 0; i < nb_groups; i++) {
452  const OptionGroupDef *p = &groups[i];
453  if (p->sep && !strcmp(p->sep, opt))
454  return i;
455  }
456 
457  return -1;
458 }
459 
460 /*
461  * Finish parsing an option group.
462  *
463  * @param group_idx which group definition should this group belong to
464  * @param arg argument of the group delimiting option
465  */
466 static void finish_group(OptionParseContext *octx, int group_idx,
467  const char *arg)
468 {
469  OptionGroupList *l = &octx->groups[group_idx];
470  OptionGroup *g;
471 
472  GROW_ARRAY(l->groups, l->nb_groups);
473  g = &l->groups[l->nb_groups - 1];
474 
475  *g = octx->cur_group;
476  g->arg = arg;
477  g->group_def = l->group_def;
478 #if CONFIG_SWSCALE
479  g->sws_opts = sws_opts;
480 #endif
481  g->codec_opts = codec_opts;
483 
484  codec_opts = NULL;
485  format_opts = NULL;
486 #if CONFIG_SWSCALE
487  sws_opts = NULL;
488 #endif
489  init_opts();
490 
491  memset(&octx->cur_group, 0, sizeof(octx->cur_group));
492 }
493 
494 /*
495  * Add an option instance to currently parsed group.
496  */
497 static void add_opt(OptionParseContext *octx, const OptionDef *opt,
498  const char *key, const char *val)
499 {
500  int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
501  OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
502 
503  GROW_ARRAY(g->opts, g->nb_opts);
504  g->opts[g->nb_opts - 1].opt = opt;
505  g->opts[g->nb_opts - 1].key = key;
506  g->opts[g->nb_opts - 1].val = val;
507 }
508 
510  const OptionGroupDef *groups, int nb_groups)
511 {
512  static const OptionGroupDef global_group = { "global" };
513  int i;
514 
515  memset(octx, 0, sizeof(*octx));
516 
517  octx->nb_groups = nb_groups;
518  octx->groups = av_mallocz(sizeof(*octx->groups) * octx->nb_groups);
519  if (!octx->groups)
520  exit(1);
521 
522  for (i = 0; i < octx->nb_groups; i++)
523  octx->groups[i].group_def = &groups[i];
524 
525  octx->global_opts.group_def = &global_group;
526  octx->global_opts.arg = "";
527 
528  init_opts();
529 }
530 
532 {
533  int i, j;
534 
535  for (i = 0; i < octx->nb_groups; i++) {
536  OptionGroupList *l = &octx->groups[i];
537 
538  for (j = 0; j < l->nb_groups; j++) {
539  av_freep(&l->groups[j].opts);
542 #if CONFIG_SWSCALE
544 #endif
545  }
546  av_freep(&l->groups);
547  }
548  av_freep(&octx->groups);
549 
550  av_freep(&octx->cur_group.opts);
551  av_freep(&octx->global_opts.opts);
552 
553  uninit_opts();
554 }
555 
556 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
557  const OptionDef *options,
558  const OptionGroupDef *groups, int nb_groups)
559 {
560  int optindex = 1;
561 
562  /* perform system-dependent conversions for arguments list */
563  prepare_app_arguments(&argc, &argv);
564 
565  init_parse_context(octx, groups, nb_groups);
566  av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
567 
568  while (optindex < argc) {
569  const char *opt = argv[optindex++], *arg;
570  const OptionDef *po;
571  int ret;
572 
573  av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
574 
575  /* unnamed group separators, e.g. output filename */
576  if (opt[0] != '-' || !opt[1]) {
577  finish_group(octx, 0, opt);
578  av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
579  continue;
580  }
581  opt++;
582 
583 #define GET_ARG(arg) \
584 do { \
585  arg = argv[optindex++]; \
586  if (!arg) { \
587  av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
588  return AVERROR(EINVAL); \
589  } \
590 } while (0)
591 
592  /* named group separators, e.g. -i */
593  if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
594  GET_ARG(arg);
595  finish_group(octx, ret, arg);
596  av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
597  groups[ret].name, arg);
598  continue;
599  }
600 
601  /* normal options */
602  po = find_option(options, opt);
603  if (po->name) {
604  if (po->flags & OPT_EXIT) {
605  /* optional argument, e.g. -h */
606  arg = argv[optindex++];
607  } else if (po->flags & HAS_ARG) {
608  GET_ARG(arg);
609  } else {
610  arg = "1";
611  }
612 
613  add_opt(octx, po, opt, arg);
614  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
615  "argument '%s'.\n", po->name, po->help, arg);
616  continue;
617  }
618 
619  /* AVOptions */
620  if (argv[optindex]) {
621  ret = opt_default(NULL, opt, argv[optindex]);
622  if (ret >= 0) {
623  av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
624  "argument '%s'.\n", opt, argv[optindex]);
625  optindex++;
626  continue;
627  } else if (ret != AVERROR_OPTION_NOT_FOUND) {
628  av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
629  "with argument '%s'.\n", opt, argv[optindex]);
630  return ret;
631  }
632  }
633 
634  /* boolean -nofoo options */
635  if (opt[0] == 'n' && opt[1] == 'o' &&
636  (po = find_option(options, opt + 2)) &&
637  po->name && po->flags & OPT_BOOL) {
638  add_opt(octx, po, opt, "0");
639  av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
640  "argument 0.\n", po->name, po->help);
641  continue;
642  }
643 
644  av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
646  }
647 
648  if (octx->cur_group.nb_opts || codec_opts || format_opts)
649  av_log(NULL, AV_LOG_WARNING, "Trailing options were found on the "
650  "commandline.\n");
651 
652  av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
653 
654  return 0;
655 }
656 
657 int opt_loglevel(void *optctx, const char *opt, const char *arg)
658 {
659  const struct { const char *name; int level; } log_levels[] = {
660  { "quiet" , AV_LOG_QUIET },
661  { "panic" , AV_LOG_PANIC },
662  { "fatal" , AV_LOG_FATAL },
663  { "error" , AV_LOG_ERROR },
664  { "warning", AV_LOG_WARNING },
665  { "info" , AV_LOG_INFO },
666  { "verbose", AV_LOG_VERBOSE },
667  { "debug" , AV_LOG_DEBUG },
668  };
669  char *tail;
670  int level;
671  int i;
672 
673  for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
674  if (!strcmp(log_levels[i].name, arg)) {
675  av_log_set_level(log_levels[i].level);
676  return 0;
677  }
678  }
679 
680  level = strtol(arg, &tail, 10);
681  if (*tail) {
682  av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
683  "Possible levels are numbers or:\n", arg);
684  for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
685  av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
686  exit(1);
687  }
688  av_log_set_level(level);
689  return 0;
690 }
691 
692 int opt_timelimit(void *optctx, const char *opt, const char *arg)
693 {
694 #if HAVE_SETRLIMIT
695  int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
696  struct rlimit rl = { lim, lim + 1 };
697  if (setrlimit(RLIMIT_CPU, &rl))
698  perror("setrlimit");
699 #else
700  av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
701 #endif
702  return 0;
703 }
704 
705 void print_error(const char *filename, int err)
706 {
707  char errbuf[128];
708  const char *errbuf_ptr = errbuf;
709 
710  if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
711  errbuf_ptr = strerror(AVUNERROR(err));
712  av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
713 }
714 
715 // Debian/Ubuntu: see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=619530
716 // https://launchpad.net/bugs/765357
717 static int warned_cfg = 1;
718 
719 #define INDENT 1
720 #define SHOW_VERSION 2
721 #define SHOW_CONFIG 4
722 
723 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
724  if (CONFIG_##LIBNAME) { \
725  const char *indent = flags & INDENT? " " : ""; \
726  if (flags & SHOW_VERSION) { \
727  unsigned int version = libname##_version(); \
728  av_log(NULL, level, \
729  "%slib%-10s %2d.%3d.%2d / %2d.%3d.%2d\n", \
730  indent, #libname, \
731  LIB##LIBNAME##_VERSION_MAJOR, \
732  LIB##LIBNAME##_VERSION_MINOR, \
733  LIB##LIBNAME##_VERSION_MICRO, \
734  version >> 16, version >> 8 & 0xff, version & 0xff); \
735  } \
736  if (flags & SHOW_CONFIG) { \
737  const char *cfg = libname##_configuration(); \
738  if (strcmp(LIBAV_CONFIGURATION, cfg)) { \
739  if (!warned_cfg) { \
740  av_log(NULL, level, \
741  "%sWARNING: library configuration mismatch\n", \
742  indent); \
743  warned_cfg = 1; \
744  } \
745  av_log(NULL, level, "%s%-11s configuration: %s\n", \
746  indent, #libname, cfg); \
747  } \
748  } \
749  } \
750 
751 static void print_all_libs_info(int flags, int level)
752 {
753  PRINT_LIB_INFO(avutil, AVUTIL, flags, level);
754  PRINT_LIB_INFO(avcodec, AVCODEC, flags, level);
755  PRINT_LIB_INFO(avformat, AVFORMAT, flags, level);
756  PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
757  PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
758  PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level);
759  PRINT_LIB_INFO(swscale, SWSCALE, flags, level);
760 }
761 
762 void show_banner(void)
763 {
765  "%s version " LIBAV_VERSION ", Copyright (c) %d-%d the Libav developers\n",
767  av_log(NULL, AV_LOG_INFO, " built on %s %s with %s\n",
768  __DATE__, __TIME__, CC_IDENT);
769  av_log(NULL, AV_LOG_VERBOSE, " configuration: " LIBAV_CONFIGURATION "\n");
772 }
773 
774 int show_version(void *optctx, const char *opt, const char *arg)
775 {
777  printf("%s " LIBAV_VERSION "\n", program_name);
779 
780  return 0;
781 }
782 
783 int show_license(void *optctx, const char *opt, const char *arg)
784 {
785  printf(
786 #if CONFIG_NONFREE
787  "This version of %s has nonfree parts compiled in.\n"
788  "Therefore it is not legally redistributable.\n",
790 #elif CONFIG_GPLV3
791  "%s is free software; you can redistribute it and/or modify\n"
792  "it under the terms of the GNU General Public License as published by\n"
793  "the Free Software Foundation; either version 3 of the License, or\n"
794  "(at your option) any later version.\n"
795  "\n"
796  "%s is distributed in the hope that it will be useful,\n"
797  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
798  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
799  "GNU General Public License for more details.\n"
800  "\n"
801  "You should have received a copy of the GNU General Public License\n"
802  "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
804 #elif CONFIG_GPL
805  "%s is free software; you can redistribute it and/or modify\n"
806  "it under the terms of the GNU General Public License as published by\n"
807  "the Free Software Foundation; either version 2 of the License, or\n"
808  "(at your option) any later version.\n"
809  "\n"
810  "%s is distributed in the hope that it will be useful,\n"
811  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
812  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
813  "GNU General Public License for more details.\n"
814  "\n"
815  "You should have received a copy of the GNU General Public License\n"
816  "along with %s; if not, write to the Free Software\n"
817  "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
819 #elif CONFIG_LGPLV3
820  "%s is free software; you can redistribute it and/or modify\n"
821  "it under the terms of the GNU Lesser General Public License as published by\n"
822  "the Free Software Foundation; either version 3 of the License, or\n"
823  "(at your option) any later version.\n"
824  "\n"
825  "%s is distributed in the hope that it will be useful,\n"
826  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
827  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
828  "GNU Lesser General Public License for more details.\n"
829  "\n"
830  "You should have received a copy of the GNU Lesser General Public License\n"
831  "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
833 #else
834  "%s is free software; you can redistribute it and/or\n"
835  "modify it under the terms of the GNU Lesser General Public\n"
836  "License as published by the Free Software Foundation; either\n"
837  "version 2.1 of the License, or (at your option) any later version.\n"
838  "\n"
839  "%s is distributed in the hope that it will be useful,\n"
840  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
841  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
842  "Lesser General Public License for more details.\n"
843  "\n"
844  "You should have received a copy of the GNU Lesser General Public\n"
845  "License along with %s; if not, write to the Free Software\n"
846  "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
848 #endif
849  );
850 
851  return 0;
852 }
853 
854 int show_formats(void *optctx, const char *opt, const char *arg)
855 {
856  AVInputFormat *ifmt = NULL;
857  AVOutputFormat *ofmt = NULL;
858  const char *last_name;
859 
860  printf("File formats:\n"
861  " D. = Demuxing supported\n"
862  " .E = Muxing supported\n"
863  " --\n");
864  last_name = "000";
865  for (;;) {
866  int decode = 0;
867  int encode = 0;
868  const char *name = NULL;
869  const char *long_name = NULL;
870 
871  while ((ofmt = av_oformat_next(ofmt))) {
872  if ((name == NULL || strcmp(ofmt->name, name) < 0) &&
873  strcmp(ofmt->name, last_name) > 0) {
874  name = ofmt->name;
875  long_name = ofmt->long_name;
876  encode = 1;
877  }
878  }
879  while ((ifmt = av_iformat_next(ifmt))) {
880  if ((name == NULL || strcmp(ifmt->name, name) < 0) &&
881  strcmp(ifmt->name, last_name) > 0) {
882  name = ifmt->name;
883  long_name = ifmt->long_name;
884  encode = 0;
885  }
886  if (name && strcmp(ifmt->name, name) == 0)
887  decode = 1;
888  }
889  if (name == NULL)
890  break;
891  last_name = name;
892 
893  printf(" %s%s %-15s %s\n",
894  decode ? "D" : " ",
895  encode ? "E" : " ",
896  name,
897  long_name ? long_name:" ");
898  }
899  return 0;
900 }
901 
902 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
903  if (codec->field) { \
904  const type *p = c->field; \
905  \
906  printf(" Supported " list_name ":"); \
907  while (*p != term) { \
908  get_name(*p); \
909  printf(" %s", name); \
910  p++; \
911  } \
912  printf("\n"); \
913  } \
914 
915 static void print_codec(const AVCodec *c)
916 {
917  int encoder = av_codec_is_encoder(c);
918 
919  printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
920  c->long_name ? c->long_name : "");
921 
922  if (c->type == AVMEDIA_TYPE_VIDEO) {
923  printf(" Threading capabilities: ");
924  switch (c->capabilities & (CODEC_CAP_FRAME_THREADS |
927  CODEC_CAP_SLICE_THREADS: printf("frame and slice"); break;
928  case CODEC_CAP_FRAME_THREADS: printf("frame"); break;
929  case CODEC_CAP_SLICE_THREADS: printf("slice"); break;
930  default: printf("no"); break;
931  }
932  printf("\n");
933  }
934 
935  if (c->supported_framerates) {
936  const AVRational *fps = c->supported_framerates;
937 
938  printf(" Supported framerates:");
939  while (fps->num) {
940  printf(" %d/%d", fps->num, fps->den);
941  fps++;
942  }
943  printf("\n");
944  }
945  PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
947  PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
949  PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
951  PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts",
952  0, GET_CH_LAYOUT_DESC);
953 
954  if (c->priv_class) {
958  }
959 }
960 
961 static char get_media_type_char(enum AVMediaType type)
962 {
963  switch (type) {
964  case AVMEDIA_TYPE_VIDEO: return 'V';
965  case AVMEDIA_TYPE_AUDIO: return 'A';
966  case AVMEDIA_TYPE_SUBTITLE: return 'S';
967  default: return '?';
968  }
969 }
970 
971 static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev,
972  int encoder)
973 {
974  while ((prev = av_codec_next(prev))) {
975  if (prev->id == id &&
976  (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev)))
977  return prev;
978  }
979  return NULL;
980 }
981 
982 static void print_codecs_for_id(enum AVCodecID id, int encoder)
983 {
984  const AVCodec *codec = NULL;
985 
986  printf(" (%s: ", encoder ? "encoders" : "decoders");
987 
988  while ((codec = next_codec_for_id(id, codec, encoder)))
989  printf("%s ", codec->name);
990 
991  printf(")");
992 }
993 
994 int show_codecs(void *optctx, const char *opt, const char *arg)
995 {
996  const AVCodecDescriptor *desc = NULL;
997 
998  printf("Codecs:\n"
999  " D..... = Decoding supported\n"
1000  " .E.... = Encoding supported\n"
1001  " ..V... = Video codec\n"
1002  " ..A... = Audio codec\n"
1003  " ..S... = Subtitle codec\n"
1004  " ...I.. = Intra frame-only codec\n"
1005  " ....L. = Lossy compression\n"
1006  " .....S = Lossless compression\n"
1007  " -------\n");
1008  while ((desc = avcodec_descriptor_next(desc))) {
1009  const AVCodec *codec = NULL;
1010 
1011  printf(avcodec_find_decoder(desc->id) ? "D" : ".");
1012  printf(avcodec_find_encoder(desc->id) ? "E" : ".");
1013 
1014  printf("%c", get_media_type_char(desc->type));
1015  printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
1016  printf((desc->props & AV_CODEC_PROP_LOSSY) ? "L" : ".");
1017  printf((desc->props & AV_CODEC_PROP_LOSSLESS) ? "S" : ".");
1018 
1019  printf(" %-20s %s", desc->name, desc->long_name ? desc->long_name : "");
1020 
1021  /* print decoders/encoders when there's more than one or their
1022  * names are different from codec name */
1023  while ((codec = next_codec_for_id(desc->id, codec, 0))) {
1024  if (strcmp(codec->name, desc->name)) {
1025  print_codecs_for_id(desc->id, 0);
1026  break;
1027  }
1028  }
1029  codec = NULL;
1030  while ((codec = next_codec_for_id(desc->id, codec, 1))) {
1031  if (strcmp(codec->name, desc->name)) {
1032  print_codecs_for_id(desc->id, 1);
1033  break;
1034  }
1035  }
1036 
1037  printf("\n");
1038  }
1039  return 0;
1040 }
1041 
1042 static void print_codecs(int encoder)
1043 {
1044  const AVCodecDescriptor *desc = NULL;
1045 
1046  printf("%s:\n"
1047  " V... = Video\n"
1048  " A... = Audio\n"
1049  " S... = Subtitle\n"
1050  " .F.. = Frame-level multithreading\n"
1051  " ..S. = Slice-level multithreading\n"
1052  " ...X = Codec is experimental\n"
1053  " ---\n",
1054  encoder ? "Encoders" : "Decoders");
1055  while ((desc = avcodec_descriptor_next(desc))) {
1056  const AVCodec *codec = NULL;
1057 
1058  while ((codec = next_codec_for_id(desc->id, codec, encoder))) {
1059  printf("%c", get_media_type_char(desc->type));
1060  printf((codec->capabilities & CODEC_CAP_FRAME_THREADS) ? "F" : ".");
1061  printf((codec->capabilities & CODEC_CAP_SLICE_THREADS) ? "S" : ".");
1062  printf((codec->capabilities & CODEC_CAP_EXPERIMENTAL) ? "X" : ".");
1063 
1064  printf(" %-20s %s", codec->name, codec->long_name ? codec->long_name : "");
1065  if (strcmp(codec->name, desc->name))
1066  printf(" (codec %s)", desc->name);
1067 
1068  printf("\n");
1069  }
1070  }
1071 }
1072 
1073 int show_decoders(void *optctx, const char *opt, const char *arg)
1074 {
1075  print_codecs(0);
1076  return 0;
1077 }
1078 
1079 int show_encoders(void *optctx, const char *opt, const char *arg)
1080 {
1081  print_codecs(1);
1082  return 0;
1083 }
1084 
1085 int show_bsfs(void *optctx, const char *opt, const char *arg)
1086 {
1087  AVBitStreamFilter *bsf = NULL;
1088 
1089  printf("Bitstream filters:\n");
1090  while ((bsf = av_bitstream_filter_next(bsf)))
1091  printf("%s\n", bsf->name);
1092  printf("\n");
1093  return 0;
1094 }
1095 
1096 int show_protocols(void *optctx, const char *opt, const char *arg)
1097 {
1098  void *opaque = NULL;
1099  const char *name;
1100 
1101  printf("Supported file protocols:\n"
1102  "Input:\n");
1103  while ((name = avio_enum_protocols(&opaque, 0)))
1104  printf("%s\n", name);
1105  printf("Output:\n");
1106  while ((name = avio_enum_protocols(&opaque, 1)))
1107  printf("%s\n", name);
1108  return 0;
1109 }
1110 
1111 int show_filters(void *optctx, const char *opt, const char *arg)
1112 {
1114 
1115  printf("Filters:\n");
1116 #if CONFIG_AVFILTER
1117  while ((filter = av_filter_next(filter)) && *filter)
1118  printf("%-16s %s\n", (*filter)->name, (*filter)->description);
1119 #endif
1120  return 0;
1121 }
1122 
1123 int show_pix_fmts(void *optctx, const char *opt, const char *arg)
1124 {
1125  const AVPixFmtDescriptor *pix_desc = NULL;
1126 
1127  printf("Pixel formats:\n"
1128  "I.... = Supported Input format for conversion\n"
1129  ".O... = Supported Output format for conversion\n"
1130  "..H.. = Hardware accelerated format\n"
1131  "...P. = Paletted format\n"
1132  "....B = Bitstream format\n"
1133  "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1134  "-----\n");
1135 
1136 #if !CONFIG_SWSCALE
1137 # define sws_isSupportedInput(x) 0
1138 # define sws_isSupportedOutput(x) 0
1139 #endif
1140 
1141  while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
1142  enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
1143  printf("%c%c%c%c%c %-16s %d %2d\n",
1144  sws_isSupportedInput (pix_fmt) ? 'I' : '.',
1145  sws_isSupportedOutput(pix_fmt) ? 'O' : '.',
1146  pix_desc->flags & PIX_FMT_HWACCEL ? 'H' : '.',
1147  pix_desc->flags & PIX_FMT_PAL ? 'P' : '.',
1148  pix_desc->flags & PIX_FMT_BITSTREAM ? 'B' : '.',
1149  pix_desc->name,
1150  pix_desc->nb_components,
1151  av_get_bits_per_pixel(pix_desc));
1152  }
1153  return 0;
1154 }
1155 
1156 int show_sample_fmts(void *optctx, const char *opt, const char *arg)
1157 {
1158  int i;
1159  char fmt_str[128];
1160  for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
1161  printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
1162  return 0;
1163 }
1164 
1165 static void show_help_codec(const char *name, int encoder)
1166 {
1167  const AVCodecDescriptor *desc;
1168  const AVCodec *codec;
1169 
1170  if (!name) {
1171  av_log(NULL, AV_LOG_ERROR, "No codec name specified.\n");
1172  return;
1173  }
1174 
1175  codec = encoder ? avcodec_find_encoder_by_name(name) :
1177 
1178  if (codec)
1179  print_codec(codec);
1180  else if ((desc = avcodec_descriptor_get_by_name(name))) {
1181  int printed = 0;
1182 
1183  while ((codec = next_codec_for_id(desc->id, codec, encoder))) {
1184  printed = 1;
1185  print_codec(codec);
1186  }
1187 
1188  if (!printed) {
1189  av_log(NULL, AV_LOG_ERROR, "Codec '%s' is known to Libav, "
1190  "but no %s for it are available. Libav might need to be "
1191  "recompiled with additional external libraries.\n",
1192  name, encoder ? "encoders" : "decoders");
1193  }
1194  } else {
1195  av_log(NULL, AV_LOG_ERROR, "Codec '%s' is not recognized by Libav.\n",
1196  name);
1197  }
1198 }
1199 
1200 static void show_help_demuxer(const char *name)
1201 {
1202  const AVInputFormat *fmt = av_find_input_format(name);
1203 
1204  if (!fmt) {
1205  av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
1206  return;
1207  }
1208 
1209  printf("Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
1210 
1211  if (fmt->extensions)
1212  printf(" Common extensions: %s.\n", fmt->extensions);
1213 
1214  if (fmt->priv_class)
1216 }
1217 
1218 static void show_help_muxer(const char *name)
1219 {
1220  const AVCodecDescriptor *desc;
1221  const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
1222 
1223  if (!fmt) {
1224  av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
1225  return;
1226  }
1227 
1228  printf("Muxer %s [%s]:\n", fmt->name, fmt->long_name);
1229 
1230  if (fmt->extensions)
1231  printf(" Common extensions: %s.\n", fmt->extensions);
1232  if (fmt->mime_type)
1233  printf(" Mime type: %s.\n", fmt->mime_type);
1234  if (fmt->video_codec != AV_CODEC_ID_NONE &&
1235  (desc = avcodec_descriptor_get(fmt->video_codec))) {
1236  printf(" Default video codec: %s.\n", desc->name);
1237  }
1238  if (fmt->audio_codec != AV_CODEC_ID_NONE &&
1239  (desc = avcodec_descriptor_get(fmt->audio_codec))) {
1240  printf(" Default audio codec: %s.\n", desc->name);
1241  }
1242  if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
1243  (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
1244  printf(" Default subtitle codec: %s.\n", desc->name);
1245  }
1246 
1247  if (fmt->priv_class)
1249 }
1250 
1251 int show_help(void *optctx, const char *opt, const char *arg)
1252 {
1253  char *topic, *par;
1255 
1256  topic = av_strdup(arg ? arg : "");
1257  par = strchr(topic, '=');
1258  if (par)
1259  *par++ = 0;
1260 
1261  if (!*topic) {
1262  show_help_default(topic, par);
1263  } else if (!strcmp(topic, "decoder")) {
1264  show_help_codec(par, 0);
1265  } else if (!strcmp(topic, "encoder")) {
1266  show_help_codec(par, 1);
1267  } else if (!strcmp(topic, "demuxer")) {
1268  show_help_demuxer(par);
1269  } else if (!strcmp(topic, "muxer")) {
1270  show_help_muxer(par);
1271  } else {
1272  show_help_default(topic, par);
1273  }
1274 
1275  av_freep(&topic);
1276  return 0;
1277 }
1278 
1279 int read_yesno(void)
1280 {
1281  int c = getchar();
1282  int yesno = (toupper(c) == 'Y');
1283 
1284  while (c != '\n' && c != EOF)
1285  c = getchar();
1286 
1287  return yesno;
1288 }
1289 
1290 int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
1291 {
1292  int ret;
1293  FILE *f = fopen(filename, "rb");
1294 
1295  if (!f) {
1296  av_log(NULL, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename,
1297  strerror(errno));
1298  return AVERROR(errno);
1299  }
1300  fseek(f, 0, SEEK_END);
1301  *size = ftell(f);
1302  fseek(f, 0, SEEK_SET);
1303  *bufptr = av_malloc(*size + 1);
1304  if (!*bufptr) {
1305  av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n");
1306  fclose(f);
1307  return AVERROR(ENOMEM);
1308  }
1309  ret = fread(*bufptr, 1, *size, f);
1310  if (ret < *size) {
1311  av_free(*bufptr);
1312  if (ferror(f)) {
1313  av_log(NULL, AV_LOG_ERROR, "Error while reading file '%s': %s\n",
1314  filename, strerror(errno));
1315  ret = AVERROR(errno);
1316  } else
1317  ret = AVERROR_EOF;
1318  } else {
1319  ret = 0;
1320  (*bufptr)[(*size)++] = '\0';
1321  }
1322 
1323  fclose(f);
1324  return ret;
1325 }
1326 
1328 {
1329  ctx->num_faulty_pts = ctx->num_faulty_dts = 0;
1330  ctx->last_pts = ctx->last_dts = INT64_MIN;
1331 }
1332 
1333 int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts,
1334  int64_t dts)
1335 {
1336  int64_t pts = AV_NOPTS_VALUE;
1337 
1338  if (dts != AV_NOPTS_VALUE) {
1339  ctx->num_faulty_dts += dts <= ctx->last_dts;
1340  ctx->last_dts = dts;
1341  }
1342  if (reordered_pts != AV_NOPTS_VALUE) {
1343  ctx->num_faulty_pts += reordered_pts <= ctx->last_pts;
1344  ctx->last_pts = reordered_pts;
1345  }
1346  if ((ctx->num_faulty_pts<=ctx->num_faulty_dts || dts == AV_NOPTS_VALUE)
1347  && reordered_pts != AV_NOPTS_VALUE)
1348  pts = reordered_pts;
1349  else
1350  pts = dts;
1351 
1352  return pts;
1353 }
1354 
1355 FILE *get_preset_file(char *filename, size_t filename_size,
1356  const char *preset_name, int is_path,
1357  const char *codec_name)
1358 {
1359  FILE *f = NULL;
1360  int i;
1361  const char *base[3] = { getenv("AVCONV_DATADIR"),
1362  getenv("HOME"),
1363  AVCONV_DATADIR, };
1364 
1365  if (is_path) {
1366  av_strlcpy(filename, preset_name, filename_size);
1367  f = fopen(filename, "r");
1368  } else {
1369  for (i = 0; i < 3 && !f; i++) {
1370  if (!base[i])
1371  continue;
1372  snprintf(filename, filename_size, "%s%s/%s.avpreset", base[i],
1373  i != 1 ? "" : "/.avconv", preset_name);
1374  f = fopen(filename, "r");
1375  if (!f && codec_name) {
1376  snprintf(filename, filename_size,
1377  "%s%s/%s-%s.avpreset",
1378  base[i], i != 1 ? "" : "/.avconv", codec_name,
1379  preset_name);
1380  f = fopen(filename, "r");
1381  }
1382  }
1383  }
1384 
1385  return f;
1386 }
1387 
1388 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
1389 {
1390  if (*spec <= '9' && *spec >= '0') /* opt:index */
1391  return strtol(spec, NULL, 0) == st->index;
1392  else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
1393  *spec == 't') { /* opt:[vasdt] */
1394  enum AVMediaType type;
1395 
1396  switch (*spec++) {
1397  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
1398  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
1399  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
1400  case 'd': type = AVMEDIA_TYPE_DATA; break;
1401  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
1402  default: av_assert0(0);
1403  }
1404  if (type != st->codec->codec_type)
1405  return 0;
1406  if (*spec++ == ':') { /* possibly followed by :index */
1407  int i, index = strtol(spec, NULL, 0);
1408  for (i = 0; i < s->nb_streams; i++)
1409  if (s->streams[i]->codec->codec_type == type && index-- == 0)
1410  return i == st->index;
1411  return 0;
1412  }
1413  return 1;
1414  } else if (*spec == 'p' && *(spec + 1) == ':') {
1415  int prog_id, i, j;
1416  char *endptr;
1417  spec += 2;
1418  prog_id = strtol(spec, &endptr, 0);
1419  for (i = 0; i < s->nb_programs; i++) {
1420  if (s->programs[i]->id != prog_id)
1421  continue;
1422 
1423  if (*endptr++ == ':') {
1424  int stream_idx = strtol(endptr, NULL, 0);
1425  return stream_idx >= 0 &&
1426  stream_idx < s->programs[i]->nb_stream_indexes &&
1427  st->index == s->programs[i]->stream_index[stream_idx];
1428  }
1429 
1430  for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)
1431  if (st->index == s->programs[i]->stream_index[j])
1432  return 1;
1433  }
1434  return 0;
1435  } else if (!*spec) /* empty specifier, matches everything */
1436  return 1;
1437 
1438  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
1439  return AVERROR(EINVAL);
1440 }
1441 
1443  AVFormatContext *s, AVStream *st, AVCodec *codec)
1444 {
1445  AVDictionary *ret = NULL;
1449  char prefix = 0;
1450  const AVClass *cc = avcodec_get_class();
1451 
1452  if (!codec)
1453  codec = s->oformat ? avcodec_find_encoder(codec_id)
1454  : avcodec_find_decoder(codec_id);
1455  if (!codec)
1456  return NULL;
1457 
1458  switch (codec->type) {
1459  case AVMEDIA_TYPE_VIDEO:
1460  prefix = 'v';
1461  flags |= AV_OPT_FLAG_VIDEO_PARAM;
1462  break;
1463  case AVMEDIA_TYPE_AUDIO:
1464  prefix = 'a';
1465  flags |= AV_OPT_FLAG_AUDIO_PARAM;
1466  break;
1467  case AVMEDIA_TYPE_SUBTITLE:
1468  prefix = 's';
1469  flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
1470  break;
1471  }
1472 
1473  while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) {
1474  char *p = strchr(t->key, ':');
1475 
1476  /* check stream specification in opt name */
1477  if (p)
1478  switch (check_stream_specifier(s, st, p + 1)) {
1479  case 1: *p = 0; break;
1480  case 0: continue;
1481  default: return NULL;
1482  }
1483 
1484  if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
1485  (codec && codec->priv_class &&
1486  av_opt_find(&codec->priv_class, t->key, NULL, flags,
1488  av_dict_set(&ret, t->key, t->value, 0);
1489  else if (t->key[0] == prefix &&
1490  av_opt_find(&cc, t->key + 1, NULL, flags,
1492  av_dict_set(&ret, t->key + 1, t->value, 0);
1493 
1494  if (p)
1495  *p = ':';
1496  }
1497  return ret;
1498 }
1499 
1501  AVDictionary *codec_opts)
1502 {
1503  int i;
1504  AVDictionary **opts;
1505 
1506  if (!s->nb_streams)
1507  return NULL;
1508  opts = av_mallocz(s->nb_streams * sizeof(*opts));
1509  if (!opts) {
1511  "Could not alloc memory for stream options.\n");
1512  return NULL;
1513  }
1514  for (i = 0; i < s->nb_streams; i++)
1515  opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codec->codec_id,
1516  s, s->streams[i], NULL);
1517  return opts;
1518 }
1519 
1520 void *grow_array(void *array, int elem_size, int *size, int new_size)
1521 {
1522  if (new_size >= INT_MAX / elem_size) {
1523  av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
1524  exit(1);
1525  }
1526  if (*size < new_size) {
1527  uint8_t *tmp = av_realloc(array, new_size*elem_size);
1528  if (!tmp) {
1529  av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
1530  exit(1);
1531  }
1532  memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1533  *size = new_size;
1534  return tmp;
1535  }
1536  return array;
1537 }
1538 
1539 static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbuf)
1540 {
1542  FrameBuffer *buf;
1543  int i, ret;
1544  int pixel_size;
1545  int h_chroma_shift, v_chroma_shift;
1546  int edge = 32; // XXX should be avcodec_get_edge_width(), but that fails on svq1
1547  int w = s->width, h = s->height;
1548 
1549  if (!desc)
1550  return AVERROR(EINVAL);
1551  pixel_size = desc->comp[0].step_minus1 + 1;
1552 
1553  buf = av_mallocz(sizeof(*buf));
1554  if (!buf)
1555  return AVERROR(ENOMEM);
1556 
1557  if (!(s->flags & CODEC_FLAG_EMU_EDGE)) {
1558  w += 2*edge;
1559  h += 2*edge;
1560  }
1561 
1562  avcodec_align_dimensions(s, &w, &h);
1563  if ((ret = av_image_alloc(buf->base, buf->linesize, w, h,
1564  s->pix_fmt, 32)) < 0) {
1565  av_freep(&buf);
1566  return ret;
1567  }
1568  /* XXX this shouldn't be needed, but some tests break without this line
1569  * those decoders are buggy and need to be fixed.
1570  * the following tests fail:
1571  * cdgraphics, ansi
1572  */
1573  memset(buf->base[0], 128, ret);
1574 
1576  &h_chroma_shift, &v_chroma_shift);
1577 
1578  for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {
1579  const int h_shift = i==0 ? 0 : h_chroma_shift;
1580  const int v_shift = i==0 ? 0 : v_chroma_shift;
1581  if (s->flags & CODEC_FLAG_EMU_EDGE)
1582  buf->data[i] = buf->base[i];
1583  else if (buf->base[i])
1584  buf->data[i] = buf->base[i] +
1585  FFALIGN((buf->linesize[i]*edge >> v_shift) +
1586  (pixel_size*edge >> h_shift), 32);
1587  }
1588  buf->w = s->width;
1589  buf->h = s->height;
1590  buf->pix_fmt = s->pix_fmt;
1591  buf->pool = pool;
1592 
1593  *pbuf = buf;
1594  return 0;
1595 }
1596 
1598 {
1599  FrameBuffer **pool = s->opaque;
1600  FrameBuffer *buf;
1601  int ret, i;
1602 
1603  if (!*pool && (ret = alloc_buffer(pool, s, pool)) < 0)
1604  return ret;
1605 
1606  buf = *pool;
1607  *pool = buf->next;
1608  buf->next = NULL;
1609  if (buf->w != s->width || buf->h != s->height || buf->pix_fmt != s->pix_fmt) {
1610  av_freep(&buf->base[0]);
1611  av_free(buf);
1612  if ((ret = alloc_buffer(pool, s, &buf)) < 0)
1613  return ret;
1614  }
1615  buf->refcount++;
1616 
1617  frame->opaque = buf;
1618  frame->type = FF_BUFFER_TYPE_USER;
1619  frame->extended_data = frame->data;
1620 
1621  for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {
1622  frame->base[i] = buf->base[i]; // XXX h264.c uses base though it shouldn't
1623  frame->data[i] = buf->data[i];
1624  frame->linesize[i] = buf->linesize[i];
1625  }
1626 
1627  return 0;
1628 }
1629 
1630 static void unref_buffer(FrameBuffer *buf)
1631 {
1632  FrameBuffer **pool = buf->pool;
1633 
1634  av_assert0(buf->refcount);
1635  buf->refcount--;
1636  if (!buf->refcount) {
1637  buf->next = *pool;
1638  *pool = buf;
1639  }
1640 }
1641 
1643 {
1644  FrameBuffer *buf = frame->opaque;
1645  int i;
1646 
1647  for (i = 0; i < FF_ARRAY_ELEMS(frame->data); i++)
1648  frame->data[i] = NULL;
1649 
1650  unref_buffer(buf);
1651 }
1652 
1654 {
1655  FrameBuffer *buf = fb->priv;
1656  av_free(fb);
1657  unref_buffer(buf);
1658 }
1659 
1661 {
1662  FrameBuffer *buf = *pool;
1663  while (buf) {
1664  *pool = buf->next;
1665  av_freep(&buf->base[0]);
1666  av_free(buf);
1667  buf = *pool;
1668  }
1669 }
int parse_optgroup(void *optctx, OptionGroup *g)
Parse an options group and write results into optctx.
Definition: cmdutils.c:343
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:63
#define INFINITY
Definition: math.h:6
int64_t num_faulty_dts
Number of incorrect PTS values so far.
Definition: cmdutils.h:454
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:61
int size
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1435
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
int show_decoders(void *optctx, const char *opt, const char *arg)
Print a listing containing all the decoders supported by the program.
Definition: cmdutils.c:1073
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:1496
const char * name
< group name
Definition: cmdutils.h:221
static void finish_group(OptionParseContext *octx, int group_idx, const char *arg)
Definition: cmdutils.c:466
#define FLAGS
Definition: cmdutils.c:401
int64_t num_faulty_pts
Definition: cmdutils.h:453
AVOption.
Definition: opt.h:233
int show_license(void *optctx, const char *opt, const char *arg)
Print the license of the program to stdout.
Definition: cmdutils.c:783
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:1628
int(* func_arg)(void *, const char *, const char *)
Definition: cmdutils.h:149
misc image utilities
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Definition: parseutils.c:482
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
Definition: imgutils.c:179
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
Split the commandline into an intermediate form convenient for further processing.
Definition: cmdutils.c:556
void show_banner(void)
Print the program banner to stderr.
Definition: cmdutils.c:762
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:1408
const AVClass * av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
Iterate over potential AVOptions-enabled children of parent.
Definition: opt.c:686
int opt_loglevel(void *optctx, const char *opt, const char *arg)
Set the libav* libraries log level.
Definition: cmdutils.c:657
enum AVCodecID video_codec
default video codec
Definition: avformat.h:387
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:1388
#define INDENT
Definition: cmdutils.c:719
void * opaque
for some private data of the user
Definition: avcodec.h:1202
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:623
uint8_t * data[4]
Definition: cmdutils.h:514
void * priv
private data to be used by a custom free function
Definition: avfilter.h:83
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
int show_protocols(void *optctx, const char *opt, const char *arg)
Print a listing containing all the protocols supported by the program.
Definition: cmdutils.c:1096
const char * arg
Definition: cmdutils.h:231
const char * sep
Option to be used as group separator.
Definition: cmdutils.h:226
#define GET_CH_LAYOUT_DESC(ch_layout)
Definition: cmdutils.h:569
A reference-counted buffer data type used by the filter system.
Definition: avfilter.h:62
int64_t last_pts
Number of incorrect DTS values so far.
Definition: cmdutils.h:455
enum AVMediaType type
Definition: avcodec.h:2973
int show_formats(void *optctx, const char *opt, const char *arg)
Print a listing containing all the formats supported by the program.
Definition: cmdutils.c:854
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Definition: log.c:178
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
int id
Definition: avformat.h:801
#define OPT_DOUBLE
Definition: cmdutils.h:146
#define CONFIG_GPLV3
Definition: config.h:333
#define OPT_FLOAT
Definition: cmdutils.h:134
AVCodec.
Definition: avcodec.h:2960
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
Definition: options.c:71
int show_pix_fmts(void *optctx, const char *opt, const char *arg)
Print a listing containing all the pixel formats supported by the program.
Definition: cmdutils.c:1123
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Filter out options for given codec.
Definition: cmdutils.c:1442
void init_pts_correction(PtsCorrectionContext *ctx)
Reset the state of the PtsCorrectionContext.
Definition: cmdutils.c:1327
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:531
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:125
const AVCodecDescriptor * avcodec_descriptor_next(const AVCodecDescriptor *prev)
Iterate over all codec descriptors known to libavcodec.
Definition: codec_desc.c:2197
Format I/O context.
Definition: avformat.h:828
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:197
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:120
unsigned int nb_stream_indexes
Definition: avformat.h:805
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
Modify width and height values so that they will result in a memory buffer that is acceptable for the...
Definition: utils.c:249
static int warned_cfg
Definition: cmdutils.c:717
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int show_codecs(void *optctx, const char *opt, const char *arg)
Print a listing containing all the codecs supported by the program.
Definition: cmdutils.c:994
Public dictionary API.
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
struct FrameBuffer * next
Definition: cmdutils.h:522
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:83
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
Definition: cmdutils.c:79
uint8_t
#define CC_IDENT
Definition: config.h:7
Opaque data information usually continuous.
Definition: avutil.h:181
int opt_default(void *optctx, const char *opt, const char *arg)
Fallback for options that are not explicitly handled, these will be parsed through AVOptions...
Definition: cmdutils.c:402
AVOptions.
#define HAS_ARG
Definition: cmdutils.h:127
void filter_release_buffer(AVFilterBuffer *fb)
A callback to be used for AVFilterBuffer.free.
Definition: cmdutils.c:1653
int nb_opts
Definition: cmdutils.h:234
#define OPT_OFFSET
Definition: cmdutils.h:141
static void init_parse_context(OptionParseContext *octx, const OptionGroupDef *groups, int nb_groups)
Definition: cmdutils.c:509
const char * name
void init_opts(void)
Initialize the cmdutils option system, in particular allocate the *_opts contexts.
Definition: cmdutils.c:61
AVStream ** streams
Definition: avformat.h:876
const char * name
Definition: avcodec.h:4490
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:480
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
Definition: cmdutils.c:312
static int flags
Definition: log.c:42
#define OPT_SPEC
Definition: cmdutils.h:142
static void print_all_libs_info(int flags, int level)
Definition: cmdutils.c:751
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:106
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
Definition: cmdutils.c:392
external api for the swscale stuff
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Print help for all options matching specified flags.
Definition: cmdutils.c:117
static void print_codecs(int encoder)
Definition: cmdutils.c:1042
unsigned int * stream_index
Definition: avformat.h:804
int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
Return index of option opt in argv or 0 if not found.
Definition: cmdutils.c:366
int codec_get_buffer(AVCodecContext *s, AVFrame *frame)
Get a frame from the pool.
Definition: cmdutils.c:1597
static float t
struct AVOutputFormat * oformat
Definition: avformat.h:842
const char * name
Definition: pixdesc.h:56
uint8_t * base[4]
Definition: cmdutils.h:513
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:1500
static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbuf)
Definition: cmdutils.c:1539
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:1501
AVDictionary * format_opts
Definition: cmdutils.c:57
#define AVCONV_DATADIR
Definition: config.h:6
int show_help(void *optctx, const char *opt, const char *arg)
Generic -h handler common to all avtools.
Definition: cmdutils.c:1251
Main libavdevice API header.
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:1282
enum AVCodecID id
Definition: avcodec.h:2974
void show_help_default(const char *opt, const char *arg)
Per-avtool specific help handler.
Definition: avconv_opt.c:1786
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:95
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:139
#define SWS_BICUBIC
Definition: swscale.h:55
const char * long_name
Descriptive name for the format, meant to be more human-readable than name.
Definition: avformat.h:382
int show_sample_fmts(void *optctx, const char *opt, const char *arg)
Print a listing containing all the sample formats supported by the program.
Definition: cmdutils.c:1156
sample_fmts
Definition: avconv_filter.c:63
#define sws_isSupportedOutput(x)
AVCodec * av_codec_next(const AVCodec *c)
If c is NULL, returns the first registered codec, if c is non-NULL, returns the next registered codec...
Definition: utils.c:101
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:1460
g
Definition: yuv2rgb.c:540
int capabilities
Codec capabilities.
Definition: avcodec.h:2979
unsigned int nb_programs
Definition: avformat.h:930
uint8_t * base[AV_NUM_DATA_POINTERS]
pointer to the first allocated byte of the picture.
Definition: avcodec.h:1073
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:113
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1434
const char * name
Definition: cmdutils.h:125
static void show_help_muxer(const char *name)
Definition: cmdutils.c:1218
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Parse one given option.
Definition: cmdutils.c:279
simple assert() macros that are a bit more flexible than ISO C assert().
#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name)
Definition: cmdutils.c:902
#define PIX_FMT_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:87
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
AVBitStreamFilter * av_bitstream_filter_next(AVBitStreamFilter *f)
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
int flags
Definition: cmdutils.h:126
void av_log_set_level(int level)
Definition: log.c:168
const char * long_name
A more descriptive name for this codec.
Definition: avcodec.h:462
const char * val
Definition: cmdutils.h:216
enum AVCodecID codec_id
Definition: mov_chan.c:432
#define LIBAV_CONFIGURATION
Definition: config.h:4
int show_filters(void *optctx, const char *opt, const char *arg)
Print a listing containing all the filters supported by the program.
Definition: cmdutils.c:1111
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:67
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2187
static const OptionDef * find_option(const OptionDef *po, const char *name)
Definition: cmdutils.c:156
int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect time...
Definition: cmdutils.c:1333
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:641
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: avcodec.h:466
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:636
void free_buffer_pool(FrameBuffer **pool)
Free all the buffers in the pool.
Definition: cmdutils.c:1660
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:318
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:875
static void unref_buffer(FrameBuffer *buf)
Definition: cmdutils.c:1630
enum AVPixelFormat pix_fmt
Definition: cmdutils.h:518
OptionGroup * groups
Definition: cmdutils.h:248
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:1451
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: utils.c:207
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
size_t off
Definition: cmdutils.h:150
external API header
int show_bsfs(void *optctx, const char *opt, const char *arg)
Print a listing containing all the bit stream filters supported by the program.
Definition: cmdutils.c:1085
int width
picture width / height.
Definition: avcodec.h:1508
int type
type of the buffer (to keep track of who has to deallocate data[*])
Definition: avcodec.h:1217
static void print_codecs_for_id(enum AVCodecID id, int encoder)
Definition: cmdutils.c:982
const char * avio_enum_protocols(void **opaque, int output)
Iterate through names of available protocols.
Definition: avio.c:86
const char * name
Definition: avformat.h:376
#define GET_PIX_FMT_NAME(pix_fmt)
Definition: cmdutils.h:555
const OptionGroupDef * group_def
Definition: cmdutils.h:246
A list of option groups that all have the same group type (e.g.
Definition: cmdutils.h:245
#define OPT_EXIT
Definition: cmdutils.h:137
int linesize[4]
Definition: cmdutils.h:515
#define PIX_FMT_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition: pixdesc.h:88
#define OPT_INT64
Definition: cmdutils.h:136
AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
Definition: utils.c:151
#define sws_isSupportedInput(x)
static const OptionGroupDef groups[]
Definition: avconv_opt.c:1862
AVFilter ** av_filter_next(AVFilter **filter)
If filter is NULL, returns a pointer to the first registered filter pointer, if filter is non-NULL...
Definition: avfilter.c:294
Opaque data information usually sparse.
Definition: avutil.h:183
enum AVPixelFormat pix_fmt
Definition: movenc.c:801
int opt_timelimit(void *optctx, const char *opt, const char *arg)
Limit the execution time.
Definition: cmdutils.c:692
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:404
void * dst_ptr
Definition: cmdutils.h:148
const AVCodecDescriptor * avcodec_descriptor_get_by_name(const char *name)
Definition: codec_desc.c:2206
AVOutputFormat * av_oformat_next(AVOutputFormat *f)
If f is NULL, returns the first registered output format, if f is non-NULL, returns the next register...
Definition: utils.c:82
const char * long_name
Descriptive name for the format, meant to be more human-readable than name.
Definition: avformat.h:462
Stream structure.
Definition: avformat.h:622
static char get_media_type_char(enum AVMediaType type)
Definition: cmdutils.c:961
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:77
#define GET_SAMPLE_RATE_NAME(rate)
Definition: cmdutils.h:561
#define PIX_FMT_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:89
const char * long_name
Descriptive name for the codec, meant to be more human readable than name.
Definition: avcodec.h:2972
NULL
Definition: eval.c:52
static const AVCodec * next_codec_for_id(enum AVCodecID id, const AVCodec *prev, int encoder)
Definition: cmdutils.c:971
#define CONFIG_NONFREE
Definition: config.h:308
enum AVMediaType codec_type
Definition: avcodec.h:1347
const AVRational * supported_framerates
array of supported framerates, or NULL if any, array is terminated by {0,0}
Definition: avcodec.h:2980
#define CONFIG_LGPLV3
Definition: config.h:339
enum AVCodecID codec_id
Definition: avcodec.h:1350
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:166
AV_SAMPLE_FMT_NONE
Definition: avconv_filter.c:63
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition: opt.c:493
const char * help
Definition: cmdutils.h:152
uint8_t flags
Definition: pixdesc.h:76
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
struct FrameBuffer ** pool
head of the buffer pool
Definition: cmdutils.h:521
main external API structure.
Definition: avcodec.h:1339
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:1515
char * av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt)
Generate a string corresponding to the sample format with sample_fmt, or a header if sample_fmt is ne...
Definition: samplefmt.c:82
const int program_birth_year
program birth year, defined by the program for show_banner()
Definition: avconv.c:83
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:63
#define SHOW_VERSION
Definition: cmdutils.c:720
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
Get a file corresponding to a preset file.
Definition: cmdutils.c:1355
const OptionGroupDef * group_def
Definition: cmdutils.h:230
#define PRINT_LIB_INFO(libname, LIBNAME, flags, level)
Definition: cmdutils.c:723
Describe the class of an AVClass context structure.
Definition: log.h:33
Filter definition.
Definition: avfilter.h:371
int index
Definition: gxfenc.c:72
GET_SAMPLE_FMT_NAME
Definition: avconv_filter.c:63
enum AVCodecID subtitle_codec
default subtitle codec
Definition: avformat.h:388
rational number numerator/denominator
Definition: rational.h:43
const char program_name[]
program name, defined by the program for show_version().
Definition: avconv.c:82
static OutputContext octx
Definition: avprobe.c:109
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Parse a string specifying a time and return its corresponding value as a number of microseconds...
Definition: cmdutils.c:105
void * grow_array(void *array, int elem_size, int *size, int new_size)
Realloc array to hold new_size elements of elem_size.
Definition: cmdutils.c:1520
const char * argname
Definition: cmdutils.h:153
#define OPT_STRING
Definition: cmdutils.h:130
struct SwsContext * sws_opts
Definition: cmdutils.c:56
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
Definition: pixdesc.h:35
AVMediaType
Definition: avutil.h:177
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:458
int64_t last_dts
PTS of the last frame.
Definition: cmdutils.h:456
static void print_codec(const AVCodec *c)
Definition: cmdutils.c:915
misc parsing utilities
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
Definition: avstring.c:77
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:450
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Parse a string and return its corresponding value as a double.
Definition: cmdutils.c:84
#define OPT_TIME
Definition: cmdutils.h:145
int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
Read the file with name filename, and put its content in a newly allocated 0-terminated buffer...
Definition: cmdutils.c:1290
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:1520
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:2986
uint8_t level
Definition: svq3.c:125
static int match_group_separator(const OptionGroupDef *groups, int nb_groups, const char *opt)
Definition: cmdutils.c:446
#define CONFIG_GPL
Definition: config.h:275
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:23
const OptionDef options[]
Definition: avserver.c:4665
enum AVMediaType type
Definition: avcodec.h:452
const char * extensions
If extensions are defined, then no probe is done.
Definition: avformat.h:476
#define OPT_BOOL
Definition: cmdutils.h:128
An option extracted from the commandline.
Definition: cmdutils.h:213
Main libavformat public API header.
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
Definition: cmdutils.c:705
static const int this_year
Definition: cmdutils.c:59
#define OPT_INT
Definition: cmdutils.h:133
AVDictionary * codec_opts
Definition: cmdutils.c:57
AVDictionary * format_opts
Definition: cmdutils.h:237
OptionGroupList * groups
Definition: cmdutils.h:255
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:116
OptionGroup global_opts
Definition: cmdutils.h:253
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
char * key
Definition: dict.h:75
int den
denominator
Definition: rational.h:45
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
Definition: cmdutils.c:69
const char * key
Definition: cmdutils.h:215
union OptionDef::@2 u
AVInputFormat * av_iformat_next(AVInputFormat *f)
If f is NULL, returns the first registered input format, if f is non-NULL, returns the next registere...
Definition: utils.c:76
enum AVCodecID id
Definition: avcodec.h:451
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:509
const OptionDef * opt
Definition: cmdutils.h:214
int refcount
Definition: cmdutils.h:520
char * value
Definition: dict.h:76
#define SHOW_CONFIG
Definition: cmdutils.c:721
int len
#define LIBAV_VERSION
Definition: version.h:1
enum AVCodecID audio_codec
default audio codec
Definition: avformat.h:386
static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
Definition: cmdutils.c:225
static int write_option(void *optctx, const OptionDef *po, const char *opt, const char *arg)
Definition: cmdutils.c:231
void show_help_children(const AVClass *class, int flags)
Show help for all options with given flags in class and all its children.
Definition: cmdutils.c:146
#define GET_ARG(arg)
OptionGroup cur_group
Definition: cmdutils.h:259
AVDictionary * codec_opts
Definition: cmdutils.h:236
Option * opts
Definition: cmdutils.h:233
int read_yesno(void)
Return a positive value if a line read from standard input starts with [yY], otherwise return 0...
Definition: cmdutils.c:1279
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:455
static void show_help_demuxer(const char *name)
Definition: cmdutils.c:1200
void codec_release_buffer(AVCodecContext *s, AVFrame *frame)
A callback to be used for AVCodecContext.release_buffer along with codec_get_buffer().
Definition: cmdutils.c:1642
int show_version(void *optctx, const char *opt, const char *arg)
Print the version of the program to stdout.
Definition: cmdutils.c:774
#define OPT_PERFILE
Definition: cmdutils.h:139
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: avcodec.h:1028
const char * extensions
comma-separated filename extensions
Definition: avformat.h:384
const char * mime_type
Definition: avformat.h:383
struct SwsContext * sws_opts
Definition: cmdutils.h:238
float min
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:209
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:158
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition: avcodec.h:1397
static void show_help_codec(const char *name, int encoder)
Definition: cmdutils.c:1165
AVProgram ** programs
Definition: avformat.h:931
int show_encoders(void *optctx, const char *opt, const char *arg)
Print a listing containing all the encoders supported by the program.
Definition: cmdutils.c:1079
simple arithmetic expression evaluator
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:1442
static void add_opt(OptionParseContext *octx, const OptionDef *opt, const char *key, const char *val)
Definition: cmdutils.c:497