51 #if HAVE_SYS_RESOURCE_H
53 #include <sys/resource.h>
81 vfprintf(stdout, fmt, vl);
85 double min,
double max)
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";
111 is_duration ?
"duration" :
"date", context, timestr);
118 int rej_flags,
int alt_flags)
124 for (po = options; po->
name !=
NULL; po++) {
127 if (((po->
flags & req_flags) != req_flags) ||
128 (alt_flags && !(po->
flags & alt_flags)) ||
129 (po->
flags & rej_flags))
141 printf(
"-%-17s %s\n", buf, po->
help);
158 const char *p = strchr(name,
':');
159 int len = p ? p - name : strlen(name);
162 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
169 #if HAVE_COMMANDLINETOARGVW
171 #include <shellapi.h>
173 static char** win32_argv_utf8 =
NULL;
174 static int win32_argc = 0;
187 int i, buffsize = 0, offset = 0;
189 if (win32_argv_utf8) {
190 *argc_ptr = win32_argc;
191 *argv_ptr = win32_argv_utf8;
196 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
197 if (win32_argc <= 0 || !argv_w)
201 for (i = 0; i < win32_argc; i++)
202 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
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) {
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],
218 win32_argv_utf8[i] =
NULL;
221 *argc_ptr = win32_argc;
222 *argv_ptr = win32_argv_utf8;
242 char *p = strchr(opt,
':');
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;
266 int ret = po->
u.
func_arg(optctx, opt, arg);
269 "Failed to set value '%s' for option '%s'\n", arg, opt);
286 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
313 void (*parse_arg_function)(
void *,
const char*))
316 int optindex, handleoptions = 1, ret;
323 while (optindex < argc) {
324 opt = argv[optindex++];
326 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
327 if (opt[1] ==
'-' && opt[2] ==
'\0') {
333 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
337 if (parse_arg_function)
338 parse_arg_function(optctx, opt);
350 for (i = 0; i < g->
nb_opts; i++) {
372 for (i = 1; i < argc; i++) {
373 const char *cur_opt = argv[i];
375 if (*cur_opt++ !=
'-')
379 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
382 if ((!po->
name && !strcmp(cur_opt, optname)) ||
383 (po->
name && !strcmp(optname, po->
name)))
397 if (idx && argv[idx + 1])
401 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
405 char opt_stripped[128];
412 if (!(p = strchr(opt,
':')))
413 p = opt + strlen(opt);
414 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
418 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
451 for (i = 0; i < nb_groups; i++) {
453 if (p->
sep && !strcmp(p->
sep, opt))
498 const char *key,
const char *val)
515 memset(octx, 0,
sizeof(*octx));
568 while (optindex < argc) {
569 const char *opt = argv[optindex++], *arg;
576 if (opt[0] !=
'-' || !opt[1]) {
583 #define GET_ARG(arg) \
585 arg = argv[optindex++]; \
587 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
588 return AVERROR(EINVAL); \
597 groups[ret].
name, arg);
606 arg = argv[optindex++];
615 "argument '%s'.\n", po->
name, po->
help, arg);
620 if (argv[optindex]) {
624 "argument '%s'.\n", opt, argv[optindex]);
629 "with argument '%s'.\n", opt, argv[optindex]);
635 if (opt[0] ==
'n' && opt[1] ==
'o' &&
640 "argument 0.\n", po->
name, po->
help);
659 const struct {
const char *
name;
int level; } log_levels[] = {
674 if (!strcmp(log_levels[i].
name, arg)) {
680 level = strtol(arg, &tail, 10);
683 "Possible levels are numbers or:\n", arg);
684 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
696 struct rlimit rl = { lim, lim + 1 };
697 if (setrlimit(RLIMIT_CPU, &rl))
708 const char *errbuf_ptr = errbuf;
720 #define SHOW_VERSION 2
721 #define SHOW_CONFIG 4
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", \
731 LIB##LIBNAME##_VERSION_MAJOR, \
732 LIB##LIBNAME##_VERSION_MINOR, \
733 LIB##LIBNAME##_VERSION_MICRO, \
734 version >> 16, version >> 8 & 0xff, version & 0xff); \
736 if (flags & SHOW_CONFIG) { \
737 const char *cfg = libname##_configuration(); \
738 if (strcmp(LIBAV_CONFIGURATION, cfg)) { \
740 av_log(NULL, level, \
741 "%sWARNING: library configuration mismatch\n", \
745 av_log(NULL, level, "%s%-11s configuration: %s\n", \
746 indent, #libname, cfg); \
765 "%s version " LIBAV_VERSION ", Copyright (c) %d-%d the Libav developers\n",
787 "This version of %s has nonfree parts compiled in.\n"
788 "Therefore it is not legally redistributable.\n",
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"
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"
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",
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"
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"
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",
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"
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"
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",
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"
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"
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",
858 const char *last_name;
860 printf(
"File formats:\n"
861 " D. = Demuxing supported\n"
862 " .E = Muxing supported\n"
869 const char *long_name =
NULL;
872 if ((name ==
NULL || strcmp(ofmt->
name, name) < 0) &&
873 strcmp(ofmt->
name, last_name) > 0) {
880 if ((name ==
NULL || strcmp(ifmt->
name, name) < 0) &&
881 strcmp(ifmt->
name, last_name) > 0) {
886 if (name && strcmp(ifmt->
name, name) == 0)
893 printf(
" %s%s %-15s %s\n",
897 long_name ? long_name:
" ");
902 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
903 if (codec->field) { \
904 const type *p = c->field; \
906 printf(" Supported " list_name ":"); \
907 while (*p != term) { \
909 printf(" %s", name); \
919 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
923 printf(
" Threading capabilities: ");
930 default: printf(
"no");
break;
938 printf(
" Supported framerates:");
940 printf(
" %d/%d", fps->
num, fps->
den);
975 if (prev->
id ==
id &&
986 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
989 printf(
"%s ", codec->
name);
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"
1024 if (strcmp(codec->
name, desc->
name)) {
1031 if (strcmp(codec->
name, desc->
name)) {
1049 " S... = Subtitle\n"
1050 " .F.. = Frame-level multithreading\n"
1051 " ..S. = Slice-level multithreading\n"
1052 " ...X = Codec is experimental\n"
1054 encoder ?
"Encoders" :
"Decoders");
1065 if (strcmp(codec->
name, desc->
name))
1066 printf(
" (codec %s)", desc->
name);
1085 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1089 printf(
"Bitstream filters:\n");
1091 printf(
"%s\n", bsf->
name);
1098 void *opaque =
NULL;
1101 printf(
"Supported file protocols:\n"
1104 printf(
"%s\n", name);
1105 printf(
"Output:\n");
1107 printf(
"%s\n", name);
1115 printf(
"Filters:\n");
1118 printf(
"%-16s %s\n", (*filter)->name, (*filter)->description);
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"
1137 # define sws_isSupportedInput(x) 0
1138 # define sws_isSupportedOutput(x) 0
1143 printf(
"%c%c%c%c%c %-16s %d %2d\n",
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");
1212 printf(
" Common extensions: %s.\n", fmt->
extensions);
1231 printf(
" Common extensions: %s.\n", fmt->
extensions);
1233 printf(
" Mime type: %s.\n", fmt->
mime_type);
1236 printf(
" Default video codec: %s.\n", desc->
name);
1240 printf(
" Default audio codec: %s.\n", desc->
name);
1244 printf(
" Default subtitle codec: %s.\n", desc->
name);
1251 int show_help(
void *optctx,
const char *opt,
const char *arg)
1257 par = strchr(topic,
'=');
1263 }
else if (!strcmp(topic,
"decoder")) {
1265 }
else if (!strcmp(topic,
"encoder")) {
1267 }
else if (!strcmp(topic,
"demuxer")) {
1269 }
else if (!strcmp(topic,
"muxer")) {
1282 int yesno = (toupper(c) ==
'Y');
1284 while (c !=
'\n' && c != EOF)
1293 FILE *f = fopen(filename,
"rb");
1300 fseek(f, 0, SEEK_END);
1302 fseek(f, 0, SEEK_SET);
1309 ret = fread(*bufptr, 1, *size, f);
1314 filename, strerror(errno));
1320 (*bufptr)[(*size)++] =
'\0';
1348 pts = reordered_pts;
1356 const char *preset_name,
int is_path,
1357 const char *codec_name)
1361 const char *base[3] = { getenv(
"AVCONV_DATADIR"),
1366 av_strlcpy(filename, preset_name, filename_size);
1367 f = fopen(filename,
"r");
1369 for (i = 0; i < 3 && !f; i++) {
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,
1380 f = fopen(filename,
"r");
1390 if (*spec <= '9' && *spec >=
'0')
1391 return strtol(spec,
NULL, 0) == st->
index;
1392 else if (*spec ==
'v' || *spec ==
'a' || *spec ==
's' || *spec ==
'd' ||
1406 if (*spec++ ==
':') {
1410 return i == st->
index;
1414 }
else if (*spec ==
'p' && *(spec + 1) ==
':') {
1418 prog_id = strtol(spec, &endptr, 0);
1423 if (*endptr++ ==
':') {
1424 int stream_idx = strtol(endptr,
NULL, 0);
1425 return stream_idx >= 0 &&
1458 switch (codec->
type) {
1474 char *p = strchr(t->
key,
':');
1479 case 1: *p = 0;
break;
1481 default:
return NULL;
1489 else if (t->
key[0] == prefix &&
1511 "Could not alloc memory for stream options.\n");
1522 if (new_size >= INT_MAX / elem_size) {
1526 if (*size < new_size) {
1532 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1545 int h_chroma_shift, v_chroma_shift;
1573 memset(buf->
base[0], 128, ret);
1576 &h_chroma_shift, &v_chroma_shift);
1579 const int h_shift = i==0 ? 0 : h_chroma_shift;
1580 const int v_shift = i==0 ? 0 : v_chroma_shift;
1583 else if (buf->
base[i])
1586 (pixel_size*edge >> h_shift), 32);