Libav
|
00001 /* 00002 * Various utilities for command line tools 00003 * Copyright (c) 2000-2003 Fabrice Bellard 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #include <string.h> 00023 #include <stdlib.h> 00024 #include <errno.h> 00025 #include <math.h> 00026 00027 /* Include only the enabled headers since some compilers (namely, Sun 00028 Studio) will not omit unused inline functions and create undefined 00029 references to libraries that are not being built. */ 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 /* parse options */ 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 /* handle 'no' bool option */ 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 // av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL)); 00221 00222 //FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this 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 /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */ 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 const char *errbuf_ptr = errbuf; 00296 00297 if (av_strerror(err, errbuf, sizeof(errbuf)) < 0) 00298 errbuf_ptr = strerror(AVUNERROR(err)); 00299 fprintf(stderr, "%s: %s\n", filename, errbuf_ptr); 00300 } 00301 00302 #define PRINT_LIB_VERSION(outstream,libname,LIBNAME,indent) \ 00303 if (CONFIG_##LIBNAME) { \ 00304 unsigned int version = libname##_version(); \ 00305 fprintf(outstream, "%slib%-10s %2d.%2d.%2d / %2d.%2d.%2d\n", \ 00306 indent? " " : "", #libname, \ 00307 LIB##LIBNAME##_VERSION_MAJOR, \ 00308 LIB##LIBNAME##_VERSION_MINOR, \ 00309 LIB##LIBNAME##_VERSION_MICRO, \ 00310 version >> 16, version >> 8 & 0xff, version & 0xff); \ 00311 } 00312 00313 static void print_all_lib_versions(FILE* outstream, int indent) 00314 { 00315 PRINT_LIB_VERSION(outstream, avutil, AVUTIL, indent); 00316 PRINT_LIB_VERSION(outstream, avcodec, AVCODEC, indent); 00317 PRINT_LIB_VERSION(outstream, avformat, AVFORMAT, indent); 00318 PRINT_LIB_VERSION(outstream, avdevice, AVDEVICE, indent); 00319 PRINT_LIB_VERSION(outstream, avfilter, AVFILTER, indent); 00320 PRINT_LIB_VERSION(outstream, swscale, SWSCALE, indent); 00321 PRINT_LIB_VERSION(outstream, postproc, POSTPROC, indent); 00322 } 00323 00324 static void maybe_print_config(const char *lib, const char *cfg) 00325 { 00326 static int warned_cfg; 00327 00328 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { 00329 if (!warned_cfg) { 00330 fprintf(stderr, " WARNING: library configuration mismatch\n"); 00331 warned_cfg = 1; 00332 } 00333 fprintf(stderr, " %-11s configuration: %s\n", lib, cfg); 00334 } 00335 } 00336 00337 #define PRINT_LIB_CONFIG(lib, tag, cfg) do { \ 00338 if (CONFIG_##lib) \ 00339 maybe_print_config(tag, cfg); \ 00340 } while (0) 00341 00342 void show_banner(void) 00343 { 00344 fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the Libav developers\n", 00345 program_name, program_birth_year, this_year); 00346 fprintf(stderr, " built on %s %s with %s %s\n", 00347 __DATE__, __TIME__, CC_TYPE, CC_VERSION); 00348 fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n"); 00349 PRINT_LIB_CONFIG(AVUTIL, "libavutil", avutil_configuration()); 00350 PRINT_LIB_CONFIG(AVCODEC, "libavcodec", avcodec_configuration()); 00351 PRINT_LIB_CONFIG(AVFORMAT, "libavformat", avformat_configuration()); 00352 PRINT_LIB_CONFIG(AVDEVICE, "libavdevice", avdevice_configuration()); 00353 PRINT_LIB_CONFIG(AVFILTER, "libavfilter", avfilter_configuration()); 00354 PRINT_LIB_CONFIG(SWSCALE, "libswscale", swscale_configuration()); 00355 PRINT_LIB_CONFIG(POSTPROC, "libpostproc", postproc_configuration()); 00356 print_all_lib_versions(stderr, 1); 00357 } 00358 00359 void show_version(void) { 00360 printf("%s " FFMPEG_VERSION "\n", program_name); 00361 print_all_lib_versions(stdout, 0); 00362 } 00363 00364 void show_license(void) 00365 { 00366 printf( 00367 #if CONFIG_NONFREE 00368 "This version of %s has nonfree parts compiled in.\n" 00369 "Therefore it is not legally redistributable.\n", 00370 program_name 00371 #elif CONFIG_GPLV3 00372 "%s is free software; you can redistribute it and/or modify\n" 00373 "it under the terms of the GNU General Public License as published by\n" 00374 "the Free Software Foundation; either version 3 of the License, or\n" 00375 "(at your option) any later version.\n" 00376 "\n" 00377 "%s is distributed in the hope that it will be useful,\n" 00378 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 00379 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 00380 "GNU General Public License for more details.\n" 00381 "\n" 00382 "You should have received a copy of the GNU General Public License\n" 00383 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n", 00384 program_name, program_name, program_name 00385 #elif CONFIG_GPL 00386 "%s is free software; you can redistribute it and/or modify\n" 00387 "it under the terms of the GNU General Public License as published by\n" 00388 "the Free Software Foundation; either version 2 of the License, or\n" 00389 "(at your option) any later version.\n" 00390 "\n" 00391 "%s is distributed in the hope that it will be useful,\n" 00392 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 00393 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 00394 "GNU General Public License for more details.\n" 00395 "\n" 00396 "You should have received a copy of the GNU General Public License\n" 00397 "along with %s; if not, write to the Free Software\n" 00398 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n", 00399 program_name, program_name, program_name 00400 #elif CONFIG_LGPLV3 00401 "%s is free software; you can redistribute it and/or modify\n" 00402 "it under the terms of the GNU Lesser General Public License as published by\n" 00403 "the Free Software Foundation; either version 3 of the License, or\n" 00404 "(at your option) any later version.\n" 00405 "\n" 00406 "%s is distributed in the hope that it will be useful,\n" 00407 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 00408 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 00409 "GNU Lesser General Public License for more details.\n" 00410 "\n" 00411 "You should have received a copy of the GNU Lesser General Public License\n" 00412 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n", 00413 program_name, program_name, program_name 00414 #else 00415 "%s is free software; you can redistribute it and/or\n" 00416 "modify it under the terms of the GNU Lesser General Public\n" 00417 "License as published by the Free Software Foundation; either\n" 00418 "version 2.1 of the License, or (at your option) any later version.\n" 00419 "\n" 00420 "%s is distributed in the hope that it will be useful,\n" 00421 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 00422 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" 00423 "Lesser General Public License for more details.\n" 00424 "\n" 00425 "You should have received a copy of the GNU Lesser General Public\n" 00426 "License along with %s; if not, write to the Free Software\n" 00427 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n", 00428 program_name, program_name, program_name 00429 #endif 00430 ); 00431 } 00432 00433 void list_fmts(void (*get_fmt_string)(char *buf, int buf_size, int fmt), int nb_fmts) 00434 { 00435 int i; 00436 char fmt_str[128]; 00437 for (i=-1; i < nb_fmts; i++) { 00438 get_fmt_string (fmt_str, sizeof(fmt_str), i); 00439 fprintf(stdout, "%s\n", fmt_str); 00440 } 00441 } 00442 00443 void show_formats(void) 00444 { 00445 AVInputFormat *ifmt=NULL; 00446 AVOutputFormat *ofmt=NULL; 00447 const char *last_name; 00448 00449 printf( 00450 "File formats:\n" 00451 " D. = Demuxing supported\n" 00452 " .E = Muxing supported\n" 00453 " --\n"); 00454 last_name= "000"; 00455 for(;;){ 00456 int decode=0; 00457 int encode=0; 00458 const char *name=NULL; 00459 const char *long_name=NULL; 00460 00461 while((ofmt= av_oformat_next(ofmt))) { 00462 if((name == NULL || strcmp(ofmt->name, name)<0) && 00463 strcmp(ofmt->name, last_name)>0){ 00464 name= ofmt->name; 00465 long_name= ofmt->long_name; 00466 encode=1; 00467 } 00468 } 00469 while((ifmt= av_iformat_next(ifmt))) { 00470 if((name == NULL || strcmp(ifmt->name, name)<0) && 00471 strcmp(ifmt->name, last_name)>0){ 00472 name= ifmt->name; 00473 long_name= ifmt->long_name; 00474 encode=0; 00475 } 00476 if(name && strcmp(ifmt->name, name)==0) 00477 decode=1; 00478 } 00479 if(name==NULL) 00480 break; 00481 last_name= name; 00482 00483 printf( 00484 " %s%s %-15s %s\n", 00485 decode ? "D":" ", 00486 encode ? "E":" ", 00487 name, 00488 long_name ? long_name:" "); 00489 } 00490 } 00491 00492 void show_codecs(void) 00493 { 00494 AVCodec *p=NULL, *p2; 00495 const char *last_name; 00496 printf( 00497 "Codecs:\n" 00498 " D..... = Decoding supported\n" 00499 " .E.... = Encoding supported\n" 00500 " ..V... = Video codec\n" 00501 " ..A... = Audio codec\n" 00502 " ..S... = Subtitle codec\n" 00503 " ...S.. = Supports draw_horiz_band\n" 00504 " ....D. = Supports direct rendering method 1\n" 00505 " .....T = Supports weird frame truncation\n" 00506 " ------\n"); 00507 last_name= "000"; 00508 for(;;){ 00509 int decode=0; 00510 int encode=0; 00511 int cap=0; 00512 const char *type_str; 00513 00514 p2=NULL; 00515 while((p= av_codec_next(p))) { 00516 if((p2==NULL || strcmp(p->name, p2->name)<0) && 00517 strcmp(p->name, last_name)>0){ 00518 p2= p; 00519 decode= encode= cap=0; 00520 } 00521 if(p2 && strcmp(p->name, p2->name)==0){ 00522 if(p->decode) decode=1; 00523 if(p->encode) encode=1; 00524 cap |= p->capabilities; 00525 } 00526 } 00527 if(p2==NULL) 00528 break; 00529 last_name= p2->name; 00530 00531 switch(p2->type) { 00532 case AVMEDIA_TYPE_VIDEO: 00533 type_str = "V"; 00534 break; 00535 case AVMEDIA_TYPE_AUDIO: 00536 type_str = "A"; 00537 break; 00538 case AVMEDIA_TYPE_SUBTITLE: 00539 type_str = "S"; 00540 break; 00541 default: 00542 type_str = "?"; 00543 break; 00544 } 00545 printf( 00546 " %s%s%s%s%s%s %-15s %s", 00547 decode ? "D": (/*p2->decoder ? "d":*/" "), 00548 encode ? "E":" ", 00549 type_str, 00550 cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ", 00551 cap & CODEC_CAP_DR1 ? "D":" ", 00552 cap & CODEC_CAP_TRUNCATED ? "T":" ", 00553 p2->name, 00554 p2->long_name ? p2->long_name : ""); 00555 /* if(p2->decoder && decode==0) 00556 printf(" use %s for decoding", p2->decoder->name);*/ 00557 printf("\n"); 00558 } 00559 printf("\n"); 00560 printf( 00561 "Note, the names of encoders and decoders do not always match, so there are\n" 00562 "several cases where the above table shows encoder only or decoder only entries\n" 00563 "even though both encoding and decoding are supported. For example, the h263\n" 00564 "decoder corresponds to the h263 and h263p encoders, for file formats it is even\n" 00565 "worse.\n"); 00566 } 00567 00568 void show_bsfs(void) 00569 { 00570 AVBitStreamFilter *bsf=NULL; 00571 00572 printf("Bitstream filters:\n"); 00573 while((bsf = av_bitstream_filter_next(bsf))) 00574 printf("%s\n", bsf->name); 00575 printf("\n"); 00576 } 00577 00578 void show_protocols(void) 00579 { 00580 URLProtocol *up=NULL; 00581 00582 printf("Supported file protocols:\n"); 00583 while((up = av_protocol_next(up))) 00584 printf("%s\n", up->name); 00585 } 00586 00587 void show_filters(void) 00588 { 00589 AVFilter av_unused(**filter) = NULL; 00590 00591 printf("Filters:\n"); 00592 #if CONFIG_AVFILTER 00593 while ((filter = av_filter_next(filter)) && *filter) 00594 printf("%-16s %s\n", (*filter)->name, (*filter)->description); 00595 #endif 00596 } 00597 00598 void show_pix_fmts(void) 00599 { 00600 enum PixelFormat pix_fmt; 00601 00602 printf( 00603 "Pixel formats:\n" 00604 "I.... = Supported Input format for conversion\n" 00605 ".O... = Supported Output format for conversion\n" 00606 "..H.. = Hardware accelerated format\n" 00607 "...P. = Paletted format\n" 00608 "....B = Bitstream format\n" 00609 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n" 00610 "-----\n"); 00611 00612 #if !CONFIG_SWSCALE 00613 # define sws_isSupportedInput(x) 0 00614 # define sws_isSupportedOutput(x) 0 00615 #endif 00616 00617 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) { 00618 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt]; 00619 printf("%c%c%c%c%c %-16s %d %2d\n", 00620 sws_isSupportedInput (pix_fmt) ? 'I' : '.', 00621 sws_isSupportedOutput(pix_fmt) ? 'O' : '.', 00622 pix_desc->flags & PIX_FMT_HWACCEL ? 'H' : '.', 00623 pix_desc->flags & PIX_FMT_PAL ? 'P' : '.', 00624 pix_desc->flags & PIX_FMT_BITSTREAM ? 'B' : '.', 00625 pix_desc->name, 00626 pix_desc->nb_components, 00627 av_get_bits_per_pixel(pix_desc)); 00628 } 00629 } 00630 00631 int read_yesno(void) 00632 { 00633 int c = getchar(); 00634 int yesno = (toupper(c) == 'Y'); 00635 00636 while (c != '\n' && c != EOF) 00637 c = getchar(); 00638 00639 return yesno; 00640 } 00641 00642 int read_file(const char *filename, char **bufptr, size_t *size) 00643 { 00644 FILE *f = fopen(filename, "rb"); 00645 00646 if (!f) { 00647 fprintf(stderr, "Cannot read file '%s': %s\n", filename, strerror(errno)); 00648 return AVERROR(errno); 00649 } 00650 fseek(f, 0, SEEK_END); 00651 *size = ftell(f); 00652 fseek(f, 0, SEEK_SET); 00653 *bufptr = av_malloc(*size + 1); 00654 if (!*bufptr) { 00655 fprintf(stderr, "Could not allocate file buffer\n"); 00656 fclose(f); 00657 return AVERROR(ENOMEM); 00658 } 00659 fread(*bufptr, 1, *size, f); 00660 (*bufptr)[*size++] = '\0'; 00661 00662 fclose(f); 00663 return 0; 00664 }