61 #include "libavformat/avformat.h" 
   62 #include "libavfilter/avfilter.h" 
   63 #include "libavdevice/avdevice.h" 
   64 #include "libswscale/swscale.h" 
   65 #include "libswresample/swresample.h" 
   66 #include "libavutil/attributes.h" 
   67 #include "libavutil/avassert.h" 
   68 #include "libavutil/avstring.h" 
   69 #include "libavutil/bprint.h" 
   70 #include "libavutil/display.h" 
   71 #include "libavutil/mathematics.h" 
   72 #include "libavutil/imgutils.h" 
   73 #include "libavutil/libm.h" 
   74 #include "libavutil/parseutils.h" 
   75 #include "libavutil/pixdesc.h" 
   76 #include "libavutil/eval.h" 
   77 #include "libavutil/dict.h" 
   78 #include "libavutil/opt.h" 
   79 #include "libavutil/cpu.h" 
   80 #include "libavutil/ffversion.h" 
   81 #include "libavutil/version.h" 
   84 #include "libavformat/network.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 
  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));
 
  241     const AVClass *child = NULL;
 
  243         av_opt_show2(&
class, NULL, flags, 0);
 
  247     while ((child = av_opt_child_class_next(
class, child)))
 
  253     const char *p = strchr(name, 
':');
 
  254     int len = p ? p - name : strlen(name);
 
  257         if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
 
  267 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32) 
  268 #include <shellapi.h> 
  270 static char** win32_argv_utf8 = NULL;
 
  271 static int win32_argc = 0;
 
  284     int i, buffsize = 0, offset = 0;
 
  286     if (win32_argv_utf8) {
 
  287         *argc_ptr = win32_argc;
 
  288         *argv_ptr = win32_argv_utf8;
 
  293     argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
 
  294     if (win32_argc <= 0 || !argv_w)
 
  298     for (i = 0; i < win32_argc; i++)
 
  299         buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
 
  300                                         NULL, 0, NULL, NULL);
 
  302     win32_argv_utf8 = av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
 
  303     argstr_flat     = (
char *)win32_argv_utf8 + 
sizeof(
char *) * (win32_argc + 1);
 
  304     if (!win32_argv_utf8) {
 
  309     for (i = 0; i < win32_argc; i++) {
 
  310         win32_argv_utf8[i] = &argstr_flat[offset];
 
  311         offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
 
  312                                       &argstr_flat[offset],
 
  313                                       buffsize - offset, NULL, NULL);
 
  315     win32_argv_utf8[i] = NULL;
 
  318     *argc_ptr = win32_argc;
 
  319     *argv_ptr = win32_argv_utf8;
 
  339         char *p = strchr(opt, 
':');
 
  342         dstcount = (
int *)(so + 1);
 
  343         *so = 
grow_array(*so, 
sizeof(**so), dstcount, *dstcount + 1);
 
  344         str = av_strdup(p ? p + 1 : 
"");
 
  346             return AVERROR(ENOMEM);
 
  347         (*so)[*dstcount - 1].specifier = str;
 
  348         dst = &(*so)[*dstcount - 1].u;
 
  353         str = av_strdup(arg);
 
  356             return AVERROR(ENOMEM);
 
  369         int ret = po->
u.
func_arg(optctx, opt, arg);
 
  372                    "Failed to set value '%s' for option '%s': %s\n",
 
  373                    arg, opt, av_err2str(ret));
 
  390     if (!po->
name && opt[0] == 
'n' && opt[1] == 
'o') {
 
  401         av_log(NULL, 
AV_LOG_ERROR, 
"Unrecognized option '%s'\n", opt);
 
  402         return AVERROR(EINVAL);
 
  405         av_log(NULL, 
AV_LOG_ERROR, 
"Missing argument for option '%s'\n", opt);
 
  406         return AVERROR(EINVAL);
 
  417                    void (*parse_arg_function)(
void *, 
const char*))
 
  420     int optindex, handleoptions = 1, ret;
 
  427     while (optindex < argc) {
 
  428         opt = argv[optindex++];
 
  430         if (handleoptions && opt[0] == 
'-' && opt[1] != 
'\0') {
 
  431             if (opt[1] == 
'-' && opt[2] == 
'\0') {
 
  436             if (optindex >= argc) {
 
  437                 if ((ret = 
parse_option(optctx, opt, NULL, options)) < 0)
 
  440                 if ((ret = 
parse_option(optctx, opt, argv[optindex], options)) < 0)
 
  445             if (parse_arg_function)
 
  446                 parse_arg_function(optctx, opt);
 
  455     av_log(NULL, 
AV_LOG_DEBUG, 
"Parsing a group of options: %s %s.\n",
 
  458     for (i = 0; i < g->
nb_opts; i++) {
 
  463             av_log(NULL, 
AV_LOG_ERROR, 
"Option %s (%s) cannot be applied to " 
  464                    "%s %s -- you are trying to apply an input option to an " 
  465                    "output file or vice versa. Move this option before the " 
  466                    "file it belongs to.\n", o->
key, o->
opt->
help,
 
  468             return AVERROR(EINVAL);
 
  471         av_log(NULL, 
AV_LOG_DEBUG, 
"Applying option %s (%s) with argument %s.\n",
 
  479     av_log(NULL, 
AV_LOG_DEBUG, 
"Successfully parsed a group of options.\n");
 
  490     for (i = 1; i < argc; i++) {
 
  491         const char *cur_opt = argv[i];
 
  493         if (*cur_opt++ != 
'-')
 
  497         if (!po->
name && cur_opt[0] == 
'n' && cur_opt[1] == 
'o')
 
  500         if ((!po->
name && !strcmp(cur_opt, optname)) ||
 
  501              (po->
name && !strcmp(optname, po->
name)))
 
  512     const unsigned char *p;
 
  515         if (!((*p >= 
'+' && *p <= 
':') || (*p >= 
'@' && *p <= 
'Z') ||
 
  516               *p == 
'_' || (*p >= 
'a' && *p <= 
'z')))
 
  523     for (p = a; *p; p++) {
 
  524         if (*p == 
'\\' || *p == 
'"' || *p == 
'$' || *p == 
'`')
 
  526         else if (*p < ' ' || *p > 
'~')
 
  552     if (idx && (idx + 1 < argc) && argv[idx + 1])
 
  555     if ((env = getenv(
"FFREPORT")) || idx) {
 
  560             for (i = 0; i < argc; i++) {
 
  572 static const AVOption *
opt_find(
void *obj, 
const char *name, 
const char *unit,
 
  573                             int opt_flags, 
int search_flags)
 
  575     const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
 
  581 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0 
  586     char opt_stripped[128];
 
  588     const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
 
  589 #if CONFIG_AVRESAMPLE 
  590     const AVClass *rc = avresample_get_class();
 
  593     const AVClass *sc = sws_get_class();
 
  595 #if CONFIG_SWRESAMPLE 
  596     const AVClass *swr_class = swr_get_class();
 
  599     if (!strcmp(opt, 
"debug") || !strcmp(opt, 
"fdebug"))
 
  602     if (!(p = strchr(opt, 
':')))
 
  603         p = opt + strlen(opt);
 
  604     av_strlcpy(opt_stripped, opt, FFMIN(
sizeof(opt_stripped), p - opt + 1));
 
  606     if ((o = 
opt_find(&cc, opt_stripped, NULL, 0,
 
  607                          AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
 
  608         ((opt[0] == 
'v' || opt[0] == 
'a' || opt[0] == 
's') &&
 
  609          (o = 
opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
 
  613     if ((o = 
opt_find(&fc, opt, NULL, 0,
 
  614                          AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
 
  617             av_log(NULL, 
AV_LOG_VERBOSE, 
"Routing option %s to both codec and muxer layer\n", opt);
 
  621     if (!consumed && (o = 
opt_find(&sc, opt, NULL, 0,
 
  622                          AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
 
  623         struct SwsContext *sws = sws_alloc_context();
 
  624         int ret = av_opt_set(sws, opt, arg, 0);
 
  625         sws_freeContext(sws);
 
  626         if (!strcmp(opt, 
"srcw") || !strcmp(opt, 
"srch") ||
 
  627             !strcmp(opt, 
"dstw") || !strcmp(opt, 
"dsth") ||
 
  628             !strcmp(opt, 
"src_format") || !strcmp(opt, 
"dst_format")) {
 
  629             av_log(NULL, 
AV_LOG_ERROR, 
"Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
 
  630             return AVERROR(EINVAL);
 
  633             av_log(NULL, 
AV_LOG_ERROR, 
"Error setting option %s.\n", opt);
 
  642     if (!consumed && !strcmp(opt, 
"sws_flags")) {
 
  643         av_log(NULL, 
AV_LOG_WARNING, 
"Ignoring %s %s, due to disabled swscale\n", opt, arg);
 
  647 #if CONFIG_SWRESAMPLE 
  648     if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
 
  649                                     AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
 
  650         struct SwrContext *swr = swr_alloc();
 
  651         int ret = av_opt_set(swr, opt, arg, 0);
 
  654             av_log(NULL, 
AV_LOG_ERROR, 
"Error setting option %s.\n", opt);
 
  661 #if CONFIG_AVRESAMPLE 
  663                        AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
 
  671     return AVERROR_OPTION_NOT_FOUND;
 
  684     for (i = 0; i < nb_groups; i++) {
 
  686         if (p->
sep && !strcmp(p->
sep, opt))
 
  731                     const char *key, 
const char *val)
 
  748     memset(octx, 0, 
sizeof(*octx));
 
  801     av_log(NULL, 
AV_LOG_DEBUG, 
"Splitting the commandline.\n");
 
  803     while (optindex < argc) {
 
  804         const char *opt = argv[optindex++], *arg;
 
  808         av_log(NULL, 
AV_LOG_DEBUG, 
"Reading option '%s' ...", opt);
 
  810         if (opt[0] == 
'-' && opt[1] == 
'-' && !opt[2]) {
 
  815         if (opt[0] != 
'-' || !opt[1] || dashdash+1 == optindex) {
 
  817             av_log(NULL, 
AV_LOG_DEBUG, 
" matched as %s.\n", groups[0].name);
 
  822 #define GET_ARG(arg)                                                           \ 
  824     if (optindex < argc) {                                                     \ 
  825         arg = argv[optindex++];                                                \ 
  827         av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\ 
  828         return AVERROR(EINVAL);                                                \ 
  836             av_log(NULL, 
AV_LOG_DEBUG, 
" matched as %s with argument '%s'.\n",
 
  837                    groups[ret].name, arg);
 
  846                 if (optindex < argc) {
 
  847                     arg = argv[optindex++];
 
  858             av_log(NULL, 
AV_LOG_DEBUG, 
" matched as option '%s' (%s) with " 
  859                    "argument '%s'.\n", po->
name, po->
help, arg);
 
  864         if ((optindex < argc) && argv[optindex]) {
 
  867                 av_log(NULL, 
AV_LOG_DEBUG, 
" matched as AVOption '%s' with " 
  868                        "argument '%s'.\n", opt, argv[optindex]);
 
  871             } 
else if (ret != AVERROR_OPTION_NOT_FOUND) {
 
  873                        "with argument '%s'.\n", opt, argv[optindex]);
 
  879         if (opt[0] == 
'n' && opt[1] == 
'o' &&
 
  883             av_log(NULL, 
AV_LOG_DEBUG, 
" matched as option '%s' (%s) with " 
  884                    "argument 0.\n", po->
name, po->
help);
 
  888         av_log(NULL, 
AV_LOG_ERROR, 
"Unrecognized option '%s'.\n", opt);
 
  889         return AVERROR_OPTION_NOT_FOUND;
 
  894                "command: may be ignored.\n");
 
  896     av_log(NULL, 
AV_LOG_DEBUG, 
"Finished splitting the commandline.\n");
 
  904     unsigned flags = av_get_cpu_flags();
 
  906     if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
 
  909     av_force_cpu_flags(flags);
 
  915     const struct { 
const char *name; 
int level; } log_levels[] = {
 
  924         { 
"trace"  , AV_LOG_TRACE   },
 
  928     int flags = av_log_get_flags();
 
  929     int level = av_log_get_level();
 
  935         if (*token == 
'+' || *token == 
'-') {
 
  943         if (!strncmp(token, 
"repeat", 6)) {
 
  945                 flags |= AV_LOG_SKIP_REPEATED;
 
  947                 flags &= ~AV_LOG_SKIP_REPEATED;
 
  950         } 
else if (!strncmp(token, 
"level", 5)) {
 
  952                 flags &= ~AV_LOG_PRINT_LEVEL;
 
  954                 flags |= AV_LOG_PRINT_LEVEL;
 
  964     } 
else if (*arg == 
'+') {
 
  967         flags = av_log_get_flags();  
 
  970     for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
 
  971         if (!strcmp(log_levels[i].name, arg)) {
 
  972             level = log_levels[i].level;
 
  977     level = strtol(arg, &tail, 10);
 
  980                "Possible levels are numbers or:\n", arg);
 
  981         for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
 
  982             av_log(NULL, 
AV_LOG_FATAL, 
"\"%s\"\n", log_levels[i].name);
 
  987     av_log_set_flags(flags);
 
  988     av_log_set_level(level);
 
  997     while ((c = *(
template++))) {
 
  999             if (!(c = *(
template++)))
 
 1006                 av_bprintf(bp, 
"%04d%02d%02d-%02d%02d%02d",
 
 1007                            tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
 
 1008                            tm->tm_hour, tm->tm_min, tm->tm_sec);
 
 1011                 av_bprint_chars(bp, c, 1);
 
 1015             av_bprint_chars(bp, c, 1);
 
 1022     char *filename_template = NULL;
 
 1025     int prog_loglevel, envlevel = 0;
 
 1033     tm = localtime(&now);
 
 1035     while (env && *env) {
 
 1036         if ((ret = av_opt_get_key_value(&env, 
"=", 
":", 0, &key, &val)) < 0) {
 
 1039                        "Failed to parse FFREPORT environment variable: %s\n",
 
 1046         if (!strcmp(key, 
"file")) {
 
 1047             av_free(filename_template);
 
 1048             filename_template = val;
 
 1050         } 
else if (!strcmp(key, 
"level")) {
 
 1054                 av_log(NULL, 
AV_LOG_FATAL, 
"Invalid report file level\n");
 
 1059             av_log(NULL, 
AV_LOG_ERROR, 
"Unknown key '%s' in FFREPORT\n", key);
 
 1065     av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
 
 1067                              av_x_if_null(filename_template, 
"%p-%t.log"), tm);
 
 1068     av_free(filename_template);
 
 1069     if (!av_bprint_is_complete(&filename)) {
 
 1070         av_log(NULL, 
AV_LOG_ERROR, 
"Out of memory building report file name\n");
 
 1071         return AVERROR(ENOMEM);
 
 1074     prog_loglevel = av_log_get_level();
 
 1080         int ret = AVERROR(errno);
 
 1081         av_log(NULL, 
AV_LOG_ERROR, 
"Failed to open report \"%s\": %s\n",
 
 1082                filename.str, strerror(errno));
 
 1087            "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n" 
 1088            "Report written to \"%s\"\n" 
 1091            tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
 
 1092            tm->tm_hour, tm->tm_min, tm->tm_sec,
 
 1094     av_bprint_finalize(&filename, NULL);
 
 1108     max = strtol(arg, &tail, 10);
 
 1110         av_log(NULL, 
AV_LOG_FATAL, 
"Invalid max_alloc \"%s\".\n", arg);
 
 1121     struct rlimit rl = { lim, lim + 1 };
 
 1122     if (setrlimit(RLIMIT_CPU, &rl))
 
 1123         perror(
"setrlimit");
 
 1125     av_log(NULL, 
AV_LOG_WARNING, 
"-%s not implemented on this OS\n", opt);
 
 1133     const char *errbuf_ptr = errbuf;
 
 1135     if (av_strerror(err, errbuf, 
sizeof(errbuf)) < 0)
 
 1136         errbuf_ptr = strerror(AVUNERROR(err));
 
 1137     av_log(NULL, 
AV_LOG_ERROR, 
"%s: %s\n", filename, errbuf_ptr);
 
 1143 #define SHOW_VERSION  2 
 1144 #define SHOW_CONFIG   4 
 1145 #define SHOW_COPYRIGHT 8 
 1147 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level)                  \ 
 1148     if (CONFIG_##LIBNAME) {                                             \ 
 1149         const char *indent = flags & INDENT? "  " : "";                 \ 
 1150         if (flags & SHOW_VERSION) {                                     \ 
 1151             unsigned int version = libname##_version();                 \ 
 1152             av_log(NULL, level,                                         \ 
 1153                    "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n",            \ 
 1155                    LIB##LIBNAME##_VERSION_MAJOR,                        \ 
 1156                    LIB##LIBNAME##_VERSION_MINOR,                        \ 
 1157                    LIB##LIBNAME##_VERSION_MICRO,                        \ 
 1158                    AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\ 
 1159                    AV_VERSION_MICRO(version));                          \ 
 1161         if (flags & SHOW_CONFIG) {                                      \ 
 1162             const char *cfg = libname##_configuration();                \ 
 1163             if (strcmp(FFMPEG_CONFIGURATION, cfg)) {                    \ 
 1164                 if (!warned_cfg) {                                      \ 
 1165                     av_log(NULL, level,                                 \ 
 1166                             "%sWARNING: library configuration mismatch\n", \ 
 1170                 av_log(NULL, level, "%s%-11s configuration: %s\n",      \ 
 1171                         indent, #libname, cfg);                         \ 
 1189     const char *indent = flags & 
INDENT? 
"  " : 
"";
 
 1191     av_log(NULL, level, 
"%s version " FFMPEG_VERSION, 
program_name);
 
 1193         av_log(NULL, level, 
" Copyright (c) %d-%d the FFmpeg developers",
 
 1195     av_log(NULL, level, 
"\n");
 
 1196     av_log(NULL, level, 
"%sbuilt with %s\n", indent, CC_IDENT);
 
 1198     av_log(NULL, level, 
"%sconfiguration: " FFMPEG_CONFIGURATION 
"\n", indent);
 
 1203     const char *indent = flags & 
INDENT ? 
"  " : 
"";
 
 1204     char str[] = { FFMPEG_CONFIGURATION };
 
 1205     char *conflist, *remove_tilde, *splitconf;
 
 1209     while ((conflist = strstr(str, 
" --")) != NULL) {
 
 1210         strncpy(conflist, 
"~--", 3);
 
 1215     while ((remove_tilde = strstr(str, 
"pkg-config~")) != NULL) {
 
 1216         strncpy(remove_tilde, 
"pkg-config ", 11);
 
 1219     splitconf = strtok(str, 
"~");
 
 1220     av_log(NULL, level, 
"\n%sconfiguration:\n", indent);
 
 1221     while (splitconf != NULL) {
 
 1222         av_log(NULL, level, 
"%s%s%s\n", indent, indent, splitconf);
 
 1223         splitconf = strtok(NULL, 
"~");
 
 1257     "This version of %s has nonfree parts compiled in.\n" 
 1258     "Therefore it is not legally redistributable.\n",
 
 1262     "%s is free software; you can redistribute it and/or modify\n" 
 1263     "it under the terms of the GNU General Public License as published by\n" 
 1264     "the Free Software Foundation; either version 3 of the License, or\n" 
 1265     "(at your option) any later version.\n" 
 1267     "%s is distributed in the hope that it will be useful,\n" 
 1268     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 
 1269     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" 
 1270     "GNU General Public License for more details.\n" 
 1272     "You should have received a copy of the GNU General Public License\n" 
 1273     "along with %s.  If not, see <http://www.gnu.org/licenses/>.\n",
 
 1277     "%s is free software; you can redistribute it and/or modify\n" 
 1278     "it under the terms of the GNU General Public License as published by\n" 
 1279     "the Free Software Foundation; either version 2 of the License, or\n" 
 1280     "(at your option) any later version.\n" 
 1282     "%s is distributed in the hope that it will be useful,\n" 
 1283     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 
 1284     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" 
 1285     "GNU General Public License for more details.\n" 
 1287     "You should have received a copy of the GNU General Public License\n" 
 1288     "along with %s; if not, write to the Free Software\n" 
 1289     "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
 
 1293     "%s is free software; you can redistribute it and/or modify\n" 
 1294     "it under the terms of the GNU Lesser General Public License as published by\n" 
 1295     "the Free Software Foundation; either version 3 of the License, or\n" 
 1296     "(at your option) any later version.\n" 
 1298     "%s is distributed in the hope that it will be useful,\n" 
 1299     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 
 1300     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" 
 1301     "GNU Lesser General Public License for more details.\n" 
 1303     "You should have received a copy of the GNU Lesser General Public License\n" 
 1304     "along with %s.  If not, see <http://www.gnu.org/licenses/>.\n",
 
 1308     "%s is free software; you can redistribute it and/or\n" 
 1309     "modify it under the terms of the GNU Lesser General Public\n" 
 1310     "License as published by the Free Software Foundation; either\n" 
 1311     "version 2.1 of the License, or (at your option) any later version.\n" 
 1313     "%s is distributed in the hope that it will be useful,\n" 
 1314     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 
 1315     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n" 
 1316     "Lesser General Public License for more details.\n" 
 1318     "You should have received a copy of the GNU Lesser General Public\n" 
 1319     "License along with %s; if not, write to the Free Software\n" 
 1320     "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
 
 1331     return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
 
 1336     void *ifmt_opaque = NULL;
 
 1337     const AVInputFormat *ifmt  = NULL;
 
 1338     void *ofmt_opaque = NULL;
 
 1339     const AVOutputFormat *ofmt = NULL;
 
 1340     const char *last_name;
 
 1344            " D. = Demuxing supported\n" 
 1345            " .E = Muxing supported\n" 
 1346            " --\n", device_only ? 
"Devices:" : 
"File formats:");
 
 1351         const char *name      = NULL;
 
 1352         const char *long_name = NULL;
 
 1356             while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
 
 1358                 if (!is_dev && device_only)
 
 1360                 if ((!name || strcmp(ofmt->name, name) < 0) &&
 
 1361                     strcmp(ofmt->name, last_name) > 0) {
 
 1363                     long_name = ofmt->long_name;
 
 1370             while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
 
 1372                 if (!is_dev && device_only)
 
 1374                 if ((!name || strcmp(ifmt->name, name) < 0) &&
 
 1375                     strcmp(ifmt->name, last_name) > 0) {
 
 1377                     long_name = ifmt->long_name;
 
 1380                 if (name && strcmp(ifmt->name, name) == 0)
 
 1392             long_name ? long_name:
" ");
 
 1417 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \ 
 1418     if (codec->field) {                                                      \ 
 1419         const type *p = codec->field;                                        \ 
 1421         av_log(NULL, AV_LOG_STDERR, "    Supported " list_name ":");                              \ 
 1422         while (*p != term) {                                                 \ 
 1424             av_log(NULL, AV_LOG_STDERR, " %s", name);                                             \ 
 1427         av_log(NULL, AV_LOG_STDERR, "\n");                                                        \ 
 1432     int encoder = av_codec_is_encoder(c);
 
 1434     av_log(NULL, 
AV_LOG_STDERR, 
"%s %s [%s]:\n", encoder ? 
"Encoder" : 
"Decoder", c->name,
 
 1435            c->long_name ? c->long_name : 
"");
 
 1438     if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
 
 1440     if (c->capabilities & AV_CODEC_CAP_DR1)
 
 1442     if (c->capabilities & AV_CODEC_CAP_TRUNCATED)
 
 1444     if (c->capabilities & AV_CODEC_CAP_DELAY)
 
 1446     if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
 
 1448     if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
 
 1450     if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
 
 1452     if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
 
 1454     if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
 
 1456     if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
 
 1458     if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
 
 1459                            AV_CODEC_CAP_SLICE_THREADS |
 
 1460                            AV_CODEC_CAP_AUTO_THREADS))
 
 1462     if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
 
 1464     if (c->capabilities & AV_CODEC_CAP_INTRA_ONLY)
 
 1466     if (c->capabilities & AV_CODEC_CAP_LOSSLESS)
 
 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_AUTO_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_AUTO_THREADS : av_log(NULL, 
AV_LOG_STDERR, 
"auto");            
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 '?';
 
 1544     while ((prev = av_codec_next(prev))) {
 
 1545         if (prev->id == 
id &&
 
 1546             (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev)))
 
 1554     const AVCodecDescriptor * 
const *da = a;
 
 1555     const AVCodecDescriptor * 
const *db = b;
 
 1557     return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
 
 1558            strcmp((*da)->name, (*db)->name);
 
 1563     const AVCodecDescriptor *desc = NULL;
 
 1564     const AVCodecDescriptor **codecs;
 
 1565     unsigned nb_codecs = 0, i = 0;
 
 1567     while ((desc = avcodec_descriptor_next(desc)))
 
 1569     if (!(codecs = av_calloc(nb_codecs, 
sizeof(*codecs)))) {
 
 1574     while ((desc = avcodec_descriptor_next(desc)))
 
 1576     av_assert0(i == nb_codecs);
 
 1584     const AVCodec *codec = NULL;
 
 1586     av_log(NULL, 
AV_LOG_STDERR, 
" (%s: ", encoder ? 
"encoders" : 
"decoders");
 
 1596     const AVCodecDescriptor **codecs;
 
 1600            " D..... = Decoding supported\n" 
 1601            " .E.... = Encoding supported\n" 
 1602            " ..V... = Video codec\n" 
 1603            " ..A... = Audio codec\n" 
 1604            " ..S... = Subtitle codec\n" 
 1605            " ...I.. = Intra frame-only codec\n" 
 1606            " ....L. = Lossy compression\n" 
 1607            " .....S = Lossless compression\n" 
 1609     for (i = 0; i < nb_codecs; i++) {
 
 1610         const AVCodecDescriptor *desc = codecs[i];
 
 1611         const AVCodec *codec = NULL;
 
 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 = NULL;
 
 1671             av_log(NULL, 
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? 
"F" : 
".");
 
 1672             av_log(NULL, 
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? 
"S" : 
".");
 
 1673             av_log(NULL, 
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL)  ? 
"X" : 
".");
 
 1674             av_log(NULL, 
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?
"B" : 
".");
 
 1675             av_log(NULL, 
AV_LOG_STDERR, (codec->capabilities & AV_CODEC_CAP_DR1)           ? 
"D" : 
".");
 
 1677             av_log(NULL, 
AV_LOG_STDERR, 
" %-20s %s", codec->name, codec->long_name ? codec->long_name : 
"");
 
 1678             if (strcmp(codec->name, desc->name))
 
 1699 int show_bsfs(
void *optctx, 
const char *opt, 
const char *arg)
 
 1701     const AVBitStreamFilter *bsf = NULL;
 
 1702     void *opaque = NULL;
 
 1705     while ((bsf = av_bsf_iterate(&opaque)))
 
 1713     void *opaque = NULL;
 
 1718     while ((name = avio_enum_protocols(&opaque, 0)))
 
 1721     while ((name = avio_enum_protocols(&opaque, 1)))
 
 1729     const AVFilter *filter = NULL;
 
 1730     char descr[64], *descr_cur;
 
 1731     void *opaque = NULL;
 
 1733     const AVFilterPad *pad;
 
 1736            "  T.. = Timeline support\n" 
 1737            "  .S. = Slice threading\n" 
 1738            "  ..C = Command support\n" 
 1739            "  A = Audio input/output\n" 
 1740            "  V = Video input/output\n" 
 1741            "  N = Dynamic number and/or type of input/output\n" 
 1742            "  | = Source or sink filter\n");
 
 1743     while ((filter = av_filter_iterate(&opaque))) {
 
 1745         for (i = 0; i < 2; i++) {
 
 1747                 *(descr_cur++) = 
'-';
 
 1748                 *(descr_cur++) = 
'>';
 
 1750             pad = i ? filter->outputs : filter->inputs;
 
 1751             for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
 
 1752                 if (descr_cur >= descr + 
sizeof(descr) - 4)
 
 1757                 *(descr_cur++) = ((!i && (filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
 
 1758                                   ( i && (filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ? 
'N' : 
'|';
 
 1762                filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ? 
'T' : 
'.',
 
 1763                filter->flags & AVFILTER_FLAG_SLICE_THREADS    ? 
'S' : 
'.',
 
 1764                filter->process_command                        ? 
'C' : 
'.',
 
 1765                filter->name, descr, filter->description);
 
 1768     av_log(NULL, 
AV_LOG_STDERR, 
"No filters available: libavfilter disabled\n");
 
 1781     for (i = 0; (name = av_get_known_color_name(i, &rgb)); i++)
 
 1782         av_log(NULL, 
AV_LOG_STDERR, 
"%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
 
 1789     const AVPixFmtDescriptor *pix_desc = NULL;
 
 1792            "I.... = Supported Input  format for conversion\n" 
 1793            ".O... = Supported Output format for conversion\n" 
 1794            "..H.. = Hardware accelerated format\n" 
 1795            "...P. = Paletted format\n" 
 1796            "....B = Bitstream format\n" 
 1797            "FLAGS NAME            NB_COMPONENTS BITS_PER_PIXEL\n" 
 1801 #   define sws_isSupportedInput(x)  0 
 1802 #   define sws_isSupportedOutput(x) 0 
 1805     while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
 
 1806         enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
 
 1810                pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL   ? 
'H' : 
'.',
 
 1811                pix_desc->flags & AV_PIX_FMT_FLAG_PAL       ? 
'P' : 
'.',
 
 1812                pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ? 
'B' : 
'.',
 
 1814                pix_desc->nb_components,
 
 1815                av_get_bits_per_pixel(pix_desc));
 
 1824     const char *name, *descr;
 
 1827            "NAME           DESCRIPTION\n");
 
 1828     for (i = 0; i < 63; i++) {
 
 1829         name = av_get_channel_name((uint64_t)1 << i);
 
 1832         descr = av_get_channel_description((uint64_t)1 << i);
 
 1836            "NAME           DECOMPOSITION\n");
 
 1837     for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
 
 1840             for (j = 1; j; j <<= 1)
 
 1842                     av_log(NULL, 
AV_LOG_STDERR, 
"%s%s", (layout & (j - 1)) ? 
"+" : 
"", av_get_channel_name(j));
 
 1853     for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
 
 1854         av_log(NULL, 
AV_LOG_STDERR, 
"%s\n", av_get_sample_fmt_string(fmt_str, 
sizeof(fmt_str), i));
 
 1860     const AVCodecDescriptor *desc;
 
 1861     const AVCodec *codec;
 
 1864         av_log(NULL, 
AV_LOG_ERROR, 
"No codec name specified.\n");
 
 1868     codec = encoder ? avcodec_find_encoder_by_name(name) :
 
 1869                       avcodec_find_decoder_by_name(name);
 
 1873     else if ((desc = avcodec_descriptor_get_by_name(name))) {
 
 1882             av_log(NULL, 
AV_LOG_ERROR, 
"Codec '%s' is known to FFmpeg, " 
 1883                    "but no %s for it are available. FFmpeg might need to be " 
 1884                    "recompiled with additional external libraries.\n",
 
 1885                    name, encoder ? 
"encoders" : 
"decoders");
 
 1888         av_log(NULL, 
AV_LOG_ERROR, 
"Codec '%s' is not recognized by FFmpeg.\n",
 
 1895     const AVInputFormat *fmt = av_find_input_format(name);
 
 1898         av_log(NULL, 
AV_LOG_ERROR, 
"Unknown format '%s'.\n", name);
 
 1902     av_log(NULL, 
AV_LOG_STDERR, 
"Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
 
 1904     if (fmt->extensions)
 
 1905         av_log(NULL, 
AV_LOG_STDERR, 
"    Common extensions: %s.\n", fmt->extensions);
 
 1907     if (fmt->priv_class)
 
 1913     const AVCodecDescriptor *desc;
 
 1914     const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
 
 1917         av_log(NULL, 
AV_LOG_ERROR, 
"Unknown format '%s'.\n", name);
 
 1921     av_log(NULL, 
AV_LOG_STDERR, 
"Muxer %s [%s]:\n", fmt->name, fmt->long_name);
 
 1923     if (fmt->extensions)
 
 1924         av_log(NULL, 
AV_LOG_STDERR, 
"    Common extensions: %s.\n", fmt->extensions);
 
 1926         av_log(NULL, 
AV_LOG_STDERR, 
"    Mime type: %s.\n", fmt->mime_type);
 
 1927     if (fmt->video_codec != AV_CODEC_ID_NONE &&
 
 1928         (desc = avcodec_descriptor_get(fmt->video_codec))) {
 
 1929         av_log(NULL, 
AV_LOG_STDERR, 
"    Default video codec: %s.\n", desc->name);
 
 1931     if (fmt->audio_codec != AV_CODEC_ID_NONE &&
 
 1932         (desc = avcodec_descriptor_get(fmt->audio_codec))) {
 
 1933         av_log(NULL, 
AV_LOG_STDERR, 
"    Default audio codec: %s.\n", desc->name);
 
 1935     if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
 
 1936         (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
 
 1937         av_log(NULL, 
AV_LOG_STDERR, 
"    Default subtitle codec: %s.\n", desc->name);
 
 1940     if (fmt->priv_class)
 
 1945 static void show_help_filter(
const char *name)
 
 1948     const AVFilter *f = avfilter_get_by_name(name);
 
 1952         av_log(NULL, 
AV_LOG_ERROR, 
"No filter name specified.\n");
 
 1955         av_log(NULL, 
AV_LOG_ERROR, 
"Unknown filter '%s'.\n", name);
 
 1963     if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
 
 1964         av_log(NULL, 
AV_LOG_STDERR, 
"    slice threading supported\n");
 
 1967     count = avfilter_pad_count(f->inputs);
 
 1968     for (i = 0; i < count; i++) {
 
 1969         av_log(NULL, 
AV_LOG_STDERR, 
"       #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
 
 1972     if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
 
 1973         av_log(NULL, 
AV_LOG_STDERR, 
"        dynamic (depending on the options)\n");
 
 1978     count = avfilter_pad_count(f->outputs);
 
 1979     for (i = 0; i < count; i++) {
 
 1980         av_log(NULL, 
AV_LOG_STDERR, 
"       #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
 
 1983     if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
 
 1984         av_log(NULL, 
AV_LOG_STDERR, 
"        dynamic (depending on the options)\n");
 
 1989         show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
 
 1990                                           AV_OPT_FLAG_AUDIO_PARAM);
 
 1991     if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
 
 1992         av_log(NULL, 
AV_LOG_STDERR, 
"This filter has support for timeline through the 'enable' option.\n");
 
 1994     av_log(NULL, 
AV_LOG_ERROR, 
"Build without libavfilter; " 
 1995            "can not to satisfy request\n");
 
 2002     const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
 
 2005         av_log(NULL, 
AV_LOG_ERROR, 
"No bitstream filter name specified.\n");
 
 2008         av_log(NULL, 
AV_LOG_ERROR, 
"Unknown bit stream filter '%s'.\n", name);
 
 2012     av_log(NULL, 
AV_LOG_STDERR, 
"Bit stream filter %s\n", bsf->name);
 
 2015     if (bsf->priv_class)
 
 2019 int show_help(
void *optctx, 
const char *opt, 
const char *arg)
 
 2023     topic = av_strdup(arg ? arg : 
"");
 
 2025         return AVERROR(ENOMEM);
 
 2026     par = strchr(topic, 
'=');
 
 2036     } 
else if (!strcmp(topic, 
"decoder")) {
 
 2038     } 
else if (!strcmp(topic, 
"encoder")) {
 
 2040     } 
else if (!strcmp(topic, 
"demuxer")) {
 
 2042     } 
else if (!strcmp(topic, 
"muxer")) {
 
 2045     } 
else if (!strcmp(topic, 
"filter")) {
 
 2046         show_help_filter(par);
 
 2048     } 
else if (!strcmp(topic, 
"bsf")) {
 
 2065     int yesno = (av_toupper(c) == 
'Y');
 
 2067     while (c != 
'\n' && c != EOF)
 
 2074                       const char *preset_name, 
int is_path,
 
 2075                       const char *codec_name)
 
 2079     const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
 
 2084         av_strlcpy(filename, preset_name, filename_size);
 
 2085         f = fopen(filename, 
"r");
 
 2087 #if HAVE_GETMODULEHANDLE 
 2088         char datadir[MAX_PATH], *ls;
 
 2091         if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, 
sizeof(datadir) - 1))
 
 2093             for (ls = datadir; ls < datadir + strlen(datadir); ls++)
 
 2094                 if (*ls == 
'\\') *ls = 
'/';
 
 2096             if (ls = strrchr(datadir, 
'/'))
 
 2099                 strncat(datadir, 
"/ffpresets",  
sizeof(datadir) - 1 - strlen(datadir));
 
 2104         for (i = 0; i < 3 && !f; i++) {
 
 2107             snprintf(filename, filename_size, 
"%s%s/%s.ffpreset", base[i],
 
 2108                      i != 1 ? 
"" : 
"/.ffmpeg", preset_name);
 
 2109             f = fopen(filename, 
"r");
 
 2110             if (!f && codec_name) {
 
 2111                 snprintf(filename, filename_size,
 
 2112                          "%s%s/%s-%s.ffpreset",
 
 2113                          base[i], i != 1 ? 
"" : 
"/.ffmpeg", codec_name,
 
 2115                 f = fopen(filename, 
"r");
 
 2125     int ret = avformat_match_stream_specifier(s, st, spec);
 
 2127         av_log(s, 
AV_LOG_ERROR, 
"Invalid stream specifier: %s.\n", spec);
 
 2132                                 AVFormatContext *s, AVStream *st, AVCodec *codec)
 
 2134     AVDictionary    *ret = NULL;
 
 2135     AVDictionaryEntry *t = NULL;
 
 2136     int            flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
 
 2137                                       : AV_OPT_FLAG_DECODING_PARAM;
 
 2139     const AVClass    *cc = avcodec_get_class();
 
 2142         codec            = s->oformat ? avcodec_find_encoder(codec_id)
 
 2143                                       : avcodec_find_decoder(codec_id);
 
 2145     switch (st->codecpar->codec_type) {
 
 2146     case AVMEDIA_TYPE_VIDEO:
 
 2148         flags  |= AV_OPT_FLAG_VIDEO_PARAM;
 
 2150     case AVMEDIA_TYPE_AUDIO:
 
 2152         flags  |= AV_OPT_FLAG_AUDIO_PARAM;
 
 2154     case AVMEDIA_TYPE_SUBTITLE:
 
 2156         flags  |= AV_OPT_FLAG_SUBTITLE_PARAM;
 
 2160     while ((t = av_dict_get(opts, 
"", t, AV_DICT_IGNORE_SUFFIX))) {
 
 2161         char *p = strchr(t->key, 
':');
 
 2166             case  1: *p = 0; 
break;
 
 2171         if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
 
 2173             (codec->priv_class &&
 
 2174              av_opt_find(&codec->priv_class, t->key, NULL, flags,
 
 2175                          AV_OPT_SEARCH_FAKE_OBJ)))
 
 2176             av_dict_set(&ret, t->key, t->value, 0);
 
 2177         else if (t->key[0] == prefix &&
 
 2178                  av_opt_find(&cc, t->key + 1, NULL, flags,
 
 2179                              AV_OPT_SEARCH_FAKE_OBJ))
 
 2180             av_dict_set(&ret, t->key + 1, t->value, 0);
 
 2192     AVDictionary **opts;
 
 2196     opts = av_mallocz_array(s->nb_streams, 
sizeof(*opts));
 
 2199                "Could not alloc memory for stream options.\n");
 
 2202     for (i = 0; i < s->nb_streams; i++)
 
 2204                                     s, s->streams[i], NULL);
 
 2210     if (new_size >= INT_MAX / elem_size) {
 
 2214     if (*
size < new_size) {
 
 2215         uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
 
 2217             av_log(NULL, 
AV_LOG_ERROR, 
"Could not alloc buffer.\n");
 
 2220         memset(tmp + *
size*elem_size, 0, (new_size-*
size) * elem_size);
 
 2229     uint8_t* displaymatrix = av_stream_get_side_data(st,
 
 2230                                                      AV_PKT_DATA_DISPLAYMATRIX, NULL);
 
 2233         theta = -av_display_rotation_get((int32_t*) displaymatrix);
 
 2235     theta -= 360*floor(theta/360 + 0.9/360);
 
 2237     if (fabs(theta - 90*round(theta/90)) > 2)
 
 2239                "If you want to help, upload a sample " 
 2240                "of this file to ftp://upload.ffmpeg.org/incoming/ " 
 2241                "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
 
 2247 static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
 
 2250     AVDeviceInfoList *device_list = NULL;
 
 2252     if (!fmt || !fmt->priv_class  || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
 
 2253         return AVERROR(EINVAL);
 
 2255     av_log(NULL, 
AV_LOG_STDERR, 
"Auto-detected sources for %s:\n", fmt->name);
 
 2256     if (!fmt->get_device_list) {
 
 2257         ret = AVERROR(ENOSYS);
 
 2258         av_log(NULL, 
AV_LOG_STDERR, 
"Cannot list sources. Not implemented.\n");
 
 2262     if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
 
 2267     for (i = 0; i < device_list->nb_devices; i++) {
 
 2268         av_log(NULL, 
AV_LOG_STDERR, 
"%s %s [%s]\n", device_list->default_device == i ? 
"*" : 
" ",
 
 2269                device_list->devices[i]->device_name, device_list->devices[i]->device_description);
 
 2273     avdevice_free_list_devices(&device_list);
 
 2277 static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
 
 2280     AVDeviceInfoList *device_list = NULL;
 
 2282     if (!fmt || !fmt->priv_class  || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
 
 2283         return AVERROR(EINVAL);
 
 2285     av_log(NULL, 
AV_LOG_STDERR, 
"Auto-detected sinks for %s:\n", fmt->name);
 
 2286     if (!fmt->get_device_list) {
 
 2287         ret = AVERROR(ENOSYS);
 
 2288         av_log(NULL, 
AV_LOG_STDERR, 
"Cannot list sinks. Not implemented.\n");
 
 2292     if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
 
 2297     for (i = 0; i < device_list->nb_devices; i++) {
 
 2298         av_log(NULL, 
AV_LOG_STDERR, 
"%s %s [%s]\n", device_list->default_device == i ? 
"*" : 
" ",
 
 2299                device_list->devices[i]->device_name, device_list->devices[i]->device_description);
 
 2303     avdevice_free_list_devices(&device_list);
 
 2307 static int show_sinks_sources_parse_arg(
const char *arg, 
char **dev, AVDictionary **opts)
 
 2311         char *opts_str = NULL;
 
 2312         av_assert0(dev && opts);
 
 2313         *dev = av_strdup(arg);
 
 2315             return AVERROR(ENOMEM);
 
 2316         if ((opts_str = strchr(*dev, 
','))) {
 
 2317             *(opts_str++) = 
'\0';
 
 2318             if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str, 
"=", 
":", 0)) < 0)) {
 
 2324         av_log(NULL, 
AV_LOG_STDERR, 
"\nDevice name is not provided.\n" 
 2325                 "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
 
 2329 int show_sources(
void *optctx, 
const char *opt, 
const char *arg)
 
 2331     AVInputFormat *fmt = NULL;
 
 2333     AVDictionary *opts = NULL;
 
 2335     int error_level = av_log_get_level();
 
 2339     if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
 
 2343         fmt = av_input_audio_device_next(fmt);
 
 2345             if (!strcmp(fmt->name, 
"lavfi"))
 
 2347             if (dev && !av_match_name(dev, fmt->name))
 
 2349             print_device_sources(fmt, opts);
 
 2353         fmt = av_input_video_device_next(fmt);
 
 2355             if (dev && !av_match_name(dev, fmt->name))
 
 2357             print_device_sources(fmt, opts);
 
 2361     av_dict_free(&opts);
 
 2363     av_log_set_level(error_level);
 
 2367 int show_sinks(
void *optctx, 
const char *opt, 
const char *arg)
 
 2369     AVOutputFormat *fmt = NULL;
 
 2371     AVDictionary *opts = NULL;
 
 2373     int error_level = av_log_get_level();
 
 2377     if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
 
 2381         fmt = av_output_audio_device_next(fmt);
 
 2383             if (dev && !av_match_name(dev, fmt->name))
 
 2385             print_device_sinks(fmt, opts);
 
 2389         fmt = av_output_video_device_next(fmt);
 
 2391             if (dev && !av_match_name(dev, fmt->name))
 
 2393             print_device_sinks(fmt, opts);
 
 2397     av_dict_free(&opts);
 
 2399     av_log_set_level(error_level);