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