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