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>
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"
39 #if CONFIG_POSTPROC
41 #endif
53 #include "version.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
69
71
73 {
74
75 if(CONFIG_SWSCALE)
78
79 if(CONFIG_SWRESAMPLE)
81 }
82
84 {
85 #if CONFIG_SWSCALE
88 #endif
89
90 if(CONFIG_SWRESAMPLE)
92
95 }
96
98 {
99 vfprintf(stdout, fmt, vl);
100 }
101
103 {
104 va_list vl2;
106 static int print_prefix = 1;
107
108 va_copy(vl2, vl);
111 va_end(vl2);
114 }
115
117 double min,
double max)
118 {
119 char *tail;
120 const char *error;
122 if (*tail)
123 error = "Expected number for %s but found: %s\n";
124 else if (d < min || d > max)
125 error = "The value for %s was %s which is not within %f - %f\n";
126 else if (type ==
OPT_INT64 && (int64_t)d != d)
127 error = "Expected int64 for %s but found %s\n";
128 else if (type ==
OPT_INT && (
int)d != d)
129 error = "Expected int for %s but found %s\n";
130 else
131 return d;
133 exit(1);
134 return 0;
135 }
136
138 int is_duration)
139 {
140 int64_t us;
143 is_duration ? "duration" : "date", context, timestr);
144 exit(1);
145 }
146 return us;
147 }
148
150 int rej_flags, int alt_flags)
151 {
153 int first;
154
155 first = 1;
156 for (po = options; po->
name !=
NULL; po++) {
157 char buf[64];
158
159 if (((po->
flags & req_flags) != req_flags) ||
160 (alt_flags && !(po->
flags & alt_flags)) ||
161 (po->
flags & rej_flags))
162 continue;
163
164 if (first) {
165 printf("%s\n", msg);
166 first = 0;
167 }
172 }
173 printf(
"-%-17s %s\n", buf, po->
help);
174 }
175 printf("\n");
176 }
177
179 {
181 if (class->option) {
183 printf("\n");
184 }
185
188 }
189
191 {
192 const char *p = strchr(name, ':');
193 int len = p ? p - name : strlen(name);
194
196 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
197 break;
198 po++;
199 }
200 return po;
201 }
202
203 #if HAVE_COMMANDLINETOARGVW
204 #include <windows.h>
205 #include <shellapi.h>
206 /* Will be leaked on exit */
207 static char** win32_argv_utf8 =
NULL;
208 static int win32_argc = 0;
209
210 /**
211 * Prepare command line arguments for executable.
212 * For Windows - perform wide-char to UTF-8 conversion.
213 * Input arguments should be main() function arguments.
214 * @param argc_ptr Arguments number (including executable)
215 * @param argv_ptr Arguments list.
216 */
218 {
219 char *argstr_flat;
220 wchar_t **argv_w;
221 int i, buffsize = 0,
offset = 0;
222
223 if (win32_argv_utf8) {
224 *argc_ptr = win32_argc;
225 *argv_ptr = win32_argv_utf8;
226 return;
227 }
228
229 win32_argc = 0;
230 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
231 if (win32_argc <= 0 || !argv_w)
232 return;
233
234 /* determine the UTF-8 buffer size (including NULL-termination symbols) */
235 for (i = 0; i < win32_argc; i++)
236 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
238
239 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
240 argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
241 if (win32_argv_utf8 ==
NULL) {
242 LocalFree(argv_w);
243 return;
244 }
245
246 for (i = 0; i < win32_argc; i++) {
247 win32_argv_utf8[i] = &argstr_flat[
offset];
248 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
251 }
252 win32_argv_utf8[i] =
NULL;
253 LocalFree(argv_w);
254
255 *argc_ptr = win32_argc;
256 *argv_ptr = win32_argv_utf8;
257 }
258 #else
260 {
261 /* nothing to do */
262 }
263 #endif /* HAVE_COMMANDLINETOARGVW */
264
267 {
268 /* new-style options contain an offset into optctx, old-style address of
269 * a global var*/
272 int *dstcount;
273
276 char *p = strchr(opt, ':');
277
278 dstcount = (int *)(so + 1);
279 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
280 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
281 dst = &(*so)[*dstcount - 1].u;
282 }
283
285 char *str;
287 // av_freep(dst);
288 *(char **)dst = str;
300 int ret = po->
u.
func_arg(optctx, opt, arg);
301 if (ret < 0) {
303 "Failed to set value '%s' for option '%s'\n", arg, opt);
304 return ret;
305 }
306 }
308 exit(0);
309
310 return 0;
311 }
312
315 {
317 int ret;
318
320 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
321 /* handle 'no' bool option */
324 arg = "0";
326 arg = "1";
327
333 }
337 }
338
340 if (ret < 0)
341 return ret;
342
344 }
345
347 void (*parse_arg_function)(void *, const char*))
348 {
349 const char *opt;
350 int optindex, handleoptions = 1, ret;
351
352 /* perform system-dependent conversions for arguments list */
354
355 /* parse options */
356 optindex = 1;
357 while (optindex < argc) {
358 opt = argv[optindex++];
359
360 if (handleoptions && opt[0] == '-' && opt[1] != '0円') {
361 if (opt[1] == '-' && opt[2] == '0円') {
362 handleoptions = 0;
363 continue;
364 }
365 opt++;
366
367 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
368 exit(1);
369 optindex += ret;
370 } else {
371 if (parse_arg_function)
372 parse_arg_function(optctx, opt);
373 }
374 }
375 }
376
378 {
379 int i, ret;
380
383
384 for (i = 0; i < g->
nb_opts; i++) {
386
389
391 if (ret < 0)
392 return ret;
393 }
394
396
397 return 0;
398 }
399
401 const char *optname)
402 {
404 int i;
405
406 for (i = 1; i < argc; i++) {
407 const char *cur_opt = argv[i];
408
409 if (*cur_opt++ != '-')
410 continue;
411
413 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
415
416 if ((!po->
name && !strcmp(cur_opt, optname)) ||
417 (po->
name && !strcmp(optname, po->
name)))
418 return i;
419
421 i++;
422 }
423 return 0;
424 }
425
427 {
428 const unsigned char *p;
429
430 for (p = a; *p; p++)
431 if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
432 *p == '_' || (*p >= 'a' && *p <= 'z')))
433 break;
434 if (!*p) {
436 return;
437 }
439 for (p = a; *p; p++) {
440 if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
442 else if (*p < ' ' || *p > '~')
444 else
446 }
448 }
449
451 {
453 const char *env;
454 if (!idx)
456 if (idx && argv[idx + 1])
459 if ((env = getenv("FFREPORT")) || idx) {
462 int i;
464 for (i = 0; i < argc; i++) {
467 }
469 }
470 }
471 }
472
473 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
475 {
477 int consumed = 0;
478 char opt_stripped[128];
479 const char *p;
482
483 if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
485
486 if (!(p = strchr(opt, ':')))
487 p = opt + strlen(opt);
488 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
489
492 ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
495 consumed = 1;
496 }
500 if(consumed)
502 consumed = 1;
503 }
504 #if CONFIG_SWSCALE
508 // XXX we only support sws_flags, not arbitrary sws options
510 if (ret < 0) {
512 return ret;
513 }
514 consumed = 1;
515 }
516 #endif
517 #if CONFIG_SWRESAMPLE
522 if (ret < 0) {
524 return ret;
525 }
526 consumed = 1;
527 }
528 #endif
529
530 if (consumed)
531 return 0;
533 }
534
535 /*
536 * Check whether given option is a group separator.
537 *
538 * @return index of the group definition that matched or -1 if none
539 */
541 const char *opt)
542 {
543 int i;
544
545 for (i = 0; i < nb_groups; i++) {
547 if (p->
sep && !strcmp(p->
sep, opt))
548 return i;
549 }
550
551 return -1;
552 }
553
554 /*
555 * Finish parsing an option group.
556 *
557 * @param group_idx which group definition should this group belong to
558 * @param arg argument of the group delimiting option
559 */
562 {
565
568
572 #if CONFIG_SWSCALE
574 #endif
578
581 #if CONFIG_SWSCALE
583 #endif
586
588 }
589
590 /*
591 * Add an option instance to currently parsed group.
592 */
594 const char *key, const char *val)
595 {
598
603 }
604
607 {
609 int i;
610
611 memset(octx, 0, sizeof(*octx));
612
616 exit(1);
617
620
623
625 }
626
628 {
629 int i, j;
630
633
638 #if CONFIG_SWSCALE
640 #endif
641 if(CONFIG_SWRESAMPLE)
643 }
645 }
647
650
652 }
653
657 {
658 int optindex = 1;
659
660 /* perform system-dependent conversions for arguments list */
662
665
666 while (optindex < argc) {
667 const char *opt = argv[optindex++], *
arg;
669 int ret;
670
672
673 /* unnamed group separators, e.g. output filename */
674 if (opt[0] != '-' || !opt[1]) {
677 continue;
678 }
679 opt++;
680
681 #define GET_ARG(arg) \
682 do { \
683 arg = argv[optindex++]; \
684 if (!arg) { \
685 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
686 return AVERROR(EINVAL); \
687 } \
688 } while (0)
689
690 /* named group separators, e.g. -i */
695 groups[ret].
name, arg);
696 continue;
697 }
698
699 /* normal options */
703 /* optional argument, e.g. -h */
704 arg = argv[optindex++];
707 } else {
708 arg = "1";
709 }
710
713 "argument '%s'.\n", po->
name, po->
help, arg);
714 continue;
715 }
716
717 /* AVOptions */
718 if (argv[optindex]) {
720 if (ret >= 0) {
722 "argument '%s'.\n", opt, argv[optindex]);
723 optindex++;
724 continue;
727 "with argument '%s'.\n", opt, argv[optindex]);
728 return ret;
729 }
730 }
731
732 /* boolean -nofoo options */
733 if (opt[0] == 'n' && opt[1] == 'o' &&
738 "argument 0.\n", po->
name, po->
help);
739 continue;
740 }
741
744 }
745
748 "commandline.\n");
749
751
752 return 0;
753 }
754
756 {
757 const struct {
const char *
name;
int level; } log_levels[] = {
766 };
767 char *tail;
769 int i;
770
772 if (!strcmp(log_levels[i].
name, arg)) {
774 return 0;
775 }
776 }
777
778 level = strtol(arg, &tail, 10);
779 if (*tail) {
781 "Possible levels are numbers or:\n", arg);
784 exit(1);
785 }
787 return 0;
788 }
789
791 struct tm *tm)
792 {
794
795 while ((c = *(template++))) {
796 if (c == '%') {
797 if (!(c = *(template++)))
798 break;
799 switch (c) {
800 case 'p':
802 break;
803 case 't':
805 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
806 tm->tm_hour, tm->tm_min, tm->tm_sec);
807 break;
808 case '%':
810 break;
811 }
812 } else {
814 }
815 }
816 }
817
819 {
820 char *filename_template =
NULL;
821 char *key, *val;
822 int ret, count = 0;
823 time_t now;
824 struct tm *tm;
826
828 return 0;
829 time(&now);
830 tm = localtime(&now);
831
832 while (env && *env) {
834 if (count)
836 "Failed to parse FFREPORT environment variable: %s\n",
838 break;
839 }
840 if (*env)
841 env++;
842 count++;
843 if (!strcmp(key, "file")) {
845 filename_template = val;
847 } else {
849 }
852 }
853
861 }
862
866 filename.str, strerror(errno));
868 }
871 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
872 "Report written to \"%s\"\n",
874 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
875 tm->tm_hour, tm->tm_min, tm->tm_sec,
876 filename.str);
879 return 0;
880 }
881
883 {
885 }
886
888 {
889 char *tail;
890 size_t max;
891
892 max = strtol(arg, &tail, 10);
893 if (*tail) {
895 exit(1);
896 }
898 return 0;
899 }
900
902 {
903 int ret;
905
907 return ret;
908
910 return 0;
911 }
912
914 {
915 #if HAVE_SETRLIMIT
917 struct rlimit rl = { lim, lim + 1 };
918 if (setrlimit(RLIMIT_CPU, &rl))
919 perror("setrlimit");
920 #else
922 #endif
923 return 0;
924 }
925
927 {
928 char errbuf[128];
929 const char *errbuf_ptr = errbuf;
930
934 }
935
937
939 #define SHOW_VERSION 2
940 #define SHOW_CONFIG 4
941 #define SHOW_COPYRIGHT 8
942
943 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
944 if (CONFIG_##LIBNAME) { \
945 const char *indent = flags & INDENT? " " : ""; \
946 if (flags & SHOW_VERSION) { \
947 unsigned int version = libname##_version(); \
948 av_log(NULL, level, \
949 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
950 indent, #libname, \
951 LIB##LIBNAME##_VERSION_MAJOR, \
952 LIB##LIBNAME##_VERSION_MINOR, \
953 LIB##LIBNAME##_VERSION_MICRO, \
954 version >> 16, version >> 8 & 0xff, version & 0xff); \
955 } \
956 if (flags & SHOW_CONFIG) { \
957 const char *cfg = libname##_configuration(); \
958 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
959 if (!warned_cfg) { \
960 av_log(NULL, level, \
961 "%sWARNING: library configuration mismatch\n", \
962 indent); \
963 warned_cfg = 1; \
964 } \
965 av_log(NULL, level, "%s%-11s configuration: %s\n", \
966 indent, #libname, cfg); \
967 } \
968 } \
969 } \
970
972 {
978 // PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level);
981 #if CONFIG_POSTPROC
983 #endif
984 }
985
987 {
988 const char *indent = flags &
INDENT?
" " :
"";
989
992 av_log(
NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
995 av_log(
NULL, level,
"%sbuilt on %s %s with %s\n",
996 indent, __DATE__, __TIME__, CC_IDENT);
997
998 av_log(
NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
999 }
1000
1002 {
1004 if (idx)
1005 return;
1006
1010 }
1011
1013 {
1017
1018 return 0;
1019 }
1020
1022 {
1023 #if CONFIG_NONFREE
1024 printf(
1025 "This version of %s has nonfree parts compiled in.\n"
1026 "Therefore it is not legally redistributable.\n",
1028 #elif CONFIG_GPLV3
1029 printf(
1030 "%s is free software; you can redistribute it and/or modify\n"
1031 "it under the terms of the GNU General Public License as published by\n"
1032 "the Free Software Foundation; either version 3 of the License, or\n"
1033 "(at your option) any later version.\n"
1034 "\n"
1035 "%s is distributed in the hope that it will be useful,\n"
1036 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1037 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1038 "GNU General Public License for more details.\n"
1039 "\n"
1040 "You should have received a copy of the GNU General Public License\n"
1041 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1043 #elif CONFIG_GPL
1044 printf(
1045 "%s is free software; you can redistribute it and/or modify\n"
1046 "it under the terms of the GNU General Public License as published by\n"
1047 "the Free Software Foundation; either version 2 of the License, or\n"
1048 "(at your option) any later version.\n"
1049 "\n"
1050 "%s is distributed in the hope that it will be useful,\n"
1051 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1052 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1053 "GNU General Public License for more details.\n"
1054 "\n"
1055 "You should have received a copy of the GNU General Public License\n"
1056 "along with %s; if not, write to the Free Software\n"
1057 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1059 #elif CONFIG_LGPLV3
1060 printf(
1061 "%s is free software; you can redistribute it and/or modify\n"
1062 "it under the terms of the GNU Lesser General Public License as published by\n"
1063 "the Free Software Foundation; either version 3 of the License, or\n"
1064 "(at your option) any later version.\n"
1065 "\n"
1066 "%s is distributed in the hope that it will be useful,\n"
1067 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1068 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1069 "GNU Lesser General Public License for more details.\n"
1070 "\n"
1071 "You should have received a copy of the GNU Lesser General Public License\n"
1072 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1074 #else
1075 printf(
1076 "%s is free software; you can redistribute it and/or\n"
1077 "modify it under the terms of the GNU Lesser General Public\n"
1078 "License as published by the Free Software Foundation; either\n"
1079 "version 2.1 of the License, or (at your option) any later version.\n"
1080 "\n"
1081 "%s is distributed in the hope that it will be useful,\n"
1082 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1083 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1084 "Lesser General Public License for more details.\n"
1085 "\n"
1086 "You should have received a copy of the GNU Lesser General Public\n"
1087 "License along with %s; if not, write to the Free Software\n"
1088 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1090 #endif
1091
1092 return 0;
1093 }
1094
1096 {
1099 const char *last_name;
1100
1101 printf("File formats:\n"
1102 " D. = Demuxing supported\n"
1103 " .E = Muxing supported\n"
1104 " --\n");
1105 last_name = "000";
1106 for (;;) {
1108 int encode = 0;
1110 const char *long_name =
NULL;
1111
1113 if ((name ==
NULL || strcmp(ofmt->
name, name) < 0) &&
1114 strcmp(ofmt->
name, last_name) > 0) {
1117 encode = 1;
1118 }
1119 }
1121 if ((name ==
NULL || strcmp(ifmt->
name, name) < 0) &&
1122 strcmp(ifmt->
name, last_name) > 0) {
1125 encode = 0;
1126 }
1127 if (name && strcmp(ifmt->
name, name) == 0)
1128 decode = 1;
1129 }
1131 break;
1133
1134 printf(" %s%s %-15s %s\n",
1135 decode ? "D" : " ",
1136 encode ? "E" : " ",
1137 name,
1138 long_name ? long_name:" ");
1139 }
1140 return 0;
1141 }
1142
1143 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1144 if (codec->field) { \
1145 const type *p = codec->field; \
1146 \
1147 printf(" Supported " list_name ":"); \
1148 while (*p != term) { \
1149 get_name(*p); \
1150 printf(" %s", name); \
1151 p++; \
1152 } \
1153 printf("\n"); \
1154 } \
1155
1157 {
1159
1160 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1162
1164 printf(" Threading capabilities: ");
1171 default: printf("no"); break;
1172 }
1173 printf("\n");
1174 }
1175
1178
1179 printf(" Supported framerates:");
1181 printf(
" %d/%d", fps->
num, fps->
den);
1182 fps++;
1183 }
1184 printf("\n");
1185 }
1194
1199 }
1200 }
1201
1203 {
1204 switch (type) {
1210 default: return '?';
1211 }
1212 }
1213
1215 int encoder)
1216 {
1218 if (prev->
id ==
id &&
1220 return prev;
1221 }
1223 }
1224
1226 {
1229
1230 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1231 strcmp((*da)->name, (*db)->name);
1232 }
1233
1235 {
1238 unsigned nb_codecs = 0, i = 0;
1239
1241 nb_codecs++;
1242 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1244 exit(1);
1245 }
1248 codecs[i++] = desc;
1251 *rcodecs = codecs;
1252 return nb_codecs;
1253 }
1254
1256 {
1258
1259 printf(" (%s: ", encoder ? "encoders" : "decoders");
1260
1262 printf(
"%s ", codec->
name);
1263
1264 printf(")");
1265 }
1266
1268 {
1271
1272 printf("Codecs:\n"
1273 " D..... = Decoding supported\n"
1274 " .E.... = Encoding supported\n"
1275 " ..V... = Video codec\n"
1276 " ..A... = Audio codec\n"
1277 " ..S... = Subtitle codec\n"
1278 " ...I.. = Intra frame-only codec\n"
1279 " ....L. = Lossy compression\n"
1280 " .....S = Lossless compression\n"
1281 " -------\n");
1282 for (i = 0; i < nb_codecs; i++) {
1285
1286 printf(" ");
1289
1294
1296
1297 /* print decoders/encoders when there's more than one or their
1298 * names are different from codec name */
1300 if (strcmp(codec->
name, desc->
name)) {
1302 break;
1303 }
1304 }
1307 if (strcmp(codec->
name, desc->
name)) {
1309 break;
1310 }
1311 }
1312
1313 printf("\n");
1314 }
1316 return 0;
1317 }
1318
1320 {
1323
1324 printf("%s:\n"
1325 " V..... = Video\n"
1326 " A..... = Audio\n"
1327 " S..... = Subtitle\n"
1328 " .F.... = Frame-level multithreading\n"
1329 " ..S... = Slice-level multithreading\n"
1330 " ...X.. = Codec is experimental\n"
1331 " ....B. = Supports draw_horiz_band\n"
1332 " .....D = Supports direct rendering method 1\n"
1333 " ------\n",
1334 encoder ? "Encoders" : "Decoders");
1335 for (i = 0; i < nb_codecs; i++) {
1338
1346
1348 if (strcmp(codec->
name, desc->
name))
1349 printf(
" (codec %s)", desc->
name);
1350
1351 printf("\n");
1352 }
1353 }
1355 }
1356
1358 {
1360 return 0;
1361 }
1362
1364 {
1366 return 0;
1367 }
1368
1370 {
1372
1373 printf("Bitstream filters:\n");
1375 printf(
"%s\n", bsf->
name);
1376 printf("\n");
1377 return 0;
1378 }
1379
1381 {
1382 void *opaque =
NULL;
1384
1385 printf("Supported file protocols:\n"
1386 "Input:\n");
1388 printf("%s\n", name);
1389 printf("Output:\n");
1391 printf("%s\n", name);
1392 return 0;
1393 }
1394
1396 {
1398 char descr[64], *descr_cur;
1399 int i, j;
1401
1402 printf("Filters:\n");
1403 #if CONFIG_AVFILTER
1405 descr_cur = descr;
1406 for (i = 0; i < 2; i++) {
1407 if (i) {
1408 *(descr_cur++) = '-';
1409 *(descr_cur++) = '>';
1410 }
1411 pad = i ? (*filter)->outputs : (*filter)->inputs;
1412 for (j = 0; pad && pad[j].
name; j++) {
1413 if (descr_cur >= descr + sizeof(descr) - 4)
1414 break;
1416 }
1417 if (!j)
1418 *(descr_cur++) = '|';
1419 }
1420 *descr_cur = 0;
1421 printf("%-16s %-10s %s\n", (*filter)->name, descr, (*filter)->description);
1422 }
1423 #endif
1424 return 0;
1425 }
1426
1428 {
1430
1431 printf("Pixel formats:\n"
1432 "I.... = Supported Input format for conversion\n"
1433 ".O... = Supported Output format for conversion\n"
1434 "..H.. = Hardware accelerated format\n"
1435 "...P. = Paletted format\n"
1436 "....B = Bitstream format\n"
1437 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1438 "-----\n");
1439
1440 #if !CONFIG_SWSCALE
1441 # define sws_isSupportedInput(x) 0
1442 # define sws_isSupportedOutput(x) 0
1443 #endif
1444
1447 printf("%c%c%c%c%c %-16s %d %2d\n",
1456 }
1457 return 0;
1458 }
1459
1461 {
1462 int i = 0;
1464 const char *
name, *descr;
1465
1466 printf("Individual channels:\n"
1467 "NAME DESCRIPTION\n");
1468 for (i = 0; i < 63; i++) {
1470 if (!name)
1471 continue;
1473 printf("%-12s%s\n", name, descr);
1474 }
1475 printf("\nStandard channel layouts:\n"
1476 "NAME DECOMPOSITION\n");
1478 if (name) {
1479 printf("%-12s", name);
1480 for (j = 1; j; j <<= 1)
1481 if ((layout & j))
1483 printf("\n");
1484 }
1485 }
1486 return 0;
1487 }
1488
1490 {
1491 int i;
1492 char fmt_str[128];
1495 return 0;
1496 }
1497
1499 {
1502
1503 if (!name) {
1505 return;
1506 }
1507
1510
1511 if (codec)
1514 int printed = 0;
1515
1517 printed = 1;
1519 }
1520
1521 if (!printed) {
1523 "but no %s for it are available. FFmpeg might need to be "
1524 "recompiled with additional external libraries.\n",
1525 name, encoder ? "encoders" : "decoders");
1526 }
1527 } else {
1529 name);
1530 }
1531 }
1532
1534 {
1536
1537 if (!fmt) {
1539 return;
1540 }
1541
1543
1545 printf(
" Common extensions: %s.\n", fmt->
extensions);
1546
1549 }
1550
1552 {
1555
1556 if (!fmt) {
1558 return;
1559 }
1560
1562
1564 printf(
" Common extensions: %s.\n", fmt->
extensions);
1566 printf(
" Mime type: %s.\n", fmt->
mime_type);
1569 printf(
" Default video codec: %s.\n", desc->
name);
1570 }
1573 printf(
" Default audio codec: %s.\n", desc->
name);
1574 }
1577 printf(
" Default subtitle codec: %s.\n", desc->
name);
1578 }
1579
1582 }
1583
1585 {
1586 char *topic, *par;
1588
1590 par = strchr(topic, '=');
1591 if (par)
1592 *par++ = 0;
1593
1594 if (!*topic) {
1596 } else if (!strcmp(topic, "decoder")) {
1598 } else if (!strcmp(topic, "encoder")) {
1600 } else if (!strcmp(topic, "demuxer")) {
1602 } else if (!strcmp(topic, "muxer")) {
1604 } else {
1606 }
1607
1609 return 0;
1610 }
1611
1613 {
1615 int yesno = (toupper(c) == 'Y');
1616
1617 while (c != '\n' && c != EOF)
1618 c = getchar();
1619
1620 return yesno;
1621 }
1622
1624 {
1625 int ret;
1626 FILE *f = fopen(filename, "rb");
1627
1628 if (!f) {
1630 strerror(errno));
1632 }
1633 fseek(f, 0, SEEK_END);
1634 *size = ftell(f);
1635 fseek(f, 0, SEEK_SET);
1636 if (*size == (size_t)-1) {
1638 fclose(f);
1640 }
1642 if (!*bufptr) {
1644 fclose(f);
1646 }
1647 ret = fread(*bufptr, 1, *size, f);
1648 if (ret < *size) {
1650 if (ferror(f)) {
1652 filename, strerror(errno));
1654 } else
1656 } else {
1657 ret = 0;
1658 (*bufptr)[(*size)++] = '0円';
1659 }
1660
1661 fclose(f);
1662 return ret;
1663 }
1664
1666 const char *preset_name, int is_path,
1667 const char *codec_name)
1668 {
1670 int i;
1671 const char *base[3] = { getenv("FFMPEG_DATADIR"),
1672 getenv("HOME"),
1673 FFMPEG_DATADIR, };
1674
1675 if (is_path) {
1676 av_strlcpy(filename, preset_name, filename_size);
1677 f = fopen(filename, "r");
1678 } else {
1679 #ifdef _WIN32
1680 char datadir[MAX_PATH], *ls;
1682
1683 if (GetModuleFileNameA(GetModuleHandleA(
NULL), datadir,
sizeof(datadir) - 1))
1684 {
1685 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1686 if (*ls == '\\') *ls = '/';
1687
1688 if (ls = strrchr(datadir, '/'))
1689 {
1690 *ls = 0;
1691 strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
1692 base[2] = datadir;
1693 }
1694 }
1695 #endif
1696 for (i = 0; i < 3 && !f; i++) {
1697 if (!base[i])
1698 continue;
1699 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1700 i != 1 ? "" : "/.ffmpeg", preset_name);
1701 f = fopen(filename, "r");
1702 if (!f && codec_name) {
1704 "%s%s/%s-%s.ffpreset",
1705 base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
1706 preset_name);
1707 f = fopen(filename, "r");
1708 }
1709 }
1710 }
1711
1712 return f;
1713 }
1714
1716 {
1718 if (ret < 0)
1720 return ret;
1721 }
1722
1725 {
1730 char prefix = 0;
1732
1733 if (!codec)
1736 if (!codec)
1738
1739 switch (codec->
type) {
1741 prefix = 'v';
1743 break;
1745 prefix = 'a';
1747 break;
1749 prefix = 's';
1751 break;
1752 }
1753
1755 char *p = strchr(t->
key,
':');
1756
1757 /* check stream specification in opt name */
1758 if (p)
1760 case 1: *p = 0; break;
1761 case 0: continue;
1762 default:
return NULL;
1763 }
1764
1770 else if (t->
key[0] == prefix &&
1774
1775 if (p)
1776 *p = ':';
1777 }
1778 return ret;
1779 }
1780
1783 {
1784 int i;
1786
1790 if (!opts) {
1792 "Could not alloc memory for stream options.\n");
1794 }
1798 return opts;
1799 }
1800
1802 {
1803 if (new_size >= INT_MAX / elem_size) {
1805 exit(1);
1806 }
1807 if (*size < new_size) {
1809 if (!tmp) {
1811 exit(1);
1812 }
1813 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1814 *size = new_size;
1815 return tmp;
1816 }
1817 return array;
1818 }
1819
1821 {
1824 int i, ret;
1825 int pixel_size;
1826 int h_chroma_shift, v_chroma_shift;
1827 int edge = 32; // XXX should be avcodec_get_edge_width(), but that fails on svq1
1829
1830 if (!desc)
1833
1835 if (!buf)
1837
1839
1841 w += 2*edge;
1842 h += 2*edge;
1843 }
1844
1849 return ret;
1850 }
1851 /* XXX this shouldn't be needed, but some tests break without this line
1852 * those decoders are buggy and need to be fixed.
1853 * the following tests fail:
1854 * cdgraphics, ansi
1855 */
1856 memset(buf->
base[0], 128, ret);
1857
1860 const int h_shift = i==0 ? 0 : h_chroma_shift;
1861 const int v_shift = i==0 ? 0 : v_chroma_shift;
1864 else
1867 (pixel_size*edge >> h_shift), 32);
1868 }
1873
1874 *pbuf = buf;
1875 return 0;
1876 }
1877
1879 {
1882 int ret, i;
1883
1886 return -1;
1887 }
1888
1890 return ret;
1891
1892 buf = *pool;
1899 return ret;
1900 }
1903
1907
1909 frame->
base[i] = buf->
base[i];
// XXX h264.c uses base though it shouldn't
1912 }
1913
1914 return 0;
1915 }
1916
1918 {
1920
1925 for(tmp= *pool; tmp; tmp= tmp->
next)
1927
1929 *pool = buf;
1930 }
1931 }
1932
1934 {
1936 int i;
1937
1940 return;
1941 }
1942
1945
1947 }
1948
1950 {
1954 }
1955
1957 {
1959 while (buf) {
1963 buf = *pool;
1964 }
1965 }