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/channel_layout.h"
74#include "libavutil/display.h"
75#include "libavutil/mathematics.h"
76#include "libavutil/imgutils.h"
77#include "libavutil/libm.h"
78#include "libavutil/parseutils.h"
79#include "libavutil/pixdesc.h"
80#include "libavutil/eval.h"
81#include "libavutil/dict.h"
82#include "libavutil/opt.h"
83#include "libavutil/cpu.h"
84#include "libavutil/ffversion.h"
85#include "libavutil/version.h"
86#include "libavcodec/bsf.h"
88#if HAVE_SYS_RESOURCE_H
90#include <sys/resource.h>
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";
185 error =
"Expected int64 for %s but found %s\n";
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)))
253 if (av_strstart(name, po->
name, &end) && (!*end || *end ==
':'))
263#if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
266static char** win32_argv_utf8 = NULL;
267static int win32_argc = 0;
280 int i, buffsize = 0, offset = 0;
282 if (win32_argv_utf8) {
283 *argc_ptr = win32_argc;
284 *argv_ptr = win32_argv_utf8;
289 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
290 if (win32_argc <= 0 || !argv_w)
294 for (i = 0; i < win32_argc; i++)
295 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
296 NULL, 0, NULL, NULL);
298 win32_argv_utf8 = av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
299 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
300 if (!win32_argv_utf8) {
305 for (i = 0; i < win32_argc; i++) {
306 win32_argv_utf8[i] = &argstr_flat[offset];
307 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
308 &argstr_flat[offset],
309 buffsize - offset, NULL, NULL);
311 win32_argv_utf8[i] = NULL;
314 *argc_ptr = win32_argc;
315 *argv_ptr = win32_argv_utf8;
335 char *p = strchr(opt,
':');
338 dstcount = (
int *)(so + 1);
339 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
340 str = av_strdup(p ? p + 1 :
"");
342 return AVERROR(ENOMEM);
343 (*so)[*dstcount - 1].specifier = str;
344 dst = &(*so)[*dstcount - 1].u;
349 str = av_strdup(arg);
352 return AVERROR(ENOMEM);
365 int ret = po->
u.
func_arg(optctx, opt, arg);
367 av_log(NULL, AV_LOG_ERROR,
368 "Failed to set value '%s' for option '%s': %s\n",
369 arg, opt, av_err2str(ret));
386 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
397 av_log(NULL, AV_LOG_ERROR,
"Unrecognized option '%s'\n", opt);
398 return AVERROR(EINVAL);
401 av_log(NULL, AV_LOG_ERROR,
"Missing argument for option '%s'\n", opt);
402 return AVERROR(EINVAL);
413 void (*parse_arg_function)(
void *,
const char*))
416 int optindex, handleoptions = 1, ret;
423 while (optindex < argc) {
424 opt = argv[optindex++];
426 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
427 if (opt[1] ==
'-' && opt[2] ==
'\0') {
432 if (optindex >= argc) {
433 if ((ret =
parse_option(optctx, opt, NULL, options)) < 0)
436 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
441 if (parse_arg_function)
442 parse_arg_function(optctx, opt);
451 av_log(NULL, AV_LOG_DEBUG,
"Parsing a group of options: %s %s.\n",
454 for (i = 0; i < g->
nb_opts; i++) {
459 av_log(NULL, AV_LOG_ERROR,
"Option %s (%s) cannot be applied to "
460 "%s %s -- you are trying to apply an input option to an "
461 "output file or vice versa. Move this option before the "
462 "file it belongs to.\n", o->
key, o->
opt->
help,
464 return AVERROR(EINVAL);
467 av_log(NULL, AV_LOG_DEBUG,
"Applying option %s (%s) with argument %s.\n",
475 av_log(NULL, AV_LOG_DEBUG,
"Successfully parsed a group of options.\n");
486 for (i = 1; i < argc; i++) {
487 const char *cur_opt = argv[i];
489 if (*cur_opt++ !=
'-')
493 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
496 if ((!po->
name && !strcmp(cur_opt, optname)) ||
497 (po->
name && !strcmp(optname, po->
name)))
508 const unsigned char *p;
511 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
512 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
519 for (p = a; *p; p++) {
520 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
522 else if (*p < ' ' || *p >
'~')
548 if (idx && (idx + 1 < argc) && argv[idx + 1])
551 if ((env = getenv(
"FFREPORT")) || idx) {
556 for (i = 0; i < argc; i++) {
568static const AVOption *
opt_find(
void *obj,
const char *name,
const char *unit,
569 int opt_flags,
int search_flags)
571 const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
577#define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
582 char opt_stripped[128];
584 const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
586 const AVClass *sc = sws_get_class();
589 const AVClass *swr_class = swr_get_class();
592 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
593 av_log_set_level(AV_LOG_DEBUG);
595 if (!(p = strchr(opt,
':')))
596 p = opt + strlen(opt);
597 av_strlcpy(opt_stripped, opt, FFMIN(
sizeof(opt_stripped), p - opt + 1));
599 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
600 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
601 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
602 (o =
opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
606 if ((o =
opt_find(&fc, opt, NULL, 0,
607 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
610 av_log(NULL, AV_LOG_VERBOSE,
"Routing option %s to both codec and muxer layer\n", opt);
614 if (!consumed && (o =
opt_find(&sc, opt, NULL, 0,
615 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
616 struct SwsContext *sws = sws_alloc_context();
617 int ret = av_opt_set(sws, opt, arg, 0);
618 sws_freeContext(sws);
619 if (!strcmp(opt,
"srcw") || !strcmp(opt,
"srch") ||
620 !strcmp(opt,
"dstw") || !strcmp(opt,
"dsth") ||
621 !strcmp(opt,
"src_format") || !strcmp(opt,
"dst_format")) {
622 av_log(NULL, AV_LOG_ERROR,
"Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
623 return AVERROR(EINVAL);
626 av_log(NULL, AV_LOG_ERROR,
"Error setting option %s.\n", opt);
635 if (!consumed && !strcmp(opt,
"sws_flags")) {
636 av_log(NULL, AV_LOG_WARNING,
"Ignoring %s %s, due to disabled swscale\n", opt, arg);
641 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
642 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
643 struct SwrContext *swr = swr_alloc();
644 int ret = av_opt_set(swr, opt, arg, 0);
647 av_log(NULL, AV_LOG_ERROR,
"Error setting option %s.\n", opt);
657 return AVERROR_OPTION_NOT_FOUND;
670 for (i = 0; i < nb_groups; i++) {
672 if (p->
sep && !strcmp(p->
sep, opt))
716 const char *key,
const char *val)
733 memset(octx, 0,
sizeof(*octx));
784 av_log(NULL, AV_LOG_DEBUG,
"Splitting the commandline.\n");
786 while (optindex < argc) {
787 const char *opt = argv[optindex++], *arg;
791 av_log(NULL, AV_LOG_DEBUG,
"Reading option '%s' ...", opt);
793 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
798 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
800 av_log(NULL, AV_LOG_DEBUG,
" matched as %s.\n", groups[0].name);
805#define GET_ARG(arg) \
807 if (optindex < argc) { \
808 arg = argv[optindex++]; \
810 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
811 return AVERROR(EINVAL); \
819 av_log(NULL, AV_LOG_DEBUG,
" matched as %s with argument '%s'.\n",
820 groups[ret].name, arg);
829 if (optindex < argc) {
830 arg = argv[optindex++];
841 av_log(NULL, AV_LOG_DEBUG,
" matched as option '%s' (%s) with "
842 "argument '%s'.\n", po->
name, po->
help, arg);
847 if ((optindex < argc) && argv[optindex]) {
850 av_log(NULL, AV_LOG_DEBUG,
" matched as AVOption '%s' with "
851 "argument '%s'.\n", opt, argv[optindex]);
854 }
else if (ret != AVERROR_OPTION_NOT_FOUND) {
855 av_log(NULL, AV_LOG_ERROR,
"Error parsing option '%s' "
856 "with argument '%s'.\n", opt, argv[optindex]);
862 if (opt[0] ==
'n' && opt[1] ==
'o' &&
866 av_log(NULL, AV_LOG_DEBUG,
" matched as option '%s' (%s) with "
867 "argument 0.\n", po->
name, po->
help);
871 av_log(NULL, AV_LOG_ERROR,
"Unrecognized option '%s'.\n", opt);
872 return AVERROR_OPTION_NOT_FOUND;
876 av_log(NULL, AV_LOG_WARNING,
"Trailing option(s) found in the "
877 "command: may be ignored.\n");
879 av_log(NULL, AV_LOG_DEBUG,
"Finished splitting the commandline.\n");
887 unsigned flags = av_get_cpu_flags();
889 if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
892 av_force_cpu_flags(flags);
901 static const AVOption opts[] = {
902 {
"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, INT_MAX, 0},
905 static const AVClass
class = {
906 .class_name =
"cpucount",
907 .item_name = av_default_item_name,
909 .version = LIBAVUTIL_VERSION_INT,
911 const AVClass *pclass = &
class;
913 ret = av_opt_eval_int(&pclass, opts, arg, &count);
916 av_cpu_force_count(count);
924 const struct {
const char *name;
int level; } log_levels[] = {
925 {
"quiet" , AV_LOG_QUIET },
926 {
"panic" , AV_LOG_PANIC },
927 {
"fatal" , AV_LOG_FATAL },
928 {
"error" , AV_LOG_ERROR },
929 {
"warning", AV_LOG_WARNING },
930 {
"info" , AV_LOG_INFO },
931 {
"verbose", AV_LOG_VERBOSE },
932 {
"debug" , AV_LOG_DEBUG },
933 {
"trace" , AV_LOG_TRACE },
937 int flags = av_log_get_flags();
938 int level = av_log_get_level();
944 if (*token ==
'+' || *token ==
'-') {
952 if (av_strstart(token,
"repeat", &arg)) {
954 flags |= AV_LOG_SKIP_REPEATED;
956 flags &= ~AV_LOG_SKIP_REPEATED;
958 }
else if (av_strstart(token,
"level", &arg)) {
960 flags &= ~AV_LOG_PRINT_LEVEL;
962 flags |= AV_LOG_PRINT_LEVEL;
971 }
else if (*arg ==
'+') {
974 flags = av_log_get_flags();
977 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
978 if (!strcmp(log_levels[i].name, arg)) {
979 level = log_levels[i].level;
984 level = strtol(arg, &tail, 10);
986 av_log(NULL, AV_LOG_FATAL,
"Invalid loglevel \"%s\". "
987 "Possible levels are numbers or:\n", arg);
988 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
989 av_log(NULL, AV_LOG_FATAL,
"\"%s\"\n", log_levels[i].name);
994 av_log_set_flags(flags);
995 av_log_set_level(level);
1004 while ((c = *(
template++))) {
1006 if (!(c = *(
template++)))
1013 av_bprintf(bp,
"%04d%02d%02d-%02d%02d%02d",
1014 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1015 tm->tm_hour, tm->tm_min, tm->tm_sec);
1018 av_bprint_chars(bp, c, 1);
1022 av_bprint_chars(bp, c, 1);
1029 char *filename_template = NULL;
1032 int prog_loglevel, envlevel = 0;
1040 tm = localtime(&now);
1042 while (env && *env) {
1043 if ((ret = av_opt_get_key_value(&env,
"=",
":", 0, &key, &val)) < 0) {
1045 av_log(NULL, AV_LOG_ERROR,
1046 "Failed to parse FFREPORT environment variable: %s\n",
1053 if (!strcmp(key,
"file")) {
1054 av_free(filename_template);
1055 filename_template = val;
1057 }
else if (!strcmp(key,
"level")) {
1061 av_log(NULL, AV_LOG_FATAL,
"Invalid report file level\n");
1066 av_log(NULL, AV_LOG_ERROR,
"Unknown key '%s' in FFREPORT\n", key);
1072 av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
1074 av_x_if_null(filename_template,
"%p-%t.log"), tm);
1075 av_free(filename_template);
1076 if (!av_bprint_is_complete(&filename)) {
1077 av_log(NULL, AV_LOG_ERROR,
"Out of memory building report file name\n");
1078 return AVERROR(ENOMEM);
1081 prog_loglevel = av_log_get_level();
1087 int ret = AVERROR(errno);
1088 av_log(NULL, AV_LOG_ERROR,
"Failed to open report \"%s\": %s\n",
1089 filename.str, strerror(errno));
1093 av_log(NULL, AV_LOG_INFO,
1094 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
1095 "Report written to \"%s\"\n"
1098 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1099 tm->tm_hour, tm->tm_min, tm->tm_sec,
1101 av_bprint_finalize(&filename, NULL);
1115 max = strtol(arg, &tail, 10);
1117 av_log(NULL, AV_LOG_FATAL,
"Invalid max_alloc \"%s\".\n", arg);
1128 struct rlimit rl = { lim, lim + 1 };
1129 if (setrlimit(RLIMIT_CPU, &rl))
1130 perror(
"setrlimit");
1132 av_log(NULL, AV_LOG_WARNING,
"-%s not implemented on this OS\n", opt);
1140 const char *errbuf_ptr = errbuf;
1142 if (av_strerror(err, errbuf,
sizeof(errbuf)) < 0)
1143 errbuf_ptr = strerror(AVUNERROR(err));
1144 av_log(NULL, AV_LOG_ERROR,
"%s: %s\n", filename, errbuf_ptr);
1150#define SHOW_VERSION 2
1151#define SHOW_CONFIG 4
1152#define SHOW_COPYRIGHT 8
1154#define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1155 if (CONFIG_##LIBNAME) { \
1156 const char *indent = flags & INDENT? " " : ""; \
1157 if (flags & SHOW_VERSION) { \
1158 unsigned int version = libname##_version(); \
1159 av_log(NULL, level, \
1160 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1162 LIB##LIBNAME##_VERSION_MAJOR, \
1163 LIB##LIBNAME##_VERSION_MINOR, \
1164 LIB##LIBNAME##_VERSION_MICRO, \
1165 AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\
1166 AV_VERSION_MICRO(version)); \
1168 if (flags & SHOW_CONFIG) { \
1169 const char *cfg = libname##_configuration(); \
1170 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1171 if (!warned_cfg) { \
1172 av_log(NULL, level, \
1173 "%sWARNING: library configuration mismatch\n", \
1177 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1178 indent, #libname, cfg); \
1196 const char *indent = flags &
INDENT?
" " :
"";
1198 av_log(NULL, level,
"%s version " FFMPEG_VERSION,
program_name);
1200 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1202 av_log(NULL, level,
"\n");
1203 av_log(NULL, level,
"%sbuilt with %s\n", indent, CC_IDENT);
1205 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1210 const char *indent = flags &
INDENT ?
" " :
"";
1211 char str[] = { FFMPEG_CONFIGURATION };
1212 char *conflist, *remove_tilde, *splitconf;
1216 while ((conflist = strstr(str,
" --")) != NULL) {
1222 while ((remove_tilde = strstr(str,
"pkg-config~")) != NULL) {
1223 remove_tilde[
sizeof(
"pkg-config~") - 2] =
' ';
1226 splitconf = strtok(str,
"~");
1227 av_log(NULL, level,
"\n%sconfiguration:\n", indent);
1228 while (splitconf != NULL) {
1229 av_log(NULL, level,
"%s%s%s\n", indent, indent, splitconf);
1230 splitconf = strtok(NULL,
"~");
1264 "This version of %s has nonfree parts compiled in.\n"
1265 "Therefore it is not legally redistributable.\n",
1269 "%s is free software; you can redistribute it and/or modify\n"
1270 "it under the terms of the GNU General Public License as published by\n"
1271 "the Free Software Foundation; either version 3 of the License, or\n"
1272 "(at your option) any later version.\n"
1274 "%s is distributed in the hope that it will be useful,\n"
1275 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1276 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1277 "GNU General Public License for more details.\n"
1279 "You should have received a copy of the GNU General Public License\n"
1280 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1284 "%s is free software; you can redistribute it and/or modify\n"
1285 "it under the terms of the GNU General Public License as published by\n"
1286 "the Free Software Foundation; either version 2 of the License, or\n"
1287 "(at your option) any later version.\n"
1289 "%s is distributed in the hope that it will be useful,\n"
1290 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1291 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1292 "GNU General Public License for more details.\n"
1294 "You should have received a copy of the GNU General Public License\n"
1295 "along with %s; if not, write to the Free Software\n"
1296 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1300 "%s is free software; you can redistribute it and/or modify\n"
1301 "it under the terms of the GNU Lesser General Public License as published by\n"
1302 "the Free Software Foundation; either version 3 of the License, or\n"
1303 "(at your option) any later version.\n"
1305 "%s is distributed in the hope that it will be useful,\n"
1306 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1307 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1308 "GNU Lesser General Public License for more details.\n"
1310 "You should have received a copy of the GNU Lesser General Public License\n"
1311 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1315 "%s is free software; you can redistribute it and/or\n"
1316 "modify it under the terms of the GNU Lesser General Public\n"
1317 "License as published by the Free Software Foundation; either\n"
1318 "version 2.1 of the License, or (at your option) any later version.\n"
1320 "%s is distributed in the hope that it will be useful,\n"
1321 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1322 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1323 "Lesser General Public License for more details.\n"
1325 "You should have received a copy of the GNU Lesser General Public\n"
1326 "License along with %s; if not, write to the Free Software\n"
1327 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1338 return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
1343 void *ifmt_opaque = NULL;
1344 const AVInputFormat *ifmt = NULL;
1345 void *ofmt_opaque = NULL;
1346 const AVOutputFormat *ofmt = NULL;
1347 const char *last_name;
1351 " D. = Demuxing supported\n"
1352 " .E = Muxing supported\n"
1353 " --\n", device_only ?
"Devices:" :
"File formats:");
1358 const char *name = NULL;
1359 const char *long_name = NULL;
1363 while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
1365 if (!is_dev && device_only)
1367 if ((!name || strcmp(ofmt->name, name) < 0) &&
1368 strcmp(ofmt->name, last_name) > 0) {
1370 long_name = ofmt->long_name;
1377 while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
1379 if (!is_dev && device_only)
1381 if ((!name || strcmp(ifmt->name, name) < 0) &&
1382 strcmp(ifmt->name, last_name) > 0) {
1384 long_name = ifmt->long_name;
1387 if (name && strcmp(ifmt->name, name) == 0)
1399 long_name ? long_name:
" ");
1424#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1425 if (codec->field) { \
1426 const type *p = codec->field; \
1428 av_log(NULL, AV_LOG_STDERR, " Supported " list_name ":"); \
1429 while (*p != term) { \
1431 av_log(NULL, AV_LOG_STDERR, " %s", name); \
1434 av_log(NULL, AV_LOG_STDERR, "\n"); \
1439 int encoder = av_codec_is_encoder(c);
1441 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->name,
1442 c->long_name ? c->long_name :
"");
1445 if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
1447 if (c->capabilities & AV_CODEC_CAP_DR1)
1449 if (c->capabilities & AV_CODEC_CAP_TRUNCATED)
1451 if (c->capabilities & AV_CODEC_CAP_DELAY)
1453 if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
1455 if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
1457 if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
1459 if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
1461 if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
1463 if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
1465 if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1466 AV_CODEC_CAP_SLICE_THREADS |
1467 AV_CODEC_CAP_OTHER_THREADS))
1469 if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
1471 if (c->capabilities & AV_CODEC_CAP_HARDWARE)
1473 if (c->capabilities & AV_CODEC_CAP_HYBRID)
1475 if (!c->capabilities)
1479 if (c->type == AVMEDIA_TYPE_VIDEO ||
1480 c->type == AVMEDIA_TYPE_AUDIO) {
1482 switch (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1483 AV_CODEC_CAP_SLICE_THREADS |
1484 AV_CODEC_CAP_OTHER_THREADS)) {
1485 case AV_CODEC_CAP_FRAME_THREADS |
1486 AV_CODEC_CAP_SLICE_THREADS: av_log(NULL,
AV_LOG_STDERR,
"frame and slice");
break;
1487 case AV_CODEC_CAP_FRAME_THREADS: av_log(NULL,
AV_LOG_STDERR,
"frame");
break;
1488 case AV_CODEC_CAP_SLICE_THREADS: av_log(NULL,
AV_LOG_STDERR,
"slice");
break;
1489 case AV_CODEC_CAP_OTHER_THREADS : av_log(NULL,
AV_LOG_STDERR,
"other");
break;
1495 if (avcodec_get_hw_config(c, 0)) {
1496 av_log(NULL,
AV_LOG_STDERR,
" Supported hardware devices: ");
1497 for (
int i = 0;; i++) {
1498 const AVCodecHWConfig *config = avcodec_get_hw_config(c, i);
1501 av_log(NULL,
AV_LOG_STDERR,
"%s ", av_hwdevice_get_type_name(config->device_type));
1506 if (c->supported_framerates) {
1507 const AVRational *fps = c->supported_framerates;
1525 if (c->priv_class) {
1527 AV_OPT_FLAG_ENCODING_PARAM |
1528 AV_OPT_FLAG_DECODING_PARAM);
1535 case AVMEDIA_TYPE_VIDEO:
return 'V';
1536 case AVMEDIA_TYPE_AUDIO:
return 'A';
1537 case AVMEDIA_TYPE_DATA:
return 'D';
1538 case AVMEDIA_TYPE_SUBTITLE:
return 'S';
1539 case AVMEDIA_TYPE_ATTACHMENT:
return 'T';
1540 default:
return '?';
1548 while ((c = av_codec_iterate(iter))) {
1550 (encoder ? av_codec_is_encoder(c) : av_codec_is_decoder(c)))
1558 const AVCodecDescriptor *
const *da = a;
1559 const AVCodecDescriptor *
const *db = b;
1561 return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
1562 strcmp((*da)->name, (*db)->name);
1567 const AVCodecDescriptor *desc = NULL;
1568 const AVCodecDescriptor **codecs;
1569 unsigned nb_codecs = 0, i = 0;
1571 while ((desc = avcodec_descriptor_next(desc)))
1573 if (!(codecs = av_calloc(nb_codecs,
sizeof(*codecs)))) {
1574 av_log(NULL, AV_LOG_ERROR,
"Out of memory\n");
1578 while ((desc = avcodec_descriptor_next(desc)))
1580 av_assert0(i == nb_codecs);
1589 const AVCodec *codec;
1591 av_log(NULL,
AV_LOG_STDERR,
" (%s: ", encoder ?
"encoders" :
"decoders");
1601 const AVCodecDescriptor **codecs;
1605 " D..... = Decoding supported\n"
1606 " .E.... = Encoding supported\n"
1607 " ..V... = Video codec\n"
1608 " ..A... = Audio codec\n"
1609 " ..S... = Subtitle codec\n"
1610 " ...I.. = Intra frame-only codec\n"
1611 " ....L. = Lossy compression\n"
1612 " .....S = Lossless compression\n"
1614 for (i = 0; i < nb_codecs; i++) {
1615 const AVCodecDescriptor *desc = codecs[i];
1616 const AVCodec *codec;
1619 if (strstr(desc->name,
"_deprecated"))
1623 av_log(NULL,
AV_LOG_STDERR, avcodec_find_decoder(desc->id) ?
"D" :
".");
1624 av_log(NULL,
AV_LOG_STDERR, avcodec_find_encoder(desc->id) ?
"E" :
".");
1627 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_INTRA_ONLY) ?
"I" :
".");
1628 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSY) ?
"L" :
".");
1629 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSLESS) ?
"S" :
".");
1631 av_log(NULL,
AV_LOG_STDERR,
" %-20s %s", desc->name, desc->long_name ? desc->long_name :
"");
1636 if (strcmp(codec->name, desc->name)) {
1643 if (strcmp(codec->name, desc->name)) {
1657 const AVCodecDescriptor **codecs;
1663 " S..... = Subtitle\n"
1664 " .F.... = Frame-level multithreading\n"
1665 " ..S... = Slice-level multithreading\n"
1666 " ...X.. = Codec is experimental\n"
1667 " ....B. = Supports draw_horiz_band\n"
1668 " .....D = Supports direct rendering method 1\n"
1670 encoder ?
"Encoders" :
"Decoders");
1671 for (i = 0; i < nb_codecs; i++) {
1672 const AVCodecDescriptor *desc = codecs[i];
1673 const AVCodec *codec;
1678 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ?
"F" :
".");
1679 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ?
"S" :
".");
1680 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ?
"X" :
".");
1681 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?
"B" :
".");
1682 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DR1) ?
"D" :
".");
1684 av_log(NULL,
AV_LOG_STDERR,
" %-20s %s", codec->name, codec->long_name ? codec->long_name :
"");
1685 if (strcmp(codec->name, desc->name))
1706int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1708 const AVBitStreamFilter *bsf = NULL;
1709 void *opaque = NULL;
1712 while ((bsf = av_bsf_iterate(&opaque)))
1720 void *opaque = NULL;
1725 while ((name = avio_enum_protocols(&opaque, 0)))
1728 while ((name = avio_enum_protocols(&opaque, 1)))
1736 const AVFilter *
filter = NULL;
1737 char descr[64], *descr_cur;
1738 void *opaque = NULL;
1740 const AVFilterPad *pad;
1743 " T.. = Timeline support\n"
1744 " .S. = Slice threading\n"
1745 " ..C = Command support\n"
1746 " A = Audio input/output\n"
1747 " V = Video input/output\n"
1748 " N = Dynamic number and/or type of input/output\n"
1749 " | = Source or sink filter\n");
1750 while ((
filter = av_filter_iterate(&opaque))) {
1752 for (i = 0; i < 2; i++) {
1754 *(descr_cur++) =
'-';
1755 *(descr_cur++) =
'>';
1758 for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
1759 if (descr_cur >= descr +
sizeof(descr) - 4)
1764 *(descr_cur++) = ((!i && (
filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
1765 ( i && (
filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ?
'N' :
'|';
1769 filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ?
'T' :
'.',
1770 filter->flags & AVFILTER_FLAG_SLICE_THREADS ?
'S' :
'.',
1771 filter->process_command ?
'C' :
'.',
1775 av_log(NULL,
AV_LOG_STDERR,
"No filters available: libavfilter disabled\n");
1788 for (i = 0; (name = av_get_known_color_name(i, &rgb)); i++)
1789 av_log(NULL,
AV_LOG_STDERR,
"%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1796 const AVPixFmtDescriptor *pix_desc = NULL;
1799 "I.... = Supported Input format for conversion\n"
1800 ".O... = Supported Output format for conversion\n"
1801 "..H.. = Hardware accelerated format\n"
1802 "...P. = Paletted format\n"
1803 "....B = Bitstream format\n"
1804 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1808# define sws_isSupportedInput(x) 0
1809# define sws_isSupportedOutput(x) 0
1812 while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
1813 enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
1817 pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ?
'H' :
'.',
1818 pix_desc->flags & AV_PIX_FMT_FLAG_PAL ?
'P' :
'.',
1819 pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ?
'B' :
'.',
1821 pix_desc->nb_components,
1822 av_get_bits_per_pixel(pix_desc));
1831 const char *name, *descr;
1834 "NAME DESCRIPTION\n");
1835 for (i = 0; i < 63; i++) {
1836 name = av_get_channel_name((uint64_t)1 << i);
1839 descr = av_get_channel_description((uint64_t)1 << i);
1843 "NAME DECOMPOSITION\n");
1844 for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
1847 for (j = 1; j; j <<= 1)
1849 av_log(NULL,
AV_LOG_STDERR,
"%s%s", (layout & (j - 1)) ?
"+" :
"", av_get_channel_name(j));
1860 for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
1861 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_get_sample_fmt_string(fmt_str,
sizeof(fmt_str), i));
1867 const AVCodecDescriptor *desc;
1868 const AVCodec *codec;
1871 av_log(NULL, AV_LOG_ERROR,
"No codec name specified.\n");
1875 codec = encoder ? avcodec_find_encoder_by_name(name) :
1876 avcodec_find_decoder_by_name(name);
1880 else if ((desc = avcodec_descriptor_get_by_name(name))) {
1890 av_log(NULL, AV_LOG_ERROR,
"Codec '%s' is known to FFmpeg, "
1891 "but no %s for it are available. FFmpeg might need to be "
1892 "recompiled with additional external libraries.\n",
1893 name, encoder ?
"encoders" :
"decoders");
1896 av_log(NULL, AV_LOG_ERROR,
"Codec '%s' is not recognized by FFmpeg.\n",
1903 const AVInputFormat *fmt = av_find_input_format(name);
1906 av_log(NULL, AV_LOG_ERROR,
"Unknown format '%s'.\n", name);
1910 av_log(NULL,
AV_LOG_STDERR,
"Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
1912 if (fmt->extensions)
1913 av_log(NULL,
AV_LOG_STDERR,
" Common extensions: %s.\n", fmt->extensions);
1915 if (fmt->priv_class)
1921 const AVClass *proto_class;
1924 av_log(NULL, AV_LOG_ERROR,
"No protocol name specified.\n");
1928 proto_class = avio_protocol_get_class(name);
1930 av_log(NULL, AV_LOG_ERROR,
"Unknown protocol '%s'.\n", name);
1934 show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
1939 const AVCodecDescriptor *desc;
1940 const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
1943 av_log(NULL, AV_LOG_ERROR,
"Unknown format '%s'.\n", name);
1947 av_log(NULL,
AV_LOG_STDERR,
"Muxer %s [%s]:\n", fmt->name, fmt->long_name);
1949 if (fmt->extensions)
1950 av_log(NULL,
AV_LOG_STDERR,
" Common extensions: %s.\n", fmt->extensions);
1952 av_log(NULL,
AV_LOG_STDERR,
" Mime type: %s.\n", fmt->mime_type);
1953 if (fmt->video_codec != AV_CODEC_ID_NONE &&
1954 (desc = avcodec_descriptor_get(fmt->video_codec))) {
1955 av_log(NULL,
AV_LOG_STDERR,
" Default video codec: %s.\n", desc->name);
1957 if (fmt->audio_codec != AV_CODEC_ID_NONE &&
1958 (desc = avcodec_descriptor_get(fmt->audio_codec))) {
1959 av_log(NULL,
AV_LOG_STDERR,
" Default audio codec: %s.\n", desc->name);
1961 if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
1962 (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
1963 av_log(NULL,
AV_LOG_STDERR,
" Default subtitle codec: %s.\n", desc->name);
1966 if (fmt->priv_class)
1971static void show_help_filter(
const char *name)
1974 const AVFilter *f = avfilter_get_by_name(name);
1978 av_log(NULL, AV_LOG_ERROR,
"No filter name specified.\n");
1981 av_log(NULL, AV_LOG_ERROR,
"Unknown filter '%s'.\n", name);
1989 if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
1990 av_log(NULL,
AV_LOG_STDERR,
" slice threading supported\n");
1993 count = avfilter_pad_count(f->inputs);
1994 for (i = 0; i < count; i++) {
1995 av_log(NULL,
AV_LOG_STDERR,
" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
1998 if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
1999 av_log(NULL,
AV_LOG_STDERR,
" dynamic (depending on the options)\n");
2004 count = avfilter_pad_count(f->outputs);
2005 for (i = 0; i < count; i++) {
2006 av_log(NULL,
AV_LOG_STDERR,
" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
2009 if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
2010 av_log(NULL,
AV_LOG_STDERR,
" dynamic (depending on the options)\n");
2015 show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
2016 AV_OPT_FLAG_AUDIO_PARAM);
2017 if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
2018 av_log(NULL,
AV_LOG_STDERR,
"This filter has support for timeline through the 'enable' option.\n");
2020 av_log(NULL, AV_LOG_ERROR,
"Build without libavfilter; "
2021 "can not to satisfy request\n");
2028 const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
2031 av_log(NULL, AV_LOG_ERROR,
"No bitstream filter name specified.\n");
2034 av_log(NULL, AV_LOG_ERROR,
"Unknown bit stream filter '%s'.\n", name);
2038 av_log(NULL,
AV_LOG_STDERR,
"Bit stream filter %s\n", bsf->name);
2041 if (bsf->priv_class)
2045int show_help(
void *optctx,
const char *opt,
const char *arg)
2049 topic = av_strdup(arg ? arg :
"");
2051 return AVERROR(ENOMEM);
2052 par = strchr(topic,
'=');
2062 }
else if (!strcmp(topic,
"decoder")) {
2064 }
else if (!strcmp(topic,
"encoder")) {
2066 }
else if (!strcmp(topic,
"demuxer")) {
2068 }
else if (!strcmp(topic,
"muxer")) {
2070 }
else if (!strcmp(topic,
"protocol")) {
2073 }
else if (!strcmp(topic,
"filter")) {
2074 show_help_filter(par);
2076 }
else if (!strcmp(topic,
"bsf")) {
2093 int yesno = (av_toupper(c) ==
'Y');
2095 while (c !=
'\n' && c != EOF)
2102 const char *preset_name,
int is_path,
2103 const char *codec_name)
2107 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
2112 av_strlcpy(filename, preset_name, filename_size);
2113 f = fopen(filename,
"r");
2115#if HAVE_GETMODULEHANDLE && defined(_WIN32)
2116 char datadir[MAX_PATH], *ls;
2119 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir,
sizeof(datadir) - 1))
2121 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
2122 if (*ls ==
'\\') *ls =
'/';
2124 if (ls = strrchr(datadir,
'/'))
2127 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
2132 for (i = 0; i < 3 && !f; i++) {
2135 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
2136 i != 1 ?
"" :
"/.ffmpeg", preset_name);
2137 f = fopen(filename,
"r");
2138 if (!f && codec_name) {
2139 snprintf(filename, filename_size,
2140 "%s%s/%s-%s.ffpreset",
2141 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
2143 f = fopen(filename,
"r");
2153 int ret = avformat_match_stream_specifier(s, st, spec);
2155 av_log(s, AV_LOG_ERROR,
"Invalid stream specifier: %s.\n", spec);
2160 AVFormatContext *s, AVStream *st,
const AVCodec *codec)
2162 AVDictionary *ret = NULL;
2163 AVDictionaryEntry *t = NULL;
2164 int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
2165 : AV_OPT_FLAG_DECODING_PARAM;
2167 const AVClass *cc = avcodec_get_class();
2170 codec = s->oformat ? avcodec_find_encoder(codec_id)
2171 : avcodec_find_decoder(codec_id);
2173 switch (st->codecpar->codec_type) {
2174 case AVMEDIA_TYPE_VIDEO:
2176 flags |= AV_OPT_FLAG_VIDEO_PARAM;
2178 case AVMEDIA_TYPE_AUDIO:
2180 flags |= AV_OPT_FLAG_AUDIO_PARAM;
2182 case AVMEDIA_TYPE_SUBTITLE:
2184 flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
2188 while ((t = av_dict_get(opts,
"", t, AV_DICT_IGNORE_SUFFIX))) {
2189 const AVClass *priv_class;
2190 char *p = strchr(t->key,
':');
2195 case 1: *p = 0;
break;
2200 if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
2202 ((priv_class = codec->priv_class) &&
2203 av_opt_find(&priv_class, t->key, NULL, flags,
2204 AV_OPT_SEARCH_FAKE_OBJ)))
2205 av_dict_set(&ret, t->key, t->value, 0);
2206 else if (t->key[0] == prefix &&
2207 av_opt_find(&cc, t->key + 1, NULL, flags,
2208 AV_OPT_SEARCH_FAKE_OBJ))
2209 av_dict_set(&ret, t->key + 1, t->value, 0);
2221 AVDictionary **opts;
2225 opts = av_mallocz_array(s->nb_streams,
sizeof(*opts));
2227 av_log(NULL, AV_LOG_ERROR,
2228 "Could not alloc memory for stream options.\n");
2231 for (i = 0; i < s->nb_streams; i++)
2233 s, s->streams[i], NULL);
2237void *
grow_array(
void *array,
int elem_size,
int *size,
int new_size)
2239 if (new_size >= INT_MAX / elem_size) {
2240 av_log(NULL, AV_LOG_ERROR,
"Array too big.\n");
2243 if (*size < new_size) {
2244 uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
2246 av_log(NULL, AV_LOG_ERROR,
"Could not alloc buffer.\n");
2249 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
2258 uint8_t* displaymatrix = av_stream_get_side_data(st,
2259 AV_PKT_DATA_DISPLAYMATRIX, NULL);
2262 theta = -av_display_rotation_get((int32_t*) displaymatrix);
2264 theta -= 360*floor(theta/360 + 0.9/360);
2266 if (fabs(theta - 90*round(theta/90)) > 2)
2267 av_log(NULL, AV_LOG_WARNING,
"Odd rotation angle.\n"
2268 "If you want to help, upload a sample "
2269 "of this file to https://streams.videolan.org/upload/ "
2270 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
2276static int print_device_sources(
const AVInputFormat *fmt, AVDictionary *opts)
2279 AVDeviceInfoList *device_list = NULL;
2281 if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
2282 return AVERROR(EINVAL);
2284 av_log(NULL,
AV_LOG_STDERR,
"Auto-detected sources for %s:\n", fmt->name);
2285 if (!fmt->get_device_list) {
2286 ret = AVERROR(ENOSYS);
2287 av_log(NULL,
AV_LOG_STDERR,
"Cannot list sources. Not implemented.\n");
2291 if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
2296 for (i = 0; i < device_list->nb_devices; i++) {
2297 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]\n", device_list->default_device == i ?
"*" :
" ",
2298 device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2302 avdevice_free_list_devices(&device_list);
2306static int print_device_sinks(
const AVOutputFormat *fmt, AVDictionary *opts)
2309 AVDeviceInfoList *device_list = NULL;
2311 if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
2312 return AVERROR(EINVAL);
2314 av_log(NULL,
AV_LOG_STDERR,
"Auto-detected sinks for %s:\n", fmt->name);
2315 if (!fmt->get_device_list) {
2316 ret = AVERROR(ENOSYS);
2317 av_log(NULL,
AV_LOG_STDERR,
"Cannot list sinks. Not implemented.\n");
2321 if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
2326 for (i = 0; i < device_list->nb_devices; i++) {
2327 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]\n", device_list->default_device == i ?
"*" :
" ",
2328 device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2332 avdevice_free_list_devices(&device_list);
2336static int show_sinks_sources_parse_arg(
const char *arg,
char **dev, AVDictionary **opts)
2340 char *opts_str = NULL;
2341 av_assert0(dev && opts);
2342 *dev = av_strdup(arg);
2344 return AVERROR(ENOMEM);
2345 if ((opts_str = strchr(*dev,
','))) {
2346 *(opts_str++) =
'\0';
2347 if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str,
"=",
":", 0)) < 0)) {
2353 av_log(NULL,
AV_LOG_STDERR,
"\nDevice name is not provided.\n"
2354 "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
2358int show_sources(
void *optctx,
const char *opt,
const char *arg)
2360 const AVInputFormat *fmt = NULL;
2362 AVDictionary *opts = NULL;
2364 int error_level = av_log_get_level();
2366 av_log_set_level(AV_LOG_WARNING);
2368 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2372 fmt = av_input_audio_device_next(fmt);
2374 if (!strcmp(fmt->name,
"lavfi"))
2376 if (dev && !av_match_name(dev, fmt->name))
2378 print_device_sources(fmt, opts);
2382 fmt = av_input_video_device_next(fmt);
2384 if (dev && !av_match_name(dev, fmt->name))
2386 print_device_sources(fmt, opts);
2390 av_dict_free(&opts);
2392 av_log_set_level(error_level);
2396int show_sinks(
void *optctx,
const char *opt,
const char *arg)
2398 const AVOutputFormat *fmt = NULL;
2400 AVDictionary *opts = NULL;
2402 int error_level = av_log_get_level();
2404 av_log_set_level(AV_LOG_WARNING);
2406 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2410 fmt = av_output_audio_device_next(fmt);
2412 if (dev && !av_match_name(dev, fmt->name))
2414 print_device_sinks(fmt, opts);
2418 fmt = av_output_video_device_next(fmt);
2420 if (dev && !av_match_name(dev, fmt->name))
2422 print_device_sinks(fmt, opts);
2426 av_dict_free(&opts);
2428 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