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 <stdint.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <math.h>
27
28 /* Include only the enabled headers since some compilers (namely, Sun
29 Studio) will not omit unused inline functions and create undefined
30 references to libraries that are not being built. */
31
32 #include "config.h"
52 #include "libavutil/ffversion.h"
54 #if CONFIG_NETWORK
56 #endif
57 #if HAVE_SYS_RESOURCE_H
58 #include <sys/time.h>
59 #include <sys/resource.h>
60 #endif
61
63
67
71
73 {
74
75 if(CONFIG_SWSCALE)
77 NULL, NULL, NULL);
78 }
79
81 {
82 #if CONFIG_SWSCALE
84 sws_opts = NULL;
85 #endif
86
91 }
92
94 {
95 vfprintf(stdout, fmt, vl);
96 }
97
99 {
100 va_list vl2;
102 static int print_prefix = 1;
103
107 va_end(vl2);
111 }
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 /* _WIN32 means using the windows libc - cygwin doesn't define that
217 * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
218 * it doesn't provide the actual command line via GetCommandLineW(). */
219 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
220 #include <windows.h>
221 #include <shellapi.h>
222 /* Will be leaked on exit */
223 static char** win32_argv_utf8 = NULL;
224 static int win32_argc = 0;
225
226 /**
227 * Prepare command line arguments for executable.
228 * For Windows - perform wide-char to UTF-8 conversion.
229 * Input arguments should be main() function arguments.
230 * @param argc_ptr Arguments number (including executable)
231 * @param argv_ptr Arguments list.
232 */
234 {
235 char *argstr_flat;
236 wchar_t **argv_w;
237 int i, buffsize = 0,
offset = 0;
238
239 if (win32_argv_utf8) {
240 *argc_ptr = win32_argc;
241 *argv_ptr = win32_argv_utf8;
242 return;
243 }
244
245 win32_argc = 0;
246 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
247 if (win32_argc <= 0 || !argv_w)
248 return;
249
250 /* determine the UTF-8 buffer size (including NULL-termination symbols) */
251 for (i = 0; i < win32_argc; i++)
252 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
253 NULL, 0, NULL, NULL);
254
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 == NULL) {
258 LocalFree(argv_w);
259 return;
260 }
261
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);
267 }
268 win32_argv_utf8[i] = NULL;
269 LocalFree(argv_w);
270
271 *argc_ptr = win32_argc;
272 *argv_ptr = win32_argv_utf8;
273 }
274 #else
276 {
277 /* nothing to do */
278 }
279 #endif /* HAVE_COMMANDLINETOARGVW */
280
283 {
284 /* new-style options contain an offset into optctx, old-style address of
285 * a global var*/
288 int *dstcount;
289
292 char *p = strchr(opt, ':');
293
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;
298 }
299
301 char *str;
304 *(char **)dst = str;
317 if (ret < 0) {
319 "Failed to set value '%s' for option '%s': %s\n",
322 }
323 }
326
327 return 0;
328 }
329
332 {
335
337 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
338 /* handle 'no' bool option */
341 arg = "0";
343 arg = "1";
344
350 }
354 }
355
357 if (ret < 0)
359
361 }
362
364 void (*parse_arg_function)(void *, const char*))
365 {
366 const char *opt;
367 int optindex, handleoptions = 1,
ret;
368
369 /* perform system-dependent conversions for arguments list */
371
372 /* parse options */
373 optindex = 1;
374 while (optindex < argc) {
375 opt = argv[optindex++];
376
377 if (handleoptions && opt[0] == '-' && opt[1] != '0円') {
378 if (opt[1] == '-' && opt[2] == '0円') {
379 handleoptions = 0;
380 continue;
381 }
382 opt++;
383
387 } else {
388 if (parse_arg_function)
389 parse_arg_function(optctx, opt);
390 }
391 }
392 }
393
395 {
397
400
401 for (i = 0; i < g->
nb_opts; i++) {
403
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,
412 }
413
416
418 if (ret < 0)
420 }
421
423
424 return 0;
425 }
426
428 const char *optname)
429 {
431 int i;
432
433 for (i = 1; i < argc; i++) {
434 const char *cur_opt = argv[i];
435
436 if (*cur_opt++ != '-')
437 continue;
438
440 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
442
443 if ((!po->
name && !strcmp(cur_opt, optname)) ||
444 (po->
name && !strcmp(optname, po->
name)))
445 return i;
446
448 i++;
449 }
450 return 0;
451 }
452
454 {
455 const unsigned char *p;
456
457 for (p = a; *p; p++)
458 if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
459 *p == '_' || (*p >= 'a' && *p <= 'z')))
460 break;
461 if (!*p) {
463 return;
464 }
466 for (p = a; *p; p++) {
467 if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
469 else if (*p < ' ' || *p > '~')
471 else
473 }
475 }
476
478 {
480 const char *env;
481 if (!idx)
483 if (idx && argv[idx + 1])
486 if ((env = getenv("FFREPORT")) || idx) {
489 int i;
491 for (i = 0; i < argc; i++) {
494 }
496 }
497 }
499 if (idx)
501 }
502
504 int opt_flags, int search_flags)
505 {
508 return NULL;
509 return o;
510 }
511
512 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
514 {
516 int consumed = 0;
517 char opt_stripped[128];
518 const char *p;
520 #if CONFIG_AVRESAMPLE
522 #endif
524
525 if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
527
528 if (!(p = strchr(opt, ':')))
529 p = opt + strlen(opt);
530 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
531
532 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
534 ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
537 consumed = 1;
538 }
542 if (consumed)
544 consumed = 1;
545 }
546 #if CONFIG_SWSCALE
548 if (!consumed &&
opt_find(&sc, opt, NULL, 0,
550 // XXX we only support sws_flags, not arbitrary sws options
552 if (ret < 0) {
555 }
556 consumed = 1;
557 }
558 #else
559 if (!consumed && !strcmp(opt, "sws_flags")) {
561 consumed = 1;
562 }
563 #endif
564 #if CONFIG_SWRESAMPLE
566 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
571 if (ret < 0) {
574 }
576 consumed = 1;
577 }
578 #endif
579 #if CONFIG_AVRESAMPLE
583 consumed = 1;
584 }
585 #endif
586
587 if (consumed)
588 return 0;
590 }
591
592 /*
593 * Check whether given option is a group separator.
594 *
595 * @return index of the group definition that matched or -1 if none
596 */
598 const char *opt)
599 {
600 int i;
601
602 for (i = 0; i < nb_groups; i++) {
604 if (p->
sep && !strcmp(p->
sep, opt))
605 return i;
606 }
607
608 return -1;
609 }
610
611 /*
612 * Finish parsing an option group.
613 *
614 * @param group_idx which group definition should this group belong to
615 * @param arg argument of the group delimiting option
616 */
619 {
622
625
629 #if CONFIG_SWSCALE
631 #endif
636
637 codec_opts = NULL;
638 format_opts = NULL;
639 resample_opts = NULL;
640 #if CONFIG_SWSCALE
641 sws_opts = NULL;
642 #endif
643 swr_opts = NULL;
645
647 }
648
649 /*
650 * Add an option instance to currently parsed group.
651 */
653 const char *key,
const char *
val)
654 {
657
662 }
663
666 {
668 int i;
669
670 memset(octx, 0, sizeof(*octx));
671
676
679
682
684 }
685
687 {
688 int i, j;
689
692
698 #if CONFIG_SWSCALE
700 #endif
702 }
704 }
706
709
711 }
712
716 {
717 int optindex = 1;
718 int dashdash = -2;
719
720 /* perform system-dependent conversions for arguments list */
722
725
726 while (optindex < argc) {
727 const char *opt = argv[optindex++], *
arg;
730
732
733 if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
734 dashdash = optindex;
735 continue;
736 }
737 /* unnamed group separators, e.g. output filename */
738 if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
741 continue;
742 }
743 opt++;
744
745 #define GET_ARG(arg) \
746 do { \
747 arg = argv[optindex++]; \
748 if (!arg) { \
749 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
750 return AVERROR(EINVAL); \
751 } \
752 } while (0)
753
754 /* named group separators, e.g. -i */
759 groups[ret].
name, arg);
760 continue;
761 }
762
763 /* normal options */
767 /* optional argument, e.g. -h */
768 arg = argv[optindex++];
771 } else {
772 arg = "1";
773 }
774
777 "argument '%s'.\n", po->
name, po->
help, arg);
778 continue;
779 }
780
781 /* AVOptions */
782 if (argv[optindex]) {
784 if (ret >= 0) {
786 "argument '%s'.\n", opt, argv[optindex]);
787 optindex++;
788 continue;
791 "with argument '%s'.\n", opt, argv[optindex]);
793 }
794 }
795
796 /* boolean -nofoo options */
797 if (opt[0] == 'n' && opt[1] == 'o' &&
802 "argument 0.\n", po->
name, po->
help);
803 continue;
804 }
805
808 }
809
812 "commandline.\n");
813
815
816 return 0;
817 }
818
820 {
823
826
828 return 0;
829 }
830
832 {
833 const struct {
const char *
name;
int level; } log_levels[] = {
842 };
843 char *tail;
846 int i;
847
849 tail = strstr(arg, "repeat");
850 if (tail)
852 else
854
856 if (tail == arg)
857 arg += 6 + (arg[6]=='+');
858 if(tail && !*arg)
859 return 0;
860
862 if (!strcmp(log_levels[i].
name, arg)) {
864 return 0;
865 }
866 }
867
868 level = strtol(arg, &tail, 10);
869 if (*tail) {
871 "Possible levels are numbers or:\n", arg);
875 }
877 return 0;
878 }
879
881 struct tm *tm)
882 {
884
885 while ((c = *(template++))) {
886 if (c == '%') {
887 if (!(c = *(template++)))
888 break;
889 switch (c) {
890 case 'p':
892 break;
893 case 't':
895 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
896 tm->tm_hour, tm->tm_min, tm->tm_sec);
897 break;
898 case '%':
900 break;
901 }
902 } else {
904 }
905 }
906 }
907
909 {
910 char *filename_template = NULL;
913 time_t now;
914 struct tm *tm;
916
918 return 0;
919 time(&now);
920 tm = localtime(&now);
921
922 while (env && *env) {
924 if (count)
926 "Failed to parse FFREPORT environment variable: %s\n",
928 break;
929 }
930 if (*env)
931 env++;
932 count++;
933 if (!strcmp(key, "file")) {
935 filename_template =
val;
936 val = NULL;
937 } else if (!strcmp(key, "level")) {
938 char *tail;
940 if (*tail) {
943 }
944 } else {
946 }
949 }
950
958 }
959
963 filename.str, strerror(errno));
965 }
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,
973 filename.str);
975 return 0;
976 }
977
979 {
981 }
982
984 {
985 char *tail;
986 size_t max;
987
988 max = strtol(arg, &tail, 10);
989 if (*tail) {
992 }
994 return 0;
995 }
996
998 {
999 #if HAVE_SETRLIMIT
1001 struct rlimit rl = { lim, lim + 1 };
1002 if (setrlimit(RLIMIT_CPU, &rl))
1003 perror("setrlimit");
1004 #else
1006 #endif
1007 return 0;
1008 }
1009
1011 {
1012 char errbuf[128];
1013 const char *errbuf_ptr = errbuf;
1014
1018 }
1019
1021
1023 #define SHOW_VERSION 2
1024 #define SHOW_CONFIG 4
1025 #define SHOW_COPYRIGHT 8
1026
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", \
1034 indent, #libname, \
1035 LIB##LIBNAME##_VERSION_MAJOR, \
1036 LIB##LIBNAME##_VERSION_MINOR, \
1037 LIB##LIBNAME##_VERSION_MICRO, \
1038 version >> 16, version >> 8 & 0xff, version & 0xff); \
1039 } \
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", \
1046 indent); \
1047 warned_cfg = 1; \
1048 } \
1049 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1050 indent, #libname, cfg); \
1051 } \
1052 } \
1053 } \
1054
1056 {
1066 }
1067
1069 {
1070 const char *indent = flags &
INDENT?
" " :
"";
1071
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);
1079
1080 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1081 }
1082
1084 {
1085 const char *indent = flags &
INDENT ?
" " :
"";
1086 char str[] = { FFMPEG_CONFIGURATION };
1087 char *conflist, *remove_tilde, *splitconf;
1088
1089 // Change all the ' --' strings to '~--' so that
1090 // they can be identified as tokens.
1091 while ((conflist = strstr(str, " --")) != NULL) {
1092 strncpy(conflist, "~--", 3);
1093 }
1094
1095 // Compensate for the weirdness this would cause
1096 // when passing 'pkg-config --static'.
1097 while ((remove_tilde = strstr(str, "pkg-config~")) != NULL) {
1098 strncpy(remove_tilde, "pkg-config ", 11);
1099 }
1100
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, "~");
1106 }
1107 }
1108
1110 {
1113 return;
1114
1118 }
1119
1121 {
1125
1126 return 0;
1127 }
1128
1130 {
1133
1134 return 0;
1135 }
1136
1138 {
1139 #if CONFIG_NONFREE
1140 printf(
1141 "This version of %s has nonfree parts compiled in.\n"
1142 "Therefore it is not legally redistributable.\n",
1144 #elif CONFIG_GPLV3
1145 printf(
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"
1150 "\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"
1155 "\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",
1159 #elif CONFIG_GPL
1160 printf(
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"
1165 "\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"
1170 "\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",
1175 #elif CONFIG_LGPLV3
1176 printf(
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"
1181 "\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"
1186 "\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",
1190 #else
1191 printf(
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"
1196 "\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"
1201 "\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",
1206 #endif
1207
1208 return 0;
1209 }
1210
1212 {
1213 if (!avclass)
1214 return 0;
1221 }
1222
1224 {
1227 const char *last_name;
1228 int is_dev;
1229
1230 printf("%s\n"
1231 " D. = Demuxing supported\n"
1232 " .E = Muxing supported\n"
1233 " --\n", device_only ? "Devices:" : "File formats:");
1234 last_name = "000";
1235 for (;;) {
1237 int encode = 0;
1238 const char *
name = NULL;
1239 const char *long_name = NULL;
1240
1243 if (!is_dev && device_only)
1244 continue;
1245 if ((name == NULL || strcmp(ofmt->
name, name) < 0) &&
1246 strcmp(ofmt->
name, last_name) > 0) {
1249 encode = 1;
1250 }
1251 }
1254 if (!is_dev && device_only)
1255 continue;
1256 if ((name == NULL || strcmp(ifmt->
name, name) < 0) &&
1257 strcmp(ifmt->
name, last_name) > 0) {
1260 encode = 0;
1261 }
1262 if (name && strcmp(ifmt->
name, name) == 0)
1263 decode = 1;
1264 }
1265 if (name == NULL)
1266 break;
1268
1269 printf(" %s%s %-15s %s\n",
1270 decode ? "D" : " ",
1271 encode ? "E" : " ",
1272 name,
1273 long_name ? long_name:" ");
1274 }
1275 return 0;
1276 }
1277
1279 {
1281 }
1282
1284 {
1286 }
1287
1288 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1289 if (codec->field) { \
1290 const type *p = codec->field; \
1291 \
1292 printf(" Supported " list_name ":"); \
1293 while (*p != term) { \
1294 get_name(*p); \
1295 printf(" %s", name); \
1296 p++; \
1297 } \
1298 printf("\n"); \
1299 } \
1300
1302 {
1304
1305 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1307
1310 printf(" Threading capabilities: ");
1317 default: printf("no"); break;
1318 }
1319 printf("\n");
1320 }
1321
1324
1325 printf(" Supported framerates:");
1327 printf(
" %d/%d", fps->
num, fps->
den);
1328 fps++;
1329 }
1330 printf("\n");
1331 }
1340
1345 }
1346 }
1347
1349 {
1350 switch (type) {
1356 default: return '?';
1357 }
1358 }
1359
1361 int encoder)
1362 {
1364 if (prev->
id ==
id &&
1366 return prev;
1367 }
1368 return NULL;
1369 }
1370
1372 {
1375
1376 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1377 strcmp((*da)->name, (*db)->name);
1378 }
1379
1381 {
1384 unsigned nb_codecs = 0, i = 0;
1385
1387 nb_codecs++;
1388 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1391 }
1392 desc = NULL;
1394 codecs[i++] = desc;
1397 *rcodecs = codecs;
1398 return nb_codecs;
1399 }
1400
1402 {
1404
1405 printf(" (%s: ", encoder ? "encoders" : "decoders");
1406
1408 printf(
"%s ", codec->
name);
1409
1410 printf(")");
1411 }
1412
1414 {
1417
1418 printf("Codecs:\n"
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"
1427 " -------\n");
1428 for (i = 0; i < nb_codecs; i++) {
1431
1432 if (strstr(desc->
name,
"_deprecated"))
1433 continue;
1434
1435 printf(" ");
1438
1443
1445
1446 /* print decoders/encoders when there's more than one or their
1447 * names are different from codec name */
1449 if (strcmp(codec->
name, desc->
name)) {
1451 break;
1452 }
1453 }
1454 codec = NULL;
1456 if (strcmp(codec->
name, desc->
name)) {
1458 break;
1459 }
1460 }
1461
1462 printf("\n");
1463 }
1465 return 0;
1466 }
1467
1469 {
1472
1473 printf("%s:\n"
1474 " V..... = Video\n"
1475 " A..... = Audio\n"
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"
1482 " ------\n",
1483 encoder ? "Encoders" : "Decoders");
1484 for (i = 0; i < nb_codecs; i++) {
1487
1495
1497 if (strcmp(codec->
name, desc->
name))
1498 printf(
" (codec %s)", desc->
name);
1499
1500 printf("\n");
1501 }
1502 }
1504 }
1505
1507 {
1509 return 0;
1510 }
1511
1513 {
1515 return 0;
1516 }
1517
1519 {
1521
1522 printf("Bitstream filters:\n");
1524 printf(
"%s\n", bsf->
name);
1525 printf("\n");
1526 return 0;
1527 }
1528
1530 {
1531 void *opaque = NULL;
1533
1534 printf("Supported file protocols:\n"
1535 "Input:\n");
1537 printf("%s\n", name);
1538 printf("Output:\n");
1540 printf("%s\n", name);
1541 return 0;
1542 }
1543
1545 {
1547 char descr[64], *descr_cur;
1548 int i, j;
1550
1551 printf("Filters:\n"
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");
1559 #if CONFIG_AVFILTER
1561 descr_cur = descr;
1562 for (i = 0; i < 2; i++) {
1563 if (i) {
1564 *(descr_cur++) = '-';
1565 *(descr_cur++) = '>';
1566 }
1568 for (j = 0; pad && pad[j].
name; j++) {
1569 if (descr_cur >= descr + sizeof(descr) - 4)
1570 break;
1572 }
1573 if (!j)
1576 }
1577 *descr_cur = 0;
1578 printf(" %c%c%c %-16s %-10s %s\n",
1581 filter->process_command ?
'C' :
'.',
1583 }
1584 #endif
1585 return 0;
1586 }
1587
1589 {
1592 int i;
1593
1594 printf("%-32s #RRGGBB\n", "name");
1595
1597 printf("%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1598
1599 return 0;
1600 }
1601
1603 {
1605
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"
1613 "-----\n");
1614
1615 #if !CONFIG_SWSCALE
1616 # define sws_isSupportedInput(x) 0
1617 # define sws_isSupportedOutput(x) 0
1618 #endif
1619
1622 printf("%c%c%c%c%c %-16s %d %2d\n",
1631 }
1632 return 0;
1633 }
1634
1636 {
1637 int i = 0;
1639 const char *
name, *descr;
1640
1641 printf("Individual channels:\n"
1642 "NAME DESCRIPTION\n");
1643 for (i = 0; i < 63; i++) {
1645 if (!name)
1646 continue;
1648 printf("%-12s%s\n", name, descr);
1649 }
1650 printf("\nStandard channel layouts:\n"
1651 "NAME DECOMPOSITION\n");
1653 if (name) {
1654 printf("%-12s", name);
1655 for (j = 1; j; j <<= 1)
1656 if ((layout & j))
1658 printf("\n");
1659 }
1660 }
1661 return 0;
1662 }
1663
1665 {
1666 int i;
1667 char fmt_str[128];
1670 return 0;
1671 }
1672
1674 {
1677
1678 if (!name) {
1680 return;
1681 }
1682
1685
1686 if (codec)
1689 int printed = 0;
1690
1692 printed = 1;
1694 }
1695
1696 if (!printed) {
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");
1701 }
1702 } else {
1704 name);
1705 }
1706 }
1707
1709 {
1711
1712 if (!fmt) {
1714 return;
1715 }
1716
1718
1720 printf(
" Common extensions: %s.\n", fmt->
extensions);
1721
1724 }
1725
1727 {
1730
1731 if (!fmt) {
1733 return;
1734 }
1735
1737
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);
1745 }
1748 printf(
" Default audio codec: %s.\n", desc->
name);
1749 }
1752 printf(
" Default subtitle codec: %s.\n", desc->
name);
1753 }
1754
1757 }
1758
1759 #if CONFIG_AVFILTER
1760 static void show_help_filter(
const char *
name)
1761 {
1762 #if CONFIG_AVFILTER
1765
1766 if (!name) {
1768 return;
1769 } else if (!f) {
1771 return;
1772 }
1773
1774 printf(
"Filter %s\n", f->
name);
1777
1779 printf(" slice threading supported\n");
1780
1781 printf(" Inputs:\n");
1783 for (i = 0; i <
count; i++) {
1786 }
1788 printf(" dynamic (depending on the options)\n");
1789 else if (!count)
1790 printf(" none (source filter)\n");
1791
1792 printf(" Outputs:\n");
1794 for (i = 0; i <
count; i++) {
1797 }
1799 printf(" dynamic (depending on the options)\n");
1800 else if (!count)
1801 printf(" none (sink filter)\n");
1802
1807 printf("This filter has support for timeline through the 'enable' option.\n");
1808 #else
1810 "can not to satisfy request\n");
1811 #endif
1812 }
1813 #endif
1814
1816 {
1817 char *topic, *par;
1819
1821 par = strchr(topic, '=');
1822 if (par)
1823 *par++ = 0;
1824
1825 if (!*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")) {
1835 #if CONFIG_AVFILTER
1836 } else if (!strcmp(topic, "filter")) {
1837 show_help_filter(par);
1838 #endif
1839 } else {
1841 }
1842
1844 return 0;
1845 }
1846
1848 {
1851
1852 while (c != '\n' && c != EOF)
1853 c = getchar();
1854
1855 return yesno;
1856 }
1857
1859 {
1862
1863 if (!f) {
1865 strerror(errno));
1867 }
1868 fseek(f, 0, SEEK_END);
1869 *size = ftell(f);
1870 fseek(f, 0, SEEK_SET);
1871 if (*size == (size_t)-1) {
1873 fclose(f);
1875 }
1877 if (!*bufptr) {
1879 fclose(f);
1881 }
1882 ret = fread(*bufptr, 1, *size, f);
1883 if (ret < *size) {
1885 if (ferror(f)) {
1887 filename, strerror(errno));
1889 } else
1891 } else {
1892 ret = 0;
1893 (*bufptr)[(*size)++] = '0円';
1894 }
1895
1896 fclose(f);
1898 }
1899
1901 const char *preset_name, int is_path,
1902 const char *codec_name)
1903 {
1904 FILE *f = NULL;
1905 int i;
1906 const char *base[3] = { getenv("FFMPEG_DATADIR"),
1907 getenv("HOME"),
1908 FFMPEG_DATADIR, };
1909
1910 if (is_path) {
1911 av_strlcpy(filename, preset_name, filename_size);
1912 f = fopen(filename, "r");
1913 } else {
1914 #ifdef _WIN32
1915 char datadir[MAX_PATH], *ls;
1916 base[2] = NULL;
1917
1918 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
1919 {
1920 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1921 if (*ls == '\\') *ls = '/';
1922
1923 if (ls = strrchr(datadir, '/'))
1924 {
1925 *ls = 0;
1926 strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
1927 base[2] = datadir;
1928 }
1929 }
1930 #endif
1931 for (i = 0; i < 3 && !f; i++) {
1932 if (!base[i])
1933 continue;
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,
1941 preset_name);
1942 f = fopen(filename, "r");
1943 }
1944 }
1945 }
1946
1947 return f;
1948 }
1949
1951 {
1953 if (ret < 0)
1956 }
1957
1960 {
1965 char prefix = 0;
1967
1968 if (!codec)
1971
1974 prefix = 'v';
1976 break;
1978 prefix = 'a';
1980 break;
1982 prefix = 's';
1984 break;
1985 }
1986
1988 char *p = strchr(t->
key,
':');
1989
1990 /* check stream specification in opt name */
1991 if (p)
1993 case 1: *p = 0; break;
1994 case 0: continue;
1995 default: return NULL;
1996 }
1997
1999 !codec ||
2004 else if (t->
key[0] == prefix &&
2008
2009 if (p)
2010 *p = ':';
2011 }
2013 }
2014
2017 {
2018 int i;
2020
2022 return NULL;
2024 if (!opts) {
2026 "Could not alloc memory for stream options.\n");
2027 return NULL;
2028 }
2032 return opts;
2033 }
2034
2036 {
2037 if (new_size >= INT_MAX / elem_size) {
2040 }
2041 if (*size < new_size) {
2043 if (!tmp) {
2046 }
2047 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
2048 *size = new_size;
2049 return tmp;
2050 }
2051 return array;
2052 }