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