52 #include "libavutil/ffversion.h"
57 #if HAVE_SYS_RESOURCE_H
59 #include <sys/resource.h>
95 vfprintf(stdout, fmt, vl);
102 static int print_prefix = 1;
130 double min,
double max)
136 error =
"Expected number for %s but found: %s\n";
137 else if (d < min || d > max)
138 error =
"The value for %s was %s which is not within %f - %f\n";
139 else if (type ==
OPT_INT64 && (int64_t)d != d)
140 error =
"Expected int64 for %s but found %s\n";
141 else if (type ==
OPT_INT && (
int)d != d)
142 error =
"Expected int for %s but found %s\n";
156 is_duration ?
"duration" :
"date", context, timestr);
163 int rej_flags,
int alt_flags)
169 for (po = options; po->
name; po++) {
172 if (((po->
flags & req_flags) != req_flags) ||
173 (alt_flags && !(po->
flags & alt_flags)) ||
174 (po->
flags & rej_flags))
186 printf(
"-%-17s %s\n", buf, po->
help);
205 const char *p = strchr(name,
':');
206 int len = p ? p - name : strlen(name);
209 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
219 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
221 #include <shellapi.h>
223 static char** win32_argv_utf8 = NULL;
224 static int win32_argc = 0;
237 int i, buffsize = 0,
offset = 0;
239 if (win32_argv_utf8) {
240 *argc_ptr = win32_argc;
241 *argv_ptr = win32_argv_utf8;
246 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
247 if (win32_argc <= 0 || !argv_w)
251 for (i = 0; i < win32_argc; i++)
252 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
253 NULL, 0, NULL, NULL);
255 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
256 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
257 if (!win32_argv_utf8) {
262 for (i = 0; i < win32_argc; i++) {
263 win32_argv_utf8[i] = &argstr_flat[
offset];
264 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
266 buffsize - offset, NULL, NULL);
268 win32_argv_utf8[i] = NULL;
271 *argc_ptr = win32_argc;
272 *argv_ptr = win32_argv_utf8;
292 char *p = strchr(opt,
':');
294 dstcount = (
int *)(so + 1);
295 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
296 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
297 dst = &(*so)[*dstcount - 1].u;
319 "Failed to set value '%s' for option '%s': %s\n",
337 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
364 void (*parse_arg_function)(
void *,
const char*))
367 int optindex, handleoptions = 1,
ret;
374 while (optindex < argc) {
375 opt = argv[optindex++];
377 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
378 if (opt[1] ==
'-' && opt[2] ==
'\0') {
388 if (parse_arg_function)
389 parse_arg_function(optctx, opt);
401 for (i = 0; i < g->
nb_opts; i++) {
407 "%s %s -- you are trying to apply an input option to an "
408 "output file or vice versa. Move this option before the "
409 "file it belongs to.\n", o->
key, o->
opt->
help,
433 for (i = 1; i < argc; i++) {
434 const char *cur_opt = argv[i];
436 if (*cur_opt++ !=
'-')
440 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
443 if ((!po->
name && !strcmp(cur_opt, optname)) ||
444 (po->
name && !strcmp(optname, po->
name)))
455 const unsigned char *p;
458 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
459 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
466 for (p = a; *p; p++) {
467 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
469 else if (*p < ' ' || *p >
'~')
483 if (idx && argv[idx + 1])
486 if ((env = getenv(
"FFREPORT")) || idx) {
491 for (i = 0; i < argc; i++) {
504 int opt_flags,
int search_flags)
512 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
517 char opt_stripped[128];
520 #if CONFIG_AVRESAMPLE
525 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
528 if (!(p = strchr(opt,
':')))
529 p = opt + strlen(opt);
530 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
532 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
534 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
548 if (!consumed &&
opt_find(&sc, opt, NULL, 0,
559 if (!consumed && !strcmp(opt,
"sws_flags")) {
564 #if CONFIG_SWRESAMPLE
566 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
579 #if CONFIG_AVRESAMPLE
602 for (i = 0; i < nb_groups; i++) {
604 if (p->
sep && !strcmp(p->
sep, opt))
639 resample_opts = NULL;
653 const char *key,
const char *
val)
670 memset(octx, 0,
sizeof(*octx));
726 while (optindex < argc) {
727 const char *opt = argv[optindex++], *
arg;
733 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
738 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
745 #define GET_ARG(arg) \
747 arg = argv[optindex++]; \
749 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
750 return AVERROR(EINVAL); \
759 groups[ret].
name, arg);
768 arg = argv[optindex++];
777 "argument '%s'.\n", po->
name, po->
help, arg);
782 if (argv[optindex]) {
786 "argument '%s'.\n", opt, argv[optindex]);
791 "with argument '%s'.\n", opt, argv[optindex]);
797 if (opt[0] ==
'n' && opt[1] ==
'o' &&
802 "argument 0.\n", po->
name, po->
help);
833 const struct {
const char *
name;
int level; } log_levels[] = {
849 tail = strstr(arg,
"repeat");
857 arg += 6 + (arg[6]==
'+');
862 if (!strcmp(log_levels[i].
name, arg)) {
868 level = strtol(arg, &tail, 10);
871 "Possible levels are numbers or:\n", arg);
885 while ((c = *(
template++))) {
887 if (!(c = *(
template++)))
895 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
896 tm->tm_hour, tm->tm_min, tm->tm_sec);
910 char *filename_template = NULL;
920 tm = localtime(&now);
922 while (env && *env) {
926 "Failed to parse FFREPORT environment variable: %s\n",
933 if (!strcmp(key,
"file")) {
935 filename_template =
val;
937 }
else if (!strcmp(key,
"level")) {
963 filename.str, strerror(errno));
968 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
969 "Report written to \"%s\"\n",
971 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
972 tm->tm_hour, tm->tm_min, tm->tm_sec,
988 max = strtol(arg, &tail, 10);
1001 struct rlimit rl = { lim, lim + 1 };
1002 if (setrlimit(RLIMIT_CPU, &rl))
1003 perror(
"setrlimit");
1013 const char *errbuf_ptr = errbuf;
1023 #define SHOW_VERSION 2
1024 #define SHOW_CONFIG 4
1025 #define SHOW_COPYRIGHT 8
1027 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1028 if (CONFIG_##LIBNAME) { \
1029 const char *indent = flags & INDENT? " " : ""; \
1030 if (flags & SHOW_VERSION) { \
1031 unsigned int version = libname##_version(); \
1032 av_log(NULL, level, \
1033 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1035 LIB##LIBNAME##_VERSION_MAJOR, \
1036 LIB##LIBNAME##_VERSION_MINOR, \
1037 LIB##LIBNAME##_VERSION_MICRO, \
1038 version >> 16, version >> 8 & 0xff, version & 0xff); \
1040 if (flags & SHOW_CONFIG) { \
1041 const char *cfg = libname##_configuration(); \
1042 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1043 if (!warned_cfg) { \
1044 av_log(NULL, level, \
1045 "%sWARNING: library configuration mismatch\n", \
1049 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1050 indent, #libname, cfg); \
1070 const char *indent = flags &
INDENT?
" " :
"";
1074 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1076 av_log(NULL, level,
"\n");
1077 av_log(NULL, level,
"%sbuilt on %s %s with %s\n",
1078 indent, __DATE__, __TIME__, CC_IDENT);
1080 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1085 const char *indent = flags &
INDENT ?
" " :
"";
1086 char str[] = { FFMPEG_CONFIGURATION };
1087 char *conflist, *remove_tilde, *splitconf;
1091 while ((conflist = strstr(str,
" --")) != NULL) {
1092 strncpy(conflist,
"~--", 3);
1097 while ((remove_tilde = strstr(str,
"pkg-config~")) != NULL) {
1098 strncpy(remove_tilde,
"pkg-config ", 11);
1101 splitconf = strtok(str,
"~");
1102 av_log(NULL, level,
"\n%sconfiguration:\n", indent);
1103 while (splitconf != NULL) {
1104 av_log(NULL, level,
"%s%s%s\n", indent, indent, splitconf);
1105 splitconf = strtok(NULL,
"~");
1141 "This version of %s has nonfree parts compiled in.\n"
1142 "Therefore it is not legally redistributable.\n",
1146 "%s is free software; you can redistribute it and/or modify\n"
1147 "it under the terms of the GNU General Public License as published by\n"
1148 "the Free Software Foundation; either version 3 of the License, or\n"
1149 "(at your option) any later version.\n"
1151 "%s is distributed in the hope that it will be useful,\n"
1152 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1153 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1154 "GNU General Public License for more details.\n"
1156 "You should have received a copy of the GNU General Public License\n"
1157 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1161 "%s is free software; you can redistribute it and/or modify\n"
1162 "it under the terms of the GNU General Public License as published by\n"
1163 "the Free Software Foundation; either version 2 of the License, or\n"
1164 "(at your option) any later version.\n"
1166 "%s is distributed in the hope that it will be useful,\n"
1167 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1168 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1169 "GNU General Public License for more details.\n"
1171 "You should have received a copy of the GNU General Public License\n"
1172 "along with %s; if not, write to the Free Software\n"
1173 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1177 "%s is free software; you can redistribute it and/or modify\n"
1178 "it under the terms of the GNU Lesser General Public License as published by\n"
1179 "the Free Software Foundation; either version 3 of the License, or\n"
1180 "(at your option) any later version.\n"
1182 "%s is distributed in the hope that it will be useful,\n"
1183 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1184 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1185 "GNU Lesser General Public License for more details.\n"
1187 "You should have received a copy of the GNU Lesser General Public License\n"
1188 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1192 "%s is free software; you can redistribute it and/or\n"
1193 "modify it under the terms of the GNU Lesser General Public\n"
1194 "License as published by the Free Software Foundation; either\n"
1195 "version 2.1 of the License, or (at your option) any later version.\n"
1197 "%s is distributed in the hope that it will be useful,\n"
1198 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1199 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1200 "Lesser General Public License for more details.\n"
1202 "You should have received a copy of the GNU Lesser General Public\n"
1203 "License along with %s; if not, write to the Free Software\n"
1204 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1227 const char *last_name;
1231 " D. = Demuxing supported\n"
1232 " .E = Muxing supported\n"
1233 " --\n", device_only ?
"Devices:" :
"File formats:");
1238 const char *
name = NULL;
1239 const char *long_name = NULL;
1243 if (!is_dev && device_only)
1245 if ((!name || strcmp(ofmt->
name, name) < 0) &&
1246 strcmp(ofmt->
name, last_name) > 0) {
1254 if (!is_dev && device_only)
1256 if ((!name || strcmp(ifmt->
name, name) < 0) &&
1257 strcmp(ifmt->
name, last_name) > 0) {
1262 if (name && strcmp(ifmt->
name, name) == 0)
1269 printf(
" %s%s %-15s %s\n",
1273 long_name ? long_name:
" ");
1288 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1289 if (codec->field) { \
1290 const type *p = codec->field; \
1292 printf(" Supported " list_name ":"); \
1293 while (*p != term) { \
1295 printf(" %s", name); \
1305 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1310 printf(
" Threading capabilities: ");
1317 default: printf(
"no");
break;
1325 printf(
" Supported framerates:");
1327 printf(
" %d/%d", fps->
num, fps->
den);
1356 default:
return '?';
1364 if (prev->
id ==
id &&
1376 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1377 strcmp((*da)->name, (*db)->name);
1384 unsigned nb_codecs = 0, i = 0;
1388 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1405 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
1408 printf(
"%s ", codec->
name);
1419 " D..... = Decoding supported\n"
1420 " .E.... = Encoding supported\n"
1421 " ..V... = Video codec\n"
1422 " ..A... = Audio codec\n"
1423 " ..S... = Subtitle codec\n"
1424 " ...I.. = Intra frame-only codec\n"
1425 " ....L. = Lossy compression\n"
1426 " .....S = Lossless compression\n"
1428 for (i = 0; i < nb_codecs; i++) {
1432 if (strstr(desc->
name,
"_deprecated"))
1449 if (strcmp(codec->
name, desc->
name)) {
1456 if (strcmp(codec->
name, desc->
name)) {
1476 " S..... = Subtitle\n"
1477 " .F.... = Frame-level multithreading\n"
1478 " ..S... = Slice-level multithreading\n"
1479 " ...X.. = Codec is experimental\n"
1480 " ....B. = Supports draw_horiz_band\n"
1481 " .....D = Supports direct rendering method 1\n"
1483 encoder ?
"Encoders" :
"Decoders");
1484 for (i = 0; i < nb_codecs; i++) {
1497 if (strcmp(codec->
name, desc->
name))
1498 printf(
" (codec %s)", desc->
name);
1522 printf(
"Bitstream filters:\n");
1524 printf(
"%s\n", bsf->
name);
1531 void *opaque = NULL;
1534 printf(
"Supported file protocols:\n"
1537 printf(
"%s\n", name);
1538 printf(
"Output:\n");
1540 printf(
"%s\n", name);
1547 char descr[64], *descr_cur;
1552 " T.. = Timeline support\n"
1553 " .S. = Slice threading\n"
1554 " ..C = Commmand support\n"
1555 " A = Audio input/output\n"
1556 " V = Video input/output\n"
1557 " N = Dynamic number and/or type of input/output\n"
1558 " | = Source or sink filter\n");
1562 for (i = 0; i < 2; i++) {
1564 *(descr_cur++) =
'-';
1565 *(descr_cur++) =
'>';
1568 for (j = 0; pad && pad[j].
name; j++) {
1569 if (descr_cur >= descr +
sizeof(descr) - 4)
1578 printf(
" %c%c%c %-16s %-10s %s\n",
1581 filter->process_command ?
'C' :
'.',
1594 printf(
"%-32s #RRGGBB\n",
"name");
1597 printf(
"%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1606 printf(
"Pixel formats:\n"
1607 "I.... = Supported Input format for conversion\n"
1608 ".O... = Supported Output format for conversion\n"
1609 "..H.. = Hardware accelerated format\n"
1610 "...P. = Paletted format\n"
1611 "....B = Bitstream format\n"
1612 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1616 # define sws_isSupportedInput(x) 0
1617 # define sws_isSupportedOutput(x) 0
1622 printf(
"%c%c%c%c%c %-16s %d %2d\n",
1639 const char *
name, *descr;
1641 printf(
"Individual channels:\n"
1642 "NAME DESCRIPTION\n");
1643 for (i = 0; i < 63; i++) {
1648 printf(
"%-14s %s\n", name, descr);
1650 printf(
"\nStandard channel layouts:\n"
1651 "NAME DECOMPOSITION\n");
1654 printf(
"%-14s ", name);
1655 for (j = 1; j; j <<= 1)
1698 "but no %s for it are available. FFmpeg might need to be "
1699 "recompiled with additional external libraries.\n",
1700 name, encoder ?
"encoders" :
"decoders");
1720 printf(
" Common extensions: %s.\n", fmt->
extensions);
1739 printf(
" Common extensions: %s.\n", fmt->
extensions);
1741 printf(
" Mime type: %s.\n", fmt->
mime_type);
1744 printf(
" Default video codec: %s.\n", desc->
name);
1748 printf(
" Default audio codec: %s.\n", desc->
name);
1752 printf(
" Default subtitle codec: %s.\n", desc->
name);
1760 static void show_help_filter(
const char *
name)
1774 printf(
"Filter %s\n", f->
name);
1779 printf(
" slice threading supported\n");
1781 printf(
" Inputs:\n");
1783 for (i = 0; i <
count; i++) {
1788 printf(
" dynamic (depending on the options)\n");
1790 printf(
" none (source filter)\n");
1792 printf(
" Outputs:\n");
1794 for (i = 0; i <
count; i++) {
1799 printf(
" dynamic (depending on the options)\n");
1801 printf(
" none (sink filter)\n");
1807 printf(
"This filter has support for timeline through the 'enable' option.\n");
1810 "can not to satisfy request\n");
1821 par = strchr(topic,
'=');
1827 }
else if (!strcmp(topic,
"decoder")) {
1829 }
else if (!strcmp(topic,
"encoder")) {
1831 }
else if (!strcmp(topic,
"demuxer")) {
1833 }
else if (!strcmp(topic,
"muxer")) {
1836 }
else if (!strcmp(topic,
"filter")) {
1837 show_help_filter(par);
1852 while (c !=
'\n' && c != EOF)
1868 fseek(f, 0, SEEK_END);
1870 fseek(f, 0, SEEK_SET);
1871 if (*size == (
size_t)-1) {
1882 ret = fread(*bufptr, 1, *size, f);
1887 filename, strerror(errno));
1893 (*bufptr)[(*size)++] =
'\0';
1901 const char *preset_name,
int is_path,
1902 const char *codec_name)
1906 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
1911 av_strlcpy(filename, preset_name, filename_size);
1912 f = fopen(filename,
"r");
1915 char datadir[MAX_PATH], *ls;
1918 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir,
sizeof(datadir) - 1))
1920 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1921 if (*ls ==
'\\') *ls =
'/';
1923 if (ls = strrchr(datadir,
'/'))
1926 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
1931 for (i = 0; i < 3 && !f; i++) {
1934 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1935 i != 1 ?
"" :
"/.ffmpeg", preset_name);
1936 f = fopen(filename,
"r");
1937 if (!f && codec_name) {
1939 "%s%s/%s-%s.ffpreset",
1940 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
1942 f = fopen(filename,
"r");
1988 char *p = strchr(t->
key,
':');
1993 case 1: *p = 0;
break;
1995 default:
return NULL;
2004 else if (t->
key[0] == prefix &&
2026 "Could not alloc memory for stream options.\n");
2037 if (new_size >= INT_MAX / elem_size) {
2041 if (*size < new_size) {
2047 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);