00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <string.h>
00023 #include <stdlib.h>
00024 #include <errno.h>
00025 #include <math.h>
00026
00027
00028
00029
00030
00031 #include "config.h"
00032 #include "libavformat/avformat.h"
00033 #include "libavfilter/avfilter.h"
00034 #include "libavdevice/avdevice.h"
00035 #include "libswscale/swscale.h"
00036 #include "libpostproc/postprocess.h"
00037 #include "libavutil/avstring.h"
00038 #include "libavutil/parseutils.h"
00039 #include "libavutil/pixdesc.h"
00040 #include "libavutil/eval.h"
00041 #include "libavutil/dict.h"
00042 #include "libavutil/opt.h"
00043 #include "cmdutils.h"
00044 #include "version.h"
00045 #if CONFIG_NETWORK
00046 #include "libavformat/network.h"
00047 #endif
00048 #if HAVE_SYS_RESOURCE_H
00049 #include <sys/resource.h>
00050 #endif
00051
00052 const char **opt_names;
00053 const char **opt_values;
00054 static int opt_name_count;
00055 AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
00056 AVFormatContext *avformat_opts;
00057 struct SwsContext *sws_opts;
00058 AVDictionary *format_opts, *video_opts, *audio_opts, *sub_opts;
00059
00060 static const int this_year = 2011;
00061
00062 void init_opts(void)
00063 {
00064 int i;
00065 for (i = 0; i < AVMEDIA_TYPE_NB; i++)
00066 avcodec_opts[i] = avcodec_alloc_context2(i);
00067 avformat_opts = avformat_alloc_context();
00068 #if CONFIG_SWSCALE
00069 sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL);
00070 #endif
00071 }
00072
00073 void uninit_opts(void)
00074 {
00075 int i;
00076 for (i = 0; i < AVMEDIA_TYPE_NB; i++)
00077 av_freep(&avcodec_opts[i]);
00078 av_freep(&avformat_opts->key);
00079 av_freep(&avformat_opts);
00080 #if CONFIG_SWSCALE
00081 sws_freeContext(sws_opts);
00082 sws_opts = NULL;
00083 #endif
00084 for (i = 0; i < opt_name_count; i++) {
00085 av_freep(&opt_names[i]);
00086 av_freep(&opt_values[i]);
00087 }
00088 av_freep(&opt_names);
00089 av_freep(&opt_values);
00090 opt_name_count = 0;
00091 av_dict_free(&format_opts);
00092 av_dict_free(&video_opts);
00093 av_dict_free(&audio_opts);
00094 av_dict_free(&sub_opts);
00095 }
00096
00097 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl)
00098 {
00099 vfprintf(stdout, fmt, vl);
00100 }
00101
00102 double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
00103 {
00104 char *tail;
00105 const char *error;
00106 double d = av_strtod(numstr, &tail);
00107 if (*tail)
00108 error= "Expected number for %s but found: %s\n";
00109 else if (d < min || d > max)
00110 error= "The value for %s was %s which is not within %f - %f\n";
00111 else if(type == OPT_INT64 && (int64_t)d != d)
00112 error= "Expected int64 for %s but found %s\n";
00113 else if (type == OPT_INT && (int)d != d)
00114 error= "Expected int for %s but found %s\n";
00115 else
00116 return d;
00117 fprintf(stderr, error, context, numstr, min, max);
00118 exit(1);
00119 }
00120
00121 int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
00122 {
00123 int64_t us;
00124 if (av_parse_time(&us, timestr, is_duration) < 0) {
00125 fprintf(stderr, "Invalid %s specification for %s: %s\n",
00126 is_duration ? "duration" : "date", context, timestr);
00127 exit(1);
00128 }
00129 return us;
00130 }
00131
00132 void show_help_options(const OptionDef *options, const char *msg, int mask, int value)
00133 {
00134 const OptionDef *po;
00135 int first;
00136
00137 first = 1;
00138 for(po = options; po->name != NULL; po++) {
00139 char buf[64];
00140 if ((po->flags & mask) == value) {
00141 if (first) {
00142 printf("%s", msg);
00143 first = 0;
00144 }
00145 av_strlcpy(buf, po->name, sizeof(buf));
00146 if (po->flags & HAS_ARG) {
00147 av_strlcat(buf, " ", sizeof(buf));
00148 av_strlcat(buf, po->argname, sizeof(buf));
00149 }
00150 printf("-%-17s %s\n", buf, po->help);
00151 }
00152 }
00153 }
00154
00155 static const OptionDef* find_option(const OptionDef *po, const char *name){
00156 while (po->name != NULL) {
00157 if (!strcmp(name, po->name))
00158 break;
00159 po++;
00160 }
00161 return po;
00162 }
00163
00164 #if defined(_WIN32) && !defined(__MINGW32CE__)
00165 #include <windows.h>
00166
00167 static char** win32_argv_utf8 = NULL;
00168 static int win32_argc = 0;
00169
00177 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
00178 {
00179 char *argstr_flat;
00180 wchar_t **argv_w;
00181 int i, buffsize = 0, offset = 0;
00182
00183 if (win32_argv_utf8) {
00184 *argc_ptr = win32_argc;
00185 *argv_ptr = win32_argv_utf8;
00186 return;
00187 }
00188
00189 win32_argc = 0;
00190 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
00191 if (win32_argc <= 0 || !argv_w)
00192 return;
00193
00194
00195 for (i = 0; i < win32_argc; i++)
00196 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
00197 NULL, 0, NULL, NULL);
00198
00199 win32_argv_utf8 = av_mallocz(sizeof(char*) * (win32_argc + 1) + buffsize);
00200 argstr_flat = (char*)win32_argv_utf8 + sizeof(char*) * (win32_argc + 1);
00201 if (win32_argv_utf8 == NULL) {
00202 LocalFree(argv_w);
00203 return;
00204 }
00205
00206 for (i = 0; i < win32_argc; i++) {
00207 win32_argv_utf8[i] = &argstr_flat[offset];
00208 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
00209 &argstr_flat[offset],
00210 buffsize - offset, NULL, NULL);
00211 }
00212 win32_argv_utf8[i] = NULL;
00213 LocalFree(argv_w);
00214
00215 *argc_ptr = win32_argc;
00216 *argv_ptr = win32_argv_utf8;
00217 }
00218 #else
00219 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
00220 {
00221
00222 }
00223 #endif
00224
00225 void parse_options(int argc, char **argv, const OptionDef *options,
00226 int (* parse_arg_function)(const char *opt, const char *arg))
00227 {
00228 const char *opt, *arg;
00229 int optindex, handleoptions=1;
00230 const OptionDef *po;
00231
00232
00233 prepare_app_arguments(&argc, &argv);
00234
00235
00236 optindex = 1;
00237 while (optindex < argc) {
00238 opt = argv[optindex++];
00239
00240 if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
00241 int bool_val = 1;
00242 if (opt[1] == '-' && opt[2] == '\0') {
00243 handleoptions = 0;
00244 continue;
00245 }
00246 opt++;
00247 po= find_option(options, opt);
00248 if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
00249
00250 po = find_option(options, opt + 2);
00251 if (!(po->name && (po->flags & OPT_BOOL)))
00252 goto unknown_opt;
00253 bool_val = 0;
00254 }
00255 if (!po->name)
00256 po= find_option(options, "default");
00257 if (!po->name) {
00258 unknown_opt:
00259 fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
00260 exit(1);
00261 }
00262 arg = NULL;
00263 if (po->flags & HAS_ARG) {
00264 arg = argv[optindex++];
00265 if (!arg) {
00266 fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
00267 exit(1);
00268 }
00269 }
00270 if (po->flags & OPT_STRING) {
00271 char *str;
00272 str = av_strdup(arg);
00273 *po->u.str_arg = str;
00274 } else if (po->flags & OPT_BOOL) {
00275 *po->u.int_arg = bool_val;
00276 } else if (po->flags & OPT_INT) {
00277 *po->u.int_arg = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
00278 } else if (po->flags & OPT_INT64) {
00279 *po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
00280 } else if (po->flags & OPT_FLOAT) {
00281 *po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
00282 } else if (po->u.func_arg) {
00283 if (po->u.func_arg(opt, arg) < 0) {
00284 fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
00285 exit(1);
00286 }
00287 }
00288 if(po->flags & OPT_EXIT)
00289 exit(0);
00290 } else {
00291 if (parse_arg_function) {
00292 if (parse_arg_function(NULL, opt) < 0)
00293 exit(1);
00294 }
00295 }
00296 }
00297 }
00298
00299 #define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
00300 #define SET_PREFIXED_OPTS(ch, flag, output) \
00301 if (opt[0] == ch && avcodec_opts[0] && (o = av_opt_find(avcodec_opts[0], opt+1, NULL, flag, 0)))\
00302 av_dict_set(&output, opt+1, arg, FLAGS);
00303 static int opt_default2(const char *opt, const char *arg)
00304 {
00305 const AVOption *o;
00306 if ((o = av_opt_find(avcodec_opts[0], opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) {
00307 if (o->flags & AV_OPT_FLAG_VIDEO_PARAM)
00308 av_dict_set(&video_opts, opt, arg, FLAGS);
00309 if (o->flags & AV_OPT_FLAG_AUDIO_PARAM)
00310 av_dict_set(&audio_opts, opt, arg, FLAGS);
00311 if (o->flags & AV_OPT_FLAG_SUBTITLE_PARAM)
00312 av_dict_set(&sub_opts, opt, arg, FLAGS);
00313 } else if ((o = av_opt_find(avformat_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN)))
00314 av_dict_set(&format_opts, opt, arg, FLAGS);
00315 else if ((o = av_opt_find(sws_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) {
00316
00317 int ret = av_set_string3(sws_opts, opt, arg, 1, NULL);
00318 if (ret < 0) {
00319 av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
00320 return ret;
00321 }
00322 }
00323
00324 if (!o) {
00325 SET_PREFIXED_OPTS('v', AV_OPT_FLAG_VIDEO_PARAM, video_opts)
00326 SET_PREFIXED_OPTS('a', AV_OPT_FLAG_AUDIO_PARAM, audio_opts)
00327 SET_PREFIXED_OPTS('s', AV_OPT_FLAG_SUBTITLE_PARAM, sub_opts)
00328 }
00329
00330 if (o)
00331 return 0;
00332 fprintf(stderr, "Unrecognized option '%s'\n", opt);
00333 return AVERROR_OPTION_NOT_FOUND;
00334 }
00335
00336 int opt_default(const char *opt, const char *arg){
00337 int type;
00338 int ret= 0;
00339 const AVOption *o= NULL;
00340 int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
00341 AVCodec *p = NULL;
00342 AVOutputFormat *oformat = NULL;
00343 AVInputFormat *iformat = NULL;
00344
00345 while ((p = av_codec_next(p))) {
00346 const AVClass *c = p->priv_class;
00347 if (c && av_find_opt(&c, opt, NULL, 0, 0))
00348 break;
00349 }
00350 if (p)
00351 goto out;
00352 while ((oformat = av_oformat_next(oformat))) {
00353 const AVClass *c = oformat->priv_class;
00354 if (c && av_find_opt(&c, opt, NULL, 0, 0))
00355 break;
00356 }
00357 if (oformat)
00358 goto out;
00359 while ((iformat = av_iformat_next(iformat))) {
00360 const AVClass *c = iformat->priv_class;
00361 if (c && av_find_opt(&c, opt, NULL, 0, 0))
00362 break;
00363 }
00364 if (iformat)
00365 goto out;
00366
00367 for(type=0; *avcodec_opts && type<AVMEDIA_TYPE_NB && ret>= 0; type++){
00368 const AVOption *o2 = av_opt_find(avcodec_opts[0], opt, NULL, opt_types[type], 0);
00369 if(o2)
00370 ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o);
00371 }
00372 if(!o && avformat_opts)
00373 ret = av_set_string3(avformat_opts, opt, arg, 1, &o);
00374 if(!o && sws_opts)
00375 ret = av_set_string3(sws_opts, opt, arg, 1, &o);
00376 if(!o){
00377 if (opt[0] == 'a' && avcodec_opts[AVMEDIA_TYPE_AUDIO])
00378 ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_AUDIO], opt+1, arg, 1, &o);
00379 else if(opt[0] == 'v' && avcodec_opts[AVMEDIA_TYPE_VIDEO])
00380 ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o);
00381 else if(opt[0] == 's' && avcodec_opts[AVMEDIA_TYPE_SUBTITLE])
00382 ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], opt+1, arg, 1, &o);
00383 if (ret >= 0)
00384 opt += 1;
00385 }
00386 if (o && ret < 0) {
00387 fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt);
00388 exit(1);
00389 }
00390 if (!o) {
00391 fprintf(stderr, "Unrecognized option '%s'\n", opt);
00392 exit(1);
00393 }
00394
00395 out:
00396 if ((ret = opt_default2(opt, arg)) < 0)
00397 return ret;
00398
00399
00400
00401 opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1));
00402 opt_values[opt_name_count] = av_strdup(arg);
00403 opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
00404 opt_names[opt_name_count++] = av_strdup(opt);
00405
00406 if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && avformat_opts->debug))
00407 av_log_set_level(AV_LOG_DEBUG);
00408 return 0;
00409 }
00410
00411 int opt_loglevel(const char *opt, const char *arg)
00412 {
00413 const struct { const char *name; int level; } log_levels[] = {
00414 { "quiet" , AV_LOG_QUIET },
00415 { "panic" , AV_LOG_PANIC },
00416 { "fatal" , AV_LOG_FATAL },
00417 { "error" , AV_LOG_ERROR },
00418 { "warning", AV_LOG_WARNING },
00419 { "info" , AV_LOG_INFO },
00420 { "verbose", AV_LOG_VERBOSE },
00421 { "debug" , AV_LOG_DEBUG },
00422 };
00423 char *tail;
00424 int level;
00425 int i;
00426
00427 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
00428 if (!strcmp(log_levels[i].name, arg)) {
00429 av_log_set_level(log_levels[i].level);
00430 return 0;
00431 }
00432 }
00433
00434 level = strtol(arg, &tail, 10);
00435 if (*tail) {
00436 fprintf(stderr, "Invalid loglevel \"%s\". "
00437 "Possible levels are numbers or:\n", arg);
00438 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
00439 fprintf(stderr, "\"%s\"\n", log_levels[i].name);
00440 exit(1);
00441 }
00442 av_log_set_level(level);
00443 return 0;
00444 }
00445
00446 int opt_timelimit(const char *opt, const char *arg)
00447 {
00448 #if HAVE_SETRLIMIT
00449 int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
00450 struct rlimit rl = { lim, lim + 1 };
00451 if (setrlimit(RLIMIT_CPU, &rl))
00452 perror("setrlimit");
00453 #else
00454 fprintf(stderr, "Warning: -%s not implemented on this OS\n", opt);
00455 #endif
00456 return 0;
00457 }
00458
00459 static void *alloc_priv_context(int size, const AVClass *class)
00460 {
00461 void *p = av_mallocz(size);
00462 if (p) {
00463 *(const AVClass **)p = class;
00464 av_opt_set_defaults(p);
00465 }
00466 return p;
00467 }
00468
00469 void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec)
00470 {
00471 int i;
00472 void *priv_ctx=NULL;
00473 if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){
00474 AVCodecContext *avctx= ctx;
00475 if(codec && codec->priv_class){
00476 if(!avctx->priv_data && codec->priv_data_size)
00477 avctx->priv_data= alloc_priv_context(codec->priv_data_size, codec->priv_class);
00478 priv_ctx= avctx->priv_data;
00479 }
00480 } else if (!strcmp("AVFormatContext", (*(AVClass**)ctx)->class_name)) {
00481 AVFormatContext *avctx = ctx;
00482 if (avctx->oformat && avctx->oformat->priv_class) {
00483 priv_ctx = avctx->priv_data;
00484 } else if (avctx->iformat && avctx->iformat->priv_class) {
00485 priv_ctx = avctx->priv_data;
00486 }
00487 }
00488
00489 for(i=0; i<opt_name_count; i++){
00490 char buf[256];
00491 const AVOption *opt;
00492 const char *str;
00493 if (priv_ctx) {
00494 if (av_find_opt(priv_ctx, opt_names[i], NULL, flags, flags)) {
00495 if (av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL) < 0) {
00496 fprintf(stderr, "Invalid value '%s' for option '%s'\n",
00497 opt_names[i], opt_values[i]);
00498 exit(1);
00499 }
00500 } else
00501 goto global;
00502 } else {
00503 global:
00504 str = av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
00505
00506 if (str && ((opt->flags & flags) == flags))
00507 av_set_string3(ctx, opt_names[i], str, 1, NULL);
00508 }
00509 }
00510 }
00511
00512 void print_error(const char *filename, int err)
00513 {
00514 char errbuf[128];
00515 const char *errbuf_ptr = errbuf;
00516
00517 if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
00518 errbuf_ptr = strerror(AVUNERROR(err));
00519 fprintf(stderr, "%s: %s\n", filename, errbuf_ptr);
00520 }
00521
00522 static int warned_cfg = 0;
00523
00524 #define INDENT 1
00525 #define SHOW_VERSION 2
00526 #define SHOW_CONFIG 4
00527
00528 #define PRINT_LIB_INFO(outstream,libname,LIBNAME,flags) \
00529 if (CONFIG_##LIBNAME) { \
00530 const char *indent = flags & INDENT? " " : ""; \
00531 if (flags & SHOW_VERSION) { \
00532 unsigned int version = libname##_version(); \
00533 fprintf(outstream, "%slib%-9s %2d.%3d.%2d / %2d.%3d.%2d\n", \
00534 indent, #libname, \
00535 LIB##LIBNAME##_VERSION_MAJOR, \
00536 LIB##LIBNAME##_VERSION_MINOR, \
00537 LIB##LIBNAME##_VERSION_MICRO, \
00538 version >> 16, version >> 8 & 0xff, version & 0xff); \
00539 } \
00540 if (flags & SHOW_CONFIG) { \
00541 const char *cfg = libname##_configuration(); \
00542 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
00543 if (!warned_cfg) { \
00544 fprintf(outstream, \
00545 "%sWARNING: library configuration mismatch\n", \
00546 indent); \
00547 warned_cfg = 1; \
00548 } \
00549 fprintf(stderr, "%s%-11s configuration: %s\n", \
00550 indent, #libname, cfg); \
00551 } \
00552 } \
00553 } \
00554
00555 static void print_all_libs_info(FILE* outstream, int flags)
00556 {
00557 PRINT_LIB_INFO(outstream, avutil, AVUTIL, flags);
00558 PRINT_LIB_INFO(outstream, avcodec, AVCODEC, flags);
00559 PRINT_LIB_INFO(outstream, avformat, AVFORMAT, flags);
00560 PRINT_LIB_INFO(outstream, avdevice, AVDEVICE, flags);
00561 PRINT_LIB_INFO(outstream, avfilter, AVFILTER, flags);
00562 PRINT_LIB_INFO(outstream, swscale, SWSCALE, flags);
00563 PRINT_LIB_INFO(outstream, postproc, POSTPROC, flags);
00564 }
00565
00566 void show_banner(void)
00567 {
00568 fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n",
00569 program_name, program_birth_year, this_year);
00570 fprintf(stderr, " built on %s %s with %s %s\n",
00571 __DATE__, __TIME__, CC_TYPE, CC_VERSION);
00572 fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n");
00573 print_all_libs_info(stderr, INDENT|SHOW_CONFIG);
00574 print_all_libs_info(stderr, INDENT|SHOW_VERSION);
00575 }
00576
00577 int opt_version(const char *opt, const char *arg) {
00578 printf("%s " FFMPEG_VERSION "\n", program_name);
00579 print_all_libs_info(stdout, SHOW_VERSION);
00580 return 0;
00581 }
00582
00583 int opt_license(const char *opt, const char *arg)
00584 {
00585 printf(
00586 #if CONFIG_NONFREE
00587 "This version of %s has nonfree parts compiled in.\n"
00588 "Therefore it is not legally redistributable.\n",
00589 program_name
00590 #elif CONFIG_GPLV3
00591 "%s is free software; you can redistribute it and/or modify\n"
00592 "it under the terms of the GNU General Public License as published by\n"
00593 "the Free Software Foundation; either version 3 of the License, or\n"
00594 "(at your option) any later version.\n"
00595 "\n"
00596 "%s is distributed in the hope that it will be useful,\n"
00597 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00598 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00599 "GNU General Public License for more details.\n"
00600 "\n"
00601 "You should have received a copy of the GNU General Public License\n"
00602 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
00603 program_name, program_name, program_name
00604 #elif CONFIG_GPL
00605 "%s is free software; you can redistribute it and/or modify\n"
00606 "it under the terms of the GNU General Public License as published by\n"
00607 "the Free Software Foundation; either version 2 of the License, or\n"
00608 "(at your option) any later version.\n"
00609 "\n"
00610 "%s is distributed in the hope that it will be useful,\n"
00611 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00612 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00613 "GNU General Public License for more details.\n"
00614 "\n"
00615 "You should have received a copy of the GNU General Public License\n"
00616 "along with %s; if not, write to the Free Software\n"
00617 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
00618 program_name, program_name, program_name
00619 #elif CONFIG_LGPLV3
00620 "%s is free software; you can redistribute it and/or modify\n"
00621 "it under the terms of the GNU Lesser General Public License as published by\n"
00622 "the Free Software Foundation; either version 3 of the License, or\n"
00623 "(at your option) any later version.\n"
00624 "\n"
00625 "%s is distributed in the hope that it will be useful,\n"
00626 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00627 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00628 "GNU Lesser General Public License for more details.\n"
00629 "\n"
00630 "You should have received a copy of the GNU Lesser General Public License\n"
00631 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
00632 program_name, program_name, program_name
00633 #else
00634 "%s is free software; you can redistribute it and/or\n"
00635 "modify it under the terms of the GNU Lesser General Public\n"
00636 "License as published by the Free Software Foundation; either\n"
00637 "version 2.1 of the License, or (at your option) any later version.\n"
00638 "\n"
00639 "%s is distributed in the hope that it will be useful,\n"
00640 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00641 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
00642 "Lesser General Public License for more details.\n"
00643 "\n"
00644 "You should have received a copy of the GNU Lesser General Public\n"
00645 "License along with %s; if not, write to the Free Software\n"
00646 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
00647 program_name, program_name, program_name
00648 #endif
00649 );
00650 return 0;
00651 }
00652
00653 int opt_formats(const char *opt, const char *arg)
00654 {
00655 AVInputFormat *ifmt=NULL;
00656 AVOutputFormat *ofmt=NULL;
00657 const char *last_name;
00658
00659 printf(
00660 "File formats:\n"
00661 " D. = Demuxing supported\n"
00662 " .E = Muxing supported\n"
00663 " --\n");
00664 last_name= "000";
00665 for(;;){
00666 int decode=0;
00667 int encode=0;
00668 const char *name=NULL;
00669 const char *long_name=NULL;
00670
00671 while((ofmt= av_oformat_next(ofmt))) {
00672 if((name == NULL || strcmp(ofmt->name, name)<0) &&
00673 strcmp(ofmt->name, last_name)>0){
00674 name= ofmt->name;
00675 long_name= ofmt->long_name;
00676 encode=1;
00677 }
00678 }
00679 while((ifmt= av_iformat_next(ifmt))) {
00680 if((name == NULL || strcmp(ifmt->name, name)<0) &&
00681 strcmp(ifmt->name, last_name)>0){
00682 name= ifmt->name;
00683 long_name= ifmt->long_name;
00684 encode=0;
00685 }
00686 if(name && strcmp(ifmt->name, name)==0)
00687 decode=1;
00688 }
00689 if(name==NULL)
00690 break;
00691 last_name= name;
00692
00693 printf(
00694 " %s%s %-15s %s\n",
00695 decode ? "D":" ",
00696 encode ? "E":" ",
00697 name,
00698 long_name ? long_name:" ");
00699 }
00700 return 0;
00701 }
00702
00703 int opt_codecs(const char *opt, const char *arg)
00704 {
00705 AVCodec *p=NULL, *p2;
00706 const char *last_name;
00707 printf(
00708 "Codecs:\n"
00709 " D..... = Decoding supported\n"
00710 " .E.... = Encoding supported\n"
00711 " ..V... = Video codec\n"
00712 " ..A... = Audio codec\n"
00713 " ..S... = Subtitle codec\n"
00714 " ...S.. = Supports draw_horiz_band\n"
00715 " ....D. = Supports direct rendering method 1\n"
00716 " .....T = Supports weird frame truncation\n"
00717 " ------\n");
00718 last_name= "000";
00719 for(;;){
00720 int decode=0;
00721 int encode=0;
00722 int cap=0;
00723 const char *type_str;
00724
00725 p2=NULL;
00726 while((p= av_codec_next(p))) {
00727 if((p2==NULL || strcmp(p->name, p2->name)<0) &&
00728 strcmp(p->name, last_name)>0){
00729 p2= p;
00730 decode= encode= cap=0;
00731 }
00732 if(p2 && strcmp(p->name, p2->name)==0){
00733 if(p->decode) decode=1;
00734 if(p->encode) encode=1;
00735 cap |= p->capabilities;
00736 }
00737 }
00738 if(p2==NULL)
00739 break;
00740 last_name= p2->name;
00741
00742 switch(p2->type) {
00743 case AVMEDIA_TYPE_VIDEO:
00744 type_str = "V";
00745 break;
00746 case AVMEDIA_TYPE_AUDIO:
00747 type_str = "A";
00748 break;
00749 case AVMEDIA_TYPE_SUBTITLE:
00750 type_str = "S";
00751 break;
00752 default:
00753 type_str = "?";
00754 break;
00755 }
00756 printf(
00757 " %s%s%s%s%s%s %-15s %s",
00758 decode ? "D": (" "),
00759 encode ? "E":" ",
00760 type_str,
00761 cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ",
00762 cap & CODEC_CAP_DR1 ? "D":" ",
00763 cap & CODEC_CAP_TRUNCATED ? "T":" ",
00764 p2->name,
00765 p2->long_name ? p2->long_name : "");
00766
00767
00768 printf("\n");
00769 }
00770 printf("\n");
00771 printf(
00772 "Note, the names of encoders and decoders do not always match, so there are\n"
00773 "several cases where the above table shows encoder only or decoder only entries\n"
00774 "even though both encoding and decoding are supported. For example, the h263\n"
00775 "decoder corresponds to the h263 and h263p encoders, for file formats it is even\n"
00776 "worse.\n");
00777 return 0;
00778 }
00779
00780 int opt_bsfs(const char *opt, const char *arg)
00781 {
00782 AVBitStreamFilter *bsf=NULL;
00783
00784 printf("Bitstream filters:\n");
00785 while((bsf = av_bitstream_filter_next(bsf)))
00786 printf("%s\n", bsf->name);
00787 printf("\n");
00788 return 0;
00789 }
00790
00791 int opt_protocols(const char *opt, const char *arg)
00792 {
00793 URLProtocol *up=NULL;
00794
00795 printf("Supported file protocols:\n"
00796 "I.. = Input supported\n"
00797 ".O. = Output supported\n"
00798 "..S = Seek supported\n"
00799 "FLAGS NAME\n"
00800 "----- \n");
00801 while((up = av_protocol_next(up)))
00802 printf("%c%c%c %s\n",
00803 up->url_read ? 'I' : '.',
00804 up->url_write ? 'O' : '.',
00805 up->url_seek ? 'S' : '.',
00806 up->name);
00807 return 0;
00808 }
00809
00810 int opt_filters(const char *opt, const char *arg)
00811 {
00812 AVFilter av_unused(**filter) = NULL;
00813
00814 printf("Filters:\n");
00815 #if CONFIG_AVFILTER
00816 while ((filter = av_filter_next(filter)) && *filter)
00817 printf("%-16s %s\n", (*filter)->name, (*filter)->description);
00818 #endif
00819 return 0;
00820 }
00821
00822 int opt_pix_fmts(const char *opt, const char *arg)
00823 {
00824 enum PixelFormat pix_fmt;
00825
00826 printf(
00827 "Pixel formats:\n"
00828 "I.... = Supported Input format for conversion\n"
00829 ".O... = Supported Output format for conversion\n"
00830 "..H.. = Hardware accelerated format\n"
00831 "...P. = Paletted format\n"
00832 "....B = Bitstream format\n"
00833 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
00834 "-----\n");
00835
00836 #if !CONFIG_SWSCALE
00837 # define sws_isSupportedInput(x) 0
00838 # define sws_isSupportedOutput(x) 0
00839 #endif
00840
00841 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) {
00842 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt];
00843 printf("%c%c%c%c%c %-16s %d %2d\n",
00844 sws_isSupportedInput (pix_fmt) ? 'I' : '.',
00845 sws_isSupportedOutput(pix_fmt) ? 'O' : '.',
00846 pix_desc->flags & PIX_FMT_HWACCEL ? 'H' : '.',
00847 pix_desc->flags & PIX_FMT_PAL ? 'P' : '.',
00848 pix_desc->flags & PIX_FMT_BITSTREAM ? 'B' : '.',
00849 pix_desc->name,
00850 pix_desc->nb_components,
00851 av_get_bits_per_pixel(pix_desc));
00852 }
00853 return 0;
00854 }
00855
00856 int read_yesno(void)
00857 {
00858 int c = getchar();
00859 int yesno = (toupper(c) == 'Y');
00860
00861 while (c != '\n' && c != EOF)
00862 c = getchar();
00863
00864 return yesno;
00865 }
00866
00867 int read_file(const char *filename, char **bufptr, size_t *size)
00868 {
00869 FILE *f = fopen(filename, "rb");
00870
00871 if (!f) {
00872 fprintf(stderr, "Cannot read file '%s': %s\n", filename, strerror(errno));
00873 return AVERROR(errno);
00874 }
00875 fseek(f, 0, SEEK_END);
00876 *size = ftell(f);
00877 fseek(f, 0, SEEK_SET);
00878 *bufptr = av_malloc(*size + 1);
00879 if (!*bufptr) {
00880 fprintf(stderr, "Could not allocate file buffer\n");
00881 fclose(f);
00882 return AVERROR(ENOMEM);
00883 }
00884 fread(*bufptr, 1, *size, f);
00885 (*bufptr)[*size++] = '\0';
00886
00887 fclose(f);
00888 return 0;
00889 }
00890
00891 FILE *get_preset_file(char *filename, size_t filename_size,
00892 const char *preset_name, int is_path, const char *codec_name)
00893 {
00894 FILE *f = NULL;
00895 int i;
00896 const char *base[3]= { getenv("FFMPEG_DATADIR"),
00897 getenv("HOME"),
00898 FFMPEG_DATADIR,
00899 };
00900
00901 if (is_path) {
00902 av_strlcpy(filename, preset_name, filename_size);
00903 f = fopen(filename, "r");
00904 } else {
00905 #ifdef _WIN32
00906 char datadir[MAX_PATH], *ls;
00907 base[2] = NULL;
00908
00909 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
00910 {
00911 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
00912 if (*ls == '\\') *ls = '/';
00913
00914 if (ls = strrchr(datadir, '/'))
00915 {
00916 *ls = 0;
00917 strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
00918 base[2] = datadir;
00919 }
00920 }
00921 #endif
00922 for (i = 0; i < 3 && !f; i++) {
00923 if (!base[i])
00924 continue;
00925 snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", preset_name);
00926 f = fopen(filename, "r");
00927 if (!f && codec_name) {
00928 snprintf(filename, filename_size,
00929 "%s%s/%s-%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", codec_name, preset_name);
00930 f = fopen(filename, "r");
00931 }
00932 }
00933 }
00934
00935 return f;
00936 }