64 #include "libavformat/avformat.h"
65 #include "libavfilter/avfilter.h"
66 #include "libavdevice/avdevice.h"
67 #include "libswscale/swscale.h"
68 #include "libswresample/swresample.h"
69 #include "libavutil/attributes.h"
70 #include "libavutil/avassert.h"
71 #include "libavutil/avstring.h"
72 #include "libavutil/bprint.h"
73 #include "libavutil/display.h"
74 #include "libavutil/mathematics.h"
75 #include "libavutil/imgutils.h"
76 #include "libavutil/libm.h"
77 #include "libavutil/parseutils.h"
78 #include "libavutil/pixdesc.h"
79 #include "libavutil/eval.h"
80 #include "libavutil/dict.h"
81 #include "libavutil/opt.h"
82 #include "libavutil/cpu.h"
83 #include "libavutil/ffversion.h"
84 #include "libavutil/version.h"
86 #if HAVE_SYS_RESOURCE_H
88 #include <sys/resource.h>
118 av_dict_set(&
sws_dict,
"flags",
"bicubic", 0);
134 static int print_prefix = 1;
138 av_log_default_callback(ptr, level, fmt, vl);
142 av_log_format_line(ptr, level, fmt, vl2, line,
sizeof(line), &print_prefix);
152 #if HAVE_SETDLLDIRECTORY && defined(_WIN32)
178 double min,
double max)
182 double d = av_strtod(numstr, &tail);
184 error =
"Expected number for %s but found: %s\n";
185 else if (d < min || d > max)
186 error =
"The value for %s was %s which is not within %f - %f\n";
187 else if (type ==
OPT_INT64 && (int64_t)d != d)
188 error =
"Expected int64 for %s but found %s\n";
189 else if (type ==
OPT_INT && (
int)d != d)
190 error =
"Expected int for %s but found %s\n";
193 av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
202 if (av_parse_time(&us, timestr, is_duration) < 0) {
203 av_log(NULL, AV_LOG_FATAL,
"Invalid %s specification for %s: %s\n",
204 is_duration ?
"duration" :
"date", context, timestr);
211 int rej_flags,
int alt_flags)
217 for (po = options; po->
name; po++) {
220 if (((po->
flags & req_flags) != req_flags) ||
221 (alt_flags && !(po->
flags & alt_flags)) ||
222 (po->
flags & rej_flags))
229 av_strlcpy(buf, po->
name,
sizeof(buf));
231 av_strlcat(buf,
" ",
sizeof(buf));
232 av_strlcat(buf, po->
argname,
sizeof(buf));
242 const AVClass *child;
244 av_opt_show2(&
class, NULL, flags, 0);
248 while ((child = av_opt_child_class_iterate(
class, &iter)))
254 const char *p = strchr(name,
':');
255 int len = p ? p - name : strlen(name);
258 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
268 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
269 #include <shellapi.h>
271 static char** win32_argv_utf8 = NULL;
272 static int win32_argc = 0;
285 int i, buffsize = 0, offset = 0;
287 if (win32_argv_utf8) {
288 *argc_ptr = win32_argc;
289 *argv_ptr = win32_argv_utf8;
294 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
295 if (win32_argc <= 0 || !argv_w)
299 for (i = 0; i < win32_argc; i++)
300 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
301 NULL, 0, NULL, NULL);
303 win32_argv_utf8 = av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
304 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
305 if (!win32_argv_utf8) {
310 for (i = 0; i < win32_argc; i++) {
311 win32_argv_utf8[i] = &argstr_flat[offset];
312 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
313 &argstr_flat[offset],
314 buffsize - offset, NULL, NULL);
316 win32_argv_utf8[i] = NULL;
319 *argc_ptr = win32_argc;
320 *argv_ptr = win32_argv_utf8;
340 char *p = strchr(opt,
':');
343 dstcount = (
int *)(so + 1);
344 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
345 str = av_strdup(p ? p + 1 :
"");
347 return AVERROR(ENOMEM);
348 (*so)[*dstcount - 1].specifier = str;
349 dst = &(*so)[*dstcount - 1].u;
354 str = av_strdup(arg);
357 return AVERROR(ENOMEM);
370 int ret = po->
u.
func_arg(optctx, opt, arg);
372 av_log(NULL, AV_LOG_ERROR,
373 "Failed to set value '%s' for option '%s': %s\n",
374 arg, opt, av_err2str(ret));
391 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
402 av_log(NULL, AV_LOG_ERROR,
"Unrecognized option '%s'\n", opt);
403 return AVERROR(EINVAL);
406 av_log(NULL, AV_LOG_ERROR,
"Missing argument for option '%s'\n", opt);
407 return AVERROR(EINVAL);
418 void (*parse_arg_function)(
void *,
const char*))
421 int optindex, handleoptions = 1, ret;
428 while (optindex < argc) {
429 opt = argv[optindex++];
431 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
432 if (opt[1] ==
'-' && opt[2] ==
'\0') {
437 if (optindex >= argc) {
438 if ((ret =
parse_option(optctx, opt, NULL, options)) < 0)
441 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
446 if (parse_arg_function)
447 parse_arg_function(optctx, opt);
456 av_log(NULL, AV_LOG_DEBUG,
"Parsing a group of options: %s %s.\n",
459 for (i = 0; i < g->
nb_opts; i++) {
464 av_log(NULL, AV_LOG_ERROR,
"Option %s (%s) cannot be applied to "
465 "%s %s -- you are trying to apply an input option to an "
466 "output file or vice versa. Move this option before the "
467 "file it belongs to.\n", o->
key, o->
opt->
help,
469 return AVERROR(EINVAL);
472 av_log(NULL, AV_LOG_DEBUG,
"Applying option %s (%s) with argument %s.\n",
480 av_log(NULL, AV_LOG_DEBUG,
"Successfully parsed a group of options.\n");
491 for (i = 1; i < argc; i++) {
492 const char *cur_opt = argv[i];
494 if (*cur_opt++ !=
'-')
498 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
501 if ((!po->
name && !strcmp(cur_opt, optname)) ||
502 (po->
name && !strcmp(optname, po->
name)))
513 const unsigned char *p;
516 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
517 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
524 for (p = a; *p; p++) {
525 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
527 else if (*p < ' ' || *p >
'~')
553 if (idx && (idx + 1 < argc) && argv[idx + 1])
556 if ((env = getenv(
"FFREPORT")) || idx) {
561 for (i = 0; i < argc; i++) {
573 static const AVOption *
opt_find(
void *obj,
const char *name,
const char *unit,
574 int opt_flags,
int search_flags)
576 const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
582 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
587 char opt_stripped[128];
589 const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
590 #if CONFIG_AVRESAMPLE
591 const AVClass *rc = avresample_get_class();
594 const AVClass *sc = sws_get_class();
596 #if CONFIG_SWRESAMPLE
597 const AVClass *swr_class = swr_get_class();
600 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
601 av_log_set_level(AV_LOG_DEBUG);
603 if (!(p = strchr(opt,
':')))
604 p = opt + strlen(opt);
605 av_strlcpy(opt_stripped, opt, FFMIN(
sizeof(opt_stripped), p - opt + 1));
607 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
608 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
609 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
610 (o =
opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
614 if ((o =
opt_find(&fc, opt, NULL, 0,
615 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
618 av_log(NULL, AV_LOG_VERBOSE,
"Routing option %s to both codec and muxer layer\n", opt);
622 if (!consumed && (o =
opt_find(&sc, opt, NULL, 0,
623 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
624 struct SwsContext *sws = sws_alloc_context();
625 int ret = av_opt_set(sws, opt, arg, 0);
626 sws_freeContext(sws);
627 if (!strcmp(opt,
"srcw") || !strcmp(opt,
"srch") ||
628 !strcmp(opt,
"dstw") || !strcmp(opt,
"dsth") ||
629 !strcmp(opt,
"src_format") || !strcmp(opt,
"dst_format")) {
630 av_log(NULL, AV_LOG_ERROR,
"Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
631 return AVERROR(EINVAL);
634 av_log(NULL, AV_LOG_ERROR,
"Error setting option %s.\n", opt);
643 if (!consumed && !strcmp(opt,
"sws_flags")) {
644 av_log(NULL, AV_LOG_WARNING,
"Ignoring %s %s, due to disabled swscale\n", opt, arg);
648 #if CONFIG_SWRESAMPLE
649 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
650 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
651 struct SwrContext *swr = swr_alloc();
652 int ret = av_opt_set(swr, opt, arg, 0);
655 av_log(NULL, AV_LOG_ERROR,
"Error setting option %s.\n", opt);
662 #if CONFIG_AVRESAMPLE
664 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
672 return AVERROR_OPTION_NOT_FOUND;
685 for (i = 0; i < nb_groups; i++) {
687 if (p->
sep && !strcmp(p->
sep, opt))
732 const char *key,
const char *val)
749 memset(octx, 0,
sizeof(*octx));
802 av_log(NULL, AV_LOG_DEBUG,
"Splitting the commandline.\n");
804 while (optindex < argc) {
805 const char *opt = argv[optindex++], *arg;
809 av_log(NULL, AV_LOG_DEBUG,
"Reading option '%s' ...", opt);
811 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
816 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
818 av_log(NULL, AV_LOG_DEBUG,
" matched as %s.\n", groups[0].name);
823 #define GET_ARG(arg) \
825 if (optindex < argc) { \
826 arg = argv[optindex++]; \
828 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
829 return AVERROR(EINVAL); \
837 av_log(NULL, AV_LOG_DEBUG,
" matched as %s with argument '%s'.\n",
838 groups[ret].name, arg);
847 if (optindex < argc) {
848 arg = argv[optindex++];
859 av_log(NULL, AV_LOG_DEBUG,
" matched as option '%s' (%s) with "
860 "argument '%s'.\n", po->
name, po->
help, arg);
865 if ((optindex < argc) && argv[optindex]) {
868 av_log(NULL, AV_LOG_DEBUG,
" matched as AVOption '%s' with "
869 "argument '%s'.\n", opt, argv[optindex]);
872 }
else if (ret != AVERROR_OPTION_NOT_FOUND) {
873 av_log(NULL, AV_LOG_ERROR,
"Error parsing option '%s' "
874 "with argument '%s'.\n", opt, argv[optindex]);
880 if (opt[0] ==
'n' && opt[1] ==
'o' &&
884 av_log(NULL, AV_LOG_DEBUG,
" matched as option '%s' (%s) with "
885 "argument 0.\n", po->
name, po->
help);
889 av_log(NULL, AV_LOG_ERROR,
"Unrecognized option '%s'.\n", opt);
890 return AVERROR_OPTION_NOT_FOUND;
894 av_log(NULL, AV_LOG_WARNING,
"Trailing option(s) found in the "
895 "command: may be ignored.\n");
897 av_log(NULL, AV_LOG_DEBUG,
"Finished splitting the commandline.\n");
905 unsigned flags = av_get_cpu_flags();
907 if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
910 av_force_cpu_flags(flags);
916 const struct {
const char *name;
int level; } log_levels[] = {
917 {
"quiet" , AV_LOG_QUIET },
918 {
"panic" , AV_LOG_PANIC },
919 {
"fatal" , AV_LOG_FATAL },
920 {
"error" , AV_LOG_ERROR },
921 {
"warning", AV_LOG_WARNING },
922 {
"info" , AV_LOG_INFO },
923 {
"verbose", AV_LOG_VERBOSE },
924 {
"debug" , AV_LOG_DEBUG },
925 {
"trace" , AV_LOG_TRACE },
929 int flags = av_log_get_flags();
930 int level = av_log_get_level();
936 if (*token ==
'+' || *token ==
'-') {
944 if (!strncmp(token,
"repeat", 6)) {
946 flags |= AV_LOG_SKIP_REPEATED;
948 flags &= ~AV_LOG_SKIP_REPEATED;
951 }
else if (!strncmp(token,
"level", 5)) {
953 flags &= ~AV_LOG_PRINT_LEVEL;
955 flags |= AV_LOG_PRINT_LEVEL;
965 }
else if (*arg ==
'+') {
968 flags = av_log_get_flags();
971 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
972 if (!strcmp(log_levels[i].name, arg)) {
973 level = log_levels[i].level;
978 level = strtol(arg, &tail, 10);
980 av_log(NULL, AV_LOG_FATAL,
"Invalid loglevel \"%s\". "
981 "Possible levels are numbers or:\n", arg);
982 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
983 av_log(NULL, AV_LOG_FATAL,
"\"%s\"\n", log_levels[i].name);
988 av_log_set_flags(flags);
989 av_log_set_level(level);
998 while ((c = *(
template++))) {
1000 if (!(c = *(
template++)))
1007 av_bprintf(bp,
"%04d%02d%02d-%02d%02d%02d",
1008 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1009 tm->tm_hour, tm->tm_min, tm->tm_sec);
1012 av_bprint_chars(bp, c, 1);
1016 av_bprint_chars(bp, c, 1);
1023 char *filename_template = NULL;
1026 int prog_loglevel, envlevel = 0;
1034 tm = localtime(&now);
1036 while (env && *env) {
1037 if ((ret = av_opt_get_key_value(&env,
"=",
":", 0, &key, &val)) < 0) {
1039 av_log(NULL, AV_LOG_ERROR,
1040 "Failed to parse FFREPORT environment variable: %s\n",
1047 if (!strcmp(key,
"file")) {
1048 av_free(filename_template);
1049 filename_template = val;
1051 }
else if (!strcmp(key,
"level")) {
1055 av_log(NULL, AV_LOG_FATAL,
"Invalid report file level\n");
1060 av_log(NULL, AV_LOG_ERROR,
"Unknown key '%s' in FFREPORT\n", key);
1066 av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
1068 av_x_if_null(filename_template,
"%p-%t.log"), tm);
1069 av_free(filename_template);
1070 if (!av_bprint_is_complete(&filename)) {
1071 av_log(NULL, AV_LOG_ERROR,
"Out of memory building report file name\n");
1072 return AVERROR(ENOMEM);
1075 prog_loglevel = av_log_get_level();
1081 int ret = AVERROR(errno);
1082 av_log(NULL, AV_LOG_ERROR,
"Failed to open report \"%s\": %s\n",
1083 filename.str, strerror(errno));
1087 av_log(NULL, AV_LOG_INFO,
1088 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
1089 "Report written to \"%s\"\n"
1092 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1093 tm->tm_hour, tm->tm_min, tm->tm_sec,
1095 av_bprint_finalize(&filename, NULL);
1109 max = strtol(arg, &tail, 10);
1111 av_log(NULL, AV_LOG_FATAL,
"Invalid max_alloc \"%s\".\n", arg);
1122 struct rlimit rl = { lim, lim + 1 };
1123 if (setrlimit(RLIMIT_CPU, &rl))
1124 perror(
"setrlimit");
1126 av_log(NULL, AV_LOG_WARNING,
"-%s not implemented on this OS\n", opt);
1134 const char *errbuf_ptr = errbuf;
1136 if (av_strerror(err, errbuf,
sizeof(errbuf)) < 0)
1137 errbuf_ptr = strerror(AVUNERROR(err));
1138 av_log(NULL, AV_LOG_ERROR,
"%s: %s\n", filename, errbuf_ptr);
1144 #define SHOW_VERSION 2
1145 #define SHOW_CONFIG 4
1146 #define SHOW_COPYRIGHT 8
1148 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1149 if (CONFIG_##LIBNAME) { \
1150 const char *indent = flags & INDENT? " " : ""; \
1151 if (flags & SHOW_VERSION) { \
1152 unsigned int version = libname##_version(); \
1153 av_log(NULL, level, \
1154 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1156 LIB##LIBNAME##_VERSION_MAJOR, \
1157 LIB##LIBNAME##_VERSION_MINOR, \
1158 LIB##LIBNAME##_VERSION_MICRO, \
1159 AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\
1160 AV_VERSION_MICRO(version)); \
1162 if (flags & SHOW_CONFIG) { \
1163 const char *cfg = libname##_configuration(); \
1164 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1165 if (!warned_cfg) { \
1166 av_log(NULL, level, \
1167 "%sWARNING: library configuration mismatch\n", \
1171 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1172 indent, #libname, cfg); \
1190 const char *indent = flags &
INDENT?
" " :
"";
1192 av_log(NULL, level,
"%s version " FFMPEG_VERSION,
program_name);
1194 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1196 av_log(NULL, level,
"\n");
1197 av_log(NULL, level,
"%sbuilt with %s\n", indent, CC_IDENT);
1199 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1204 const char *indent = flags &
INDENT ?
" " :
"";
1205 char str[] = { FFMPEG_CONFIGURATION };
1206 char *conflist, *remove_tilde, *splitconf;
1210 while ((conflist = strstr(str,
" --")) != NULL) {
1211 strncpy(conflist,
"~--", 3);
1216 while ((remove_tilde = strstr(str,
"pkg-config~")) != NULL) {
1217 strncpy(remove_tilde,
"pkg-config ", 11);
1220 splitconf = strtok(str,
"~");
1221 av_log(NULL, level,
"\n%sconfiguration:\n", indent);
1222 while (splitconf != NULL) {
1223 av_log(NULL, level,
"%s%s%s\n", indent, indent, splitconf);
1224 splitconf = strtok(NULL,
"~");
1258 "This version of %s has nonfree parts compiled in.\n"
1259 "Therefore it is not legally redistributable.\n",
1263 "%s is free software; you can redistribute it and/or modify\n"
1264 "it under the terms of the GNU General Public License as published by\n"
1265 "the Free Software Foundation; either version 3 of the License, or\n"
1266 "(at your option) any later version.\n"
1268 "%s is distributed in the hope that it will be useful,\n"
1269 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1270 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1271 "GNU General Public License for more details.\n"
1273 "You should have received a copy of the GNU General Public License\n"
1274 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1278 "%s is free software; you can redistribute it and/or modify\n"
1279 "it under the terms of the GNU General Public License as published by\n"
1280 "the Free Software Foundation; either version 2 of the License, or\n"
1281 "(at your option) any later version.\n"
1283 "%s is distributed in the hope that it will be useful,\n"
1284 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1285 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1286 "GNU General Public License for more details.\n"
1288 "You should have received a copy of the GNU General Public License\n"
1289 "along with %s; if not, write to the Free Software\n"
1290 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1294 "%s is free software; you can redistribute it and/or modify\n"
1295 "it under the terms of the GNU Lesser General Public License as published by\n"
1296 "the Free Software Foundation; either version 3 of the License, or\n"
1297 "(at your option) any later version.\n"
1299 "%s is distributed in the hope that it will be useful,\n"
1300 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1301 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1302 "GNU Lesser General Public License for more details.\n"
1304 "You should have received a copy of the GNU Lesser General Public License\n"
1305 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1309 "%s is free software; you can redistribute it and/or\n"
1310 "modify it under the terms of the GNU Lesser General Public\n"
1311 "License as published by the Free Software Foundation; either\n"
1312 "version 2.1 of the License, or (at your option) any later version.\n"
1314 "%s is distributed in the hope that it will be useful,\n"
1315 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1316 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1317 "Lesser General Public License for more details.\n"
1319 "You should have received a copy of the GNU Lesser General Public\n"
1320 "License along with %s; if not, write to the Free Software\n"
1321 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1332 return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
1337 void *ifmt_opaque = NULL;
1338 const AVInputFormat *ifmt = NULL;
1339 void *ofmt_opaque = NULL;
1340 const AVOutputFormat *ofmt = NULL;
1341 const char *last_name;
1345 " D. = Demuxing supported\n"
1346 " .E = Muxing supported\n"
1347 " --\n", device_only ?
"Devices:" :
"File formats:");
1352 const char *name = NULL;
1353 const char *long_name = NULL;
1357 while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
1359 if (!is_dev && device_only)
1361 if ((!name || strcmp(ofmt->name, name) < 0) &&
1362 strcmp(ofmt->name, last_name) > 0) {
1364 long_name = ofmt->long_name;
1371 while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
1373 if (!is_dev && device_only)
1375 if ((!name || strcmp(ifmt->name, name) < 0) &&
1376 strcmp(ifmt->name, last_name) > 0) {
1378 long_name = ifmt->long_name;
1381 if (name && strcmp(ifmt->name, name) == 0)
1393 long_name ? long_name:
" ");
1418 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1419 if (codec->field) { \
1420 const type *p = codec->field; \
1422 av_log(NULL, AV_LOG_STDERR, " Supported " list_name ":"); \
1423 while (*p != term) { \
1425 av_log(NULL, AV_LOG_STDERR, " %s", name); \
1428 av_log(NULL, AV_LOG_STDERR, "\n"); \
1433 int encoder = av_codec_is_encoder(c);
1435 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->name,
1436 c->long_name ? c->long_name :
"");
1439 if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
1441 if (c->capabilities & AV_CODEC_CAP_DR1)
1443 if (c->capabilities & AV_CODEC_CAP_TRUNCATED)
1445 if (c->capabilities & AV_CODEC_CAP_DELAY)
1447 if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
1449 if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
1451 if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
1453 if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
1455 if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
1457 if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
1459 if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1460 AV_CODEC_CAP_SLICE_THREADS |
1461 AV_CODEC_CAP_AUTO_THREADS))
1463 if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
1465 if (c->capabilities & AV_CODEC_CAP_HARDWARE)
1467 if (c->capabilities & AV_CODEC_CAP_HYBRID)
1469 if (!c->capabilities)
1473 if (c->type == AVMEDIA_TYPE_VIDEO ||
1474 c->type == AVMEDIA_TYPE_AUDIO) {
1476 switch (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1477 AV_CODEC_CAP_SLICE_THREADS |
1478 AV_CODEC_CAP_AUTO_THREADS)) {
1479 case AV_CODEC_CAP_FRAME_THREADS |
1480 AV_CODEC_CAP_SLICE_THREADS: av_log(NULL,
AV_LOG_STDERR,
"frame and slice");
break;
1481 case AV_CODEC_CAP_FRAME_THREADS: av_log(NULL,
AV_LOG_STDERR,
"frame");
break;
1482 case AV_CODEC_CAP_SLICE_THREADS: av_log(NULL,
AV_LOG_STDERR,
"slice");
break;
1483 case AV_CODEC_CAP_AUTO_THREADS : av_log(NULL,
AV_LOG_STDERR,
"auto");
break;
1489 if (avcodec_get_hw_config(c, 0)) {
1490 av_log(NULL,
AV_LOG_STDERR,
" Supported hardware devices: ");
1491 for (
int i = 0;; i++) {
1492 const AVCodecHWConfig *config = avcodec_get_hw_config(c, i);
1495 av_log(NULL,
AV_LOG_STDERR,
"%s ", av_hwdevice_get_type_name(config->device_type));
1500 if (c->supported_framerates) {
1501 const AVRational *fps = c->supported_framerates;
1519 if (c->priv_class) {
1521 AV_OPT_FLAG_ENCODING_PARAM |
1522 AV_OPT_FLAG_DECODING_PARAM);
1529 case AVMEDIA_TYPE_VIDEO:
return 'V';
1530 case AVMEDIA_TYPE_AUDIO:
return 'A';
1531 case AVMEDIA_TYPE_DATA:
return 'D';
1532 case AVMEDIA_TYPE_SUBTITLE:
return 'S';
1533 case AVMEDIA_TYPE_ATTACHMENT:
return 'T';
1534 default:
return '?';
1542 while ((c = av_codec_iterate(iter))) {
1544 (encoder ? av_codec_is_encoder(c) : av_codec_is_decoder(c)))
1552 const AVCodecDescriptor *
const *da = a;
1553 const AVCodecDescriptor *
const *db = b;
1555 return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
1556 strcmp((*da)->name, (*db)->name);
1561 const AVCodecDescriptor *desc = NULL;
1562 const AVCodecDescriptor **codecs;
1563 unsigned nb_codecs = 0, i = 0;
1565 while ((desc = avcodec_descriptor_next(desc)))
1567 if (!(codecs = av_calloc(nb_codecs,
sizeof(*codecs)))) {
1568 av_log(NULL, AV_LOG_ERROR,
"Out of memory\n");
1572 while ((desc = avcodec_descriptor_next(desc)))
1574 av_assert0(i == nb_codecs);
1583 const AVCodec *codec;
1585 av_log(NULL,
AV_LOG_STDERR,
" (%s: ", encoder ?
"encoders" :
"decoders");
1595 const AVCodecDescriptor **codecs;
1599 " D..... = Decoding supported\n"
1600 " .E.... = Encoding supported\n"
1601 " ..V... = Video codec\n"
1602 " ..A... = Audio codec\n"
1603 " ..S... = Subtitle codec\n"
1604 " ...I.. = Intra frame-only codec\n"
1605 " ....L. = Lossy compression\n"
1606 " .....S = Lossless compression\n"
1608 for (i = 0; i < nb_codecs; i++) {
1609 const AVCodecDescriptor *desc = codecs[i];
1610 const AVCodec *codec;
1613 if (strstr(desc->name,
"_deprecated"))
1617 av_log(NULL,
AV_LOG_STDERR, avcodec_find_decoder(desc->id) ?
"D" :
".");
1618 av_log(NULL,
AV_LOG_STDERR, avcodec_find_encoder(desc->id) ?
"E" :
".");
1621 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_INTRA_ONLY) ?
"I" :
".");
1622 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSY) ?
"L" :
".");
1623 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSLESS) ?
"S" :
".");
1625 av_log(NULL,
AV_LOG_STDERR,
" %-20s %s", desc->name, desc->long_name ? desc->long_name :
"");
1630 if (strcmp(codec->name, desc->name)) {
1637 if (strcmp(codec->name, desc->name)) {
1651 const AVCodecDescriptor **codecs;
1657 " S..... = Subtitle\n"
1658 " .F.... = Frame-level multithreading\n"
1659 " ..S... = Slice-level multithreading\n"
1660 " ...X.. = Codec is experimental\n"
1661 " ....B. = Supports draw_horiz_band\n"
1662 " .....D = Supports direct rendering method 1\n"
1664 encoder ?
"Encoders" :
"Decoders");
1665 for (i = 0; i < nb_codecs; i++) {
1666 const AVCodecDescriptor *desc = codecs[i];
1667 const AVCodec *codec;
1672 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ?
"F" :
".");
1673 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ?
"S" :
".");
1674 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ?
"X" :
".");
1675 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?
"B" :
".");
1676 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DR1) ?
"D" :
".");
1678 av_log(NULL,
AV_LOG_STDERR,
" %-20s %s", codec->name, codec->long_name ? codec->long_name :
"");
1679 if (strcmp(codec->name, desc->name))
1700 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1702 const AVBitStreamFilter *bsf = NULL;
1703 void *opaque = NULL;
1706 while ((bsf = av_bsf_iterate(&opaque)))
1714 void *opaque = NULL;
1719 while ((name = avio_enum_protocols(&opaque, 0)))
1722 while ((name = avio_enum_protocols(&opaque, 1)))
1730 const AVFilter *filter = NULL;
1731 char descr[64], *descr_cur;
1732 void *opaque = NULL;
1734 const AVFilterPad *pad;
1737 " T.. = Timeline support\n"
1738 " .S. = Slice threading\n"
1739 " ..C = Command support\n"
1740 " A = Audio input/output\n"
1741 " V = Video input/output\n"
1742 " N = Dynamic number and/or type of input/output\n"
1743 " | = Source or sink filter\n");
1744 while ((filter = av_filter_iterate(&opaque))) {
1746 for (i = 0; i < 2; i++) {
1748 *(descr_cur++) =
'-';
1749 *(descr_cur++) =
'>';
1751 pad = i ? filter->outputs : filter->inputs;
1752 for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
1753 if (descr_cur >= descr +
sizeof(descr) - 4)
1758 *(descr_cur++) = ((!i && (filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
1759 ( i && (filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ?
'N' :
'|';
1763 filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ?
'T' :
'.',
1764 filter->flags & AVFILTER_FLAG_SLICE_THREADS ?
'S' :
'.',
1765 filter->process_command ?
'C' :
'.',
1766 filter->name, descr, filter->description);
1769 av_log(NULL,
AV_LOG_STDERR,
"No filters available: libavfilter disabled\n");
1782 for (i = 0; (name = av_get_known_color_name(i, &rgb)); i++)
1783 av_log(NULL,
AV_LOG_STDERR,
"%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1790 const AVPixFmtDescriptor *pix_desc = NULL;
1793 "I.... = Supported Input format for conversion\n"
1794 ".O... = Supported Output format for conversion\n"
1795 "..H.. = Hardware accelerated format\n"
1796 "...P. = Paletted format\n"
1797 "....B = Bitstream format\n"
1798 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1802 # define sws_isSupportedInput(x) 0
1803 # define sws_isSupportedOutput(x) 0
1806 while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
1807 enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
1811 pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ?
'H' :
'.',
1812 pix_desc->flags & AV_PIX_FMT_FLAG_PAL ?
'P' :
'.',
1813 pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ?
'B' :
'.',
1815 pix_desc->nb_components,
1816 av_get_bits_per_pixel(pix_desc));
1825 const char *name, *descr;
1828 "NAME DESCRIPTION\n");
1829 for (i = 0; i < 63; i++) {
1830 name = av_get_channel_name((uint64_t)1 << i);
1833 descr = av_get_channel_description((uint64_t)1 << i);
1837 "NAME DECOMPOSITION\n");
1838 for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
1841 for (j = 1; j; j <<= 1)
1843 av_log(NULL,
AV_LOG_STDERR,
"%s%s", (layout & (j - 1)) ?
"+" :
"", av_get_channel_name(j));
1854 for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
1855 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_get_sample_fmt_string(fmt_str,
sizeof(fmt_str), i));
1861 const AVCodecDescriptor *desc;
1862 const AVCodec *codec;
1865 av_log(NULL, AV_LOG_ERROR,
"No codec name specified.\n");
1869 codec = encoder ? avcodec_find_encoder_by_name(name) :
1870 avcodec_find_decoder_by_name(name);
1874 else if ((desc = avcodec_descriptor_get_by_name(name))) {
1884 av_log(NULL, AV_LOG_ERROR,
"Codec '%s' is known to FFmpeg, "
1885 "but no %s for it are available. FFmpeg might need to be "
1886 "recompiled with additional external libraries.\n",
1887 name, encoder ?
"encoders" :
"decoders");
1890 av_log(NULL, AV_LOG_ERROR,
"Codec '%s' is not recognized by FFmpeg.\n",
1897 const AVInputFormat *fmt = av_find_input_format(name);
1900 av_log(NULL, AV_LOG_ERROR,
"Unknown format '%s'.\n", name);
1904 av_log(NULL,
AV_LOG_STDERR,
"Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
1906 if (fmt->extensions)
1907 av_log(NULL,
AV_LOG_STDERR,
" Common extensions: %s.\n", fmt->extensions);
1909 if (fmt->priv_class)
1915 const AVClass *proto_class;
1918 av_log(NULL, AV_LOG_ERROR,
"No protocol name specified.\n");
1922 proto_class = avio_protocol_get_class(name);
1924 av_log(NULL, AV_LOG_ERROR,
"Unknown protocol '%s'.\n", name);
1928 show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
1933 const AVCodecDescriptor *desc;
1934 const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
1937 av_log(NULL, AV_LOG_ERROR,
"Unknown format '%s'.\n", name);
1941 av_log(NULL,
AV_LOG_STDERR,
"Muxer %s [%s]:\n", fmt->name, fmt->long_name);
1943 if (fmt->extensions)
1944 av_log(NULL,
AV_LOG_STDERR,
" Common extensions: %s.\n", fmt->extensions);
1946 av_log(NULL,
AV_LOG_STDERR,
" Mime type: %s.\n", fmt->mime_type);
1947 if (fmt->video_codec != AV_CODEC_ID_NONE &&
1948 (desc = avcodec_descriptor_get(fmt->video_codec))) {
1949 av_log(NULL,
AV_LOG_STDERR,
" Default video codec: %s.\n", desc->name);
1951 if (fmt->audio_codec != AV_CODEC_ID_NONE &&
1952 (desc = avcodec_descriptor_get(fmt->audio_codec))) {
1953 av_log(NULL,
AV_LOG_STDERR,
" Default audio codec: %s.\n", desc->name);
1955 if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
1956 (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
1957 av_log(NULL,
AV_LOG_STDERR,
" Default subtitle codec: %s.\n", desc->name);
1960 if (fmt->priv_class)
1965 static void show_help_filter(
const char *name)
1968 const AVFilter *f = avfilter_get_by_name(name);
1972 av_log(NULL, AV_LOG_ERROR,
"No filter name specified.\n");
1975 av_log(NULL, AV_LOG_ERROR,
"Unknown filter '%s'.\n", name);
1983 if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
1984 av_log(NULL,
AV_LOG_STDERR,
" slice threading supported\n");
1987 count = avfilter_pad_count(f->inputs);
1988 for (i = 0; i < count; i++) {
1989 av_log(NULL,
AV_LOG_STDERR,
" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
1992 if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
1993 av_log(NULL,
AV_LOG_STDERR,
" dynamic (depending on the options)\n");
1998 count = avfilter_pad_count(f->outputs);
1999 for (i = 0; i < count; i++) {
2000 av_log(NULL,
AV_LOG_STDERR,
" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
2003 if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
2004 av_log(NULL,
AV_LOG_STDERR,
" dynamic (depending on the options)\n");
2009 show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
2010 AV_OPT_FLAG_AUDIO_PARAM);
2011 if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
2012 av_log(NULL,
AV_LOG_STDERR,
"This filter has support for timeline through the 'enable' option.\n");
2014 av_log(NULL, AV_LOG_ERROR,
"Build without libavfilter; "
2015 "can not to satisfy request\n");
2022 const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
2025 av_log(NULL, AV_LOG_ERROR,
"No bitstream filter name specified.\n");
2028 av_log(NULL, AV_LOG_ERROR,
"Unknown bit stream filter '%s'.\n", name);
2032 av_log(NULL,
AV_LOG_STDERR,
"Bit stream filter %s\n", bsf->name);
2035 if (bsf->priv_class)
2039 int show_help(
void *optctx,
const char *opt,
const char *arg)
2043 topic = av_strdup(arg ? arg :
"");
2045 return AVERROR(ENOMEM);
2046 par = strchr(topic,
'=');
2056 }
else if (!strcmp(topic,
"decoder")) {
2058 }
else if (!strcmp(topic,
"encoder")) {
2060 }
else if (!strcmp(topic,
"demuxer")) {
2062 }
else if (!strcmp(topic,
"muxer")) {
2064 }
else if (!strcmp(topic,
"protocol")) {
2067 }
else if (!strcmp(topic,
"filter")) {
2068 show_help_filter(par);
2070 }
else if (!strcmp(topic,
"bsf")) {
2087 int yesno = (av_toupper(c) ==
'Y');
2089 while (c !=
'\n' && c != EOF)
2096 const char *preset_name,
int is_path,
2097 const char *codec_name)
2101 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
2106 av_strlcpy(filename, preset_name, filename_size);
2107 f = fopen(filename,
"r");
2109 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
2110 char datadir[MAX_PATH], *ls;
2113 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir,
sizeof(datadir) - 1))
2115 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
2116 if (*ls ==
'\\') *ls =
'/';
2118 if (ls = strrchr(datadir,
'/'))
2121 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
2126 for (i = 0; i < 3 && !f; i++) {
2129 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
2130 i != 1 ?
"" :
"/.ffmpeg", preset_name);
2131 f = fopen(filename,
"r");
2132 if (!f && codec_name) {
2133 snprintf(filename, filename_size,
2134 "%s%s/%s-%s.ffpreset",
2135 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
2137 f = fopen(filename,
"r");
2147 int ret = avformat_match_stream_specifier(s, st, spec);
2149 av_log(s, AV_LOG_ERROR,
"Invalid stream specifier: %s.\n", spec);
2154 AVFormatContext *s, AVStream *st, AVCodec *codec)
2156 AVDictionary *ret = NULL;
2157 AVDictionaryEntry *t = NULL;
2158 int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
2159 : AV_OPT_FLAG_DECODING_PARAM;
2161 const AVClass *cc = avcodec_get_class();
2164 codec = s->oformat ? avcodec_find_encoder(codec_id)
2165 : avcodec_find_decoder(codec_id);
2167 switch (st->codecpar->codec_type) {
2168 case AVMEDIA_TYPE_VIDEO:
2170 flags |= AV_OPT_FLAG_VIDEO_PARAM;
2172 case AVMEDIA_TYPE_AUDIO:
2174 flags |= AV_OPT_FLAG_AUDIO_PARAM;
2176 case AVMEDIA_TYPE_SUBTITLE:
2178 flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
2182 while ((t = av_dict_get(opts,
"", t, AV_DICT_IGNORE_SUFFIX))) {
2183 char *p = strchr(t->key,
':');
2188 case 1: *p = 0;
break;
2193 if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
2195 (codec->priv_class &&
2196 av_opt_find(&codec->priv_class, t->key, NULL, flags,
2197 AV_OPT_SEARCH_FAKE_OBJ)))
2198 av_dict_set(&ret, t->key, t->value, 0);
2199 else if (t->key[0] == prefix &&
2200 av_opt_find(&cc, t->key + 1, NULL, flags,
2201 AV_OPT_SEARCH_FAKE_OBJ))
2202 av_dict_set(&ret, t->key + 1, t->value, 0);
2214 AVDictionary **opts;
2218 opts = av_mallocz_array(s->nb_streams,
sizeof(*opts));
2220 av_log(NULL, AV_LOG_ERROR,
2221 "Could not alloc memory for stream options.\n");
2224 for (i = 0; i < s->nb_streams; i++)
2226 s, s->streams[i], NULL);
2230 void *
grow_array(
void *array,
int elem_size,
int *size,
int new_size)
2232 if (new_size >= INT_MAX / elem_size) {
2233 av_log(NULL, AV_LOG_ERROR,
"Array too big.\n");
2236 if (*size < new_size) {
2237 uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
2239 av_log(NULL, AV_LOG_ERROR,
"Could not alloc buffer.\n");
2242 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
2251 uint8_t* displaymatrix = av_stream_get_side_data(st,
2252 AV_PKT_DATA_DISPLAYMATRIX, NULL);
2255 theta = -av_display_rotation_get((int32_t*) displaymatrix);
2257 theta -= 360*floor(theta/360 + 0.9/360);
2259 if (fabs(theta - 90*round(theta/90)) > 2)
2260 av_log(NULL, AV_LOG_WARNING,
"Odd rotation angle.\n"
2261 "If you want to help, upload a sample "
2262 "of this file to https://streams.videolan.org/upload/ "
2263 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
2269 static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
2272 AVDeviceInfoList *device_list = NULL;
2274 if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
2275 return AVERROR(EINVAL);
2277 av_log(NULL,
AV_LOG_STDERR,
"Auto-detected sources for %s:\n", fmt->name);
2278 if (!fmt->get_device_list) {
2279 ret = AVERROR(ENOSYS);
2280 av_log(NULL,
AV_LOG_STDERR,
"Cannot list sources. Not implemented.\n");
2284 if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
2289 for (i = 0; i < device_list->nb_devices; i++) {
2290 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]\n", device_list->default_device == i ?
"*" :
" ",
2291 device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2295 avdevice_free_list_devices(&device_list);
2299 static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
2302 AVDeviceInfoList *device_list = NULL;
2304 if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
2305 return AVERROR(EINVAL);
2307 av_log(NULL,
AV_LOG_STDERR,
"Auto-detected sinks for %s:\n", fmt->name);
2308 if (!fmt->get_device_list) {
2309 ret = AVERROR(ENOSYS);
2310 av_log(NULL,
AV_LOG_STDERR,
"Cannot list sinks. Not implemented.\n");
2314 if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
2319 for (i = 0; i < device_list->nb_devices; i++) {
2320 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]\n", device_list->default_device == i ?
"*" :
" ",
2321 device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2325 avdevice_free_list_devices(&device_list);
2329 static int show_sinks_sources_parse_arg(
const char *arg,
char **dev, AVDictionary **opts)
2333 char *opts_str = NULL;
2334 av_assert0(dev && opts);
2335 *dev = av_strdup(arg);
2337 return AVERROR(ENOMEM);
2338 if ((opts_str = strchr(*dev,
','))) {
2339 *(opts_str++) =
'\0';
2340 if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str,
"=",
":", 0)) < 0)) {
2346 av_log(NULL,
AV_LOG_STDERR,
"\nDevice name is not provided.\n"
2347 "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
2351 int show_sources(
void *optctx,
const char *opt,
const char *arg)
2353 AVInputFormat *fmt = NULL;
2355 AVDictionary *opts = NULL;
2357 int error_level = av_log_get_level();
2359 av_log_set_level(AV_LOG_WARNING);
2361 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2365 fmt = av_input_audio_device_next(fmt);
2367 if (!strcmp(fmt->name,
"lavfi"))
2369 if (dev && !av_match_name(dev, fmt->name))
2371 print_device_sources(fmt, opts);
2375 fmt = av_input_video_device_next(fmt);
2377 if (dev && !av_match_name(dev, fmt->name))
2379 print_device_sources(fmt, opts);
2383 av_dict_free(&opts);
2385 av_log_set_level(error_level);
2389 int show_sinks(
void *optctx,
const char *opt,
const char *arg)
2391 AVOutputFormat *fmt = NULL;
2393 AVDictionary *opts = NULL;
2395 int error_level = av_log_get_level();
2397 av_log_set_level(AV_LOG_WARNING);
2399 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2403 fmt = av_output_audio_device_next(fmt);
2405 if (dev && !av_match_name(dev, fmt->name))
2407 print_device_sinks(fmt, opts);
2411 fmt = av_output_video_device_next(fmt);
2413 if (dev && !av_match_name(dev, fmt->name))
2415 print_device_sinks(fmt, opts);
2419 av_dict_free(&opts);
2421 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