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