53 #if HAVE_SYS_RESOURCE_H
55 #include <sys/resource.h>
84 vfprintf(stdout, fmt, vl);
103 double min,
double max)
109 error =
"Expected number for %s but found: %s\n";
110 else if (d < min || d > max)
111 error =
"The value for %s was %s which is not within %f - %f\n";
112 else if (type ==
OPT_INT64 && (int64_t)d != d)
113 error =
"Expected int64 for %s but found %s\n";
114 else if (type ==
OPT_INT && (
int)d != d)
115 error =
"Expected int for %s but found %s\n";
129 is_duration ?
"duration" :
"date", context, timestr);
136 int rej_flags,
int alt_flags)
142 for (po = options; po->
name !=
NULL; po++) {
145 if (((po->
flags & req_flags) != req_flags) ||
146 (alt_flags && !(po->
flags & alt_flags)) ||
147 (po->
flags & rej_flags))
159 printf(
"-%-17s %s\n", buf, po->
help);
176 const char *p = strchr(name,
':');
177 int len = p ? p - name : strlen(name);
180 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
190 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
192 #include <shellapi.h>
194 static char** win32_argv_utf8 =
NULL;
195 static int win32_argc = 0;
208 int i, buffsize = 0, offset = 0;
210 if (win32_argv_utf8) {
211 *argc_ptr = win32_argc;
212 *argv_ptr = win32_argv_utf8;
217 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
218 if (win32_argc <= 0 || !argv_w)
222 for (i = 0; i < win32_argc; i++)
223 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
226 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
227 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
228 if (win32_argv_utf8 ==
NULL) {
233 for (i = 0; i < win32_argc; i++) {
234 win32_argv_utf8[i] = &argstr_flat[offset];
235 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
236 &argstr_flat[offset],
239 win32_argv_utf8[i] =
NULL;
242 *argc_ptr = win32_argc;
243 *argv_ptr = win32_argv_utf8;
263 char *p = strchr(opt,
':');
265 dstcount = (
int *)(so + 1);
266 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
267 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
268 dst = &(*so)[*dstcount - 1].u;
287 int ret = po->
u.
func_arg(optctx, opt, arg);
290 "Failed to set value '%s' for option '%s'\n", arg, opt);
307 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
334 void (*parse_arg_function)(
void *,
const char*))
337 int optindex, handleoptions = 1, ret;
344 while (optindex < argc) {
345 opt = argv[optindex++];
347 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
348 if (opt[1] ==
'-' && opt[2] ==
'\0') {
354 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
358 if (parse_arg_function)
359 parse_arg_function(optctx, opt);
371 for (i = 0; i < g->
nb_opts; i++) {
377 "%s %s -- you are trying to apply an input option to an "
378 "output file or vice versa. Move this option before the "
379 "file it belongs to.\n", o->
key, o->
opt->
help,
403 for (i = 1; i < argc; i++) {
404 const char *cur_opt = argv[i];
406 if (*cur_opt++ !=
'-')
410 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
413 if ((!po->
name && !strcmp(cur_opt, optname)) ||
414 (po->
name && !strcmp(optname, po->
name)))
428 if (idx && argv[idx + 1])
432 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
436 char opt_stripped[128];
439 #if CONFIG_AVRESAMPLE
446 if (!(p = strchr(opt,
':')))
447 p = opt + strlen(opt);
448 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
452 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
458 #if CONFIG_AVRESAMPLE
490 for (i = 0; i < nb_groups; i++) {
492 if (p->
sep && !strcmp(p->
sep, opt))
526 resample_opts =
NULL;
539 const char *key,
const char *val)
556 memset(octx, 0,
sizeof(*octx));
610 while (optindex < argc) {
611 const char *opt = argv[optindex++], *arg;
618 if (opt[0] !=
'-' || !opt[1]) {
625 #define GET_ARG(arg) \
627 arg = argv[optindex++]; \
629 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
630 return AVERROR(EINVAL); \
639 groups[ret].
name, arg);
648 arg = argv[optindex++];
657 "argument '%s'.\n", po->
name, po->
help, arg);
662 if (argv[optindex]) {
666 "argument '%s'.\n", opt, argv[optindex]);
671 "with argument '%s'.\n", opt, argv[optindex]);
677 if (opt[0] ==
'n' && opt[1] ==
'o' &&
682 "argument 0.\n", po->
name, po->
help);
712 const struct {
const char *
name;
int level; } log_levels[] = {
727 if (!strcmp(log_levels[i].
name, arg)) {
733 level = strtol(arg, &tail, 10);
736 "Possible levels are numbers or:\n", arg);
749 struct rlimit rl = { lim, lim + 1 };
750 if (setrlimit(RLIMIT_CPU, &rl))
761 const char *errbuf_ptr = errbuf;
773 #define SHOW_VERSION 2
774 #define SHOW_CONFIG 4
776 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
777 if (CONFIG_##LIBNAME) { \
778 const char *indent = flags & INDENT? " " : ""; \
779 if (flags & SHOW_VERSION) { \
780 unsigned int version = libname##_version(); \
781 av_log(NULL, level, \
782 "%slib%-10s %2d.%3d.%2d / %2d.%3d.%2d\n", \
784 LIB##LIBNAME##_VERSION_MAJOR, \
785 LIB##LIBNAME##_VERSION_MINOR, \
786 LIB##LIBNAME##_VERSION_MICRO, \
787 version >> 16, version >> 8 & 0xff, version & 0xff); \
789 if (flags & SHOW_CONFIG) { \
790 const char *cfg = libname##_configuration(); \
791 if (strcmp(LIBAV_CONFIGURATION, cfg)) { \
793 av_log(NULL, level, \
794 "%sWARNING: library configuration mismatch\n", \
798 av_log(NULL, level, "%s%-11s configuration: %s\n", \
799 indent, #libname, cfg); \
818 "%s version " LIBAV_VERSION ", Copyright (c) %d-%d the Libav developers\n",
840 "This version of %s has nonfree parts compiled in.\n"
841 "Therefore it is not legally redistributable.\n",
844 "%s is free software; you can redistribute it and/or modify\n"
845 "it under the terms of the GNU General Public License as published by\n"
846 "the Free Software Foundation; either version 3 of the License, or\n"
847 "(at your option) any later version.\n"
849 "%s is distributed in the hope that it will be useful,\n"
850 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
851 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
852 "GNU General Public License for more details.\n"
854 "You should have received a copy of the GNU General Public License\n"
855 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
858 "%s is free software; you can redistribute it and/or modify\n"
859 "it under the terms of the GNU General Public License as published by\n"
860 "the Free Software Foundation; either version 2 of the License, or\n"
861 "(at your option) any later version.\n"
863 "%s is distributed in the hope that it will be useful,\n"
864 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
865 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
866 "GNU General Public License for more details.\n"
868 "You should have received a copy of the GNU General Public License\n"
869 "along with %s; if not, write to the Free Software\n"
870 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
873 "%s is free software; you can redistribute it and/or modify\n"
874 "it under the terms of the GNU Lesser General Public License as published by\n"
875 "the Free Software Foundation; either version 3 of the License, or\n"
876 "(at your option) any later version.\n"
878 "%s is distributed in the hope that it will be useful,\n"
879 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
880 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
881 "GNU Lesser General Public License for more details.\n"
883 "You should have received a copy of the GNU Lesser General Public License\n"
884 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
887 "%s is free software; you can redistribute it and/or\n"
888 "modify it under the terms of the GNU Lesser General Public\n"
889 "License as published by the Free Software Foundation; either\n"
890 "version 2.1 of the License, or (at your option) any later version.\n"
892 "%s is distributed in the hope that it will be useful,\n"
893 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
894 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
895 "Lesser General Public License for more details.\n"
897 "You should have received a copy of the GNU Lesser General Public\n"
898 "License along with %s; if not, write to the Free Software\n"
899 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
911 const char *last_name;
913 printf(
"File formats:\n"
914 " D. = Demuxing supported\n"
915 " .E = Muxing supported\n"
922 const char *long_name =
NULL;
925 if ((name ==
NULL || strcmp(ofmt->
name, name) < 0) &&
926 strcmp(ofmt->
name, last_name) > 0) {
933 if ((name ==
NULL || strcmp(ifmt->
name, name) < 0) &&
934 strcmp(ifmt->
name, last_name) > 0) {
939 if (name && strcmp(ifmt->
name, name) == 0)
946 printf(
" %s%s %-15s %s\n",
950 long_name ? long_name:
" ");
955 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
956 if (codec->field) { \
957 const type *p = c->field; \
959 printf(" Supported " list_name ":"); \
960 while (*p != term) { \
962 printf(" %s", name); \
972 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
976 printf(
" Threading capabilities: ");
983 default: printf(
"no");
break;
991 printf(
" Supported framerates:");
993 printf(
" %d/%d", fps->
num, fps->
den);
1020 default:
return '?';
1028 if (prev->
id ==
id &&
1039 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
1042 printf(
"%s ", codec->
name);
1052 " D..... = Decoding supported\n"
1053 " .E.... = Encoding supported\n"
1054 " ..V... = Video codec\n"
1055 " ..A... = Audio codec\n"
1056 " ..S... = Subtitle codec\n"
1057 " ...I.. = Intra frame-only codec\n"
1058 " ....L. = Lossy compression\n"
1059 " .....S = Lossless compression\n"
1077 if (strcmp(codec->
name, desc->
name)) {
1084 if (strcmp(codec->
name, desc->
name)) {
1102 " S... = Subtitle\n"
1103 " .F.. = Frame-level multithreading\n"
1104 " ..S. = Slice-level multithreading\n"
1105 " ...X = Codec is experimental\n"
1107 encoder ?
"Encoders" :
"Decoders");
1118 if (strcmp(codec->
name, desc->
name))
1119 printf(
" (codec %s)", desc->
name);
1138 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1142 printf(
"Bitstream filters:\n");
1144 printf(
"%s\n", bsf->
name);
1151 void *opaque =
NULL;
1154 printf(
"Supported file protocols:\n"
1157 printf(
"%s\n", name);
1158 printf(
"Output:\n");
1160 printf(
"%s\n", name);
1168 printf(
"Filters:\n");
1171 printf(
"%-16s %s\n",
filter->name,
filter->description);
1180 printf(
"Pixel formats:\n"
1181 "I.... = Supported Input format for conversion\n"
1182 ".O... = Supported Output format for conversion\n"
1183 "..H.. = Hardware accelerated format\n"
1184 "...P. = Paletted format\n"
1185 "....B = Bitstream format\n"
1186 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1190 # define sws_isSupportedInput(x) 0
1191 # define sws_isSupportedOutput(x) 0
1196 printf(
"%c%c%c%c%c %-16s %d %2d\n",
1243 "but no %s for it are available. Libav might need to be "
1244 "recompiled with additional external libraries.\n",
1245 name, encoder ?
"encoders" :
"decoders");
1265 printf(
" Common extensions: %s.\n", fmt->
extensions);
1284 printf(
" Common extensions: %s.\n", fmt->
extensions);
1286 printf(
" Mime type: %s.\n", fmt->
mime_type);
1289 printf(
" Default video codec: %s.\n", desc->
name);
1293 printf(
" Default audio codec: %s.\n", desc->
name);
1297 printf(
" Default subtitle codec: %s.\n", desc->
name);
1305 static void show_help_filter(
const char *
name)
1321 printf(
" slice threading supported\n");
1323 printf(
" Inputs:\n");
1325 for (i = 0; i < count; i++) {
1330 printf(
" dynamic (depending on the options)\n");
1332 printf(
" Outputs:\n");
1334 for (i = 0; i < count; i++) {
1339 printf(
" dynamic (depending on the options)\n");
1347 int show_help(
void *optctx,
const char *opt,
const char *arg)
1353 par = strchr(topic,
'=');
1359 }
else if (!strcmp(topic,
"decoder")) {
1361 }
else if (!strcmp(topic,
"encoder")) {
1363 }
else if (!strcmp(topic,
"demuxer")) {
1365 }
else if (!strcmp(topic,
"muxer")) {
1368 }
else if (!strcmp(topic,
"filter")) {
1369 show_help_filter(par);
1384 while (c !=
'\n' && c != EOF)
1393 FILE *f = fopen(filename,
"rb");
1400 fseek(f, 0, SEEK_END);
1402 fseek(f, 0, SEEK_SET);
1409 ret = fread(*bufptr, 1, *size, f);
1414 filename, strerror(errno));
1420 (*bufptr)[(*size)++] =
'\0';
1448 pts = reordered_pts;
1456 const char *preset_name,
int is_path,
1457 const char *codec_name)
1461 const char *base[3] = { getenv(
"AVCONV_DATADIR"),
1466 av_strlcpy(filename, preset_name, filename_size);
1467 f = fopen(filename,
"r");
1469 for (i = 0; i < 3 && !f; i++) {
1472 snprintf(filename, filename_size,
"%s%s/%s.avpreset", base[i],
1473 i != 1 ?
"" :
"/.avconv", preset_name);
1474 f = fopen(filename,
"r");
1475 if (!f && codec_name) {
1476 snprintf(filename, filename_size,
1477 "%s%s/%s-%s.avpreset",
1478 base[i], i != 1 ?
"" :
"/.avconv", codec_name,
1480 f = fopen(filename,
"r");
1490 if (*spec <= '9' && *spec >=
'0')
1491 return strtol(spec,
NULL, 0) == st->
index;
1492 else if (*spec ==
'v' || *spec ==
'a' || *spec ==
's' || *spec ==
'd' ||
1506 if (*spec++ ==
':') {
1510 return i == st->
index;
1514 }
else if (*spec ==
'p' && *(spec + 1) ==
':') {
1518 prog_id = strtol(spec, &endptr, 0);
1523 if (*endptr++ ==
':') {
1524 int stream_idx = strtol(endptr,
NULL, 0);
1525 return stream_idx >= 0 &&
1572 char *p = strchr(t->
key,
':');
1577 case 1: *p = 0;
break;
1579 default:
return NULL;
1587 else if (t->
key[0] == prefix &&
1609 "Could not alloc memory for stream options.\n");
1620 if (new_size >= INT_MAX / elem_size) {
1624 if (*size < new_size) {
1630 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1639 switch (media_type) {
1645 default:
return "unknown";