61 #include "libavformat/avformat.h"
62 #include "libavfilter/avfilter.h"
63 #include "libavdevice/avdevice.h"
64 #include "libswscale/swscale.h"
65 #include "libswresample/swresample.h"
66 #include "libavutil/attributes.h"
67 #include "libavutil/avassert.h"
68 #include "libavutil/avstring.h"
69 #include "libavutil/bprint.h"
70 #include "libavutil/display.h"
71 #include "libavutil/mathematics.h"
72 #include "libavutil/imgutils.h"
73 #include "libavutil/libm.h"
74 #include "libavutil/parseutils.h"
75 #include "libavutil/pixdesc.h"
76 #include "libavutil/eval.h"
77 #include "libavutil/dict.h"
78 #include "libavutil/opt.h"
79 #include "libavutil/cpu.h"
80 #include "libavutil/ffversion.h"
81 #include "libavutil/version.h"
83 #if HAVE_SYS_RESOURCE_H
85 #include <sys/resource.h>
115 av_dict_set(&
sws_dict,
"flags",
"bicubic", 0);
131 static int print_prefix = 1;
135 av_log_default_callback(ptr, level, fmt, vl);
139 av_log_format_line(ptr, level, fmt, vl2, line,
sizeof(line), &print_prefix);
149 #if HAVE_SETDLLDIRECTORY && defined(_WIN32)
175 double min,
double max)
179 double d = av_strtod(numstr, &tail);
181 error =
"Expected number for %s but found: %s\n";
182 else if (d < min || d > max)
183 error =
"The value for %s was %s which is not within %f - %f\n";
184 else if (type ==
OPT_INT64 && (int64_t)d != d)
185 error =
"Expected int64 for %s but found %s\n";
186 else if (type ==
OPT_INT && (
int)d != d)
187 error =
"Expected int for %s but found %s\n";
190 av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
199 if (av_parse_time(&us, timestr, is_duration) < 0) {
200 av_log(NULL, AV_LOG_FATAL,
"Invalid %s specification for %s: %s\n",
201 is_duration ?
"duration" :
"date", context, timestr);
208 int rej_flags,
int alt_flags)
214 for (po = options; po->
name; po++) {
217 if (((po->
flags & req_flags) != req_flags) ||
218 (alt_flags && !(po->
flags & alt_flags)) ||
219 (po->
flags & rej_flags))
226 av_strlcpy(buf, po->
name,
sizeof(buf));
228 av_strlcat(buf,
" ",
sizeof(buf));
229 av_strlcat(buf, po->
argname,
sizeof(buf));
239 const AVClass *child;
241 av_opt_show2(&
class, NULL, flags, 0);
245 while ((child = av_opt_child_class_iterate(
class, &iter)))
251 const char *p = strchr(name,
':');
252 int len = p ? p - name : strlen(name);
255 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
265 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
266 #include <shellapi.h>
268 static char** win32_argv_utf8 = NULL;
269 static int win32_argc = 0;
282 int i, buffsize = 0, offset = 0;
284 if (win32_argv_utf8) {
285 *argc_ptr = win32_argc;
286 *argv_ptr = win32_argv_utf8;
291 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
292 if (win32_argc <= 0 || !argv_w)
296 for (i = 0; i < win32_argc; i++)
297 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
298 NULL, 0, NULL, NULL);
300 win32_argv_utf8 = av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
301 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
302 if (!win32_argv_utf8) {
307 for (i = 0; i < win32_argc; i++) {
308 win32_argv_utf8[i] = &argstr_flat[offset];
309 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
310 &argstr_flat[offset],
311 buffsize - offset, NULL, NULL);
313 win32_argv_utf8[i] = NULL;
316 *argc_ptr = win32_argc;
317 *argv_ptr = win32_argv_utf8;
337 char *p = strchr(opt,
':');
340 dstcount = (
int *)(so + 1);
341 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
342 str = av_strdup(p ? p + 1 :
"");
344 return AVERROR(ENOMEM);
345 (*so)[*dstcount - 1].specifier = str;
346 dst = &(*so)[*dstcount - 1].u;
351 str = av_strdup(arg);
354 return AVERROR(ENOMEM);
367 int ret = po->
u.
func_arg(optctx, opt, arg);
369 av_log(NULL, AV_LOG_ERROR,
370 "Failed to set value '%s' for option '%s': %s\n",
371 arg, opt, av_err2str(ret));
388 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
399 av_log(NULL, AV_LOG_ERROR,
"Unrecognized option '%s'\n", opt);
400 return AVERROR(EINVAL);
403 av_log(NULL, AV_LOG_ERROR,
"Missing argument for option '%s'\n", opt);
404 return AVERROR(EINVAL);
415 void (*parse_arg_function)(
void *,
const char*))
418 int optindex, handleoptions = 1, ret;
425 while (optindex < argc) {
426 opt = argv[optindex++];
428 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
429 if (opt[1] ==
'-' && opt[2] ==
'\0') {
434 if (optindex >= argc) {
435 if ((ret =
parse_option(optctx, opt, NULL, options)) < 0)
438 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
443 if (parse_arg_function)
444 parse_arg_function(optctx, opt);
453 av_log(NULL, AV_LOG_DEBUG,
"Parsing a group of options: %s %s.\n",
456 for (i = 0; i < g->
nb_opts; i++) {
461 av_log(NULL, AV_LOG_ERROR,
"Option %s (%s) cannot be applied to "
462 "%s %s -- you are trying to apply an input option to an "
463 "output file or vice versa. Move this option before the "
464 "file it belongs to.\n", o->
key, o->
opt->
help,
466 return AVERROR(EINVAL);
469 av_log(NULL, AV_LOG_DEBUG,
"Applying option %s (%s) with argument %s.\n",
477 av_log(NULL, AV_LOG_DEBUG,
"Successfully parsed a group of options.\n");
488 for (i = 1; i < argc; i++) {
489 const char *cur_opt = argv[i];
491 if (*cur_opt++ !=
'-')
495 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
498 if ((!po->
name && !strcmp(cur_opt, optname)) ||
499 (po->
name && !strcmp(optname, po->
name)))
510 const unsigned char *p;
513 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
514 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
521 for (p = a; *p; p++) {
522 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
524 else if (*p < ' ' || *p >
'~')
550 if (idx && (idx + 1 < argc) && argv[idx + 1])
553 if ((env = getenv(
"FFREPORT")) || idx) {
558 for (i = 0; i < argc; i++) {
570 static const AVOption *
opt_find(
void *obj,
const char *name,
const char *unit,
571 int opt_flags,
int search_flags)
573 const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
579 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
584 char opt_stripped[128];
586 const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
587 #if CONFIG_AVRESAMPLE
588 const AVClass *rc = avresample_get_class();
591 const AVClass *sc = sws_get_class();
593 #if CONFIG_SWRESAMPLE
594 const AVClass *swr_class = swr_get_class();
597 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
598 av_log_set_level(AV_LOG_DEBUG);
600 if (!(p = strchr(opt,
':')))
601 p = opt + strlen(opt);
602 av_strlcpy(opt_stripped, opt, FFMIN(
sizeof(opt_stripped), p - opt + 1));
604 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
605 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
606 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
607 (o =
opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
611 if ((o =
opt_find(&fc, opt, NULL, 0,
612 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
615 av_log(NULL, AV_LOG_VERBOSE,
"Routing option %s to both codec and muxer layer\n", opt);
619 if (!consumed && (o =
opt_find(&sc, opt, NULL, 0,
620 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
621 struct SwsContext *sws = sws_alloc_context();
622 int ret = av_opt_set(sws, opt, arg, 0);
623 sws_freeContext(sws);
624 if (!strcmp(opt,
"srcw") || !strcmp(opt,
"srch") ||
625 !strcmp(opt,
"dstw") || !strcmp(opt,
"dsth") ||
626 !strcmp(opt,
"src_format") || !strcmp(opt,
"dst_format")) {
627 av_log(NULL, AV_LOG_ERROR,
"Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
628 return AVERROR(EINVAL);
631 av_log(NULL, AV_LOG_ERROR,
"Error setting option %s.\n", opt);
640 if (!consumed && !strcmp(opt,
"sws_flags")) {
641 av_log(NULL, AV_LOG_WARNING,
"Ignoring %s %s, due to disabled swscale\n", opt, arg);
645 #if CONFIG_SWRESAMPLE
646 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
647 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
648 struct SwrContext *swr = swr_alloc();
649 int ret = av_opt_set(swr, opt, arg, 0);
652 av_log(NULL, AV_LOG_ERROR,
"Error setting option %s.\n", opt);
659 #if CONFIG_AVRESAMPLE
661 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
669 return AVERROR_OPTION_NOT_FOUND;
682 for (i = 0; i < nb_groups; i++) {
684 if (p->
sep && !strcmp(p->
sep, opt))
729 const char *key,
const char *val)
746 memset(octx, 0,
sizeof(*octx));
799 av_log(NULL, AV_LOG_DEBUG,
"Splitting the commandline.\n");
801 while (optindex < argc) {
802 const char *opt = argv[optindex++], *arg;
806 av_log(NULL, AV_LOG_DEBUG,
"Reading option '%s' ...", opt);
808 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
813 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
815 av_log(NULL, AV_LOG_DEBUG,
" matched as %s.\n", groups[0].name);
820 #define GET_ARG(arg) \
822 if (optindex < argc) { \
823 arg = argv[optindex++]; \
825 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
826 return AVERROR(EINVAL); \
834 av_log(NULL, AV_LOG_DEBUG,
" matched as %s with argument '%s'.\n",
835 groups[ret].name, arg);
844 if (optindex < argc) {
845 arg = argv[optindex++];
856 av_log(NULL, AV_LOG_DEBUG,
" matched as option '%s' (%s) with "
857 "argument '%s'.\n", po->
name, po->
help, arg);
862 if ((optindex < argc) && argv[optindex]) {
865 av_log(NULL, AV_LOG_DEBUG,
" matched as AVOption '%s' with "
866 "argument '%s'.\n", opt, argv[optindex]);
869 }
else if (ret != AVERROR_OPTION_NOT_FOUND) {
870 av_log(NULL, AV_LOG_ERROR,
"Error parsing option '%s' "
871 "with argument '%s'.\n", opt, argv[optindex]);
877 if (opt[0] ==
'n' && opt[1] ==
'o' &&
881 av_log(NULL, AV_LOG_DEBUG,
" matched as option '%s' (%s) with "
882 "argument 0.\n", po->
name, po->
help);
886 av_log(NULL, AV_LOG_ERROR,
"Unrecognized option '%s'.\n", opt);
887 return AVERROR_OPTION_NOT_FOUND;
891 av_log(NULL, AV_LOG_WARNING,
"Trailing option(s) found in the "
892 "command: may be ignored.\n");
894 av_log(NULL, AV_LOG_DEBUG,
"Finished splitting the commandline.\n");
902 unsigned flags = av_get_cpu_flags();
904 if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
907 av_force_cpu_flags(flags);
913 const struct {
const char *name;
int level; } log_levels[] = {
914 {
"quiet" , AV_LOG_QUIET },
915 {
"panic" , AV_LOG_PANIC },
916 {
"fatal" , AV_LOG_FATAL },
917 {
"error" , AV_LOG_ERROR },
918 {
"warning", AV_LOG_WARNING },
919 {
"info" , AV_LOG_INFO },
920 {
"verbose", AV_LOG_VERBOSE },
921 {
"debug" , AV_LOG_DEBUG },
922 {
"trace" , AV_LOG_TRACE },
926 int flags = av_log_get_flags();
927 int level = av_log_get_level();
933 if (*token ==
'+' || *token ==
'-') {
941 if (!strncmp(token,
"repeat", 6)) {
943 flags |= AV_LOG_SKIP_REPEATED;
945 flags &= ~AV_LOG_SKIP_REPEATED;
948 }
else if (!strncmp(token,
"level", 5)) {
950 flags &= ~AV_LOG_PRINT_LEVEL;
952 flags |= AV_LOG_PRINT_LEVEL;
962 }
else if (*arg ==
'+') {
965 flags = av_log_get_flags();
968 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
969 if (!strcmp(log_levels[i].name, arg)) {
970 level = log_levels[i].level;
975 level = strtol(arg, &tail, 10);
977 av_log(NULL, AV_LOG_FATAL,
"Invalid loglevel \"%s\". "
978 "Possible levels are numbers or:\n", arg);
979 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
980 av_log(NULL, AV_LOG_FATAL,
"\"%s\"\n", log_levels[i].name);
985 av_log_set_flags(flags);
986 av_log_set_level(level);
995 while ((c = *(
template++))) {
997 if (!(c = *(
template++)))
1004 av_bprintf(bp,
"%04d%02d%02d-%02d%02d%02d",
1005 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1006 tm->tm_hour, tm->tm_min, tm->tm_sec);
1009 av_bprint_chars(bp, c, 1);
1013 av_bprint_chars(bp, c, 1);
1020 char *filename_template = NULL;
1023 int prog_loglevel, envlevel = 0;
1031 tm = localtime(&now);
1033 while (env && *env) {
1034 if ((ret = av_opt_get_key_value(&env,
"=",
":", 0, &key, &val)) < 0) {
1036 av_log(NULL, AV_LOG_ERROR,
1037 "Failed to parse FFREPORT environment variable: %s\n",
1044 if (!strcmp(key,
"file")) {
1045 av_free(filename_template);
1046 filename_template = val;
1048 }
else if (!strcmp(key,
"level")) {
1052 av_log(NULL, AV_LOG_FATAL,
"Invalid report file level\n");
1057 av_log(NULL, AV_LOG_ERROR,
"Unknown key '%s' in FFREPORT\n", key);
1063 av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
1065 av_x_if_null(filename_template,
"%p-%t.log"), tm);
1066 av_free(filename_template);
1067 if (!av_bprint_is_complete(&filename)) {
1068 av_log(NULL, AV_LOG_ERROR,
"Out of memory building report file name\n");
1069 return AVERROR(ENOMEM);
1072 prog_loglevel = av_log_get_level();
1078 int ret = AVERROR(errno);
1079 av_log(NULL, AV_LOG_ERROR,
"Failed to open report \"%s\": %s\n",
1080 filename.str, strerror(errno));
1084 av_log(NULL, AV_LOG_INFO,
1085 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
1086 "Report written to \"%s\"\n"
1089 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1090 tm->tm_hour, tm->tm_min, tm->tm_sec,
1092 av_bprint_finalize(&filename, NULL);
1106 max = strtol(arg, &tail, 10);
1108 av_log(NULL, AV_LOG_FATAL,
"Invalid max_alloc \"%s\".\n", arg);
1119 struct rlimit rl = { lim, lim + 1 };
1120 if (setrlimit(RLIMIT_CPU, &rl))
1121 perror(
"setrlimit");
1123 av_log(NULL, AV_LOG_WARNING,
"-%s not implemented on this OS\n", opt);
1131 const char *errbuf_ptr = errbuf;
1133 if (av_strerror(err, errbuf,
sizeof(errbuf)) < 0)
1134 errbuf_ptr = strerror(AVUNERROR(err));
1135 av_log(NULL, AV_LOG_ERROR,
"%s: %s\n", filename, errbuf_ptr);
1141 #define SHOW_VERSION 2
1142 #define SHOW_CONFIG 4
1143 #define SHOW_COPYRIGHT 8
1145 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1146 if (CONFIG_##LIBNAME) { \
1147 const char *indent = flags & INDENT? " " : ""; \
1148 if (flags & SHOW_VERSION) { \
1149 unsigned int version = libname##_version(); \
1150 av_log(NULL, level, \
1151 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1153 LIB##LIBNAME##_VERSION_MAJOR, \
1154 LIB##LIBNAME##_VERSION_MINOR, \
1155 LIB##LIBNAME##_VERSION_MICRO, \
1156 AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\
1157 AV_VERSION_MICRO(version)); \
1159 if (flags & SHOW_CONFIG) { \
1160 const char *cfg = libname##_configuration(); \
1161 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1162 if (!warned_cfg) { \
1163 av_log(NULL, level, \
1164 "%sWARNING: library configuration mismatch\n", \
1168 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1169 indent, #libname, cfg); \
1187 const char *indent = flags &
INDENT?
" " :
"";
1189 av_log(NULL, level,
"%s version " FFMPEG_VERSION,
program_name);
1191 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1193 av_log(NULL, level,
"\n");
1194 av_log(NULL, level,
"%sbuilt with %s\n", indent, CC_IDENT);
1196 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1201 const char *indent = flags &
INDENT ?
" " :
"";
1202 char str[] = { FFMPEG_CONFIGURATION };
1203 char *conflist, *remove_tilde, *splitconf;
1207 while ((conflist = strstr(str,
" --")) != NULL) {
1208 strncpy(conflist,
"~--", 3);
1213 while ((remove_tilde = strstr(str,
"pkg-config~")) != NULL) {
1214 strncpy(remove_tilde,
"pkg-config ", 11);
1217 splitconf = strtok(str,
"~");
1218 av_log(NULL, level,
"\n%sconfiguration:\n", indent);
1219 while (splitconf != NULL) {
1220 av_log(NULL, level,
"%s%s%s\n", indent, indent, splitconf);
1221 splitconf = strtok(NULL,
"~");
1255 "This version of %s has nonfree parts compiled in.\n"
1256 "Therefore it is not legally redistributable.\n",
1260 "%s is free software; you can redistribute it and/or modify\n"
1261 "it under the terms of the GNU General Public License as published by\n"
1262 "the Free Software Foundation; either version 3 of the License, or\n"
1263 "(at your option) any later version.\n"
1265 "%s is distributed in the hope that it will be useful,\n"
1266 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1267 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1268 "GNU General Public License for more details.\n"
1270 "You should have received a copy of the GNU General Public License\n"
1271 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1275 "%s is free software; you can redistribute it and/or modify\n"
1276 "it under the terms of the GNU General Public License as published by\n"
1277 "the Free Software Foundation; either version 2 of the License, or\n"
1278 "(at your option) any later version.\n"
1280 "%s is distributed in the hope that it will be useful,\n"
1281 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1282 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1283 "GNU General Public License for more details.\n"
1285 "You should have received a copy of the GNU General Public License\n"
1286 "along with %s; if not, write to the Free Software\n"
1287 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1291 "%s is free software; you can redistribute it and/or modify\n"
1292 "it under the terms of the GNU Lesser General Public License as published by\n"
1293 "the Free Software Foundation; either version 3 of the License, or\n"
1294 "(at your option) any later version.\n"
1296 "%s is distributed in the hope that it will be useful,\n"
1297 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1298 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1299 "GNU Lesser General Public License for more details.\n"
1301 "You should have received a copy of the GNU Lesser General Public License\n"
1302 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1306 "%s is free software; you can redistribute it and/or\n"
1307 "modify it under the terms of the GNU Lesser General Public\n"
1308 "License as published by the Free Software Foundation; either\n"
1309 "version 2.1 of the License, or (at your option) any later version.\n"
1311 "%s is distributed in the hope that it will be useful,\n"
1312 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1313 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1314 "Lesser General Public License for more details.\n"
1316 "You should have received a copy of the GNU Lesser General Public\n"
1317 "License along with %s; if not, write to the Free Software\n"
1318 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1329 return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
1334 void *ifmt_opaque = NULL;
1335 const AVInputFormat *ifmt = NULL;
1336 void *ofmt_opaque = NULL;
1337 const AVOutputFormat *ofmt = NULL;
1338 const char *last_name;
1342 " D. = Demuxing supported\n"
1343 " .E = Muxing supported\n"
1344 " --\n", device_only ?
"Devices:" :
"File formats:");
1349 const char *name = NULL;
1350 const char *long_name = NULL;
1354 while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
1356 if (!is_dev && device_only)
1358 if ((!name || strcmp(ofmt->name, name) < 0) &&
1359 strcmp(ofmt->name, last_name) > 0) {
1361 long_name = ofmt->long_name;
1368 while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
1370 if (!is_dev && device_only)
1372 if ((!name || strcmp(ifmt->name, name) < 0) &&
1373 strcmp(ifmt->name, last_name) > 0) {
1375 long_name = ifmt->long_name;
1378 if (name && strcmp(ifmt->name, name) == 0)
1390 long_name ? long_name:
" ");
1415 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1416 if (codec->field) { \
1417 const type *p = codec->field; \
1419 av_log(NULL, AV_LOG_STDERR, " Supported " list_name ":"); \
1420 while (*p != term) { \
1422 av_log(NULL, AV_LOG_STDERR, " %s", name); \
1425 av_log(NULL, AV_LOG_STDERR, "\n"); \
1430 int encoder = av_codec_is_encoder(c);
1432 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->name,
1433 c->long_name ? c->long_name :
"");
1436 if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
1438 if (c->capabilities & AV_CODEC_CAP_DR1)
1440 if (c->capabilities & AV_CODEC_CAP_TRUNCATED)
1442 if (c->capabilities & AV_CODEC_CAP_DELAY)
1444 if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
1446 if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
1448 if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
1450 if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
1452 if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
1454 if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
1456 if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1457 AV_CODEC_CAP_SLICE_THREADS |
1458 AV_CODEC_CAP_AUTO_THREADS))
1460 if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
1462 if (c->capabilities & AV_CODEC_CAP_HARDWARE)
1464 if (c->capabilities & AV_CODEC_CAP_HYBRID)
1466 if (!c->capabilities)
1470 if (c->type == AVMEDIA_TYPE_VIDEO ||
1471 c->type == AVMEDIA_TYPE_AUDIO) {
1473 switch (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1474 AV_CODEC_CAP_SLICE_THREADS |
1475 AV_CODEC_CAP_AUTO_THREADS)) {
1476 case AV_CODEC_CAP_FRAME_THREADS |
1477 AV_CODEC_CAP_SLICE_THREADS: av_log(NULL,
AV_LOG_STDERR,
"frame and slice");
break;
1478 case AV_CODEC_CAP_FRAME_THREADS: av_log(NULL,
AV_LOG_STDERR,
"frame");
break;
1479 case AV_CODEC_CAP_SLICE_THREADS: av_log(NULL,
AV_LOG_STDERR,
"slice");
break;
1480 case AV_CODEC_CAP_AUTO_THREADS : av_log(NULL,
AV_LOG_STDERR,
"auto");
break;
1486 if (avcodec_get_hw_config(c, 0)) {
1487 av_log(NULL,
AV_LOG_STDERR,
" Supported hardware devices: ");
1488 for (
int i = 0;; i++) {
1489 const AVCodecHWConfig *config = avcodec_get_hw_config(c, i);
1492 av_log(NULL,
AV_LOG_STDERR,
"%s ", av_hwdevice_get_type_name(config->device_type));
1497 if (c->supported_framerates) {
1498 const AVRational *fps = c->supported_framerates;
1516 if (c->priv_class) {
1518 AV_OPT_FLAG_ENCODING_PARAM |
1519 AV_OPT_FLAG_DECODING_PARAM);
1526 case AVMEDIA_TYPE_VIDEO:
return 'V';
1527 case AVMEDIA_TYPE_AUDIO:
return 'A';
1528 case AVMEDIA_TYPE_DATA:
return 'D';
1529 case AVMEDIA_TYPE_SUBTITLE:
return 'S';
1530 case AVMEDIA_TYPE_ATTACHMENT:
return 'T';
1531 default:
return '?';
1539 while ((c = av_codec_iterate(iter))) {
1541 (encoder ? av_codec_is_encoder(c) : av_codec_is_decoder(c)))
1549 const AVCodecDescriptor *
const *da = a;
1550 const AVCodecDescriptor *
const *db = b;
1552 return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
1553 strcmp((*da)->name, (*db)->name);
1558 const AVCodecDescriptor *desc = NULL;
1559 const AVCodecDescriptor **codecs;
1560 unsigned nb_codecs = 0, i = 0;
1562 while ((desc = avcodec_descriptor_next(desc)))
1564 if (!(codecs = av_calloc(nb_codecs,
sizeof(*codecs)))) {
1565 av_log(NULL, AV_LOG_ERROR,
"Out of memory\n");
1569 while ((desc = avcodec_descriptor_next(desc)))
1571 av_assert0(i == nb_codecs);
1580 const AVCodec *codec;
1582 av_log(NULL,
AV_LOG_STDERR,
" (%s: ", encoder ?
"encoders" :
"decoders");
1592 const AVCodecDescriptor **codecs;
1596 " D..... = Decoding supported\n"
1597 " .E.... = Encoding supported\n"
1598 " ..V... = Video codec\n"
1599 " ..A... = Audio codec\n"
1600 " ..S... = Subtitle codec\n"
1601 " ...I.. = Intra frame-only codec\n"
1602 " ....L. = Lossy compression\n"
1603 " .....S = Lossless compression\n"
1605 for (i = 0; i < nb_codecs; i++) {
1606 const AVCodecDescriptor *desc = codecs[i];
1607 const AVCodec *codec;
1610 if (strstr(desc->name,
"_deprecated"))
1614 av_log(NULL,
AV_LOG_STDERR, avcodec_find_decoder(desc->id) ?
"D" :
".");
1615 av_log(NULL,
AV_LOG_STDERR, avcodec_find_encoder(desc->id) ?
"E" :
".");
1618 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_INTRA_ONLY) ?
"I" :
".");
1619 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSY) ?
"L" :
".");
1620 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSLESS) ?
"S" :
".");
1622 av_log(NULL,
AV_LOG_STDERR,
" %-20s %s", desc->name, desc->long_name ? desc->long_name :
"");
1627 if (strcmp(codec->name, desc->name)) {
1634 if (strcmp(codec->name, desc->name)) {
1648 const AVCodecDescriptor **codecs;
1654 " S..... = Subtitle\n"
1655 " .F.... = Frame-level multithreading\n"
1656 " ..S... = Slice-level multithreading\n"
1657 " ...X.. = Codec is experimental\n"
1658 " ....B. = Supports draw_horiz_band\n"
1659 " .....D = Supports direct rendering method 1\n"
1661 encoder ?
"Encoders" :
"Decoders");
1662 for (i = 0; i < nb_codecs; i++) {
1663 const AVCodecDescriptor *desc = codecs[i];
1664 const AVCodec *codec;
1669 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ?
"F" :
".");
1670 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ?
"S" :
".");
1671 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ?
"X" :
".");
1672 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?
"B" :
".");
1673 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DR1) ?
"D" :
".");
1675 av_log(NULL,
AV_LOG_STDERR,
" %-20s %s", codec->name, codec->long_name ? codec->long_name :
"");
1676 if (strcmp(codec->name, desc->name))
1697 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1699 const AVBitStreamFilter *bsf = NULL;
1700 void *opaque = NULL;
1703 while ((bsf = av_bsf_iterate(&opaque)))
1711 void *opaque = NULL;
1716 while ((name = avio_enum_protocols(&opaque, 0)))
1719 while ((name = avio_enum_protocols(&opaque, 1)))
1727 const AVFilter *filter = NULL;
1728 char descr[64], *descr_cur;
1729 void *opaque = NULL;
1731 const AVFilterPad *pad;
1734 " T.. = Timeline support\n"
1735 " .S. = Slice threading\n"
1736 " ..C = Command support\n"
1737 " A = Audio input/output\n"
1738 " V = Video input/output\n"
1739 " N = Dynamic number and/or type of input/output\n"
1740 " | = Source or sink filter\n");
1741 while ((filter = av_filter_iterate(&opaque))) {
1743 for (i = 0; i < 2; i++) {
1745 *(descr_cur++) =
'-';
1746 *(descr_cur++) =
'>';
1748 pad = i ? filter->outputs : filter->inputs;
1749 for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
1750 if (descr_cur >= descr +
sizeof(descr) - 4)
1755 *(descr_cur++) = ((!i && (filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
1756 ( i && (filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ?
'N' :
'|';
1760 filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ?
'T' :
'.',
1761 filter->flags & AVFILTER_FLAG_SLICE_THREADS ?
'S' :
'.',
1762 filter->process_command ?
'C' :
'.',
1763 filter->name, descr, filter->description);
1766 av_log(NULL,
AV_LOG_STDERR,
"No filters available: libavfilter disabled\n");
1779 for (i = 0; (name = av_get_known_color_name(i, &rgb)); i++)
1780 av_log(NULL,
AV_LOG_STDERR,
"%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1787 const AVPixFmtDescriptor *pix_desc = NULL;
1790 "I.... = Supported Input format for conversion\n"
1791 ".O... = Supported Output format for conversion\n"
1792 "..H.. = Hardware accelerated format\n"
1793 "...P. = Paletted format\n"
1794 "....B = Bitstream format\n"
1795 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1799 # define sws_isSupportedInput(x) 0
1800 # define sws_isSupportedOutput(x) 0
1803 while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
1804 enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
1808 pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ?
'H' :
'.',
1809 pix_desc->flags & AV_PIX_FMT_FLAG_PAL ?
'P' :
'.',
1810 pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ?
'B' :
'.',
1812 pix_desc->nb_components,
1813 av_get_bits_per_pixel(pix_desc));
1822 const char *name, *descr;
1825 "NAME DESCRIPTION\n");
1826 for (i = 0; i < 63; i++) {
1827 name = av_get_channel_name((uint64_t)1 << i);
1830 descr = av_get_channel_description((uint64_t)1 << i);
1834 "NAME DECOMPOSITION\n");
1835 for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
1838 for (j = 1; j; j <<= 1)
1840 av_log(NULL,
AV_LOG_STDERR,
"%s%s", (layout & (j - 1)) ?
"+" :
"", av_get_channel_name(j));
1851 for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
1852 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_get_sample_fmt_string(fmt_str,
sizeof(fmt_str), i));
1858 const AVCodecDescriptor *desc;
1859 const AVCodec *codec;
1862 av_log(NULL, AV_LOG_ERROR,
"No codec name specified.\n");
1866 codec = encoder ? avcodec_find_encoder_by_name(name) :
1867 avcodec_find_decoder_by_name(name);
1871 else if ((desc = avcodec_descriptor_get_by_name(name))) {
1881 av_log(NULL, AV_LOG_ERROR,
"Codec '%s' is known to FFmpeg, "
1882 "but no %s for it are available. FFmpeg might need to be "
1883 "recompiled with additional external libraries.\n",
1884 name, encoder ?
"encoders" :
"decoders");
1887 av_log(NULL, AV_LOG_ERROR,
"Codec '%s' is not recognized by FFmpeg.\n",
1894 const AVInputFormat *fmt = av_find_input_format(name);
1897 av_log(NULL, AV_LOG_ERROR,
"Unknown format '%s'.\n", name);
1901 av_log(NULL,
AV_LOG_STDERR,
"Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
1903 if (fmt->extensions)
1904 av_log(NULL,
AV_LOG_STDERR,
" Common extensions: %s.\n", fmt->extensions);
1906 if (fmt->priv_class)
1912 const AVClass *proto_class;
1915 av_log(NULL, AV_LOG_ERROR,
"No protocol name specified.\n");
1919 proto_class = avio_protocol_get_class(name);
1921 av_log(NULL, AV_LOG_ERROR,
"Unknown protocol '%s'.\n", name);
1925 show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
1930 const AVCodecDescriptor *desc;
1931 const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
1934 av_log(NULL, AV_LOG_ERROR,
"Unknown format '%s'.\n", name);
1938 av_log(NULL,
AV_LOG_STDERR,
"Muxer %s [%s]:\n", fmt->name, fmt->long_name);
1940 if (fmt->extensions)
1941 av_log(NULL,
AV_LOG_STDERR,
" Common extensions: %s.\n", fmt->extensions);
1943 av_log(NULL,
AV_LOG_STDERR,
" Mime type: %s.\n", fmt->mime_type);
1944 if (fmt->video_codec != AV_CODEC_ID_NONE &&
1945 (desc = avcodec_descriptor_get(fmt->video_codec))) {
1946 av_log(NULL,
AV_LOG_STDERR,
" Default video codec: %s.\n", desc->name);
1948 if (fmt->audio_codec != AV_CODEC_ID_NONE &&
1949 (desc = avcodec_descriptor_get(fmt->audio_codec))) {
1950 av_log(NULL,
AV_LOG_STDERR,
" Default audio codec: %s.\n", desc->name);
1952 if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
1953 (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
1954 av_log(NULL,
AV_LOG_STDERR,
" Default subtitle codec: %s.\n", desc->name);
1957 if (fmt->priv_class)
1962 static void show_help_filter(
const char *name)
1965 const AVFilter *f = avfilter_get_by_name(name);
1969 av_log(NULL, AV_LOG_ERROR,
"No filter name specified.\n");
1972 av_log(NULL, AV_LOG_ERROR,
"Unknown filter '%s'.\n", name);
1980 if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
1981 av_log(NULL,
AV_LOG_STDERR,
" slice threading supported\n");
1984 count = avfilter_pad_count(f->inputs);
1985 for (i = 0; i < count; i++) {
1986 av_log(NULL,
AV_LOG_STDERR,
" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
1989 if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
1990 av_log(NULL,
AV_LOG_STDERR,
" dynamic (depending on the options)\n");
1995 count = avfilter_pad_count(f->outputs);
1996 for (i = 0; i < count; i++) {
1997 av_log(NULL,
AV_LOG_STDERR,
" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
2000 if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
2001 av_log(NULL,
AV_LOG_STDERR,
" dynamic (depending on the options)\n");
2006 show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
2007 AV_OPT_FLAG_AUDIO_PARAM);
2008 if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
2009 av_log(NULL,
AV_LOG_STDERR,
"This filter has support for timeline through the 'enable' option.\n");
2011 av_log(NULL, AV_LOG_ERROR,
"Build without libavfilter; "
2012 "can not to satisfy request\n");
2019 const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
2022 av_log(NULL, AV_LOG_ERROR,
"No bitstream filter name specified.\n");
2025 av_log(NULL, AV_LOG_ERROR,
"Unknown bit stream filter '%s'.\n", name);
2029 av_log(NULL,
AV_LOG_STDERR,
"Bit stream filter %s\n", bsf->name);
2032 if (bsf->priv_class)
2036 int show_help(
void *optctx,
const char *opt,
const char *arg)
2040 topic = av_strdup(arg ? arg :
"");
2042 return AVERROR(ENOMEM);
2043 par = strchr(topic,
'=');
2053 }
else if (!strcmp(topic,
"decoder")) {
2055 }
else if (!strcmp(topic,
"encoder")) {
2057 }
else if (!strcmp(topic,
"demuxer")) {
2059 }
else if (!strcmp(topic,
"muxer")) {
2061 }
else if (!strcmp(topic,
"protocol")) {
2064 }
else if (!strcmp(topic,
"filter")) {
2065 show_help_filter(par);
2067 }
else if (!strcmp(topic,
"bsf")) {
2084 int yesno = (av_toupper(c) ==
'Y');
2086 while (c !=
'\n' && c != EOF)
2093 const char *preset_name,
int is_path,
2094 const char *codec_name)
2098 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
2103 av_strlcpy(filename, preset_name, filename_size);
2104 f = fopen(filename,
"r");
2106 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
2107 char datadir[MAX_PATH], *ls;
2110 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir,
sizeof(datadir) - 1))
2112 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
2113 if (*ls ==
'\\') *ls =
'/';
2115 if (ls = strrchr(datadir,
'/'))
2118 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
2123 for (i = 0; i < 3 && !f; i++) {
2126 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
2127 i != 1 ?
"" :
"/.ffmpeg", preset_name);
2128 f = fopen(filename,
"r");
2129 if (!f && codec_name) {
2130 snprintf(filename, filename_size,
2131 "%s%s/%s-%s.ffpreset",
2132 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
2134 f = fopen(filename,
"r");
2144 int ret = avformat_match_stream_specifier(s, st, spec);
2146 av_log(s, AV_LOG_ERROR,
"Invalid stream specifier: %s.\n", spec);
2151 AVFormatContext *s, AVStream *st, AVCodec *codec)
2153 AVDictionary *ret = NULL;
2154 AVDictionaryEntry *t = NULL;
2155 int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
2156 : AV_OPT_FLAG_DECODING_PARAM;
2158 const AVClass *cc = avcodec_get_class();
2161 codec = s->oformat ? avcodec_find_encoder(codec_id)
2162 : avcodec_find_decoder(codec_id);
2164 switch (st->codecpar->codec_type) {
2165 case AVMEDIA_TYPE_VIDEO:
2167 flags |= AV_OPT_FLAG_VIDEO_PARAM;
2169 case AVMEDIA_TYPE_AUDIO:
2171 flags |= AV_OPT_FLAG_AUDIO_PARAM;
2173 case AVMEDIA_TYPE_SUBTITLE:
2175 flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
2179 while ((t = av_dict_get(opts,
"", t, AV_DICT_IGNORE_SUFFIX))) {
2180 char *p = strchr(t->key,
':');
2185 case 1: *p = 0;
break;
2190 if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
2192 (codec->priv_class &&
2193 av_opt_find(&codec->priv_class, t->key, NULL, flags,
2194 AV_OPT_SEARCH_FAKE_OBJ)))
2195 av_dict_set(&ret, t->key, t->value, 0);
2196 else if (t->key[0] == prefix &&
2197 av_opt_find(&cc, t->key + 1, NULL, flags,
2198 AV_OPT_SEARCH_FAKE_OBJ))
2199 av_dict_set(&ret, t->key + 1, t->value, 0);
2211 AVDictionary **opts;
2215 opts = av_mallocz_array(s->nb_streams,
sizeof(*opts));
2217 av_log(NULL, AV_LOG_ERROR,
2218 "Could not alloc memory for stream options.\n");
2221 for (i = 0; i < s->nb_streams; i++)
2223 s, s->streams[i], NULL);
2227 void *
grow_array(
void *array,
int elem_size,
int *size,
int new_size)
2229 if (new_size >= INT_MAX / elem_size) {
2230 av_log(NULL, AV_LOG_ERROR,
"Array too big.\n");
2233 if (*size < new_size) {
2234 uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
2236 av_log(NULL, AV_LOG_ERROR,
"Could not alloc buffer.\n");
2239 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
2248 uint8_t* displaymatrix = av_stream_get_side_data(st,
2249 AV_PKT_DATA_DISPLAYMATRIX, NULL);
2252 theta = -av_display_rotation_get((int32_t*) displaymatrix);
2254 theta -= 360*floor(theta/360 + 0.9/360);
2256 if (fabs(theta - 90*round(theta/90)) > 2)
2257 av_log(NULL, AV_LOG_WARNING,
"Odd rotation angle.\n"
2258 "If you want to help, upload a sample "
2259 "of this file to https://streams.videolan.org/upload/ "
2260 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
2266 static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
2269 AVDeviceInfoList *device_list = NULL;
2271 if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
2272 return AVERROR(EINVAL);
2274 av_log(NULL,
AV_LOG_STDERR,
"Auto-detected sources for %s:\n", fmt->name);
2275 if (!fmt->get_device_list) {
2276 ret = AVERROR(ENOSYS);
2277 av_log(NULL,
AV_LOG_STDERR,
"Cannot list sources. Not implemented.\n");
2281 if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
2286 for (i = 0; i < device_list->nb_devices; i++) {
2287 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]\n", device_list->default_device == i ?
"*" :
" ",
2288 device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2292 avdevice_free_list_devices(&device_list);
2296 static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
2299 AVDeviceInfoList *device_list = NULL;
2301 if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
2302 return AVERROR(EINVAL);
2304 av_log(NULL,
AV_LOG_STDERR,
"Auto-detected sinks for %s:\n", fmt->name);
2305 if (!fmt->get_device_list) {
2306 ret = AVERROR(ENOSYS);
2307 av_log(NULL,
AV_LOG_STDERR,
"Cannot list sinks. Not implemented.\n");
2311 if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
2316 for (i = 0; i < device_list->nb_devices; i++) {
2317 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]\n", device_list->default_device == i ?
"*" :
" ",
2318 device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2322 avdevice_free_list_devices(&device_list);
2326 static int show_sinks_sources_parse_arg(
const char *arg,
char **dev, AVDictionary **opts)
2330 char *opts_str = NULL;
2331 av_assert0(dev && opts);
2332 *dev = av_strdup(arg);
2334 return AVERROR(ENOMEM);
2335 if ((opts_str = strchr(*dev,
','))) {
2336 *(opts_str++) =
'\0';
2337 if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str,
"=",
":", 0)) < 0)) {
2343 av_log(NULL,
AV_LOG_STDERR,
"\nDevice name is not provided.\n"
2344 "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
2348 int show_sources(
void *optctx,
const char *opt,
const char *arg)
2350 AVInputFormat *fmt = NULL;
2352 AVDictionary *opts = NULL;
2354 int error_level = av_log_get_level();
2356 av_log_set_level(AV_LOG_WARNING);
2358 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2362 fmt = av_input_audio_device_next(fmt);
2364 if (!strcmp(fmt->name,
"lavfi"))
2366 if (dev && !av_match_name(dev, fmt->name))
2368 print_device_sources(fmt, opts);
2372 fmt = av_input_video_device_next(fmt);
2374 if (dev && !av_match_name(dev, fmt->name))
2376 print_device_sources(fmt, opts);
2380 av_dict_free(&opts);
2382 av_log_set_level(error_level);
2386 int show_sinks(
void *optctx,
const char *opt,
const char *arg)
2388 AVOutputFormat *fmt = NULL;
2390 AVDictionary *opts = NULL;
2392 int error_level = av_log_get_level();
2394 av_log_set_level(AV_LOG_WARNING);
2396 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2400 fmt = av_output_audio_device_next(fmt);
2402 if (dev && !av_match_name(dev, fmt->name))
2404 print_device_sinks(fmt, opts);
2408 fmt = av_output_video_device_next(fmt);
2410 if (dev && !av_match_name(dev, fmt->name))
2412 print_device_sinks(fmt, opts);
2416 av_dict_free(&opts);
2418 av_log_set_level(error_level);
__thread jmp_buf ex_buf__
int(* func_arg)(void *, const char *, const char *)
const OptionGroupDef * group_def
AVDictionary * codec_opts
AVDictionary * format_opts
AVDictionary * resample_opts
const OptionGroupDef * group_def