57 #if HAVE_SYS_RESOURCE_H
59 #include <sys/resource.h>
99 vfprintf(stdout, fmt, vl);
106 static int print_prefix = 1;
117 double min,
double max)
123 error =
"Expected number for %s but found: %s\n";
124 else if (d < min || d > max)
125 error =
"The value for %s was %s which is not within %f - %f\n";
126 else if (type ==
OPT_INT64 && (int64_t)d != d)
127 error =
"Expected int64 for %s but found %s\n";
128 else if (type ==
OPT_INT && (
int)d != d)
129 error =
"Expected int for %s but found %s\n";
143 is_duration ?
"duration" :
"date", context, timestr);
150 int rej_flags,
int alt_flags)
156 for (po = options; po->
name !=
NULL; po++) {
159 if (((po->
flags & req_flags) != req_flags) ||
160 (alt_flags && !(po->
flags & alt_flags)) ||
161 (po->
flags & rej_flags))
173 printf(
"-%-17s %s\n", buf, po->
help);
192 const char *p = strchr(name,
':');
193 int len = p ? p - name : strlen(name);
196 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
203 #if HAVE_COMMANDLINETOARGVW
205 #include <shellapi.h>
207 static char** win32_argv_utf8 =
NULL;
208 static int win32_argc = 0;
221 int i, buffsize = 0,
offset = 0;
223 if (win32_argv_utf8) {
224 *argc_ptr = win32_argc;
225 *argv_ptr = win32_argv_utf8;
230 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
231 if (win32_argc <= 0 || !argv_w)
235 for (i = 0; i < win32_argc; i++)
236 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
239 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
240 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
241 if (win32_argv_utf8 ==
NULL) {
246 for (i = 0; i < win32_argc; i++) {
247 win32_argv_utf8[i] = &argstr_flat[
offset];
248 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
252 win32_argv_utf8[i] =
NULL;
255 *argc_ptr = win32_argc;
256 *argv_ptr = win32_argv_utf8;
276 char *p = strchr(opt,
':');
278 dstcount = (
int *)(so + 1);
279 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
280 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
281 dst = &(*so)[*dstcount - 1].u;
300 int ret = po->
u.
func_arg(optctx, opt, arg);
303 "Failed to set value '%s' for option '%s'\n", arg, opt);
320 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
347 void (*parse_arg_function)(
void *,
const char*))
350 int optindex, handleoptions = 1, ret;
357 while (optindex < argc) {
358 opt = argv[optindex++];
360 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
361 if (opt[1] ==
'-' && opt[2] ==
'\0') {
367 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
371 if (parse_arg_function)
372 parse_arg_function(optctx, opt);
384 for (i = 0; i < g->
nb_opts; i++) {
406 for (i = 1; i < argc; i++) {
407 const char *cur_opt = argv[i];
409 if (*cur_opt++ !=
'-')
413 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
416 if ((!po->
name && !strcmp(cur_opt, optname)) ||
417 (po->
name && !strcmp(optname, po->
name)))
428 const unsigned char *p;
431 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
432 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
439 for (p = a; *p; p++) {
440 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
442 else if (*p < ' ' || *p >
'~')
456 if (idx && argv[idx + 1])
459 if ((env = getenv(
"FFREPORT")) || idx) {
464 for (i = 0; i < argc; i++) {
473 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
478 char opt_stripped[128];
483 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
486 if (!(p = strchr(opt,
':')))
487 p = opt + strlen(opt);
488 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
492 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
517 #if CONFIG_SWRESAMPLE
545 for (i = 0; i < nb_groups; i++) {
547 if (p->
sep && !strcmp(p->
sep, opt))
594 const char *key,
const char *val)
611 memset(octx, 0,
sizeof(*octx));
641 if(CONFIG_SWRESAMPLE)
666 while (optindex < argc) {
667 const char *opt = argv[optindex++], *
arg;
674 if (opt[0] !=
'-' || !opt[1]) {
681 #define GET_ARG(arg) \
683 arg = argv[optindex++]; \
685 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
686 return AVERROR(EINVAL); \
695 groups[ret].
name, arg);
704 arg = argv[optindex++];
713 "argument '%s'.\n", po->
name, po->
help, arg);
718 if (argv[optindex]) {
722 "argument '%s'.\n", opt, argv[optindex]);
727 "with argument '%s'.\n", opt, argv[optindex]);
733 if (opt[0] ==
'n' && opt[1] ==
'o' &&
738 "argument 0.\n", po->
name, po->
help);
757 const struct {
const char *
name;
int level; } log_levels[] = {
772 if (!strcmp(log_levels[i].
name, arg)) {
778 level = strtol(arg, &tail, 10);
781 "Possible levels are numbers or:\n", arg);
795 while ((c = *(
template++))) {
797 if (!(c = *(
template++)))
805 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
806 tm->tm_hour, tm->tm_min, tm->tm_sec);
820 char *filename_template =
NULL;
830 tm = localtime(&now);
832 while (env && *env) {
836 "Failed to parse FFREPORT environment variable: %s\n",
843 if (!strcmp(key,
"file")) {
845 filename_template = val;
866 filename.str, strerror(errno));
871 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
872 "Report written to \"%s\"\n",
874 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
875 tm->tm_hour, tm->tm_min, tm->tm_sec,
892 max = strtol(arg, &tail, 10);
917 struct rlimit rl = { lim, lim + 1 };
918 if (setrlimit(RLIMIT_CPU, &rl))
929 const char *errbuf_ptr = errbuf;
939 #define SHOW_VERSION 2
940 #define SHOW_CONFIG 4
941 #define SHOW_COPYRIGHT 8
943 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
944 if (CONFIG_##LIBNAME) { \
945 const char *indent = flags & INDENT? " " : ""; \
946 if (flags & SHOW_VERSION) { \
947 unsigned int version = libname##_version(); \
948 av_log(NULL, level, \
949 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
951 LIB##LIBNAME##_VERSION_MAJOR, \
952 LIB##LIBNAME##_VERSION_MINOR, \
953 LIB##LIBNAME##_VERSION_MICRO, \
954 version >> 16, version >> 8 & 0xff, version & 0xff); \
956 if (flags & SHOW_CONFIG) { \
957 const char *cfg = libname##_configuration(); \
958 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
960 av_log(NULL, level, \
961 "%sWARNING: library configuration mismatch\n", \
965 av_log(NULL, level, "%s%-11s configuration: %s\n", \
966 indent, #libname, cfg); \
988 const char *indent = flags &
INDENT?
" " :
"";
992 av_log(
NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
995 av_log(
NULL, level,
"%sbuilt on %s %s with %s\n",
996 indent, __DATE__, __TIME__, CC_IDENT);
998 av_log(
NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1025 "This version of %s has nonfree parts compiled in.\n"
1026 "Therefore it is not legally redistributable.\n",
1030 "%s is free software; you can redistribute it and/or modify\n"
1031 "it under the terms of the GNU General Public License as published by\n"
1032 "the Free Software Foundation; either version 3 of the License, or\n"
1033 "(at your option) any later version.\n"
1035 "%s is distributed in the hope that it will be useful,\n"
1036 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1037 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1038 "GNU General Public License for more details.\n"
1040 "You should have received a copy of the GNU General Public License\n"
1041 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1045 "%s is free software; you can redistribute it and/or modify\n"
1046 "it under the terms of the GNU General Public License as published by\n"
1047 "the Free Software Foundation; either version 2 of the License, or\n"
1048 "(at your option) any later version.\n"
1050 "%s is distributed in the hope that it will be useful,\n"
1051 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1052 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1053 "GNU General Public License for more details.\n"
1055 "You should have received a copy of the GNU General Public License\n"
1056 "along with %s; if not, write to the Free Software\n"
1057 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1061 "%s is free software; you can redistribute it and/or modify\n"
1062 "it under the terms of the GNU Lesser General Public License as published by\n"
1063 "the Free Software Foundation; either version 3 of the License, or\n"
1064 "(at your option) any later version.\n"
1066 "%s is distributed in the hope that it will be useful,\n"
1067 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1068 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1069 "GNU Lesser General Public License for more details.\n"
1071 "You should have received a copy of the GNU Lesser General Public License\n"
1072 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1076 "%s is free software; you can redistribute it and/or\n"
1077 "modify it under the terms of the GNU Lesser General Public\n"
1078 "License as published by the Free Software Foundation; either\n"
1079 "version 2.1 of the License, or (at your option) any later version.\n"
1081 "%s is distributed in the hope that it will be useful,\n"
1082 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1083 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1084 "Lesser General Public License for more details.\n"
1086 "You should have received a copy of the GNU Lesser General Public\n"
1087 "License along with %s; if not, write to the Free Software\n"
1088 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1099 const char *last_name;
1101 printf(
"File formats:\n"
1102 " D. = Demuxing supported\n"
1103 " .E = Muxing supported\n"
1110 const char *long_name =
NULL;
1113 if ((name ==
NULL || strcmp(ofmt->
name, name) < 0) &&
1114 strcmp(ofmt->
name, last_name) > 0) {
1121 if ((name ==
NULL || strcmp(ifmt->
name, name) < 0) &&
1122 strcmp(ifmt->
name, last_name) > 0) {
1127 if (name && strcmp(ifmt->
name, name) == 0)
1134 printf(
" %s%s %-15s %s\n",
1138 long_name ? long_name:
" ");
1143 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1144 if (codec->field) { \
1145 const type *p = codec->field; \
1147 printf(" Supported " list_name ":"); \
1148 while (*p != term) { \
1150 printf(" %s", name); \
1160 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1164 printf(
" Threading capabilities: ");
1171 default: printf(
"no");
break;
1179 printf(
" Supported framerates:");
1181 printf(
" %d/%d", fps->
num, fps->
den);
1210 default:
return '?';
1218 if (prev->
id ==
id &&
1230 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1231 strcmp((*da)->name, (*db)->name);
1238 unsigned nb_codecs = 0, i = 0;
1242 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1259 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
1262 printf(
"%s ", codec->
name);
1273 " D..... = Decoding supported\n"
1274 " .E.... = Encoding supported\n"
1275 " ..V... = Video codec\n"
1276 " ..A... = Audio codec\n"
1277 " ..S... = Subtitle codec\n"
1278 " ...I.. = Intra frame-only codec\n"
1279 " ....L. = Lossy compression\n"
1280 " .....S = Lossless compression\n"
1282 for (i = 0; i < nb_codecs; i++) {
1300 if (strcmp(codec->
name, desc->
name)) {
1307 if (strcmp(codec->
name, desc->
name)) {
1327 " S..... = Subtitle\n"
1328 " .F.... = Frame-level multithreading\n"
1329 " ..S... = Slice-level multithreading\n"
1330 " ...X.. = Codec is experimental\n"
1331 " ....B. = Supports draw_horiz_band\n"
1332 " .....D = Supports direct rendering method 1\n"
1334 encoder ?
"Encoders" :
"Decoders");
1335 for (i = 0; i < nb_codecs; i++) {
1348 if (strcmp(codec->
name, desc->
name))
1349 printf(
" (codec %s)", desc->
name);
1373 printf(
"Bitstream filters:\n");
1375 printf(
"%s\n", bsf->
name);
1382 void *opaque =
NULL;
1385 printf(
"Supported file protocols:\n"
1388 printf(
"%s\n", name);
1389 printf(
"Output:\n");
1391 printf(
"%s\n", name);
1398 char descr[64], *descr_cur;
1402 printf(
"Filters:\n");
1406 for (i = 0; i < 2; i++) {
1408 *(descr_cur++) =
'-';
1409 *(descr_cur++) =
'>';
1411 pad = i ? (*filter)->outputs : (*filter)->inputs;
1412 for (j = 0; pad && pad[j].
name; j++) {
1413 if (descr_cur >= descr +
sizeof(descr) - 4)
1418 *(descr_cur++) =
'|';
1421 printf(
"%-16s %-10s %s\n", (*filter)->name, descr, (*filter)->description);
1431 printf(
"Pixel formats:\n"
1432 "I.... = Supported Input format for conversion\n"
1433 ".O... = Supported Output format for conversion\n"
1434 "..H.. = Hardware accelerated format\n"
1435 "...P. = Paletted format\n"
1436 "....B = Bitstream format\n"
1437 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1441 # define sws_isSupportedInput(x) 0
1442 # define sws_isSupportedOutput(x) 0
1447 printf(
"%c%c%c%c%c %-16s %d %2d\n",
1464 const char *
name, *descr;
1466 printf(
"Individual channels:\n"
1467 "NAME DESCRIPTION\n");
1468 for (i = 0; i < 63; i++) {
1473 printf(
"%-12s%s\n", name, descr);
1475 printf(
"\nStandard channel layouts:\n"
1476 "NAME DECOMPOSITION\n");
1479 printf(
"%-12s", name);
1480 for (j = 1; j; j <<= 1)
1523 "but no %s for it are available. FFmpeg might need to be "
1524 "recompiled with additional external libraries.\n",
1525 name, encoder ?
"encoders" :
"decoders");
1545 printf(
" Common extensions: %s.\n", fmt->
extensions);
1564 printf(
" Common extensions: %s.\n", fmt->
extensions);
1566 printf(
" Mime type: %s.\n", fmt->
mime_type);
1569 printf(
" Default video codec: %s.\n", desc->
name);
1573 printf(
" Default audio codec: %s.\n", desc->
name);
1577 printf(
" Default subtitle codec: %s.\n", desc->
name);
1590 par = strchr(topic,
'=');
1596 }
else if (!strcmp(topic,
"decoder")) {
1598 }
else if (!strcmp(topic,
"encoder")) {
1600 }
else if (!strcmp(topic,
"demuxer")) {
1602 }
else if (!strcmp(topic,
"muxer")) {
1615 int yesno = (toupper(c) ==
'Y');
1617 while (c !=
'\n' && c != EOF)
1626 FILE *f = fopen(filename,
"rb");
1633 fseek(f, 0, SEEK_END);
1635 fseek(f, 0, SEEK_SET);
1636 if (*size == (
size_t)-1) {
1647 ret = fread(*bufptr, 1, *size, f);
1652 filename, strerror(errno));
1658 (*bufptr)[(*size)++] =
'\0';
1666 const char *preset_name,
int is_path,
1667 const char *codec_name)
1671 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
1676 av_strlcpy(filename, preset_name, filename_size);
1677 f = fopen(filename,
"r");
1680 char datadir[MAX_PATH], *ls;
1683 if (GetModuleFileNameA(GetModuleHandleA(
NULL), datadir,
sizeof(datadir) - 1))
1685 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1686 if (*ls ==
'\\') *ls =
'/';
1688 if (ls = strrchr(datadir,
'/'))
1691 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
1696 for (i = 0; i < 3 && !f; i++) {
1699 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1700 i != 1 ?
"" :
"/.ffmpeg", preset_name);
1701 f = fopen(filename,
"r");
1702 if (!f && codec_name) {
1704 "%s%s/%s-%s.ffpreset",
1705 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
1707 f = fopen(filename,
"r");
1739 switch (codec->
type) {
1755 char *p = strchr(t->
key,
':');
1760 case 1: *p = 0;
break;
1762 default:
return NULL;
1770 else if (t->
key[0] == prefix &&
1792 "Could not alloc memory for stream options.\n");
1803 if (new_size >= INT_MAX / elem_size) {
1807 if (*size < new_size) {
1813 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1826 int h_chroma_shift, v_chroma_shift;
1856 memset(buf->
base[0], 128, ret);
1860 const int h_shift = i==0 ? 0 : h_chroma_shift;
1861 const int v_shift = i==0 ? 0 : v_chroma_shift;
1867 (pixel_size*edge >> h_shift), 32);
1925 for(tmp= *pool; tmp; tmp= tmp->
next)