55 #if HAVE_SYS_RESOURCE_H
57 #include <sys/resource.h>
97 vfprintf(stdout, fmt, vl);
104 static int print_prefix = 1;
115 double min,
double max)
121 error =
"Expected number for %s but found: %s\n";
122 else if (d < min || d > max)
123 error =
"The value for %s was %s which is not within %f - %f\n";
124 else if (type ==
OPT_INT64 && (int64_t)d != d)
125 error =
"Expected int64 for %s but found %s\n";
126 else if (type ==
OPT_INT && (
int)d != d)
127 error =
"Expected int for %s but found %s\n";
141 is_duration ?
"duration" :
"date", context, timestr);
148 int rej_flags,
int alt_flags)
154 for (po = options; po->
name !=
NULL; po++) {
157 if (((po->
flags & req_flags) != req_flags) ||
158 (alt_flags && !(po->
flags & alt_flags)) ||
159 (po->
flags & rej_flags))
171 printf(
"-%-17s %s\n", buf, po->
help);
190 const char *p = strchr(name,
':');
191 int len = p ? p - name : strlen(name);
194 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
201 #if HAVE_COMMANDLINETOARGVW
203 #include <shellapi.h>
205 static char** win32_argv_utf8 =
NULL;
206 static int win32_argc = 0;
219 int i, buffsize = 0,
offset = 0;
221 if (win32_argv_utf8) {
222 *argc_ptr = win32_argc;
223 *argv_ptr = win32_argv_utf8;
228 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
229 if (win32_argc <= 0 || !argv_w)
233 for (i = 0; i < win32_argc; i++)
234 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
237 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
238 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
239 if (win32_argv_utf8 ==
NULL) {
244 for (i = 0; i < win32_argc; i++) {
245 win32_argv_utf8[i] = &argstr_flat[
offset];
246 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
250 win32_argv_utf8[i] =
NULL;
253 *argc_ptr = win32_argc;
254 *argv_ptr = win32_argv_utf8;
274 char *p = strchr(opt,
':');
276 dstcount = (
int *)(so + 1);
277 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
278 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
279 dst = &(*so)[*dstcount - 1].u;
301 "Failed to set value '%s' for option '%s': %s\n",
319 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
346 void (*parse_arg_function)(
void *,
const char*))
349 int optindex, handleoptions = 1,
ret;
356 while (optindex < argc) {
357 opt = argv[optindex++];
359 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
360 if (opt[1] ==
'-' && opt[2] ==
'\0') {
370 if (parse_arg_function)
371 parse_arg_function(optctx, opt);
383 for (i = 0; i < g->
nb_opts; i++) {
389 "%s %s -- you are trying to apply an input option to an "
390 "output file or vice versa. Move this option before the "
391 "file it belongs to.\n", o->
key, o->
opt->
help,
415 for (i = 1; i < argc; i++) {
416 const char *cur_opt = argv[i];
418 if (*cur_opt++ !=
'-')
422 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
425 if ((!po->
name && !strcmp(cur_opt, optname)) ||
426 (po->
name && !strcmp(optname, po->
name)))
437 const unsigned char *p;
440 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
441 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
448 for (p = a; *p; p++) {
449 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
451 else if (*p < ' ' || *p >
'~')
465 if (idx && argv[idx + 1])
468 if ((env = getenv(
"FFREPORT")) || idx) {
473 for (i = 0; i < argc; i++) {
482 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
487 char opt_stripped[128];
490 #if CONFIG_AVRESAMPLE
495 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
498 if (!(p = strchr(opt,
':')))
499 p = opt + strlen(opt);
500 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
504 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
529 #if CONFIG_SWRESAMPLE
544 #if CONFIG_AVRESAMPLE
567 for (i = 0; i < nb_groups; i++) {
569 if (p->
sep && !strcmp(p->
sep, opt))
604 resample_opts =
NULL;
618 const char *key,
const char *
val)
635 memset(octx, 0,
sizeof(*octx));
691 while (optindex < argc) {
692 const char *opt = argv[optindex++], *
arg;
698 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
703 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
710 #define GET_ARG(arg) \
712 arg = argv[optindex++]; \
714 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
715 return AVERROR(EINVAL); \
724 groups[ret].
name, arg);
733 arg = argv[optindex++];
742 "argument '%s'.\n", po->
name, po->
help, arg);
747 if (argv[optindex]) {
751 "argument '%s'.\n", opt, argv[optindex]);
756 "with argument '%s'.\n", opt, argv[optindex]);
762 if (opt[0] ==
'n' && opt[1] ==
'o' &&
767 "argument 0.\n", po->
name, po->
help);
786 const struct {
const char *
name;
int level; } log_levels[] = {
800 tail = strstr(arg,
"repeat");
803 arg += 6 + (arg[6]==
'+');
808 if (!strcmp(log_levels[i].
name, arg)) {
814 level = strtol(arg, &tail, 10);
817 "Possible levels are numbers or:\n", arg);
831 while ((c = *(
template++))) {
833 if (!(c = *(
template++)))
841 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
842 tm->tm_hour, tm->tm_min, tm->tm_sec);
856 char *filename_template =
NULL;
866 tm = localtime(&now);
868 while (env && *env) {
872 "Failed to parse FFREPORT environment variable: %s\n",
879 if (!strcmp(key,
"file")) {
881 filename_template =
val;
902 filename.str, strerror(errno));
907 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
908 "Report written to \"%s\"\n",
910 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
911 tm->tm_hour, tm->tm_min, tm->tm_sec,
928 max = strtol(arg, &tail, 10);
953 struct rlimit rl = { lim, lim + 1 };
954 if (setrlimit(RLIMIT_CPU, &rl))
963 int opt_opencl(
void *optctx,
const char *opt,
const char *
arg)
966 const char *opts =
arg;
985 const char *errbuf_ptr = errbuf;
995 #define SHOW_VERSION 2
996 #define SHOW_CONFIG 4
997 #define SHOW_COPYRIGHT 8
999 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1000 if (CONFIG_##LIBNAME) { \
1001 const char *indent = flags & INDENT? " " : ""; \
1002 if (flags & SHOW_VERSION) { \
1003 unsigned int version = libname##_version(); \
1004 av_log(NULL, level, \
1005 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1007 LIB##LIBNAME##_VERSION_MAJOR, \
1008 LIB##LIBNAME##_VERSION_MINOR, \
1009 LIB##LIBNAME##_VERSION_MICRO, \
1010 version >> 16, version >> 8 & 0xff, version & 0xff); \
1012 if (flags & SHOW_CONFIG) { \
1013 const char *cfg = libname##_configuration(); \
1014 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1015 if (!warned_cfg) { \
1016 av_log(NULL, level, \
1017 "%sWARNING: library configuration mismatch\n", \
1021 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1022 indent, #libname, cfg); \
1042 const char *indent = flags &
INDENT?
" " :
"";
1046 av_log(
NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1049 av_log(
NULL, level,
"%sbuilt on %s %s with %s\n",
1050 indent, __DATE__, __TIME__, CC_IDENT);
1052 av_log(
NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1079 "This version of %s has nonfree parts compiled in.\n"
1080 "Therefore it is not legally redistributable.\n",
1084 "%s is free software; you can redistribute it and/or modify\n"
1085 "it under the terms of the GNU General Public License as published by\n"
1086 "the Free Software Foundation; either version 3 of the License, or\n"
1087 "(at your option) any later version.\n"
1089 "%s is distributed in the hope that it will be useful,\n"
1090 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1091 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1092 "GNU General Public License for more details.\n"
1094 "You should have received a copy of the GNU General Public License\n"
1095 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1099 "%s is free software; you can redistribute it and/or modify\n"
1100 "it under the terms of the GNU General Public License as published by\n"
1101 "the Free Software Foundation; either version 2 of the License, or\n"
1102 "(at your option) any later version.\n"
1104 "%s is distributed in the hope that it will be useful,\n"
1105 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1106 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1107 "GNU General Public License for more details.\n"
1109 "You should have received a copy of the GNU General Public License\n"
1110 "along with %s; if not, write to the Free Software\n"
1111 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1115 "%s is free software; you can redistribute it and/or modify\n"
1116 "it under the terms of the GNU Lesser General Public License as published by\n"
1117 "the Free Software Foundation; either version 3 of the License, or\n"
1118 "(at your option) any later version.\n"
1120 "%s is distributed in the hope that it will be useful,\n"
1121 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1122 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1123 "GNU Lesser General Public License for more details.\n"
1125 "You should have received a copy of the GNU Lesser General Public License\n"
1126 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1130 "%s is free software; you can redistribute it and/or\n"
1131 "modify it under the terms of the GNU Lesser General Public\n"
1132 "License as published by the Free Software Foundation; either\n"
1133 "version 2.1 of the License, or (at your option) any later version.\n"
1135 "%s is distributed in the hope that it will be useful,\n"
1136 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1137 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1138 "Lesser General Public License for more details.\n"
1140 "You should have received a copy of the GNU Lesser General Public\n"
1141 "License along with %s; if not, write to the Free Software\n"
1142 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1153 const char *last_name;
1155 printf(
"File formats:\n"
1156 " D. = Demuxing supported\n"
1157 " .E = Muxing supported\n"
1164 const char *long_name =
NULL;
1167 if ((name ==
NULL || strcmp(ofmt->
name, name) < 0) &&
1168 strcmp(ofmt->
name, last_name) > 0) {
1175 if ((name ==
NULL || strcmp(ifmt->
name, name) < 0) &&
1176 strcmp(ifmt->
name, last_name) > 0) {
1181 if (name && strcmp(ifmt->
name, name) == 0)
1188 printf(
" %s%s %-15s %s\n",
1192 long_name ? long_name:
" ");
1197 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1198 if (codec->field) { \
1199 const type *p = codec->field; \
1201 printf(" Supported " list_name ":"); \
1202 while (*p != term) { \
1204 printf(" %s", name); \
1214 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1218 printf(
" Threading capabilities: ");
1225 default: printf(
"no");
break;
1233 printf(
" Supported framerates:");
1235 printf(
" %d/%d", fps->
num, fps->
den);
1264 default:
return '?';
1272 if (prev->
id ==
id &&
1284 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1285 strcmp((*da)->name, (*db)->name);
1292 unsigned nb_codecs = 0, i = 0;
1296 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1313 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
1316 printf(
"%s ", codec->
name);
1327 " D..... = Decoding supported\n"
1328 " .E.... = Encoding supported\n"
1329 " ..V... = Video codec\n"
1330 " ..A... = Audio codec\n"
1331 " ..S... = Subtitle codec\n"
1332 " ...I.. = Intra frame-only codec\n"
1333 " ....L. = Lossy compression\n"
1334 " .....S = Lossless compression\n"
1336 for (i = 0; i < nb_codecs; i++) {
1354 if (strcmp(codec->
name, desc->
name)) {
1361 if (strcmp(codec->
name, desc->
name)) {
1381 " S..... = Subtitle\n"
1382 " .F.... = Frame-level multithreading\n"
1383 " ..S... = Slice-level multithreading\n"
1384 " ...X.. = Codec is experimental\n"
1385 " ....B. = Supports draw_horiz_band\n"
1386 " .....D = Supports direct rendering method 1\n"
1388 encoder ?
"Encoders" :
"Decoders");
1389 for (i = 0; i < nb_codecs; i++) {
1402 if (strcmp(codec->
name, desc->
name))
1403 printf(
" (codec %s)", desc->
name);
1423 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1427 printf(
"Bitstream filters:\n");
1429 printf(
"%s\n", bsf->
name);
1436 void *opaque =
NULL;
1439 printf(
"Supported file protocols:\n"
1442 printf(
"%s\n", name);
1443 printf(
"Output:\n");
1445 printf(
"%s\n", name);
1452 char descr[64], *descr_cur;
1457 " T. = Timeline support\n"
1458 " .S = Slice threading\n"
1459 " A = Audio input/output\n"
1460 " V = Video input/output\n"
1461 " N = Dynamic number and/or type of input/output\n"
1462 " | = Source or sink filter\n");
1466 for (i = 0; i < 2; i++) {
1468 *(descr_cur++) =
'-';
1469 *(descr_cur++) =
'>';
1472 for (j = 0; pad && pad[j].
name; j++) {
1473 if (descr_cur >= descr +
sizeof(descr) - 4)
1482 printf(
" %c%c %-16s %-10s %s\n",
1495 printf(
"Pixel formats:\n"
1496 "I.... = Supported Input format for conversion\n"
1497 ".O... = Supported Output format for conversion\n"
1498 "..H.. = Hardware accelerated format\n"
1499 "...P. = Paletted format\n"
1500 "....B = Bitstream format\n"
1501 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1505 # define sws_isSupportedInput(x) 0
1506 # define sws_isSupportedOutput(x) 0
1511 printf(
"%c%c%c%c%c %-16s %d %2d\n",
1528 const char *
name, *descr;
1530 printf(
"Individual channels:\n"
1531 "NAME DESCRIPTION\n");
1532 for (i = 0; i < 63; i++) {
1537 printf(
"%-12s%s\n", name, descr);
1539 printf(
"\nStandard channel layouts:\n"
1540 "NAME DECOMPOSITION\n");
1543 printf(
"%-12s", name);
1544 for (j = 1; j; j <<= 1)
1587 "but no %s for it are available. FFmpeg might need to be "
1588 "recompiled with additional external libraries.\n",
1589 name, encoder ?
"encoders" :
"decoders");
1609 printf(
" Common extensions: %s.\n", fmt->
extensions);
1628 printf(
" Common extensions: %s.\n", fmt->
extensions);
1630 printf(
" Mime type: %s.\n", fmt->
mime_type);
1633 printf(
" Default video codec: %s.\n", desc->
name);
1637 printf(
" Default audio codec: %s.\n", desc->
name);
1641 printf(
" Default subtitle codec: %s.\n", desc->
name);
1649 static void show_help_filter(
const char *
name)
1663 printf(
"Filter %s\n", f->
name);
1668 printf(
" slice threading supported\n");
1670 printf(
" Inputs:\n");
1672 for (i = 0; i <
count; i++) {
1677 printf(
" dynamic (depending on the options)\n");
1679 printf(
" none (source filter)\n");
1681 printf(
" Outputs:\n");
1683 for (i = 0; i <
count; i++) {
1688 printf(
" dynamic (depending on the options)\n");
1690 printf(
" none (sink filter)\n");
1696 printf(
"This filter has support for timeline through the 'enable' option.\n");
1699 "can not to satisfy request\n");
1704 int show_help(
void *optctx,
const char *opt,
const char *arg)
1710 par = strchr(topic,
'=');
1716 }
else if (!strcmp(topic,
"decoder")) {
1718 }
else if (!strcmp(topic,
"encoder")) {
1720 }
else if (!strcmp(topic,
"demuxer")) {
1722 }
else if (!strcmp(topic,
"muxer")) {
1725 }
else if (!strcmp(topic,
"filter")) {
1726 show_help_filter(par);
1741 while (c !=
'\n' && c != EOF)
1750 FILE *f = fopen(filename,
"rb");
1757 fseek(f, 0, SEEK_END);
1759 fseek(f, 0, SEEK_SET);
1760 if (*size == (
size_t)-1) {
1771 ret = fread(*bufptr, 1, *size, f);
1776 filename, strerror(errno));
1782 (*bufptr)[(*size)++] =
'\0';
1790 const char *preset_name,
int is_path,
1791 const char *codec_name)
1795 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
1800 av_strlcpy(filename, preset_name, filename_size);
1801 f = fopen(filename,
"r");
1804 char datadir[MAX_PATH], *ls;
1807 if (GetModuleFileNameA(GetModuleHandleA(
NULL), datadir,
sizeof(datadir) - 1))
1809 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1810 if (*ls ==
'\\') *ls =
'/';
1812 if (ls = strrchr(datadir,
'/'))
1815 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
1820 for (i = 0; i < 3 && !f; i++) {
1823 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1824 i != 1 ?
"" :
"/.ffmpeg", preset_name);
1825 f = fopen(filename,
"r");
1826 if (!f && codec_name) {
1828 "%s%s/%s-%s.ffpreset",
1829 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
1831 f = fopen(filename,
"r");
1877 char *p = strchr(t->
key,
':');
1882 case 1: *p = 0;
break;
1884 default:
return NULL;
1892 else if (t->
key[0] == prefix &&
1914 "Could not alloc memory for stream options.\n");
1925 if (new_size >= INT_MAX / elem_size) {
1929 if (*size < new_size) {
1935 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);