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 {
00218 po->u.func_arg(arg);
00219 }
00220 if(po->flags & OPT_EXIT)
00221 exit(0);
00222 } else {
00223 if (parse_arg_function)
00224 parse_arg_function(opt);
00225 }
00226 }
00227 }
00228
00229 int opt_default(const char *opt, const char *arg){
00230 int type;
00231 int ret= 0;
00232 const AVOption *o= NULL;
00233 int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
00234
00235 for(type=0; *avcodec_opts && type<AVMEDIA_TYPE_NB && ret>= 0; type++){
00236 const AVOption *o2 = av_find_opt(avcodec_opts[0], opt, NULL, opt_types[type], opt_types[type]);
00237 if(o2)
00238 ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o);
00239 }
00240 if(!o && avformat_opts)
00241 ret = av_set_string3(avformat_opts, opt, arg, 1, &o);
00242 if(!o && sws_opts)
00243 ret = av_set_string3(sws_opts, opt, arg, 1, &o);
00244 if(!o){
00245 if (opt[0] == 'a' && avcodec_opts[AVMEDIA_TYPE_AUDIO])
00246 ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_AUDIO], opt+1, arg, 1, &o);
00247 else if(opt[0] == 'v' && avcodec_opts[AVMEDIA_TYPE_VIDEO])
00248 ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o);
00249 else if(opt[0] == 's' && avcodec_opts[AVMEDIA_TYPE_SUBTITLE])
00250 ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], opt+1, arg, 1, &o);
00251 }
00252 if (o && ret < 0) {
00253 fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt);
00254 exit(1);
00255 }
00256 if (!o) {
00257 AVCodec *p = NULL;
00258 AVOutputFormat *oformat = NULL;
00259 while ((p=av_codec_next(p))){
00260 AVClass *c= p->priv_class;
00261 if(c && av_find_opt(&c, opt, NULL, 0, 0))
00262 break;
00263 }
00264 if (!p) {
00265 while ((oformat = av_oformat_next(oformat))) {
00266 const AVClass *c = oformat->priv_class;
00267 if (c && av_find_opt(&c, opt, NULL, 0, 0))
00268 break;
00269 }
00270 }
00271 if(!p && !oformat){
00272 fprintf(stderr, "Unrecognized option '%s'\n", opt);
00273 exit(1);
00274 }
00275 }
00276
00277
00278
00279
00280 opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1));
00281 opt_values[opt_name_count]= o ? NULL : av_strdup(arg);
00282 opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
00283 opt_names[opt_name_count++]= o ? o->name : av_strdup(opt);
00284
00285 if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && avformat_opts->debug))
00286 av_log_set_level(AV_LOG_DEBUG);
00287 return 0;
00288 }
00289
00290 int opt_loglevel(const char *opt, const char *arg)
00291 {
00292 const struct { const char *name; int level; } log_levels[] = {
00293 { "quiet" , AV_LOG_QUIET },
00294 { "panic" , AV_LOG_PANIC },
00295 { "fatal" , AV_LOG_FATAL },
00296 { "error" , AV_LOG_ERROR },
00297 { "warning", AV_LOG_WARNING },
00298 { "info" , AV_LOG_INFO },
00299 { "verbose", AV_LOG_VERBOSE },
00300 { "debug" , AV_LOG_DEBUG },
00301 };
00302 char *tail;
00303 int level;
00304 int i;
00305
00306 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
00307 if (!strcmp(log_levels[i].name, arg)) {
00308 av_log_set_level(log_levels[i].level);
00309 return 0;
00310 }
00311 }
00312
00313 level = strtol(arg, &tail, 10);
00314 if (*tail) {
00315 fprintf(stderr, "Invalid loglevel \"%s\". "
00316 "Possible levels are numbers or:\n", arg);
00317 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
00318 fprintf(stderr, "\"%s\"\n", log_levels[i].name);
00319 exit(1);
00320 }
00321 av_log_set_level(level);
00322 return 0;
00323 }
00324
00325 int opt_timelimit(const char *opt, const char *arg)
00326 {
00327 #if HAVE_SETRLIMIT
00328 int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
00329 struct rlimit rl = { lim, lim + 1 };
00330 if (setrlimit(RLIMIT_CPU, &rl))
00331 perror("setrlimit");
00332 #else
00333 fprintf(stderr, "Warning: -%s not implemented on this OS\n", opt);
00334 #endif
00335 return 0;
00336 }
00337
00338 void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec)
00339 {
00340 int i;
00341 void *priv_ctx=NULL;
00342 if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){
00343 AVCodecContext *avctx= ctx;
00344 if(codec && codec->priv_class && avctx->priv_data){
00345 priv_ctx= avctx->priv_data;
00346 }
00347 } else if (!strcmp("AVFormatContext", (*(AVClass**)ctx)->class_name)) {
00348 AVFormatContext *avctx = ctx;
00349 if (avctx->oformat && avctx->oformat->priv_class) {
00350 priv_ctx = avctx->priv_data;
00351 }
00352 }
00353
00354 for(i=0; i<opt_name_count; i++){
00355 char buf[256];
00356 const AVOption *opt;
00357 const char *str= av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
00358
00359 if(str && ((opt->flags & flags) == flags))
00360 av_set_string3(ctx, opt_names[i], str, 1, NULL);
00361
00362
00363
00364 if(!str && priv_ctx && av_get_string(priv_ctx, opt_names[i], &opt, buf, sizeof(buf))){
00365 av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL);
00366 }
00367 }
00368 }
00369
00370 void print_error(const char *filename, int err)
00371 {
00372 char errbuf[128];
00373 const char *errbuf_ptr = errbuf;
00374
00375 if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
00376 errbuf_ptr = strerror(AVUNERROR(err));
00377 fprintf(stderr, "%s: %s\n", filename, errbuf_ptr);
00378 }
00379
00380 static int warned_cfg = 0;
00381
00382 #define INDENT 1
00383 #define SHOW_VERSION 2
00384 #define SHOW_CONFIG 4
00385
00386 #define PRINT_LIB_INFO(outstream,libname,LIBNAME,flags) \
00387 if (CONFIG_##LIBNAME) { \
00388 const char *indent = flags & INDENT? " " : ""; \
00389 if (flags & SHOW_VERSION) { \
00390 unsigned int version = libname##_version(); \
00391 fprintf(outstream, "%slib%-9s %2d.%3d.%2d / %2d.%3d.%2d\n", \
00392 indent, #libname, \
00393 LIB##LIBNAME##_VERSION_MAJOR, \
00394 LIB##LIBNAME##_VERSION_MINOR, \
00395 LIB##LIBNAME##_VERSION_MICRO, \
00396 version >> 16, version >> 8 & 0xff, version & 0xff); \
00397 } \
00398 if (flags & SHOW_CONFIG) { \
00399 const char *cfg = libname##_configuration(); \
00400 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
00401 if (!warned_cfg) { \
00402 fprintf(outstream, \
00403 "%sWARNING: library configuration mismatch\n", \
00404 indent); \
00405 warned_cfg = 1; \
00406 } \
00407 fprintf(stderr, "%s%-11s configuration: %s\n", \
00408 indent, #libname, cfg); \
00409 } \
00410 } \
00411 } \
00412
00413 static void print_all_libs_info(FILE* outstream, int flags)
00414 {
00415 PRINT_LIB_INFO(outstream, avutil, AVUTIL, flags);
00416 PRINT_LIB_INFO(outstream, avcodec, AVCODEC, flags);
00417 PRINT_LIB_INFO(outstream, avformat, AVFORMAT, flags);
00418 PRINT_LIB_INFO(outstream, avdevice, AVDEVICE, flags);
00419 PRINT_LIB_INFO(outstream, avfilter, AVFILTER, flags);
00420 PRINT_LIB_INFO(outstream, swscale, SWSCALE, flags);
00421 PRINT_LIB_INFO(outstream, postproc, POSTPROC, flags);
00422 }
00423
00424 void show_banner(void)
00425 {
00426 fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n",
00427 program_name, program_birth_year, this_year);
00428 fprintf(stderr, " built on %s %s with %s %s\n",
00429 __DATE__, __TIME__, CC_TYPE, CC_VERSION);
00430 fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n");
00431 print_all_libs_info(stderr, INDENT|SHOW_CONFIG);
00432 print_all_libs_info(stderr, INDENT|SHOW_VERSION);
00433 }
00434
00435 void show_version(void) {
00436 printf("%s " FFMPEG_VERSION "\n", program_name);
00437 print_all_libs_info(stdout, SHOW_VERSION);
00438 }
00439
00440 void show_license(void)
00441 {
00442 printf(
00443 #if CONFIG_NONFREE
00444 "This version of %s has nonfree parts compiled in.\n"
00445 "Therefore it is not legally redistributable.\n",
00446 program_name
00447 #elif CONFIG_GPLV3
00448 "%s is free software; you can redistribute it and/or modify\n"
00449 "it under the terms of the GNU General Public License as published by\n"
00450 "the Free Software Foundation; either version 3 of the License, or\n"
00451 "(at your option) any later version.\n"
00452 "\n"
00453 "%s is distributed in the hope that it will be useful,\n"
00454 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00455 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00456 "GNU General Public License for more details.\n"
00457 "\n"
00458 "You should have received a copy of the GNU General Public License\n"
00459 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
00460 program_name, program_name, program_name
00461 #elif CONFIG_GPL
00462 "%s is free software; you can redistribute it and/or modify\n"
00463 "it under the terms of the GNU General Public License as published by\n"
00464 "the Free Software Foundation; either version 2 of the License, or\n"
00465 "(at your option) any later version.\n"
00466 "\n"
00467 "%s is distributed in the hope that it will be useful,\n"
00468 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00469 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00470 "GNU General Public License for more details.\n"
00471 "\n"
00472 "You should have received a copy of the GNU General Public License\n"
00473 "along with %s; if not, write to the Free Software\n"
00474 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
00475 program_name, program_name, program_name
00476 #elif CONFIG_LGPLV3
00477 "%s is free software; you can redistribute it and/or modify\n"
00478 "it under the terms of the GNU Lesser General Public License as published by\n"
00479 "the Free Software Foundation; either version 3 of the License, or\n"
00480 "(at your option) any later version.\n"
00481 "\n"
00482 "%s is distributed in the hope that it will be useful,\n"
00483 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00484 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00485 "GNU Lesser General Public License for more details.\n"
00486 "\n"
00487 "You should have received a copy of the GNU Lesser General Public License\n"
00488 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
00489 program_name, program_name, program_name
00490 #else
00491 "%s is free software; you can redistribute it and/or\n"
00492 "modify it under the terms of the GNU Lesser General Public\n"
00493 "License as published by the Free Software Foundation; either\n"
00494 "version 2.1 of the License, or (at your option) any later version.\n"
00495 "\n"
00496 "%s is distributed in the hope that it will be useful,\n"
00497 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00498 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
00499 "Lesser General Public License for more details.\n"
00500 "\n"
00501 "You should have received a copy of the GNU Lesser General Public\n"
00502 "License along with %s; if not, write to the Free Software\n"
00503 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
00504 program_name, program_name, program_name
00505 #endif
00506 );
00507 }
00508
00509 void list_fmts(void (*get_fmt_string)(char *buf, int buf_size, int fmt), int nb_fmts)
00510 {
00511 int i;
00512 char fmt_str[128];
00513 for (i=-1; i < nb_fmts; i++) {
00514 get_fmt_string (fmt_str, sizeof(fmt_str), i);
00515 fprintf(stdout, "%s\n", fmt_str);
00516 }
00517 }
00518
00519 void show_formats(void)
00520 {
00521 AVInputFormat *ifmt=NULL;
00522 AVOutputFormat *ofmt=NULL;
00523 const char *last_name;
00524
00525 printf(
00526 "File formats:\n"
00527 " D. = Demuxing supported\n"
00528 " .E = Muxing supported\n"
00529 " --\n");
00530 last_name= "000";
00531 for(;;){
00532 int decode=0;
00533 int encode=0;
00534 const char *name=NULL;
00535 const char *long_name=NULL;
00536
00537 while((ofmt= av_oformat_next(ofmt))) {
00538 if((name == NULL || strcmp(ofmt->name, name)<0) &&
00539 strcmp(ofmt->name, last_name)>0){
00540 name= ofmt->name;
00541 long_name= ofmt->long_name;
00542 encode=1;
00543 }
00544 }
00545 while((ifmt= av_iformat_next(ifmt))) {
00546 if((name == NULL || strcmp(ifmt->name, name)<0) &&
00547 strcmp(ifmt->name, last_name)>0){
00548 name= ifmt->name;
00549 long_name= ifmt->long_name;
00550 encode=0;
00551 }
00552 if(name && strcmp(ifmt->name, name)==0)
00553 decode=1;
00554 }
00555 if(name==NULL)
00556 break;
00557 last_name= name;
00558
00559 printf(
00560 " %s%s %-15s %s\n",
00561 decode ? "D":" ",
00562 encode ? "E":" ",
00563 name,
00564 long_name ? long_name:" ");
00565 }
00566 }
00567
00568 void show_codecs(void)
00569 {
00570 AVCodec *p=NULL, *p2;
00571 const char *last_name;
00572 printf(
00573 "Codecs:\n"
00574 " D..... = Decoding supported\n"
00575 " .E.... = Encoding supported\n"
00576 " ..V... = Video codec\n"
00577 " ..A... = Audio codec\n"
00578 " ..S... = Subtitle codec\n"
00579 " ...S.. = Supports draw_horiz_band\n"
00580 " ....D. = Supports direct rendering method 1\n"
00581 " .....T = Supports weird frame truncation\n"
00582 " ------\n");
00583 last_name= "000";
00584 for(;;){
00585 int decode=0;
00586 int encode=0;
00587 int cap=0;
00588 const char *type_str;
00589
00590 p2=NULL;
00591 while((p= av_codec_next(p))) {
00592 if((p2==NULL || strcmp(p->name, p2->name)<0) &&
00593 strcmp(p->name, last_name)>0){
00594 p2= p;
00595 decode= encode= cap=0;
00596 }
00597 if(p2 && strcmp(p->name, p2->name)==0){
00598 if(p->decode) decode=1;
00599 if(p->encode) encode=1;
00600 cap |= p->capabilities;
00601 }
00602 }
00603 if(p2==NULL)
00604 break;
00605 last_name= p2->name;
00606
00607 switch(p2->type) {
00608 case AVMEDIA_TYPE_VIDEO:
00609 type_str = "V";
00610 break;
00611 case AVMEDIA_TYPE_AUDIO:
00612 type_str = "A";
00613 break;
00614 case AVMEDIA_TYPE_SUBTITLE:
00615 type_str = "S";
00616 break;
00617 default:
00618 type_str = "?";
00619 break;
00620 }
00621 printf(
00622 " %s%s%s%s%s%s %-15s %s",
00623 decode ? "D": (" "),
00624 encode ? "E":" ",
00625 type_str,
00626 cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ",
00627 cap & CODEC_CAP_DR1 ? "D":" ",
00628 cap & CODEC_CAP_TRUNCATED ? "T":" ",
00629 p2->name,
00630 p2->long_name ? p2->long_name : "");
00631
00632
00633 printf("\n");
00634 }
00635 printf("\n");
00636 printf(
00637 "Note, the names of encoders and decoders do not always match, so there are\n"
00638 "several cases where the above table shows encoder only or decoder only entries\n"
00639 "even though both encoding and decoding are supported. For example, the h263\n"
00640 "decoder corresponds to the h263 and h263p encoders, for file formats it is even\n"
00641 "worse.\n");
00642 }
00643
00644 void show_bsfs(void)
00645 {
00646 AVBitStreamFilter *bsf=NULL;
00647
00648 printf("Bitstream filters:\n");
00649 while((bsf = av_bitstream_filter_next(bsf)))
00650 printf("%s\n", bsf->name);
00651 printf("\n");
00652 }
00653
00654 void show_protocols(void)
00655 {
00656 URLProtocol *up=NULL;
00657
00658 printf("Supported file protocols:\n"
00659 "I.. = Input supported\n"
00660 ".O. = Output supported\n"
00661 "..S = Seek supported\n"
00662 "FLAGS NAME\n"
00663 "----- \n");
00664 while((up = av_protocol_next(up)))
00665 printf("%c%c%c %s\n",
00666 up->url_read ? 'I' : '.',
00667 up->url_write ? 'O' : '.',
00668 up->url_seek ? 'S' : '.',
00669 up->name);
00670 }
00671
00672 void show_filters(void)
00673 {
00674 AVFilter av_unused(**filter) = NULL;
00675
00676 printf("Filters:\n");
00677 #if CONFIG_AVFILTER
00678 while ((filter = av_filter_next(filter)) && *filter)
00679 printf("%-16s %s\n", (*filter)->name, (*filter)->description);
00680 #endif
00681 }
00682
00683 void show_pix_fmts(void)
00684 {
00685 enum PixelFormat pix_fmt;
00686
00687 printf(
00688 "Pixel formats:\n"
00689 "I.... = Supported Input format for conversion\n"
00690 ".O... = Supported Output format for conversion\n"
00691 "..H.. = Hardware accelerated format\n"
00692 "...P. = Paletted format\n"
00693 "....B = Bitstream format\n"
00694 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
00695 "-----\n");
00696
00697 #if !CONFIG_SWSCALE
00698 # define sws_isSupportedInput(x) 0
00699 # define sws_isSupportedOutput(x) 0
00700 #endif
00701
00702 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) {
00703 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt];
00704 printf("%c%c%c%c%c %-16s %d %2d\n",
00705 sws_isSupportedInput (pix_fmt) ? 'I' : '.',
00706 sws_isSupportedOutput(pix_fmt) ? 'O' : '.',
00707 pix_desc->flags & PIX_FMT_HWACCEL ? 'H' : '.',
00708 pix_desc->flags & PIX_FMT_PAL ? 'P' : '.',
00709 pix_desc->flags & PIX_FMT_BITSTREAM ? 'B' : '.',
00710 pix_desc->name,
00711 pix_desc->nb_components,
00712 av_get_bits_per_pixel(pix_desc));
00713 }
00714 }
00715
00716 int read_yesno(void)
00717 {
00718 int c = getchar();
00719 int yesno = (toupper(c) == 'Y');
00720
00721 while (c != '\n' && c != EOF)
00722 c = getchar();
00723
00724 return yesno;
00725 }
00726
00727 int read_file(const char *filename, char **bufptr, size_t *size)
00728 {
00729 FILE *f = fopen(filename, "rb");
00730
00731 if (!f) {
00732 fprintf(stderr, "Cannot read file '%s': %s\n", filename, strerror(errno));
00733 return AVERROR(errno);
00734 }
00735 fseek(f, 0, SEEK_END);
00736 *size = ftell(f);
00737 fseek(f, 0, SEEK_SET);
00738 *bufptr = av_malloc(*size + 1);
00739 if (!*bufptr) {
00740 fprintf(stderr, "Could not allocate file buffer\n");
00741 fclose(f);
00742 return AVERROR(ENOMEM);
00743 }
00744 fread(*bufptr, 1, *size, f);
00745 (*bufptr)[*size++] = '\0';
00746
00747 fclose(f);
00748 return 0;
00749 }
00750
00751 void init_pts_correction(PtsCorrectionContext *ctx)
00752 {
00753 ctx->num_faulty_pts = ctx->num_faulty_dts = 0;
00754 ctx->last_pts = ctx->last_dts = INT64_MIN;
00755 }
00756
00757 int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
00758 {
00759 int64_t pts = AV_NOPTS_VALUE;
00760
00761 if (dts != AV_NOPTS_VALUE) {
00762 ctx->num_faulty_dts += dts <= ctx->last_dts;
00763 ctx->last_dts = dts;
00764 }
00765 if (reordered_pts != AV_NOPTS_VALUE) {
00766 ctx->num_faulty_pts += reordered_pts <= ctx->last_pts;
00767 ctx->last_pts = reordered_pts;
00768 }
00769 if ((ctx->num_faulty_pts<=ctx->num_faulty_dts || dts == AV_NOPTS_VALUE)
00770 && reordered_pts != AV_NOPTS_VALUE)
00771 pts = reordered_pts;
00772 else
00773 pts = dts;
00774
00775 return pts;
00776 }
00777
00778 FILE *get_preset_file(char *filename, size_t filename_size,
00779 const char *preset_name, int is_path, const char *codec_name)
00780 {
00781 FILE *f = NULL;
00782 int i;
00783 const char *base[3]= { getenv("FFMPEG_DATADIR"),
00784 getenv("HOME"),
00785 FFMPEG_DATADIR,
00786 };
00787
00788 if (is_path) {
00789 av_strlcpy(filename, preset_name, filename_size);
00790 f = fopen(filename, "r");
00791 } else {
00792 for (i = 0; i < 3 && !f; i++) {
00793 if (!base[i])
00794 continue;
00795 snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", preset_name);
00796 f = fopen(filename, "r");
00797 if (!f && codec_name) {
00798 snprintf(filename, filename_size,
00799 "%s%s/%s-%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", codec_name, preset_name);
00800 f = fopen(filename, "r");
00801 }
00802 }
00803 }
00804
00805 return f;
00806 }
00807
00808 #if CONFIG_AVFILTER
00809
00810 static int ffsink_init(AVFilterContext *ctx, const char *args, void *opaque)
00811 {
00812 FFSinkContext *priv = ctx->priv;
00813
00814 if (!opaque)
00815 return AVERROR(EINVAL);
00816 *priv = *(FFSinkContext *)opaque;
00817
00818 return 0;
00819 }
00820
00821 static void null_end_frame(AVFilterLink *inlink) { }
00822
00823 static int ffsink_query_formats(AVFilterContext *ctx)
00824 {
00825 FFSinkContext *priv = ctx->priv;
00826 enum PixelFormat pix_fmts[] = { priv->pix_fmt, PIX_FMT_NONE };
00827
00828 avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
00829 return 0;
00830 }
00831
00832 AVFilter ffsink = {
00833 .name = "ffsink",
00834 .priv_size = sizeof(FFSinkContext),
00835 .init = ffsink_init,
00836
00837 .query_formats = ffsink_query_formats,
00838
00839 .inputs = (AVFilterPad[]) {{ .name = "default",
00840 .type = AVMEDIA_TYPE_VIDEO,
00841 .end_frame = null_end_frame,
00842 .min_perms = AV_PERM_READ, },
00843 { .name = NULL }},
00844 .outputs = (AVFilterPad[]) {{ .name = NULL }},
00845 };
00846
00847 int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
00848 AVFilterBufferRef **picref_ptr, AVRational *tb)
00849 {
00850 int ret;
00851 AVFilterBufferRef *picref;
00852
00853 if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0)
00854 return ret;
00855 if (!(picref = ctx->inputs[0]->cur_buf))
00856 return AVERROR(ENOENT);
00857 *picref_ptr = picref;
00858 ctx->inputs[0]->cur_buf = NULL;
00859 *tb = ctx->inputs[0]->time_base;
00860
00861 memcpy(frame->data, picref->data, sizeof(frame->data));
00862 memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
00863 frame->interlaced_frame = picref->video->interlaced;
00864 frame->top_field_first = picref->video->top_field_first;
00865
00866 return 1;
00867 }
00868
00869 #endif