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"
52 #include "version.h"
53 #if CONFIG_NETWORK
55 #endif
56 #if HAVE_SYS_RESOURCE_H
57 #include <sys/time.h>
58 #include <sys/resource.h>
59 #endif
60 #if CONFIG_OPENCL
62 #endif
63
64
66
70
72
74
76 {
77
78 if(CONFIG_SWSCALE)
80 NULL, NULL, NULL);
81 }
82
84 {
85 #if CONFIG_SWSCALE
87 sws_opts = NULL;
88 #endif
89
94 }
95
97 {
98 vfprintf(stdout, fmt, vl);
99 }
100
102 {
103 va_list vl2;
105 static int print_prefix = 1;
106
107 va_copy(vl2, vl);
110 va_end(vl2);
113 }
114
116
118 {
120 }
121
123 {
126
127 exit(ret);
128 }
129
131 double min,
double max)
132 {
133 char *tail;
134 const char *error;
136 if (*tail)
137 error = "Expected number for %s but found: %s\n";
138 else if (d < min || d > max)
139 error = "The value for %s was %s which is not within %f - %f\n";
140 else if (type ==
OPT_INT64 && (int64_t)d != d)
141 error = "Expected int64 for %s but found %s\n";
142 else if (type ==
OPT_INT && (
int)d != d)
143 error = "Expected int for %s but found %s\n";
144 else
145 return d;
148 return 0;
149 }
150
152 int is_duration)
153 {
154 int64_t us;
157 is_duration ? "duration" : "date", context, timestr);
159 }
160 return us;
161 }
162
164 int rej_flags, int alt_flags)
165 {
167 int first;
168
169 first = 1;
170 for (po = options; po->
name != NULL; po++) {
172
173 if (((po->
flags & req_flags) != req_flags) ||
174 (alt_flags && !(po->
flags & alt_flags)) ||
175 (po->
flags & rej_flags))
176 continue;
177
178 if (first) {
179 printf("%s\n", msg);
180 first = 0;
181 }
186 }
187 printf(
"-%-17s %s\n", buf, po->
help);
188 }
189 printf("\n");
190 }
191
193 {
197 printf("\n");
198 }
199
202 }
203
205 {
206 const char *p = strchr(name, ':');
207 int len = p ? p - name : strlen(name);
208
209 while (po->
name != NULL) {
210 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
211 break;
212 po++;
213 }
214 return po;
215 }
216
217 /* _WIN32 means using the windows libc - cygwin doesn't define that
218 * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
219 * it doesn't provide the actual command line via GetCommandLineW(). */
220 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
221 #include <windows.h>
222 #include <shellapi.h>
223 /* Will be leaked on exit */
224 static char** win32_argv_utf8 = NULL;
225 static int win32_argc = 0;
226
227 /**
228 * Prepare command line arguments for executable.
229 * For Windows - perform wide-char to UTF-8 conversion.
230 * Input arguments should be main() function arguments.
231 * @param argc_ptr Arguments number (including executable)
232 * @param argv_ptr Arguments list.
233 */
235 {
236 char *argstr_flat;
237 wchar_t **argv_w;
238 int i, buffsize = 0,
offset = 0;
239
240 if (win32_argv_utf8) {
241 *argc_ptr = win32_argc;
242 *argv_ptr = win32_argv_utf8;
243 return;
244 }
245
246 win32_argc = 0;
247 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
248 if (win32_argc <= 0 || !argv_w)
249 return;
250
251 /* determine the UTF-8 buffer size (including NULL-termination symbols) */
252 for (i = 0; i < win32_argc; i++)
253 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
254 NULL, 0, NULL, NULL);
255
256 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
257 argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
258 if (win32_argv_utf8 == NULL) {
259 LocalFree(argv_w);
260 return;
261 }
262
263 for (i = 0; i < win32_argc; i++) {
264 win32_argv_utf8[i] = &argstr_flat[
offset];
265 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
267 buffsize - offset, NULL, NULL);
268 }
269 win32_argv_utf8[i] = NULL;
270 LocalFree(argv_w);
271
272 *argc_ptr = win32_argc;
273 *argv_ptr = win32_argv_utf8;
274 }
275 #else
277 {
278 /* nothing to do */
279 }
280 #endif /* HAVE_COMMANDLINETOARGVW */
281
284 {
285 /* new-style options contain an offset into optctx, old-style address of
286 * a global var*/
289 int *dstcount;
290
293 char *p = strchr(opt, ':');
294
295 dstcount = (int *)(so + 1);
296 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
297 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
298 dst = &(*so)[*dstcount - 1].u;
299 }
300
302 char *str;
305 *(char **)dst = str;
318 if (ret < 0) {
320 "Failed to set value '%s' for option '%s': %s\n",
323 }
324 }
327
328 return 0;
329 }
330
333 {
336
338 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
339 /* handle 'no' bool option */
342 arg = "0";
344 arg = "1";
345
351 }
355 }
356
358 if (ret < 0)
360
362 }
363
365 void (*parse_arg_function)(void *, const char*))
366 {
367 const char *opt;
368 int optindex, handleoptions = 1,
ret;
369
370 /* perform system-dependent conversions for arguments list */
372
373 /* parse options */
374 optindex = 1;
375 while (optindex < argc) {
376 opt = argv[optindex++];
377
378 if (handleoptions && opt[0] == '-' && opt[1] != '0円') {
379 if (opt[1] == '-' && opt[2] == '0円') {
380 handleoptions = 0;
381 continue;
382 }
383 opt++;
384
388 } else {
389 if (parse_arg_function)
390 parse_arg_function(optctx, opt);
391 }
392 }
393 }
394
396 {
398
401
402 for (i = 0; i < g->
nb_opts; i++) {
404
408 "%s %s -- you are trying to apply an input option to an "
409 "output file or vice versa. Move this option before the "
410 "file it belongs to.\n", o->
key, o->
opt->
help,
413 }
414
417
419 if (ret < 0)
421 }
422
424
425 return 0;
426 }
427
429 const char *optname)
430 {
432 int i;
433
434 for (i = 1; i < argc; i++) {
435 const char *cur_opt = argv[i];
436
437 if (*cur_opt++ != '-')
438 continue;
439
441 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
443
444 if ((!po->
name && !strcmp(cur_opt, optname)) ||
445 (po->
name && !strcmp(optname, po->
name)))
446 return i;
447
449 i++;
450 }
451 return 0;
452 }
453
455 {
456 const unsigned char *p;
457
458 for (p = a; *p; p++)
459 if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
460 *p == '_' || (*p >= 'a' && *p <= 'z')))
461 break;
462 if (!*p) {
464 return;
465 }
467 for (p = a; *p; p++) {
468 if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
470 else if (*p < ' ' || *p > '~')
472 else
474 }
476 }
477
479 {
481 const char *env;
482 if (!idx)
484 if (idx && argv[idx + 1])
487 if ((env = getenv("FFREPORT")) || idx) {
490 int i;
492 for (i = 0; i < argc; i++) {
495 }
497 }
498 }
499 }
500
502 int opt_flags, int search_flags)
503 {
506 return NULL;
507 return o;
508 }
509
510 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
512 {
514 int consumed = 0;
515 char opt_stripped[128];
516 const char *p;
518 #if CONFIG_AVRESAMPLE
520 #endif
522
523 if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
525
526 if (!(p = strchr(opt, ':')))
527 p = opt + strlen(opt);
528 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
529
530 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
532 ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
535 consumed = 1;
536 }
540 if (consumed)
542 consumed = 1;
543 }
544 #if CONFIG_SWSCALE
546 if (!consumed &&
opt_find(&sc, opt, NULL, 0,
548 // XXX we only support sws_flags, not arbitrary sws options
550 if (ret < 0) {
553 }
554 consumed = 1;
555 }
556 #endif
557 #if CONFIG_SWRESAMPLE
559 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
564 if (ret < 0) {
567 }
569 consumed = 1;
570 }
571 #endif
572 #if CONFIG_AVRESAMPLE
576 consumed = 1;
577 }
578 #endif
579
580 if (consumed)
581 return 0;
583 }
584
585 /*
586 * Check whether given option is a group separator.
587 *
588 * @return index of the group definition that matched or -1 if none
589 */
591 const char *opt)
592 {
593 int i;
594
595 for (i = 0; i < nb_groups; i++) {
597 if (p->
sep && !strcmp(p->
sep, opt))
598 return i;
599 }
600
601 return -1;
602 }
603
604 /*
605 * Finish parsing an option group.
606 *
607 * @param group_idx which group definition should this group belong to
608 * @param arg argument of the group delimiting option
609 */
612 {
615
618
622 #if CONFIG_SWSCALE
624 #endif
629
630 codec_opts = NULL;
631 format_opts = NULL;
632 resample_opts = NULL;
633 #if CONFIG_SWSCALE
634 sws_opts = NULL;
635 #endif
636 swr_opts = NULL;
638
640 }
641
642 /*
643 * Add an option instance to currently parsed group.
644 */
646 const char *key,
const char *
val)
647 {
650
655 }
656
659 {
661 int i;
662
663 memset(octx, 0, sizeof(*octx));
664
669
672
675
677 }
678
680 {
681 int i, j;
682
685
691 #if CONFIG_SWSCALE
693 #endif
695 }
697 }
699
702
704 }
705
709 {
710 int optindex = 1;
711 int dashdash = -2;
712
713 /* perform system-dependent conversions for arguments list */
715
718
719 while (optindex < argc) {
720 const char *opt = argv[optindex++], *
arg;
723
725
726 if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
727 dashdash = optindex;
728 continue;
729 }
730 /* unnamed group separators, e.g. output filename */
731 if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
734 continue;
735 }
736 opt++;
737
738 #define GET_ARG(arg) \
739 do { \
740 arg = argv[optindex++]; \
741 if (!arg) { \
742 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
743 return AVERROR(EINVAL); \
744 } \
745 } while (0)
746
747 /* named group separators, e.g. -i */
752 groups[ret].
name, arg);
753 continue;
754 }
755
756 /* normal options */
760 /* optional argument, e.g. -h */
761 arg = argv[optindex++];
764 } else {
765 arg = "1";
766 }
767
770 "argument '%s'.\n", po->
name, po->
help, arg);
771 continue;
772 }
773
774 /* AVOptions */
775 if (argv[optindex]) {
777 if (ret >= 0) {
779 "argument '%s'.\n", opt, argv[optindex]);
780 optindex++;
781 continue;
784 "with argument '%s'.\n", opt, argv[optindex]);
786 }
787 }
788
789 /* boolean -nofoo options */
790 if (opt[0] == 'n' && opt[1] == 'o' &&
795 "argument 0.\n", po->
name, po->
help);
796 continue;
797 }
798
801 }
802
805 "commandline.\n");
806
808
809 return 0;
810 }
811
813 {
816
819
821 return 0;
822 }
823
825 {
826 const struct {
const char *
name;
int level; } log_levels[] = {
835 };
836 char *tail;
838 int i;
839
840 tail = strstr(arg, "repeat");
842 if (tail == arg)
843 arg += 6 + (arg[6]=='+');
844 if(tail && !*arg)
845 return 0;
846
848 if (!strcmp(log_levels[i].
name, arg)) {
850 return 0;
851 }
852 }
853
854 level = strtol(arg, &tail, 10);
855 if (*tail) {
857 "Possible levels are numbers or:\n", arg);
861 }
863 return 0;
864 }
865
867 struct tm *tm)
868 {
870
871 while ((c = *(template++))) {
872 if (c == '%') {
873 if (!(c = *(template++)))
874 break;
875 switch (c) {
876 case 'p':
878 break;
879 case 't':
881 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
882 tm->tm_hour, tm->tm_min, tm->tm_sec);
883 break;
884 case '%':
886 break;
887 }
888 } else {
890 }
891 }
892 }
893
895 {
896 char *filename_template = NULL;
899 time_t now;
900 struct tm *tm;
902
904 return 0;
905 time(&now);
906 tm = localtime(&now);
907
908 while (env && *env) {
910 if (count)
912 "Failed to parse FFREPORT environment variable: %s\n",
914 break;
915 }
916 if (*env)
917 env++;
918 count++;
919 if (!strcmp(key, "file")) {
921 filename_template =
val;
922 val = NULL;
923 } else {
925 }
928 }
929
937 }
938
942 filename.str, strerror(errno));
944 }
947 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
948 "Report written to \"%s\"\n",
950 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
951 tm->tm_hour, tm->tm_min, tm->tm_sec,
952 filename.str);
954 return 0;
955 }
956
958 {
960 }
961
963 {
964 char *tail;
965 size_t max;
966
967 max = strtol(arg, &tail, 10);
968 if (*tail) {
971 }
973 return 0;
974 }
975
977 {
978 #if HAVE_SETRLIMIT
980 struct rlimit rl = { lim, lim + 1 };
981 if (setrlimit(RLIMIT_CPU, &rl))
982 perror("setrlimit");
983 #else
985 #endif
986 return 0;
987 }
988
989 #if CONFIG_OPENCL
990 int opt_opencl(
void *optctx,
const char *opt,
const char *
arg)
991 {
993 const char *opts =
arg;
995 while (*opts) {
997 if (ret < 0)
1000 if (ret < 0)
1002 if (*opts)
1003 opts++;
1004 }
1006 }
1007 #endif
1008
1010 {
1011 char errbuf[128];
1012 const char *errbuf_ptr = errbuf;
1013
1017 }
1018
1020
1022 #define SHOW_VERSION 2
1023 #define SHOW_CONFIG 4
1024 #define SHOW_COPYRIGHT 8
1025
1026 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1027 if (CONFIG_##LIBNAME) { \
1028 const char *indent = flags & INDENT? " " : ""; \
1029 if (flags & SHOW_VERSION) { \
1030 unsigned int version = libname##_version(); \
1031 av_log(NULL, level, \
1032 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1033 indent, #libname, \
1034 LIB##LIBNAME##_VERSION_MAJOR, \
1035 LIB##LIBNAME##_VERSION_MINOR, \
1036 LIB##LIBNAME##_VERSION_MICRO, \
1037 version >> 16, version >> 8 & 0xff, version & 0xff); \
1038 } \
1039 if (flags & SHOW_CONFIG) { \
1040 const char *cfg = libname##_configuration(); \
1041 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1042 if (!warned_cfg) { \
1043 av_log(NULL, level, \
1044 "%sWARNING: library configuration mismatch\n", \
1045 indent); \
1046 warned_cfg = 1; \
1047 } \
1048 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1049 indent, #libname, cfg); \
1050 } \
1051 } \
1052 } \
1053
1055 {
1065 }
1066
1068 {
1069 const char *indent = flags &
INDENT?
" " :
"";
1070
1073 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1075 av_log(NULL, level,
"\n");
1076 av_log(NULL, level,
"%sbuilt on %s %s with %s\n",
1077 indent, __DATE__, __TIME__, CC_IDENT);
1078
1079 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1080 }
1081
1083 {
1085 if (idx)
1086 return;
1087
1091 }
1092
1094 {
1098
1099 return 0;
1100 }
1101
1103 {
1104 #if CONFIG_NONFREE
1105 printf(
1106 "This version of %s has nonfree parts compiled in.\n"
1107 "Therefore it is not legally redistributable.\n",
1109 #elif CONFIG_GPLV3
1110 printf(
1111 "%s is free software; you can redistribute it and/or modify\n"
1112 "it under the terms of the GNU General Public License as published by\n"
1113 "the Free Software Foundation; either version 3 of the License, or\n"
1114 "(at your option) any later version.\n"
1115 "\n"
1116 "%s is distributed in the hope that it will be useful,\n"
1117 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1118 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1119 "GNU General Public License for more details.\n"
1120 "\n"
1121 "You should have received a copy of the GNU General Public License\n"
1122 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1124 #elif CONFIG_GPL
1125 printf(
1126 "%s is free software; you can redistribute it and/or modify\n"
1127 "it under the terms of the GNU General Public License as published by\n"
1128 "the Free Software Foundation; either version 2 of the License, or\n"
1129 "(at your option) any later version.\n"
1130 "\n"
1131 "%s is distributed in the hope that it will be useful,\n"
1132 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1133 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1134 "GNU General Public License for more details.\n"
1135 "\n"
1136 "You should have received a copy of the GNU General Public License\n"
1137 "along with %s; if not, write to the Free Software\n"
1138 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1140 #elif CONFIG_LGPLV3
1141 printf(
1142 "%s is free software; you can redistribute it and/or modify\n"
1143 "it under the terms of the GNU Lesser General Public License as published by\n"
1144 "the Free Software Foundation; either version 3 of the License, or\n"
1145 "(at your option) any later version.\n"
1146 "\n"
1147 "%s is distributed in the hope that it will be useful,\n"
1148 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1149 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1150 "GNU Lesser General Public License for more details.\n"
1151 "\n"
1152 "You should have received a copy of the GNU Lesser General Public License\n"
1153 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1155 #else
1156 printf(
1157 "%s is free software; you can redistribute it and/or\n"
1158 "modify it under the terms of the GNU Lesser General Public\n"
1159 "License as published by the Free Software Foundation; either\n"
1160 "version 2.1 of the License, or (at your option) any later version.\n"
1161 "\n"
1162 "%s is distributed in the hope that it will be useful,\n"
1163 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1164 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1165 "Lesser General Public License for more details.\n"
1166 "\n"
1167 "You should have received a copy of the GNU Lesser General Public\n"
1168 "License along with %s; if not, write to the Free Software\n"
1169 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1171 #endif
1172
1173 return 0;
1174 }
1175
1177 {
1180 const char *last_name;
1181
1182 printf("File formats:\n"
1183 " D. = Demuxing supported\n"
1184 " .E = Muxing supported\n"
1185 " --\n");
1186 last_name = "000";
1187 for (;;) {
1189 int encode = 0;
1190 const char *
name = NULL;
1191 const char *long_name = NULL;
1192
1194 if ((name == NULL || strcmp(ofmt->
name, name) < 0) &&
1195 strcmp(ofmt->
name, last_name) > 0) {
1198 encode = 1;
1199 }
1200 }
1202 if ((name == NULL || strcmp(ifmt->
name, name) < 0) &&
1203 strcmp(ifmt->
name, last_name) > 0) {
1206 encode = 0;
1207 }
1208 if (name && strcmp(ifmt->
name, name) == 0)
1209 decode = 1;
1210 }
1211 if (name == NULL)
1212 break;
1214
1215 printf(" %s%s %-15s %s\n",
1216 decode ? "D" : " ",
1217 encode ? "E" : " ",
1218 name,
1219 long_name ? long_name:" ");
1220 }
1221 return 0;
1222 }
1223
1224 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1225 if (codec->field) { \
1226 const type *p = codec->field; \
1227 \
1228 printf(" Supported " list_name ":"); \
1229 while (*p != term) { \
1230 get_name(*p); \
1231 printf(" %s", name); \
1232 p++; \
1233 } \
1234 printf("\n"); \
1235 } \
1236
1238 {
1240
1241 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1243
1246 printf(" Threading capabilities: ");
1253 default: printf("no"); break;
1254 }
1255 printf("\n");
1256 }
1257
1260
1261 printf(" Supported framerates:");
1263 printf(
" %d/%d", fps->
num, fps->
den);
1264 fps++;
1265 }
1266 printf("\n");
1267 }
1276
1281 }
1282 }
1283
1285 {
1286 switch (type) {
1292 default: return '?';
1293 }
1294 }
1295
1297 int encoder)
1298 {
1300 if (prev->
id ==
id &&
1302 return prev;
1303 }
1304 return NULL;
1305 }
1306
1308 {
1311
1312 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1313 strcmp((*da)->name, (*db)->name);
1314 }
1315
1317 {
1320 unsigned nb_codecs = 0, i = 0;
1321
1323 nb_codecs++;
1324 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1327 }
1328 desc = NULL;
1330 codecs[i++] = desc;
1333 *rcodecs = codecs;
1334 return nb_codecs;
1335 }
1336
1338 {
1340
1341 printf(" (%s: ", encoder ? "encoders" : "decoders");
1342
1344 printf(
"%s ", codec->
name);
1345
1346 printf(")");
1347 }
1348
1350 {
1353
1354 printf("Codecs:\n"
1355 " D..... = Decoding supported\n"
1356 " .E.... = Encoding supported\n"
1357 " ..V... = Video codec\n"
1358 " ..A... = Audio codec\n"
1359 " ..S... = Subtitle codec\n"
1360 " ...I.. = Intra frame-only codec\n"
1361 " ....L. = Lossy compression\n"
1362 " .....S = Lossless compression\n"
1363 " -------\n");
1364 for (i = 0; i < nb_codecs; i++) {
1367
1368 printf(" ");
1371
1376
1378
1379 /* print decoders/encoders when there's more than one or their
1380 * names are different from codec name */
1382 if (strcmp(codec->
name, desc->
name)) {
1384 break;
1385 }
1386 }
1387 codec = NULL;
1389 if (strcmp(codec->
name, desc->
name)) {
1391 break;
1392 }
1393 }
1394
1395 printf("\n");
1396 }
1398 return 0;
1399 }
1400
1402 {
1405
1406 printf("%s:\n"
1407 " V..... = Video\n"
1408 " A..... = Audio\n"
1409 " S..... = Subtitle\n"
1410 " .F.... = Frame-level multithreading\n"
1411 " ..S... = Slice-level multithreading\n"
1412 " ...X.. = Codec is experimental\n"
1413 " ....B. = Supports draw_horiz_band\n"
1414 " .....D = Supports direct rendering method 1\n"
1415 " ------\n",
1416 encoder ? "Encoders" : "Decoders");
1417 for (i = 0; i < nb_codecs; i++) {
1420
1428
1430 if (strcmp(codec->
name, desc->
name))
1431 printf(
" (codec %s)", desc->
name);
1432
1433 printf("\n");
1434 }
1435 }
1437 }
1438
1440 {
1442 return 0;
1443 }
1444
1446 {
1448 return 0;
1449 }
1450
1451 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1452 {
1454
1455 printf("Bitstream filters:\n");
1457 printf(
"%s\n", bsf->
name);
1458 printf("\n");
1459 return 0;
1460 }
1461
1463 {
1464 void *opaque = NULL;
1466
1467 printf("Supported file protocols:\n"
1468 "Input:\n");
1470 printf("%s\n", name);
1471 printf("Output:\n");
1473 printf("%s\n", name);
1474 return 0;
1475 }
1476
1478 {
1480 char descr[64], *descr_cur;
1481 int i, j;
1483
1484 printf("Filters:\n"
1485 " T.. = Timeline support\n"
1486 " .S. = Slice threading\n"
1487 " ..C = Commmand support\n"
1488 " A = Audio input/output\n"
1489 " V = Video input/output\n"
1490 " N = Dynamic number and/or type of input/output\n"
1491 " | = Source or sink filter\n");
1492 #if CONFIG_AVFILTER
1494 descr_cur = descr;
1495 for (i = 0; i < 2; i++) {
1496 if (i) {
1497 *(descr_cur++) = '-';
1498 *(descr_cur++) = '>';
1499 }
1501 for (j = 0; pad && pad[j].
name; j++) {
1502 if (descr_cur >= descr + sizeof(descr) - 4)
1503 break;
1505 }
1506 if (!j)
1509 }
1510 *descr_cur = 0;
1511 printf(" %c%c%c %-16s %-10s %s\n",
1514 filter->process_command ?
'C' :
'.',
1516 }
1517 #endif
1518 return 0;
1519 }
1520
1522 {
1525 int i;
1526
1527 printf("%-32s #RRGGBB\n", "name");
1528
1530 printf("%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1531 }
1532
1534 {
1536
1537 printf("Pixel formats:\n"
1538 "I.... = Supported Input format for conversion\n"
1539 ".O... = Supported Output format for conversion\n"
1540 "..H.. = Hardware accelerated format\n"
1541 "...P. = Paletted format\n"
1542 "....B = Bitstream format\n"
1543 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1544 "-----\n");
1545
1546 #if !CONFIG_SWSCALE
1547 # define sws_isSupportedInput(x) 0
1548 # define sws_isSupportedOutput(x) 0
1549 #endif
1550
1553 printf("%c%c%c%c%c %-16s %d %2d\n",
1562 }
1563 return 0;
1564 }
1565
1567 {
1568 int i = 0;
1570 const char *
name, *descr;
1571
1572 printf("Individual channels:\n"
1573 "NAME DESCRIPTION\n");
1574 for (i = 0; i < 63; i++) {
1576 if (!name)
1577 continue;
1579 printf("%-12s%s\n", name, descr);
1580 }
1581 printf("\nStandard channel layouts:\n"
1582 "NAME DECOMPOSITION\n");
1584 if (name) {
1585 printf("%-12s", name);
1586 for (j = 1; j; j <<= 1)
1587 if ((layout & j))
1589 printf("\n");
1590 }
1591 }
1592 return 0;
1593 }
1594
1596 {
1597 int i;
1598 char fmt_str[128];
1601 return 0;
1602 }
1603
1605 {
1608
1609 if (!name) {
1611 return;
1612 }
1613
1616
1617 if (codec)
1620 int printed = 0;
1621
1623 printed = 1;
1625 }
1626
1627 if (!printed) {
1629 "but no %s for it are available. FFmpeg might need to be "
1630 "recompiled with additional external libraries.\n",
1631 name, encoder ? "encoders" : "decoders");
1632 }
1633 } else {
1635 name);
1636 }
1637 }
1638
1640 {
1642
1643 if (!fmt) {
1645 return;
1646 }
1647
1649
1651 printf(
" Common extensions: %s.\n", fmt->
extensions);
1652
1655 }
1656
1658 {
1661
1662 if (!fmt) {
1664 return;
1665 }
1666
1668
1670 printf(
" Common extensions: %s.\n", fmt->
extensions);
1672 printf(
" Mime type: %s.\n", fmt->
mime_type);
1675 printf(
" Default video codec: %s.\n", desc->
name);
1676 }
1679 printf(
" Default audio codec: %s.\n", desc->
name);
1680 }
1683 printf(
" Default subtitle codec: %s.\n", desc->
name);
1684 }
1685
1688 }
1689
1690 #if CONFIG_AVFILTER
1691 static void show_help_filter(
const char *
name)
1692 {
1693 #if CONFIG_AVFILTER
1696
1697 if (!name) {
1699 return;
1700 } else if (!f) {
1702 return;
1703 }
1704
1705 printf(
"Filter %s\n", f->
name);
1708
1710 printf(" slice threading supported\n");
1711
1712 printf(" Inputs:\n");
1714 for (i = 0; i <
count; i++) {
1717 }
1719 printf(" dynamic (depending on the options)\n");
1720 else if (!count)
1721 printf(" none (source filter)\n");
1722
1723 printf(" Outputs:\n");
1725 for (i = 0; i <
count; i++) {
1728 }
1730 printf(" dynamic (depending on the options)\n");
1731 else if (!count)
1732 printf(" none (sink filter)\n");
1733
1738 printf("This filter has support for timeline through the 'enable' option.\n");
1739 #else
1741 "can not to satisfy request\n");
1742 #endif
1743 }
1744 #endif
1745
1746 int show_help(
void *optctx,
const char *opt,
const char *arg)
1747 {
1748 char *topic, *par;
1750
1752 par = strchr(topic, '=');
1753 if (par)
1754 *par++ = 0;
1755
1756 if (!*topic) {
1758 } else if (!strcmp(topic, "decoder")) {
1760 } else if (!strcmp(topic, "encoder")) {
1762 } else if (!strcmp(topic, "demuxer")) {
1764 } else if (!strcmp(topic, "muxer")) {
1766 #if CONFIG_AVFILTER
1767 } else if (!strcmp(topic, "filter")) {
1768 show_help_filter(par);
1769 #endif
1770 } else {
1772 }
1773
1775 return 0;
1776 }
1777
1779 {
1782
1783 while (c != '\n' && c != EOF)
1784 c = getchar();
1785
1786 return yesno;
1787 }
1788
1790 {
1792 FILE *f = fopen(filename, "rb");
1793
1794 if (!f) {
1796 strerror(errno));
1798 }
1799 fseek(f, 0, SEEK_END);
1800 *size = ftell(f);
1801 fseek(f, 0, SEEK_SET);
1802 if (*size == (size_t)-1) {
1804 fclose(f);
1806 }
1808 if (!*bufptr) {
1810 fclose(f);
1812 }
1813 ret = fread(*bufptr, 1, *size, f);
1814 if (ret < *size) {
1816 if (ferror(f)) {
1818 filename, strerror(errno));
1820 } else
1822 } else {
1823 ret = 0;
1824 (*bufptr)[(*size)++] = '0円';
1825 }
1826
1827 fclose(f);
1829 }
1830
1832 const char *preset_name, int is_path,
1833 const char *codec_name)
1834 {
1835 FILE *f = NULL;
1836 int i;
1837 const char *base[3] = { getenv("FFMPEG_DATADIR"),
1838 getenv("HOME"),
1839 FFMPEG_DATADIR, };
1840
1841 if (is_path) {
1842 av_strlcpy(filename, preset_name, filename_size);
1843 f = fopen(filename, "r");
1844 } else {
1845 #ifdef _WIN32
1846 char datadir[MAX_PATH], *ls;
1847 base[2] = NULL;
1848
1849 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
1850 {
1851 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1852 if (*ls == '\\') *ls = '/';
1853
1854 if (ls = strrchr(datadir, '/'))
1855 {
1856 *ls = 0;
1857 strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
1858 base[2] = datadir;
1859 }
1860 }
1861 #endif
1862 for (i = 0; i < 3 && !f; i++) {
1863 if (!base[i])
1864 continue;
1865 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1866 i != 1 ? "" : "/.ffmpeg", preset_name);
1867 f = fopen(filename, "r");
1868 if (!f && codec_name) {
1870 "%s%s/%s-%s.ffpreset",
1871 base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
1872 preset_name);
1873 f = fopen(filename, "r");
1874 }
1875 }
1876 }
1877
1878 return f;
1879 }
1880
1882 {
1884 if (ret < 0)
1887 }
1888
1891 {
1896 char prefix = 0;
1898
1899 if (!codec)
1902
1905 prefix = 'v';
1907 break;
1909 prefix = 'a';
1911 break;
1913 prefix = 's';
1915 break;
1916 }
1917
1919 char *p = strchr(t->
key,
':');
1920
1921 /* check stream specification in opt name */
1922 if (p)
1924 case 1: *p = 0; break;
1925 case 0: continue;
1926 default: return NULL;
1927 }
1928
1934 else if (t->
key[0] == prefix &&
1938
1939 if (p)
1940 *p = ':';
1941 }
1943 }
1944
1947 {
1948 int i;
1950
1952 return NULL;
1954 if (!opts) {
1956 "Could not alloc memory for stream options.\n");
1957 return NULL;
1958 }
1962 return opts;
1963 }
1964
1966 {
1967 if (new_size >= INT_MAX / elem_size) {
1970 }
1971 if (*size < new_size) {
1973 if (!tmp) {
1976 }
1977 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1978 *size = new_size;
1979 return tmp;
1980 }
1981 return array;
1982 }