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/channel_layout.h"
71#include "libavutil/display.h"
72#include "libavutil/mathematics.h"
73#include "libavutil/imgutils.h"
74#include "libavutil/libm.h"
75#include "libavutil/parseutils.h"
76#include "libavutil/pixdesc.h"
77#include "libavutil/eval.h"
78#include "libavutil/dict.h"
79#include "libavutil/opt.h"
80#include "libavutil/cpu.h"
81#include "libavutil/ffversion.h"
82#include "libavutil/version.h"
83#include "libavcodec/bsf.h"
85#if HAVE_SYS_RESOURCE_H
87#include <sys/resource.h>
128 static int print_prefix = 1;
132 av_log_default_callback(ptr, level, fmt, vl);
136 av_log_format_line(ptr, level, fmt, vl2, line,
sizeof(line), &print_prefix);
146#if HAVE_SETDLLDIRECTORY && defined(_WIN32)
172 double min,
double max)
176 double d = av_strtod(numstr, &tail);
178 error =
"Expected number for %s but found: %s\n";
179 else if (d < min || d > max)
180 error =
"The value for %s was %s which is not within %f - %f\n";
182 error =
"Expected int64 for %s but found %s\n";
184 error =
"Expected int for %s but found %s\n";
187 av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
196 if (av_parse_time(&us, timestr, is_duration) < 0) {
197 av_log(NULL, AV_LOG_FATAL,
"Invalid %s specification for %s: %s\n",
198 is_duration ?
"duration" :
"date", context, timestr);
205 int rej_flags,
int alt_flags)
211 for (po = options; po->
name; po++) {
214 if (((po->
flags & req_flags) != req_flags) ||
215 (alt_flags && !(po->
flags & alt_flags)) ||
216 (po->
flags & rej_flags))
223 av_strlcpy(buf, po->
name,
sizeof(buf));
225 av_strlcat(buf,
" ",
sizeof(buf));
226 av_strlcat(buf, po->
argname,
sizeof(buf));
236 const AVClass *child;
238 av_opt_show2(&
class, NULL, flags, 0);
242 while ((child = av_opt_child_class_iterate(
class, &iter)))
250 if (av_strstart(name, po->
name, &end) && (!*end || *end ==
':'))
260#if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
263static char** win32_argv_utf8 = NULL;
264static int win32_argc = 0;
277 int i, buffsize = 0, offset = 0;
279 if (win32_argv_utf8) {
280 *argc_ptr = win32_argc;
281 *argv_ptr = win32_argv_utf8;
286 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
287 if (win32_argc <= 0 || !argv_w)
291 for (i = 0; i < win32_argc; i++)
292 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
293 NULL, 0, NULL, NULL);
295 win32_argv_utf8 = av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
296 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
297 if (!win32_argv_utf8) {
302 for (i = 0; i < win32_argc; i++) {
303 win32_argv_utf8[i] = &argstr_flat[offset];
304 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
305 &argstr_flat[offset],
306 buffsize - offset, NULL, NULL);
308 win32_argv_utf8[i] = NULL;
311 *argc_ptr = win32_argc;
312 *argv_ptr = win32_argv_utf8;
332 char *p = strchr(opt,
':');
335 dstcount = (
int *)(so + 1);
336 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
337 str = av_strdup(p ? p + 1 :
"");
339 return AVERROR(ENOMEM);
340 (*so)[*dstcount - 1].specifier = str;
341 dst = &(*so)[*dstcount - 1].u;
346 str = av_strdup(arg);
349 return AVERROR(ENOMEM);
362 int ret = po->
u.
func_arg(optctx, opt, arg);
364 av_log(NULL, AV_LOG_ERROR,
365 "Failed to set value '%s' for option '%s': %s\n",
366 arg, opt, av_err2str(ret));
383 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
394 av_log(NULL, AV_LOG_ERROR,
"Unrecognized option '%s'\n", opt);
395 return AVERROR(EINVAL);
398 av_log(NULL, AV_LOG_ERROR,
"Missing argument for option '%s'\n", opt);
399 return AVERROR(EINVAL);
410 void (*parse_arg_function)(
void *,
const char*))
413 int optindex, handleoptions = 1, ret;
420 while (optindex < argc) {
421 opt = argv[optindex++];
423 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
424 if (opt[1] ==
'-' && opt[2] ==
'\0') {
429 if (optindex >= argc) {
430 if ((ret =
parse_option(optctx, opt, NULL, options)) < 0)
433 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
438 if (parse_arg_function)
439 parse_arg_function(optctx, opt);
448 av_log(NULL, AV_LOG_DEBUG,
"Parsing a group of options: %s %s.\n",
451 for (i = 0; i < g->
nb_opts; i++) {
456 av_log(NULL, AV_LOG_ERROR,
"Option %s (%s) cannot be applied to "
457 "%s %s -- you are trying to apply an input option to an "
458 "output file or vice versa. Move this option before the "
459 "file it belongs to.\n", o->
key, o->
opt->
help,
461 return AVERROR(EINVAL);
464 av_log(NULL, AV_LOG_DEBUG,
"Applying option %s (%s) with argument %s.\n",
472 av_log(NULL, AV_LOG_DEBUG,
"Successfully parsed a group of options.\n");
483 for (i = 1; i < argc; i++) {
484 const char *cur_opt = argv[i];
486 if (*cur_opt++ !=
'-')
490 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
493 if ((!po->
name && !strcmp(cur_opt, optname)) ||
494 (po->
name && !strcmp(optname, po->
name)))
505 const unsigned char *p;
508 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
509 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
516 for (p = a; *p; p++) {
517 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
519 else if (*p < ' ' || *p >
'~')
545 if (idx && (idx + 1 < argc) && argv[idx + 1])
548 if ((env = getenv(
"FFREPORT")) || idx) {
553 for (i = 0; i < argc; i++) {
565static const AVOption *
opt_find(
void *obj,
const char *name,
const char *unit,
566 int opt_flags,
int search_flags)
568 const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
574#define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
579 char opt_stripped[128];
581 const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
583 const AVClass *sc = sws_get_class();
586 const AVClass *swr_class = swr_get_class();
589 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
590 av_log_set_level(AV_LOG_DEBUG);
592 if (!(p = strchr(opt,
':')))
593 p = opt + strlen(opt);
594 av_strlcpy(opt_stripped, opt, FFMIN(
sizeof(opt_stripped), p - opt + 1));
596 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
597 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
598 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
599 (o =
opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
603 if ((o =
opt_find(&fc, opt, NULL, 0,
604 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
607 av_log(NULL, AV_LOG_VERBOSE,
"Routing option %s to both codec and muxer layer\n", opt);
611 if (!consumed && (o =
opt_find(&sc, opt, NULL, 0,
612 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
613 struct SwsContext *sws = sws_alloc_context();
614 int ret = av_opt_set(sws, opt, arg, 0);
615 sws_freeContext(sws);
616 if (!strcmp(opt,
"srcw") || !strcmp(opt,
"srch") ||
617 !strcmp(opt,
"dstw") || !strcmp(opt,
"dsth") ||
618 !strcmp(opt,
"src_format") || !strcmp(opt,
"dst_format")) {
619 av_log(NULL, AV_LOG_ERROR,
"Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
620 return AVERROR(EINVAL);
623 av_log(NULL, AV_LOG_ERROR,
"Error setting option %s.\n", opt);
632 if (!consumed && !strcmp(opt,
"sws_flags")) {
633 av_log(NULL, AV_LOG_WARNING,
"Ignoring %s %s, due to disabled swscale\n", opt, arg);
638 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
639 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
640 struct SwrContext *swr = swr_alloc();
641 int ret = av_opt_set(swr, opt, arg, 0);
644 av_log(NULL, AV_LOG_ERROR,
"Error setting option %s.\n", opt);
654 return AVERROR_OPTION_NOT_FOUND;
667 for (i = 0; i < nb_groups; i++) {
669 if (p->
sep && !strcmp(p->
sep, opt))
713 const char *key,
const char *val)
730 memset(octx, 0,
sizeof(*octx));
781 av_log(NULL, AV_LOG_DEBUG,
"Splitting the commandline.\n");
783 while (optindex < argc) {
784 const char *opt = argv[optindex++], *arg;
788 av_log(NULL, AV_LOG_DEBUG,
"Reading option '%s' ...", opt);
790 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
795 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
797 av_log(NULL, AV_LOG_DEBUG,
" matched as %s.\n", groups[0].name);
802#define GET_ARG(arg) \
804 if (optindex < argc) { \
805 arg = argv[optindex++]; \
807 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
808 return AVERROR(EINVAL); \
816 av_log(NULL, AV_LOG_DEBUG,
" matched as %s with argument '%s'.\n",
817 groups[ret].name, arg);
826 if (optindex < argc) {
827 arg = argv[optindex++];
838 av_log(NULL, AV_LOG_DEBUG,
" matched as option '%s' (%s) with "
839 "argument '%s'.\n", po->
name, po->
help, arg);
844 if ((optindex < argc) && argv[optindex]) {
847 av_log(NULL, AV_LOG_DEBUG,
" matched as AVOption '%s' with "
848 "argument '%s'.\n", opt, argv[optindex]);
851 }
else if (ret != AVERROR_OPTION_NOT_FOUND) {
852 av_log(NULL, AV_LOG_ERROR,
"Error parsing option '%s' "
853 "with argument '%s'.\n", opt, argv[optindex]);
859 if (opt[0] ==
'n' && opt[1] ==
'o' &&
863 av_log(NULL, AV_LOG_DEBUG,
" matched as option '%s' (%s) with "
864 "argument 0.\n", po->
name, po->
help);
868 av_log(NULL, AV_LOG_ERROR,
"Unrecognized option '%s'.\n", opt);
869 return AVERROR_OPTION_NOT_FOUND;
873 av_log(NULL, AV_LOG_WARNING,
"Trailing option(s) found in the "
874 "command: may be ignored.\n");
876 av_log(NULL, AV_LOG_DEBUG,
"Finished splitting the commandline.\n");
884 unsigned flags = av_get_cpu_flags();
886 if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
889 av_force_cpu_flags(flags);
898 static const AVOption opts[] = {
899 {
"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, INT_MAX, 0},
902 static const AVClass
class = {
903 .class_name =
"cpucount",
904 .item_name = av_default_item_name,
906 .version = LIBAVUTIL_VERSION_INT,
908 const AVClass *pclass = &
class;
910 ret = av_opt_eval_int(&pclass, opts, arg, &count);
913 av_cpu_force_count(count);
921 const struct {
const char *name;
int level; } log_levels[] = {
922 {
"quiet" , AV_LOG_QUIET },
923 {
"panic" , AV_LOG_PANIC },
924 {
"fatal" , AV_LOG_FATAL },
925 {
"error" , AV_LOG_ERROR },
926 {
"warning", AV_LOG_WARNING },
927 {
"info" , AV_LOG_INFO },
928 {
"verbose", AV_LOG_VERBOSE },
929 {
"debug" , AV_LOG_DEBUG },
930 {
"trace" , AV_LOG_TRACE },
934 int flags = av_log_get_flags();
935 int level = av_log_get_level();
941 if (*token ==
'+' || *token ==
'-') {
949 if (av_strstart(token,
"repeat", &arg)) {
951 flags |= AV_LOG_SKIP_REPEATED;
953 flags &= ~AV_LOG_SKIP_REPEATED;
955 }
else if (av_strstart(token,
"level", &arg)) {
957 flags &= ~AV_LOG_PRINT_LEVEL;
959 flags |= AV_LOG_PRINT_LEVEL;
968 }
else if (*arg ==
'+') {
971 flags = av_log_get_flags();
974 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
975 if (!strcmp(log_levels[i].name, arg)) {
976 level = log_levels[i].level;
981 level = strtol(arg, &tail, 10);
983 av_log(NULL, AV_LOG_FATAL,
"Invalid loglevel \"%s\". "
984 "Possible levels are numbers or:\n", arg);
985 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
986 av_log(NULL, AV_LOG_FATAL,
"\"%s\"\n", log_levels[i].name);
991 av_log_set_flags(flags);
992 av_log_set_level(level);
1001 while ((c = *(
template++))) {
1003 if (!(c = *(
template++)))
1010 av_bprintf(bp,
"%04d%02d%02d-%02d%02d%02d",
1011 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1012 tm->tm_hour, tm->tm_min, tm->tm_sec);
1015 av_bprint_chars(bp, c, 1);
1019 av_bprint_chars(bp, c, 1);
1026 char *filename_template = NULL;
1029 int prog_loglevel, envlevel = 0;
1037 tm = localtime(&now);
1039 while (env && *env) {
1040 if ((ret = av_opt_get_key_value(&env,
"=",
":", 0, &key, &val)) < 0) {
1042 av_log(NULL, AV_LOG_ERROR,
1043 "Failed to parse FFREPORT environment variable: %s\n",
1050 if (!strcmp(key,
"file")) {
1051 av_free(filename_template);
1052 filename_template = val;
1054 }
else if (!strcmp(key,
"level")) {
1058 av_log(NULL, AV_LOG_FATAL,
"Invalid report file level\n");
1063 av_log(NULL, AV_LOG_ERROR,
"Unknown key '%s' in FFREPORT\n", key);
1069 av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
1071 av_x_if_null(filename_template,
"%p-%t.log"), tm);
1072 av_free(filename_template);
1073 if (!av_bprint_is_complete(&filename)) {
1074 av_log(NULL, AV_LOG_ERROR,
"Out of memory building report file name\n");
1075 return AVERROR(ENOMEM);
1078 prog_loglevel = av_log_get_level();
1084 int ret = AVERROR(errno);
1085 av_log(NULL, AV_LOG_ERROR,
"Failed to open report \"%s\": %s\n",
1086 filename.str, strerror(errno));
1090 av_log(NULL, AV_LOG_INFO,
1091 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
1092 "Report written to \"%s\"\n"
1095 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1096 tm->tm_hour, tm->tm_min, tm->tm_sec,
1098 av_bprint_finalize(&filename, NULL);
1112 max = strtol(arg, &tail, 10);
1114 av_log(NULL, AV_LOG_FATAL,
"Invalid max_alloc \"%s\".\n", arg);
1125 struct rlimit rl = { lim, lim + 1 };
1126 if (setrlimit(RLIMIT_CPU, &rl))
1127 perror(
"setrlimit");
1129 av_log(NULL, AV_LOG_WARNING,
"-%s not implemented on this OS\n", opt);
1137 const char *errbuf_ptr = errbuf;
1139 if (av_strerror(err, errbuf,
sizeof(errbuf)) < 0)
1140 errbuf_ptr = strerror(AVUNERROR(err));
1141 av_log(NULL, AV_LOG_ERROR,
"%s: %s\n", filename, errbuf_ptr);
1147#define SHOW_VERSION 2
1148#define SHOW_CONFIG 4
1149#define SHOW_COPYRIGHT 8
1151#define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1152 if (CONFIG_##LIBNAME) { \
1153 const char *indent = flags & INDENT? " " : ""; \
1154 if (flags & SHOW_VERSION) { \
1155 unsigned int version = libname##_version(); \
1156 av_log(NULL, level, \
1157 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1159 LIB##LIBNAME##_VERSION_MAJOR, \
1160 LIB##LIBNAME##_VERSION_MINOR, \
1161 LIB##LIBNAME##_VERSION_MICRO, \
1162 AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\
1163 AV_VERSION_MICRO(version)); \
1165 if (flags & SHOW_CONFIG) { \
1166 const char *cfg = libname##_configuration(); \
1167 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1168 if (!warned_cfg) { \
1169 av_log(NULL, level, \
1170 "%sWARNING: library configuration mismatch\n", \
1174 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1175 indent, #libname, cfg); \
1193 const char *indent = flags &
INDENT?
" " :
"";
1195 av_log(NULL, level,
"%s version " FFMPEG_VERSION,
program_name);
1197 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1199 av_log(NULL, level,
"\n");
1200 av_log(NULL, level,
"%sbuilt with %s\n", indent, CC_IDENT);
1202 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1207 const char *indent = flags &
INDENT ?
" " :
"";
1208 char str[] = { FFMPEG_CONFIGURATION };
1209 char *conflist, *remove_tilde, *splitconf;
1213 while ((conflist = strstr(str,
" --")) != NULL) {
1219 while ((remove_tilde = strstr(str,
"pkg-config~")) != NULL) {
1220 remove_tilde[
sizeof(
"pkg-config~") - 2] =
' ';
1223 splitconf = strtok(str,
"~");
1224 av_log(NULL, level,
"\n%sconfiguration:\n", indent);
1225 while (splitconf != NULL) {
1226 av_log(NULL, level,
"%s%s%s\n", indent, indent, splitconf);
1227 splitconf = strtok(NULL,
"~");
1261 "This version of %s has nonfree parts compiled in.\n"
1262 "Therefore it is not legally redistributable.\n",
1266 "%s is free software; you can redistribute it and/or modify\n"
1267 "it under the terms of the GNU General Public License as published by\n"
1268 "the Free Software Foundation; either version 3 of the License, or\n"
1269 "(at your option) any later version.\n"
1271 "%s is distributed in the hope that it will be useful,\n"
1272 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1273 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1274 "GNU General Public License for more details.\n"
1276 "You should have received a copy of the GNU General Public License\n"
1277 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1281 "%s is free software; you can redistribute it and/or modify\n"
1282 "it under the terms of the GNU General Public License as published by\n"
1283 "the Free Software Foundation; either version 2 of the License, or\n"
1284 "(at your option) any later version.\n"
1286 "%s is distributed in the hope that it will be useful,\n"
1287 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1288 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1289 "GNU General Public License for more details.\n"
1291 "You should have received a copy of the GNU General Public License\n"
1292 "along with %s; if not, write to the Free Software\n"
1293 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1297 "%s is free software; you can redistribute it and/or modify\n"
1298 "it under the terms of the GNU Lesser General Public License as published by\n"
1299 "the Free Software Foundation; either version 3 of the License, or\n"
1300 "(at your option) any later version.\n"
1302 "%s is distributed in the hope that it will be useful,\n"
1303 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1304 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1305 "GNU Lesser General Public License for more details.\n"
1307 "You should have received a copy of the GNU Lesser General Public License\n"
1308 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1312 "%s is free software; you can redistribute it and/or\n"
1313 "modify it under the terms of the GNU Lesser General Public\n"
1314 "License as published by the Free Software Foundation; either\n"
1315 "version 2.1 of the License, or (at your option) any later version.\n"
1317 "%s is distributed in the hope that it will be useful,\n"
1318 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1319 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1320 "Lesser General Public License for more details.\n"
1322 "You should have received a copy of the GNU Lesser General Public\n"
1323 "License along with %s; if not, write to the Free Software\n"
1324 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1335 return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
1340 void *ifmt_opaque = NULL;
1341 const AVInputFormat *ifmt = NULL;
1342 void *ofmt_opaque = NULL;
1343 const AVOutputFormat *ofmt = NULL;
1344 const char *last_name;
1348 " D. = Demuxing supported\n"
1349 " .E = Muxing supported\n"
1350 " --\n", device_only ?
"Devices:" :
"File formats:");
1355 const char *name = NULL;
1356 const char *long_name = NULL;
1360 while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
1362 if (!is_dev && device_only)
1364 if ((!name || strcmp(ofmt->name, name) < 0) &&
1365 strcmp(ofmt->name, last_name) > 0) {
1367 long_name = ofmt->long_name;
1374 while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
1376 if (!is_dev && device_only)
1378 if ((!name || strcmp(ifmt->name, name) < 0) &&
1379 strcmp(ifmt->name, last_name) > 0) {
1381 long_name = ifmt->long_name;
1384 if (name && strcmp(ifmt->name, name) == 0)
1396 long_name ? long_name:
" ");
1421#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1422 if (codec->field) { \
1423 const type *p = codec->field; \
1425 av_log(NULL, AV_LOG_STDERR, " Supported " list_name ":"); \
1426 while (*p != term) { \
1428 av_log(NULL, AV_LOG_STDERR, " %s", name); \
1431 av_log(NULL, AV_LOG_STDERR, "\n"); \
1436 int encoder = av_codec_is_encoder(c);
1438 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->name,
1439 c->long_name ? c->long_name :
"");
1442 if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
1444 if (c->capabilities & AV_CODEC_CAP_DR1)
1446 if (c->capabilities & AV_CODEC_CAP_TRUNCATED)
1448 if (c->capabilities & AV_CODEC_CAP_DELAY)
1450 if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
1452 if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
1454 if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
1456 if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
1458 if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
1460 if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
1462 if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1463 AV_CODEC_CAP_SLICE_THREADS |
1464 AV_CODEC_CAP_OTHER_THREADS))
1466 if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
1468 if (c->capabilities & AV_CODEC_CAP_HARDWARE)
1470 if (c->capabilities & AV_CODEC_CAP_HYBRID)
1472 if (!c->capabilities)
1476 if (c->type == AVMEDIA_TYPE_VIDEO ||
1477 c->type == AVMEDIA_TYPE_AUDIO) {
1479 switch (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
1480 AV_CODEC_CAP_SLICE_THREADS |
1481 AV_CODEC_CAP_OTHER_THREADS)) {
1482 case AV_CODEC_CAP_FRAME_THREADS |
1483 AV_CODEC_CAP_SLICE_THREADS: av_log(NULL,
AV_LOG_STDERR,
"frame and slice");
break;
1484 case AV_CODEC_CAP_FRAME_THREADS: av_log(NULL,
AV_LOG_STDERR,
"frame");
break;
1485 case AV_CODEC_CAP_SLICE_THREADS: av_log(NULL,
AV_LOG_STDERR,
"slice");
break;
1486 case AV_CODEC_CAP_OTHER_THREADS : av_log(NULL,
AV_LOG_STDERR,
"other");
break;
1492 if (avcodec_get_hw_config(c, 0)) {
1493 av_log(NULL,
AV_LOG_STDERR,
" Supported hardware devices: ");
1494 for (
int i = 0;; i++) {
1495 const AVCodecHWConfig *config = avcodec_get_hw_config(c, i);
1498 av_log(NULL,
AV_LOG_STDERR,
"%s ", av_hwdevice_get_type_name(config->device_type));
1503 if (c->supported_framerates) {
1504 const AVRational *fps = c->supported_framerates;
1522 if (c->priv_class) {
1524 AV_OPT_FLAG_ENCODING_PARAM |
1525 AV_OPT_FLAG_DECODING_PARAM);
1532 case AVMEDIA_TYPE_VIDEO:
return 'V';
1533 case AVMEDIA_TYPE_AUDIO:
return 'A';
1534 case AVMEDIA_TYPE_DATA:
return 'D';
1535 case AVMEDIA_TYPE_SUBTITLE:
return 'S';
1536 case AVMEDIA_TYPE_ATTACHMENT:
return 'T';
1537 default:
return '?';
1545 while ((c = av_codec_iterate(iter))) {
1547 (encoder ? av_codec_is_encoder(c) : av_codec_is_decoder(c)))
1555 const AVCodecDescriptor *
const *da = a;
1556 const AVCodecDescriptor *
const *db = b;
1558 return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
1559 strcmp((*da)->name, (*db)->name);
1564 const AVCodecDescriptor *desc = NULL;
1565 const AVCodecDescriptor **codecs;
1566 unsigned nb_codecs = 0, i = 0;
1568 while ((desc = avcodec_descriptor_next(desc)))
1570 if (!(codecs = av_calloc(nb_codecs,
sizeof(*codecs)))) {
1571 av_log(NULL, AV_LOG_ERROR,
"Out of memory\n");
1575 while ((desc = avcodec_descriptor_next(desc)))
1577 av_assert0(i == nb_codecs);
1586 const AVCodec *codec;
1588 av_log(NULL,
AV_LOG_STDERR,
" (%s: ", encoder ?
"encoders" :
"decoders");
1598 const AVCodecDescriptor **codecs;
1602 " D..... = Decoding supported\n"
1603 " .E.... = Encoding supported\n"
1604 " ..V... = Video codec\n"
1605 " ..A... = Audio codec\n"
1606 " ..S... = Subtitle codec\n"
1607 " ...I.. = Intra frame-only codec\n"
1608 " ....L. = Lossy compression\n"
1609 " .....S = Lossless compression\n"
1611 for (i = 0; i < nb_codecs; i++) {
1612 const AVCodecDescriptor *desc = codecs[i];
1613 const AVCodec *codec;
1616 if (strstr(desc->name,
"_deprecated"))
1620 av_log(NULL,
AV_LOG_STDERR, avcodec_find_decoder(desc->id) ?
"D" :
".");
1621 av_log(NULL,
AV_LOG_STDERR, avcodec_find_encoder(desc->id) ?
"E" :
".");
1624 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_INTRA_ONLY) ?
"I" :
".");
1625 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSY) ?
"L" :
".");
1626 av_log(NULL,
AV_LOG_STDERR, (desc->props & AV_CODEC_PROP_LOSSLESS) ?
"S" :
".");
1628 av_log(NULL,
AV_LOG_STDERR,
" %-20s %s", desc->name, desc->long_name ? desc->long_name :
"");
1633 if (strcmp(codec->name, desc->name)) {
1640 if (strcmp(codec->name, desc->name)) {
1654 const AVCodecDescriptor **codecs;
1660 " S..... = Subtitle\n"
1661 " .F.... = Frame-level multithreading\n"
1662 " ..S... = Slice-level multithreading\n"
1663 " ...X.. = Codec is experimental\n"
1664 " ....B. = Supports draw_horiz_band\n"
1665 " .....D = Supports direct rendering method 1\n"
1667 encoder ?
"Encoders" :
"Decoders");
1668 for (i = 0; i < nb_codecs; i++) {
1669 const AVCodecDescriptor *desc = codecs[i];
1670 const AVCodec *codec;
1675 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ?
"F" :
".");
1676 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ?
"S" :
".");
1677 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ?
"X" :
".");
1678 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?
"B" :
".");
1679 av_log(NULL,
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DR1) ?
"D" :
".");
1681 av_log(NULL,
AV_LOG_STDERR,
" %-20s %s", codec->name, codec->long_name ? codec->long_name :
"");
1682 if (strcmp(codec->name, desc->name))
1703int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1705 const AVBitStreamFilter *bsf = NULL;
1706 void *opaque = NULL;
1709 while ((bsf = av_bsf_iterate(&opaque)))
1717 void *opaque = NULL;
1722 while ((name = avio_enum_protocols(&opaque, 0)))
1725 while ((name = avio_enum_protocols(&opaque, 1)))
1733 const AVFilter *
filter = NULL;
1734 char descr[64], *descr_cur;
1735 void *opaque = NULL;
1737 const AVFilterPad *pad;
1740 " T.. = Timeline support\n"
1741 " .S. = Slice threading\n"
1742 " ..C = Command support\n"
1743 " A = Audio input/output\n"
1744 " V = Video input/output\n"
1745 " N = Dynamic number and/or type of input/output\n"
1746 " | = Source or sink filter\n");
1747 while ((
filter = av_filter_iterate(&opaque))) {
1749 for (i = 0; i < 2; i++) {
1751 *(descr_cur++) =
'-';
1752 *(descr_cur++) =
'>';
1755 for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
1756 if (descr_cur >= descr +
sizeof(descr) - 4)
1761 *(descr_cur++) = ((!i && (
filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
1762 ( i && (
filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ?
'N' :
'|';
1766 filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ?
'T' :
'.',
1767 filter->flags & AVFILTER_FLAG_SLICE_THREADS ?
'S' :
'.',
1768 filter->process_command ?
'C' :
'.',
1772 av_log(NULL,
AV_LOG_STDERR,
"No filters available: libavfilter disabled\n");
1785 for (i = 0; (name = av_get_known_color_name(i, &rgb)); i++)
1786 av_log(NULL,
AV_LOG_STDERR,
"%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1793 const AVPixFmtDescriptor *pix_desc = NULL;
1796 "I.... = Supported Input format for conversion\n"
1797 ".O... = Supported Output format for conversion\n"
1798 "..H.. = Hardware accelerated format\n"
1799 "...P. = Paletted format\n"
1800 "....B = Bitstream format\n"
1801 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1805# define sws_isSupportedInput(x) 0
1806# define sws_isSupportedOutput(x) 0
1809 while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
1810 enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
1814 pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ?
'H' :
'.',
1815 pix_desc->flags & AV_PIX_FMT_FLAG_PAL ?
'P' :
'.',
1816 pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ?
'B' :
'.',
1818 pix_desc->nb_components,
1819 av_get_bits_per_pixel(pix_desc));
1828 const char *name, *descr;
1831 "NAME DESCRIPTION\n");
1832 for (i = 0; i < 63; i++) {
1833 name = av_get_channel_name((uint64_t)1 << i);
1836 descr = av_get_channel_description((uint64_t)1 << i);
1840 "NAME DECOMPOSITION\n");
1841 for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
1844 for (j = 1; j; j <<= 1)
1846 av_log(NULL,
AV_LOG_STDERR,
"%s%s", (layout & (j - 1)) ?
"+" :
"", av_get_channel_name(j));
1857 for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
1858 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_get_sample_fmt_string(fmt_str,
sizeof(fmt_str), i));
1864 const AVCodecDescriptor *desc;
1865 const AVCodec *codec;
1868 av_log(NULL, AV_LOG_ERROR,
"No codec name specified.\n");
1872 codec = encoder ? avcodec_find_encoder_by_name(name) :
1873 avcodec_find_decoder_by_name(name);
1877 else if ((desc = avcodec_descriptor_get_by_name(name))) {
1887 av_log(NULL, AV_LOG_ERROR,
"Codec '%s' is known to FFmpeg, "
1888 "but no %s for it are available. FFmpeg might need to be "
1889 "recompiled with additional external libraries.\n",
1890 name, encoder ?
"encoders" :
"decoders");
1893 av_log(NULL, AV_LOG_ERROR,
"Codec '%s' is not recognized by FFmpeg.\n",
1900 const AVInputFormat *fmt = av_find_input_format(name);
1903 av_log(NULL, AV_LOG_ERROR,
"Unknown format '%s'.\n", name);
1907 av_log(NULL,
AV_LOG_STDERR,
"Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
1909 if (fmt->extensions)
1910 av_log(NULL,
AV_LOG_STDERR,
" Common extensions: %s.\n", fmt->extensions);
1912 if (fmt->priv_class)
1918 const AVClass *proto_class;
1921 av_log(NULL, AV_LOG_ERROR,
"No protocol name specified.\n");
1925 proto_class = avio_protocol_get_class(name);
1927 av_log(NULL, AV_LOG_ERROR,
"Unknown protocol '%s'.\n", name);
1931 show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
1936 const AVCodecDescriptor *desc;
1937 const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
1940 av_log(NULL, AV_LOG_ERROR,
"Unknown format '%s'.\n", name);
1944 av_log(NULL,
AV_LOG_STDERR,
"Muxer %s [%s]:\n", fmt->name, fmt->long_name);
1946 if (fmt->extensions)
1947 av_log(NULL,
AV_LOG_STDERR,
" Common extensions: %s.\n", fmt->extensions);
1949 av_log(NULL,
AV_LOG_STDERR,
" Mime type: %s.\n", fmt->mime_type);
1950 if (fmt->video_codec != AV_CODEC_ID_NONE &&
1951 (desc = avcodec_descriptor_get(fmt->video_codec))) {
1952 av_log(NULL,
AV_LOG_STDERR,
" Default video codec: %s.\n", desc->name);
1954 if (fmt->audio_codec != AV_CODEC_ID_NONE &&
1955 (desc = avcodec_descriptor_get(fmt->audio_codec))) {
1956 av_log(NULL,
AV_LOG_STDERR,
" Default audio codec: %s.\n", desc->name);
1958 if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
1959 (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
1960 av_log(NULL,
AV_LOG_STDERR,
" Default subtitle codec: %s.\n", desc->name);
1963 if (fmt->priv_class)
1968static void show_help_filter(
const char *name)
1971 const AVFilter *f = avfilter_get_by_name(name);
1975 av_log(NULL, AV_LOG_ERROR,
"No filter name specified.\n");
1978 av_log(NULL, AV_LOG_ERROR,
"Unknown filter '%s'.\n", name);
1986 if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
1987 av_log(NULL,
AV_LOG_STDERR,
" slice threading supported\n");
1990 count = avfilter_pad_count(f->inputs);
1991 for (i = 0; i < count; i++) {
1992 av_log(NULL,
AV_LOG_STDERR,
" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
1995 if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
1996 av_log(NULL,
AV_LOG_STDERR,
" dynamic (depending on the options)\n");
2001 count = avfilter_pad_count(f->outputs);
2002 for (i = 0; i < count; i++) {
2003 av_log(NULL,
AV_LOG_STDERR,
" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
2006 if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
2007 av_log(NULL,
AV_LOG_STDERR,
" dynamic (depending on the options)\n");
2012 show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
2013 AV_OPT_FLAG_AUDIO_PARAM);
2014 if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
2015 av_log(NULL,
AV_LOG_STDERR,
"This filter has support for timeline through the 'enable' option.\n");
2017 av_log(NULL, AV_LOG_ERROR,
"Build without libavfilter; "
2018 "can not to satisfy request\n");
2025 const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
2028 av_log(NULL, AV_LOG_ERROR,
"No bitstream filter name specified.\n");
2031 av_log(NULL, AV_LOG_ERROR,
"Unknown bit stream filter '%s'.\n", name);
2035 av_log(NULL,
AV_LOG_STDERR,
"Bit stream filter %s\n", bsf->name);
2038 if (bsf->priv_class)
2042int show_help(
void *optctx,
const char *opt,
const char *arg)
2046 topic = av_strdup(arg ? arg :
"");
2048 return AVERROR(ENOMEM);
2049 par = strchr(topic,
'=');
2059 }
else if (!strcmp(topic,
"decoder")) {
2061 }
else if (!strcmp(topic,
"encoder")) {
2063 }
else if (!strcmp(topic,
"demuxer")) {
2065 }
else if (!strcmp(topic,
"muxer")) {
2067 }
else if (!strcmp(topic,
"protocol")) {
2070 }
else if (!strcmp(topic,
"filter")) {
2071 show_help_filter(par);
2073 }
else if (!strcmp(topic,
"bsf")) {
2090 int yesno = (av_toupper(c) ==
'Y');
2092 while (c !=
'\n' && c != EOF)
2099 const char *preset_name,
int is_path,
2100 const char *codec_name)
2104 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
2109 av_strlcpy(filename, preset_name, filename_size);
2110 f = fopen(filename,
"r");
2112#if HAVE_GETMODULEHANDLE && defined(_WIN32)
2113 char datadir[MAX_PATH], *ls;
2116 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir,
sizeof(datadir) - 1))
2118 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
2119 if (*ls ==
'\\') *ls =
'/';
2121 if (ls = strrchr(datadir,
'/'))
2124 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
2129 for (i = 0; i < 3 && !f; i++) {
2132 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
2133 i != 1 ?
"" :
"/.ffmpeg", preset_name);
2134 f = fopen(filename,
"r");
2135 if (!f && codec_name) {
2136 snprintf(filename, filename_size,
2137 "%s%s/%s-%s.ffpreset",
2138 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
2140 f = fopen(filename,
"r");
2150 int ret = avformat_match_stream_specifier(s, st, spec);
2152 av_log(s, AV_LOG_ERROR,
"Invalid stream specifier: %s.\n", spec);
2157 AVFormatContext *s, AVStream *st,
const AVCodec *codec)
2159 AVDictionary *ret = NULL;
2160 AVDictionaryEntry *t = NULL;
2161 int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
2162 : AV_OPT_FLAG_DECODING_PARAM;
2164 const AVClass *cc = avcodec_get_class();
2167 codec = s->oformat ? avcodec_find_encoder(codec_id)
2168 : avcodec_find_decoder(codec_id);
2170 switch (st->codecpar->codec_type) {
2171 case AVMEDIA_TYPE_VIDEO:
2173 flags |= AV_OPT_FLAG_VIDEO_PARAM;
2175 case AVMEDIA_TYPE_AUDIO:
2177 flags |= AV_OPT_FLAG_AUDIO_PARAM;
2179 case AVMEDIA_TYPE_SUBTITLE:
2181 flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
2185 while ((t = av_dict_get(opts,
"", t, AV_DICT_IGNORE_SUFFIX))) {
2186 const AVClass *priv_class;
2187 char *p = strchr(t->key,
':');
2192 case 1: *p = 0;
break;
2197 if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
2199 ((priv_class = codec->priv_class) &&
2200 av_opt_find(&priv_class, t->key, NULL, flags,
2201 AV_OPT_SEARCH_FAKE_OBJ)))
2202 av_dict_set(&ret, t->key, t->value, 0);
2203 else if (t->key[0] == prefix &&
2204 av_opt_find(&cc, t->key + 1, NULL, flags,
2205 AV_OPT_SEARCH_FAKE_OBJ))
2206 av_dict_set(&ret, t->key + 1, t->value, 0);
2218 AVDictionary **opts;
2222 opts = av_mallocz_array(s->nb_streams,
sizeof(*opts));
2224 av_log(NULL, AV_LOG_ERROR,
2225 "Could not alloc memory for stream options.\n");
2228 for (i = 0; i < s->nb_streams; i++)
2230 s, s->streams[i], NULL);
2234void *
grow_array(
void *array,
int elem_size,
int *size,
int new_size)
2236 if (new_size >= INT_MAX / elem_size) {
2237 av_log(NULL, AV_LOG_ERROR,
"Array too big.\n");
2240 if (*size < new_size) {
2241 uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
2243 av_log(NULL, AV_LOG_ERROR,
"Could not alloc buffer.\n");
2246 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
2255 uint8_t* displaymatrix = av_stream_get_side_data(st,
2256 AV_PKT_DATA_DISPLAYMATRIX, NULL);
2259 theta = -av_display_rotation_get((int32_t*) displaymatrix);
2261 theta -= 360*floor(theta/360 + 0.9/360);
2263 if (fabs(theta - 90*round(theta/90)) > 2)
2264 av_log(NULL, AV_LOG_WARNING,
"Odd rotation angle.\n"
2265 "If you want to help, upload a sample "
2266 "of this file to https://streams.videolan.org/upload/ "
2267 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
2273static int print_device_sources(
const AVInputFormat *fmt, AVDictionary *opts)
2276 AVDeviceInfoList *device_list = NULL;
2278 if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
2279 return AVERROR(EINVAL);
2281 av_log(NULL,
AV_LOG_STDERR,
"Auto-detected sources for %s:\n", fmt->name);
2282 if (!fmt->get_device_list) {
2283 ret = AVERROR(ENOSYS);
2284 av_log(NULL,
AV_LOG_STDERR,
"Cannot list sources. Not implemented.\n");
2288 if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
2293 for (i = 0; i < device_list->nb_devices; i++) {
2294 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]\n", device_list->default_device == i ?
"*" :
" ",
2295 device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2299 avdevice_free_list_devices(&device_list);
2303static int print_device_sinks(
const AVOutputFormat *fmt, AVDictionary *opts)
2306 AVDeviceInfoList *device_list = NULL;
2308 if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
2309 return AVERROR(EINVAL);
2311 av_log(NULL,
AV_LOG_STDERR,
"Auto-detected sinks for %s:\n", fmt->name);
2312 if (!fmt->get_device_list) {
2313 ret = AVERROR(ENOSYS);
2314 av_log(NULL,
AV_LOG_STDERR,
"Cannot list sinks. Not implemented.\n");
2318 if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
2323 for (i = 0; i < device_list->nb_devices; i++) {
2324 av_log(NULL,
AV_LOG_STDERR,
"%s %s [%s]\n", device_list->default_device == i ?
"*" :
" ",
2325 device_list->devices[i]->device_name, device_list->devices[i]->device_description);
2329 avdevice_free_list_devices(&device_list);
2333static int show_sinks_sources_parse_arg(
const char *arg,
char **dev, AVDictionary **opts)
2337 char *opts_str = NULL;
2338 av_assert0(dev && opts);
2339 *dev = av_strdup(arg);
2341 return AVERROR(ENOMEM);
2342 if ((opts_str = strchr(*dev,
','))) {
2343 *(opts_str++) =
'\0';
2344 if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str,
"=",
":", 0)) < 0)) {
2350 av_log(NULL,
AV_LOG_STDERR,
"\nDevice name is not provided.\n"
2351 "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
2355int show_sources(
void *optctx,
const char *opt,
const char *arg)
2357 const AVInputFormat *fmt = NULL;
2359 AVDictionary *opts = NULL;
2361 int error_level = av_log_get_level();
2363 av_log_set_level(AV_LOG_WARNING);
2365 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2369 fmt = av_input_audio_device_next(fmt);
2371 if (!strcmp(fmt->name,
"lavfi"))
2373 if (dev && !av_match_name(dev, fmt->name))
2375 print_device_sources(fmt, opts);
2379 fmt = av_input_video_device_next(fmt);
2381 if (dev && !av_match_name(dev, fmt->name))
2383 print_device_sources(fmt, opts);
2387 av_dict_free(&opts);
2389 av_log_set_level(error_level);
2393int show_sinks(
void *optctx,
const char *opt,
const char *arg)
2395 const AVOutputFormat *fmt = NULL;
2397 AVDictionary *opts = NULL;
2399 int error_level = av_log_get_level();
2401 av_log_set_level(AV_LOG_WARNING);
2403 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
2407 fmt = av_output_audio_device_next(fmt);
2409 if (dev && !av_match_name(dev, fmt->name))
2411 print_device_sinks(fmt, opts);
2415 fmt = av_output_video_device_next(fmt);
2417 if (dev && !av_match_name(dev, fmt->name))
2419 print_device_sinks(fmt, opts);
2423 av_dict_free(&opts);
2425 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