1 /*
2 * Various utilities for command line tools
3 * Copyright (c) 2000-2003 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <string.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <math.h>
26
27 /* Include only the enabled headers since some compilers (namely, Sun
28 Studio) will not omit unused inline functions and create undefined
29 references to libraries that are not being built. */
30
31 #include "config.h"
51 #include "version.h"
52 #if CONFIG_NETWORK
54 #endif
55 #if HAVE_SYS_RESOURCE_H
56 #include <sys/time.h>
57 #include <sys/resource.h>
58 #endif
59 #if CONFIG_OPENCL
61 #endif
62
63
65
69
71
73
75 {
76
77 if(CONFIG_SWSCALE)
79 NULL, NULL, NULL);
80 }
81
83 {
84 #if CONFIG_SWSCALE
86 sws_opts = NULL;
87 #endif
88
93 }
94
96 {
97 vfprintf(stdout, fmt, vl);
98 }
99
101 {
102 va_list vl2;
104 static int print_prefix = 1;
105
106 va_copy(vl2, vl);
109 va_end(vl2);
112 }
113
115
117 {
119 }
120
122 {
125
126 exit(ret);
127 }
128
130 double min,
double max)
131 {
132 char *tail;
133 const char *error;
135 if (*tail)
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";
143 else
144 return d;
147 return 0;
148 }
149
151 int is_duration)
152 {
153 int64_t us;
156 is_duration ? "duration" : "date", context, timestr);
158 }
159 return us;
160 }
161
163 int rej_flags, int alt_flags)
164 {
166 int first;
167
168 first = 1;
169 for (po = options; po->
name != NULL; po++) {
171
172 if (((po->
flags & req_flags) != req_flags) ||
173 (alt_flags && !(po->
flags & alt_flags)) ||
174 (po->
flags & rej_flags))
175 continue;
176
177 if (first) {
178 printf("%s\n", msg);
179 first = 0;
180 }
185 }
186 printf(
"-%-17s %s\n", buf, po->
help);
187 }
188 printf("\n");
189 }
190
192 {
196 printf("\n");
197 }
198
201 }
202
204 {
205 const char *p = strchr(name, ':');
206 int len = p ? p - name : strlen(name);
207
208 while (po->
name != NULL) {
209 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
210 break;
211 po++;
212 }
213 return po;
214 }
215
216 #if HAVE_COMMANDLINETOARGVW
217 #include <windows.h>
218 #include <shellapi.h>
219 /* Will be leaked on exit */
220 static char** win32_argv_utf8 = NULL;
221 static int win32_argc = 0;
222
223 /**
224 * Prepare command line arguments for executable.
225 * For Windows - perform wide-char to UTF-8 conversion.
226 * Input arguments should be main() function arguments.
227 * @param argc_ptr Arguments number (including executable)
228 * @param argv_ptr Arguments list.
229 */
231 {
232 char *argstr_flat;
233 wchar_t **argv_w;
234 int i, buffsize = 0,
offset = 0;
235
236 if (win32_argv_utf8) {
237 *argc_ptr = win32_argc;
238 *argv_ptr = win32_argv_utf8;
239 return;
240 }
241
242 win32_argc = 0;
243 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
244 if (win32_argc <= 0 || !argv_w)
245 return;
246
247 /* determine the UTF-8 buffer size (including NULL-termination symbols) */
248 for (i = 0; i < win32_argc; i++)
249 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
250 NULL, 0, NULL, NULL);
251
252 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
253 argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
254 if (win32_argv_utf8 == NULL) {
255 LocalFree(argv_w);
256 return;
257 }
258
259 for (i = 0; i < win32_argc; i++) {
260 win32_argv_utf8[i] = &argstr_flat[
offset];
261 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
263 buffsize - offset, NULL, NULL);
264 }
265 win32_argv_utf8[i] = NULL;
266 LocalFree(argv_w);
267
268 *argc_ptr = win32_argc;
269 *argv_ptr = win32_argv_utf8;
270 }
271 #else
273 {
274 /* nothing to do */
275 }
276 #endif /* HAVE_COMMANDLINETOARGVW */
277
280 {
281 /* new-style options contain an offset into optctx, old-style address of
282 * a global var*/
285 int *dstcount;
286
289 char *p = strchr(opt, ':');
290
291 dstcount = (int *)(so + 1);
292 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
293 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
294 dst = &(*so)[*dstcount - 1].u;
295 }
296
298 char *str;
301 *(char **)dst = str;
314 if (ret < 0) {
316 "Failed to set value '%s' for option '%s': %s\n",
319 }
320 }
323
324 return 0;
325 }
326
329 {
332
334 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
335 /* handle 'no' bool option */
338 arg = "0";
340 arg = "1";
341
347 }
351 }
352
354 if (ret < 0)
356
358 }
359
361 void (*parse_arg_function)(void *, const char*))
362 {
363 const char *opt;
364 int optindex, handleoptions = 1,
ret;
365
366 /* perform system-dependent conversions for arguments list */
368
369 /* parse options */
370 optindex = 1;
371 while (optindex < argc) {
372 opt = argv[optindex++];
373
374 if (handleoptions && opt[0] == '-' && opt[1] != '0円') {
375 if (opt[1] == '-' && opt[2] == '0円') {
376 handleoptions = 0;
377 continue;
378 }
379 opt++;
380
384 } else {
385 if (parse_arg_function)
386 parse_arg_function(optctx, opt);
387 }
388 }
389 }
390
392 {
394
397
398 for (i = 0; i < g->
nb_opts; i++) {
400
404 "%s %s -- you are trying to apply an input option to an "
405 "output file or vice versa. Move this option before the "
406 "file it belongs to.\n", o->
key, o->
opt->
help,
409 }
410
413
415 if (ret < 0)
417 }
418
420
421 return 0;
422 }
423
425 const char *optname)
426 {
428 int i;
429
430 for (i = 1; i < argc; i++) {
431 const char *cur_opt = argv[i];
432
433 if (*cur_opt++ != '-')
434 continue;
435
437 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
439
440 if ((!po->
name && !strcmp(cur_opt, optname)) ||
441 (po->
name && !strcmp(optname, po->
name)))
442 return i;
443
445 i++;
446 }
447 return 0;
448 }
449
451 {
452 const unsigned char *p;
453
454 for (p = a; *p; p++)
455 if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
456 *p == '_' || (*p >= 'a' && *p <= 'z')))
457 break;
458 if (!*p) {
460 return;
461 }
463 for (p = a; *p; p++) {
464 if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
466 else if (*p < ' ' || *p > '~')
468 else
470 }
472 }
473
475 {
477 const char *env;
478 if (!idx)
480 if (idx && argv[idx + 1])
483 if ((env = getenv("FFREPORT")) || idx) {
486 int i;
488 for (i = 0; i < argc; i++) {
491 }
493 }
494 }
495 }
496
497 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
499 {
501 int consumed = 0;
502 char opt_stripped[128];
503 const char *p;
505 #if CONFIG_AVRESAMPLE
507 #endif
509
510 if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
512
513 if (!(p = strchr(opt, ':')))
514 p = opt + strlen(opt);
515 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
516
519 ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
522 consumed = 1;
523 }
527 if (consumed)
529 consumed = 1;
530 }
531 #if CONFIG_SWSCALE
535 // XXX we only support sws_flags, not arbitrary sws options
537 if (ret < 0) {
540 }
541 consumed = 1;
542 }
543 #endif
544 #if CONFIG_SWRESAMPLE
546 if (!consumed && (o=
av_opt_find(&swr_class, opt, NULL, 0,
551 if (ret < 0) {
554 }
556 consumed = 1;
557 }
558 #endif
559 #if CONFIG_AVRESAMPLE
563 consumed = 1;
564 }
565 #endif
566
567 if (consumed)
568 return 0;
570 }
571
572 /*
573 * Check whether given option is a group separator.
574 *
575 * @return index of the group definition that matched or -1 if none
576 */
578 const char *opt)
579 {
580 int i;
581
582 for (i = 0; i < nb_groups; i++) {
584 if (p->
sep && !strcmp(p->
sep, opt))
585 return i;
586 }
587
588 return -1;
589 }
590
591 /*
592 * Finish parsing an option group.
593 *
594 * @param group_idx which group definition should this group belong to
595 * @param arg argument of the group delimiting option
596 */
599 {
602
605
609 #if CONFIG_SWSCALE
611 #endif
616
617 codec_opts = NULL;
618 format_opts = NULL;
619 resample_opts = NULL;
620 #if CONFIG_SWSCALE
621 sws_opts = NULL;
622 #endif
623 swr_opts = NULL;
625
627 }
628
629 /*
630 * Add an option instance to currently parsed group.
631 */
633 const char *key,
const char *
val)
634 {
637
642 }
643
646 {
648 int i;
649
650 memset(octx, 0, sizeof(*octx));
651
656
659
662
664 }
665
667 {
668 int i, j;
669
672
678 #if CONFIG_SWSCALE
680 #endif
682 }
684 }
686
689
691 }
692
696 {
697 int optindex = 1;
698 int dashdash = -2;
699
700 /* perform system-dependent conversions for arguments list */
702
705
706 while (optindex < argc) {
707 const char *opt = argv[optindex++], *
arg;
710
712
713 if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
714 dashdash = optindex;
715 continue;
716 }
717 /* unnamed group separators, e.g. output filename */
718 if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
721 continue;
722 }
723 opt++;
724
725 #define GET_ARG(arg) \
726 do { \
727 arg = argv[optindex++]; \
728 if (!arg) { \
729 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
730 return AVERROR(EINVAL); \
731 } \
732 } while (0)
733
734 /* named group separators, e.g. -i */
739 groups[ret].
name, arg);
740 continue;
741 }
742
743 /* normal options */
747 /* optional argument, e.g. -h */
748 arg = argv[optindex++];
751 } else {
752 arg = "1";
753 }
754
757 "argument '%s'.\n", po->
name, po->
help, arg);
758 continue;
759 }
760
761 /* AVOptions */
762 if (argv[optindex]) {
764 if (ret >= 0) {
766 "argument '%s'.\n", opt, argv[optindex]);
767 optindex++;
768 continue;
771 "with argument '%s'.\n", opt, argv[optindex]);
773 }
774 }
775
776 /* boolean -nofoo options */
777 if (opt[0] == 'n' && opt[1] == 'o' &&
782 "argument 0.\n", po->
name, po->
help);
783 continue;
784 }
785
788 }
789
792 "commandline.\n");
793
795
796 return 0;
797 }
798
800 {
801 const struct {
const char *
name;
int level; } log_levels[] = {
810 };
811 char *tail;
813 int i;
814
815 tail = strstr(arg, "repeat");
817 if (tail == arg)
818 arg += 6 + (arg[6]=='+');
819 if(tail && !*arg)
820 return 0;
821
823 if (!strcmp(log_levels[i].
name, arg)) {
825 return 0;
826 }
827 }
828
829 level = strtol(arg, &tail, 10);
830 if (*tail) {
832 "Possible levels are numbers or:\n", arg);
836 }
838 return 0;
839 }
840
842 struct tm *tm)
843 {
845
846 while ((c = *(template++))) {
847 if (c == '%') {
848 if (!(c = *(template++)))
849 break;
850 switch (c) {
851 case 'p':
853 break;
854 case 't':
856 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
857 tm->tm_hour, tm->tm_min, tm->tm_sec);
858 break;
859 case '%':
861 break;
862 }
863 } else {
865 }
866 }
867 }
868
870 {
871 char *filename_template = NULL;
874 time_t now;
875 struct tm *tm;
877
879 return 0;
880 time(&now);
881 tm = localtime(&now);
882
883 while (env && *env) {
885 if (count)
887 "Failed to parse FFREPORT environment variable: %s\n",
889 break;
890 }
891 if (*env)
892 env++;
893 count++;
894 if (!strcmp(key, "file")) {
896 filename_template =
val;
897 val = NULL;
898 } else {
900 }
903 }
904
912 }
913
917 filename.str, strerror(errno));
919 }
922 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
923 "Report written to \"%s\"\n",
925 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
926 tm->tm_hour, tm->tm_min, tm->tm_sec,
927 filename.str);
929 return 0;
930 }
931
933 {
935 }
936
938 {
939 char *tail;
940 size_t max;
941
942 max = strtol(arg, &tail, 10);
943 if (*tail) {
946 }
948 return 0;
949 }
950
952 {
955
958
960 return 0;
961 }
962
964 {
965 #if HAVE_SETRLIMIT
967 struct rlimit rl = { lim, lim + 1 };
968 if (setrlimit(RLIMIT_CPU, &rl))
969 perror("setrlimit");
970 #else
972 #endif
973 return 0;
974 }
975
976 #if CONFIG_OPENCL
977 int opt_opencl(
void *optctx,
const char *opt,
const char *
arg)
978 {
980 const char *opts =
arg;
982 while (*opts) {
984 if (ret < 0)
987 if (ret < 0)
989 if (*opts)
990 opts++;
991 }
993 }
994 #endif
995
997 {
998 char errbuf[128];
999 const char *errbuf_ptr = errbuf;
1000
1004 }
1005
1007
1009 #define SHOW_VERSION 2
1010 #define SHOW_CONFIG 4
1011 #define SHOW_COPYRIGHT 8
1012
1013 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1014 if (CONFIG_##LIBNAME) { \
1015 const char *indent = flags & INDENT? " " : ""; \
1016 if (flags & SHOW_VERSION) { \
1017 unsigned int version = libname##_version(); \
1018 av_log(NULL, level, \
1019 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1020 indent, #libname, \
1021 LIB##LIBNAME##_VERSION_MAJOR, \
1022 LIB##LIBNAME##_VERSION_MINOR, \
1023 LIB##LIBNAME##_VERSION_MICRO, \
1024 version >> 16, version >> 8 & 0xff, version & 0xff); \
1025 } \
1026 if (flags & SHOW_CONFIG) { \
1027 const char *cfg = libname##_configuration(); \
1028 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1029 if (!warned_cfg) { \
1030 av_log(NULL, level, \
1031 "%sWARNING: library configuration mismatch\n", \
1032 indent); \
1033 warned_cfg = 1; \
1034 } \
1035 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1036 indent, #libname, cfg); \
1037 } \
1038 } \
1039 } \
1040
1042 {
1052 }
1053
1055 {
1056 const char *indent = flags &
INDENT?
" " :
"";
1057
1060 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1062 av_log(NULL, level,
"\n");
1063 av_log(NULL, level,
"%sbuilt on %s %s with %s\n",
1064 indent, __DATE__, __TIME__, CC_IDENT);
1065
1066 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1067 }
1068
1070 {
1072 if (idx)
1073 return;
1074
1078 }
1079
1081 {
1085
1086 return 0;
1087 }
1088
1090 {
1091 #if CONFIG_NONFREE
1092 printf(
1093 "This version of %s has nonfree parts compiled in.\n"
1094 "Therefore it is not legally redistributable.\n",
1096 #elif CONFIG_GPLV3
1097 printf(
1098 "%s is free software; you can redistribute it and/or modify\n"
1099 "it under the terms of the GNU General Public License as published by\n"
1100 "the Free Software Foundation; either version 3 of the License, or\n"
1101 "(at your option) any later version.\n"
1102 "\n"
1103 "%s is distributed in the hope that it will be useful,\n"
1104 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1105 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1106 "GNU General Public License for more details.\n"
1107 "\n"
1108 "You should have received a copy of the GNU General Public License\n"
1109 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1111 #elif CONFIG_GPL
1112 printf(
1113 "%s is free software; you can redistribute it and/or modify\n"
1114 "it under the terms of the GNU General Public License as published by\n"
1115 "the Free Software Foundation; either version 2 of the License, or\n"
1116 "(at your option) any later version.\n"
1117 "\n"
1118 "%s is distributed in the hope that it will be useful,\n"
1119 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1120 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1121 "GNU General Public License for more details.\n"
1122 "\n"
1123 "You should have received a copy of the GNU General Public License\n"
1124 "along with %s; if not, write to the Free Software\n"
1125 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1127 #elif CONFIG_LGPLV3
1128 printf(
1129 "%s is free software; you can redistribute it and/or modify\n"
1130 "it under the terms of the GNU Lesser General Public License as published by\n"
1131 "the Free Software Foundation; either version 3 of the License, or\n"
1132 "(at your option) any later version.\n"
1133 "\n"
1134 "%s is distributed in the hope that it will be useful,\n"
1135 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1136 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1137 "GNU Lesser General Public License for more details.\n"
1138 "\n"
1139 "You should have received a copy of the GNU Lesser General Public License\n"
1140 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1142 #else
1143 printf(
1144 "%s is free software; you can redistribute it and/or\n"
1145 "modify it under the terms of the GNU Lesser General Public\n"
1146 "License as published by the Free Software Foundation; either\n"
1147 "version 2.1 of the License, or (at your option) any later version.\n"
1148 "\n"
1149 "%s is distributed in the hope that it will be useful,\n"
1150 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1151 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1152 "Lesser General Public License for more details.\n"
1153 "\n"
1154 "You should have received a copy of the GNU Lesser General Public\n"
1155 "License along with %s; if not, write to the Free Software\n"
1156 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1158 #endif
1159
1160 return 0;
1161 }
1162
1164 {
1167 const char *last_name;
1168
1169 printf("File formats:\n"
1170 " D. = Demuxing supported\n"
1171 " .E = Muxing supported\n"
1172 " --\n");
1173 last_name = "000";
1174 for (;;) {
1176 int encode = 0;
1177 const char *
name = NULL;
1178 const char *long_name = NULL;
1179
1181 if ((name == NULL || strcmp(ofmt->
name, name) < 0) &&
1182 strcmp(ofmt->
name, last_name) > 0) {
1185 encode = 1;
1186 }
1187 }
1189 if ((name == NULL || strcmp(ifmt->
name, name) < 0) &&
1190 strcmp(ifmt->
name, last_name) > 0) {
1193 encode = 0;
1194 }
1195 if (name && strcmp(ifmt->
name, name) == 0)
1196 decode = 1;
1197 }
1198 if (name == NULL)
1199 break;
1201
1202 printf(" %s%s %-15s %s\n",
1203 decode ? "D" : " ",
1204 encode ? "E" : " ",
1205 name,
1206 long_name ? long_name:" ");
1207 }
1208 return 0;
1209 }
1210
1211 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1212 if (codec->field) { \
1213 const type *p = codec->field; \
1214 \
1215 printf(" Supported " list_name ":"); \
1216 while (*p != term) { \
1217 get_name(*p); \
1218 printf(" %s", name); \
1219 p++; \
1220 } \
1221 printf("\n"); \
1222 } \
1223
1225 {
1227
1228 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1230
1233 printf(" Threading capabilities: ");
1240 default: printf("no"); break;
1241 }
1242 printf("\n");
1243 }
1244
1247
1248 printf(" Supported framerates:");
1250 printf(
" %d/%d", fps->
num, fps->
den);
1251 fps++;
1252 }
1253 printf("\n");
1254 }
1263
1268 }
1269 }
1270
1272 {
1273 switch (type) {
1279 default: return '?';
1280 }
1281 }
1282
1284 int encoder)
1285 {
1287 if (prev->
id ==
id &&
1289 return prev;
1290 }
1291 return NULL;
1292 }
1293
1295 {
1298
1299 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1300 strcmp((*da)->name, (*db)->name);
1301 }
1302
1304 {
1307 unsigned nb_codecs = 0, i = 0;
1308
1310 nb_codecs++;
1311 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1314 }
1315 desc = NULL;
1317 codecs[i++] = desc;
1320 *rcodecs = codecs;
1321 return nb_codecs;
1322 }
1323
1325 {
1327
1328 printf(" (%s: ", encoder ? "encoders" : "decoders");
1329
1331 printf(
"%s ", codec->
name);
1332
1333 printf(")");
1334 }
1335
1337 {
1340
1341 printf("Codecs:\n"
1342 " D..... = Decoding supported\n"
1343 " .E.... = Encoding supported\n"
1344 " ..V... = Video codec\n"
1345 " ..A... = Audio codec\n"
1346 " ..S... = Subtitle codec\n"
1347 " ...I.. = Intra frame-only codec\n"
1348 " ....L. = Lossy compression\n"
1349 " .....S = Lossless compression\n"
1350 " -------\n");
1351 for (i = 0; i < nb_codecs; i++) {
1354
1355 printf(" ");
1358
1363
1365
1366 /* print decoders/encoders when there's more than one or their
1367 * names are different from codec name */
1369 if (strcmp(codec->
name, desc->
name)) {
1371 break;
1372 }
1373 }
1374 codec = NULL;
1376 if (strcmp(codec->
name, desc->
name)) {
1378 break;
1379 }
1380 }
1381
1382 printf("\n");
1383 }
1385 return 0;
1386 }
1387
1389 {
1392
1393 printf("%s:\n"
1394 " V..... = Video\n"
1395 " A..... = Audio\n"
1396 " S..... = Subtitle\n"
1397 " .F.... = Frame-level multithreading\n"
1398 " ..S... = Slice-level multithreading\n"
1399 " ...X.. = Codec is experimental\n"
1400 " ....B. = Supports draw_horiz_band\n"
1401 " .....D = Supports direct rendering method 1\n"
1402 " ------\n",
1403 encoder ? "Encoders" : "Decoders");
1404 for (i = 0; i < nb_codecs; i++) {
1407
1415
1417 if (strcmp(codec->
name, desc->
name))
1418 printf(
" (codec %s)", desc->
name);
1419
1420 printf("\n");
1421 }
1422 }
1424 }
1425
1427 {
1429 return 0;
1430 }
1431
1433 {
1435 return 0;
1436 }
1437
1438 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1439 {
1441
1442 printf("Bitstream filters:\n");
1444 printf(
"%s\n", bsf->
name);
1445 printf("\n");
1446 return 0;
1447 }
1448
1450 {
1451 void *opaque = NULL;
1453
1454 printf("Supported file protocols:\n"
1455 "Input:\n");
1457 printf("%s\n", name);
1458 printf("Output:\n");
1460 printf("%s\n", name);
1461 return 0;
1462 }
1463
1465 {
1467 char descr[64], *descr_cur;
1468 int i, j;
1470
1471 printf("Filters:\n"
1472 " T. = Timeline support\n"
1473 " .S = Slice threading\n"
1474 " A = Audio input/output\n"
1475 " V = Video input/output\n"
1476 " N = Dynamic number and/or type of input/output\n"
1477 " | = Source or sink filter\n");
1478 #if CONFIG_AVFILTER
1480 descr_cur = descr;
1481 for (i = 0; i < 2; i++) {
1482 if (i) {
1483 *(descr_cur++) = '-';
1484 *(descr_cur++) = '>';
1485 }
1487 for (j = 0; pad && pad[j].
name; j++) {
1488 if (descr_cur >= descr + sizeof(descr) - 4)
1489 break;
1491 }
1492 if (!j)
1495 }
1496 *descr_cur = 0;
1497 printf(" %c%c %-16s %-10s %s\n",
1501 }
1502 #endif
1503 return 0;
1504 }
1505
1507 {
1509
1510 printf("Pixel formats:\n"
1511 "I.... = Supported Input format for conversion\n"
1512 ".O... = Supported Output format for conversion\n"
1513 "..H.. = Hardware accelerated format\n"
1514 "...P. = Paletted format\n"
1515 "....B = Bitstream format\n"
1516 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1517 "-----\n");
1518
1519 #if !CONFIG_SWSCALE
1520 # define sws_isSupportedInput(x) 0
1521 # define sws_isSupportedOutput(x) 0
1522 #endif
1523
1526 printf("%c%c%c%c%c %-16s %d %2d\n",
1535 }
1536 return 0;
1537 }
1538
1540 {
1541 int i = 0;
1543 const char *
name, *descr;
1544
1545 printf("Individual channels:\n"
1546 "NAME DESCRIPTION\n");
1547 for (i = 0; i < 63; i++) {
1549 if (!name)
1550 continue;
1552 printf("%-12s%s\n", name, descr);
1553 }
1554 printf("\nStandard channel layouts:\n"
1555 "NAME DECOMPOSITION\n");
1557 if (name) {
1558 printf("%-12s", name);
1559 for (j = 1; j; j <<= 1)
1560 if ((layout & j))
1562 printf("\n");
1563 }
1564 }
1565 return 0;
1566 }
1567
1569 {
1570 int i;
1571 char fmt_str[128];
1574 return 0;
1575 }
1576
1578 {
1581
1582 if (!name) {
1584 return;
1585 }
1586
1589
1590 if (codec)
1593 int printed = 0;
1594
1596 printed = 1;
1598 }
1599
1600 if (!printed) {
1602 "but no %s for it are available. FFmpeg might need to be "
1603 "recompiled with additional external libraries.\n",
1604 name, encoder ? "encoders" : "decoders");
1605 }
1606 } else {
1608 name);
1609 }
1610 }
1611
1613 {
1615
1616 if (!fmt) {
1618 return;
1619 }
1620
1622
1624 printf(
" Common extensions: %s.\n", fmt->
extensions);
1625
1628 }
1629
1631 {
1634
1635 if (!fmt) {
1637 return;
1638 }
1639
1641
1643 printf(
" Common extensions: %s.\n", fmt->
extensions);
1645 printf(
" Mime type: %s.\n", fmt->
mime_type);
1648 printf(
" Default video codec: %s.\n", desc->
name);
1649 }
1652 printf(
" Default audio codec: %s.\n", desc->
name);
1653 }
1656 printf(
" Default subtitle codec: %s.\n", desc->
name);
1657 }
1658
1661 }
1662
1663 #if CONFIG_AVFILTER
1664 static void show_help_filter(
const char *
name)
1665 {
1666 #if CONFIG_AVFILTER
1669
1670 if (!name) {
1672 return;
1673 } else if (!f) {
1675 return;
1676 }
1677
1678 printf(
"Filter %s\n", f->
name);
1681
1683 printf(" slice threading supported\n");
1684
1685 printf(" Inputs:\n");
1687 for (i = 0; i <
count; i++) {
1690 }
1692 printf(" dynamic (depending on the options)\n");
1693 else if (!count)
1694 printf(" none (source filter)\n");
1695
1696 printf(" Outputs:\n");
1698 for (i = 0; i <
count; i++) {
1701 }
1703 printf(" dynamic (depending on the options)\n");
1704 else if (!count)
1705 printf(" none (sink filter)\n");
1706
1711 printf("This filter has support for timeline through the 'enable' option.\n");
1712 #else
1714 "can not to satisfy request\n");
1715 #endif
1716 }
1717 #endif
1718
1719 int show_help(
void *optctx,
const char *opt,
const char *arg)
1720 {
1721 char *topic, *par;
1723
1725 par = strchr(topic, '=');
1726 if (par)
1727 *par++ = 0;
1728
1729 if (!*topic) {
1731 } else if (!strcmp(topic, "decoder")) {
1733 } else if (!strcmp(topic, "encoder")) {
1735 } else if (!strcmp(topic, "demuxer")) {
1737 } else if (!strcmp(topic, "muxer")) {
1739 #if CONFIG_AVFILTER
1740 } else if (!strcmp(topic, "filter")) {
1741 show_help_filter(par);
1742 #endif
1743 } else {
1745 }
1746
1748 return 0;
1749 }
1750
1752 {
1755
1756 while (c != '\n' && c != EOF)
1757 c = getchar();
1758
1759 return yesno;
1760 }
1761
1763 {
1765 FILE *f = fopen(filename, "rb");
1766
1767 if (!f) {
1769 strerror(errno));
1771 }
1772 fseek(f, 0, SEEK_END);
1773 *size = ftell(f);
1774 fseek(f, 0, SEEK_SET);
1775 if (*size == (size_t)-1) {
1777 fclose(f);
1779 }
1781 if (!*bufptr) {
1783 fclose(f);
1785 }
1786 ret = fread(*bufptr, 1, *size, f);
1787 if (ret < *size) {
1789 if (ferror(f)) {
1791 filename, strerror(errno));
1793 } else
1795 } else {
1796 ret = 0;
1797 (*bufptr)[(*size)++] = '0円';
1798 }
1799
1800 fclose(f);
1802 }
1803
1805 const char *preset_name, int is_path,
1806 const char *codec_name)
1807 {
1808 FILE *f = NULL;
1809 int i;
1810 const char *base[3] = { getenv("FFMPEG_DATADIR"),
1811 getenv("HOME"),
1812 FFMPEG_DATADIR, };
1813
1814 if (is_path) {
1815 av_strlcpy(filename, preset_name, filename_size);
1816 f = fopen(filename, "r");
1817 } else {
1818 #ifdef _WIN32
1819 char datadir[MAX_PATH], *ls;
1820 base[2] = NULL;
1821
1822 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
1823 {
1824 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1825 if (*ls == '\\') *ls = '/';
1826
1827 if (ls = strrchr(datadir, '/'))
1828 {
1829 *ls = 0;
1830 strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
1831 base[2] = datadir;
1832 }
1833 }
1834 #endif
1835 for (i = 0; i < 3 && !f; i++) {
1836 if (!base[i])
1837 continue;
1838 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1839 i != 1 ? "" : "/.ffmpeg", preset_name);
1840 f = fopen(filename, "r");
1841 if (!f && codec_name) {
1843 "%s%s/%s-%s.ffpreset",
1844 base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
1845 preset_name);
1846 f = fopen(filename, "r");
1847 }
1848 }
1849 }
1850
1851 return f;
1852 }
1853
1855 {
1857 if (ret < 0)
1860 }
1861
1864 {
1869 char prefix = 0;
1871
1872 if (!codec)
1875
1878 prefix = 'v';
1880 break;
1882 prefix = 'a';
1884 break;
1886 prefix = 's';
1888 break;
1889 }
1890
1892 char *p = strchr(t->
key,
':');
1893
1894 /* check stream specification in opt name */
1895 if (p)
1897 case 1: *p = 0; break;
1898 case 0: continue;
1899 default: return NULL;
1900 }
1901
1907 else if (t->
key[0] == prefix &&
1911
1912 if (p)
1913 *p = ':';
1914 }
1916 }
1917
1920 {
1921 int i;
1923
1925 return NULL;
1927 if (!opts) {
1929 "Could not alloc memory for stream options.\n");
1930 return NULL;
1931 }
1935 return opts;
1936 }
1937
1939 {
1940 if (new_size >= INT_MAX / elem_size) {
1943 }
1944 if (*size < new_size) {
1946 if (!tmp) {
1949 }
1950 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1951 *size = new_size;
1952 return tmp;
1953 }
1954 return array;
1955 }