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
00026 #include "avformat.h"
00027 #include "avdevice.h"
00028 #include "cmdutils.h"
00029 #include "avstring.h"
00030 #include "version.h"
00031 #include "config.h"
00032
00033 #undef exit
00034
00035 void show_help_options(const OptionDef *options, const char *msg, int mask, int value)
00036 {
00037 const OptionDef *po;
00038 int first;
00039
00040 first = 1;
00041 for(po = options; po->name != NULL; po++) {
00042 char buf[64];
00043 if ((po->flags & mask) == value) {
00044 if (first) {
00045 printf("%s", msg);
00046 first = 0;
00047 }
00048 av_strlcpy(buf, po->name, sizeof(buf));
00049 if (po->flags & HAS_ARG) {
00050 av_strlcat(buf, " ", sizeof(buf));
00051 av_strlcat(buf, po->argname, sizeof(buf));
00052 }
00053 printf("-%-17s %s\n", buf, po->help);
00054 }
00055 }
00056 }
00057
00058 static const OptionDef* find_option(const OptionDef *po, const char *name){
00059 while (po->name != NULL) {
00060 if (!strcmp(name, po->name))
00061 break;
00062 po++;
00063 }
00064 return po;
00065 }
00066
00067 void parse_options(int argc, char **argv, const OptionDef *options,
00068 void (* parse_arg_function)(const char*))
00069 {
00070 const char *opt, *arg;
00071 int optindex, handleoptions=1;
00072 const OptionDef *po;
00073
00074
00075 optindex = 1;
00076 while (optindex < argc) {
00077 opt = argv[optindex++];
00078
00079 if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
00080 if (opt[1] == '-' && opt[2] == '\0') {
00081 handleoptions = 0;
00082 continue;
00083 }
00084 po= find_option(options, opt + 1);
00085 if (!po->name)
00086 po= find_option(options, "default");
00087 if (!po->name) {
00088 unknown_opt:
00089 fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
00090 exit(1);
00091 }
00092 arg = NULL;
00093 if (po->flags & HAS_ARG) {
00094 arg = argv[optindex++];
00095 if (!arg) {
00096 fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
00097 exit(1);
00098 }
00099 }
00100 if (po->flags & OPT_STRING) {
00101 char *str;
00102 str = av_strdup(arg);
00103 *po->u.str_arg = str;
00104 } else if (po->flags & OPT_BOOL) {
00105 *po->u.int_arg = 1;
00106 } else if (po->flags & OPT_INT) {
00107 *po->u.int_arg = atoi(arg);
00108 } else if (po->flags & OPT_INT64) {
00109 *po->u.int64_arg = strtoll(arg, (char **)NULL, 10);
00110 } else if (po->flags & OPT_FLOAT) {
00111 *po->u.float_arg = atof(arg);
00112 } else if (po->flags & OPT_FUNC2) {
00113 if(po->u.func2_arg(opt+1, arg)<0)
00114 goto unknown_opt;
00115 } else {
00116 po->u.func_arg(arg);
00117 }
00118 } else {
00119 if (parse_arg_function)
00120 parse_arg_function(opt);
00121 }
00122 }
00123 }
00124
00125 void print_error(const char *filename, int err)
00126 {
00127 switch(err) {
00128 case AVERROR_NUMEXPECTED:
00129 fprintf(stderr, "%s: Incorrect image filename syntax.\n"
00130 "Use '%%d' to specify the image number:\n"
00131 " for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
00132 " for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
00133 filename);
00134 break;
00135 case AVERROR_INVALIDDATA:
00136 fprintf(stderr, "%s: Error while parsing header\n", filename);
00137 break;
00138 case AVERROR_NOFMT:
00139 fprintf(stderr, "%s: Unknown format\n", filename);
00140 break;
00141 case AVERROR(EIO):
00142 fprintf(stderr, "%s: I/O error occured\n"
00143 "Usually that means that input file is truncated and/or corrupted.\n",
00144 filename);
00145 break;
00146 case AVERROR(ENOMEM):
00147 fprintf(stderr, "%s: memory allocation error occured\n", filename);
00148 break;
00149 case AVERROR(ENOENT):
00150 fprintf(stderr, "%s: no such file or directory\n", filename);
00151 break;
00152 default:
00153 fprintf(stderr, "%s: Error while opening file\n", filename);
00154 break;
00155 }
00156 }
00157
00158 void show_banner(const char *program_name, int program_birth_year)
00159 {
00160 fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-2008 Fabrice Bellard, et al.\n",
00161 program_name, program_birth_year);
00162 fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n");
00163 fprintf(stderr, " libavutil version: " AV_STRINGIFY(LIBAVUTIL_VERSION) "\n");
00164 fprintf(stderr, " libavcodec version: " AV_STRINGIFY(LIBAVCODEC_VERSION) "\n");
00165 fprintf(stderr, " libavformat version: " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\n");
00166 fprintf(stderr, " libavdevice version: " AV_STRINGIFY(LIBAVDEVICE_VERSION) "\n");
00167 fprintf(stderr, " built on " __DATE__ " " __TIME__);
00168 #ifdef __GNUC__
00169 fprintf(stderr, ", gcc: " __VERSION__ "\n");
00170 #else
00171 fprintf(stderr, ", using a non-gcc compiler\n");
00172 #endif
00173 }
00174
00175 void show_version(const char *program_name) {
00176
00177 printf("%s " FFMPEG_VERSION "\n", program_name);
00178 printf("libavutil %d\n"
00179 "libavcodec %d\n"
00180 "libavformat %d\n"
00181 "libavdevice %d\n",
00182 LIBAVUTIL_BUILD, avcodec_build(), LIBAVFORMAT_BUILD, LIBAVDEVICE_BUILD);
00183 }
00184
00185 void show_license(void)
00186 {
00187 #ifdef CONFIG_NONFREE
00188 printf(
00189 "This version of FFmpeg has nonfree parts compiled in.\n"
00190 "Therefore it is not legally redistributable.\n"
00191 );
00192 #elif CONFIG_GPL
00193 printf(
00194 "FFmpeg is free software; you can redistribute it and/or modify\n"
00195 "it under the terms of the GNU General Public License as published by\n"
00196 "the Free Software Foundation; either version 2 of the License, or\n"
00197 "(at your option) any later version.\n"
00198 "\n"
00199 "FFmpeg is distributed in the hope that it will be useful,\n"
00200 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00201 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00202 "GNU General Public License for more details.\n"
00203 "\n"
00204 "You should have received a copy of the GNU General Public License\n"
00205 "along with FFmpeg; if not, write to the Free Software\n"
00206 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
00207 );
00208 #else
00209 printf(
00210 "FFmpeg is free software; you can redistribute it and/or\n"
00211 "modify it under the terms of the GNU Lesser General Public\n"
00212 "License as published by the Free Software Foundation; either\n"
00213 "version 2.1 of the License, or (at your option) any later version.\n"
00214 "\n"
00215 "FFmpeg is distributed in the hope that it will be useful,\n"
00216 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00217 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
00218 "Lesser General Public License for more details.\n"
00219 "\n"
00220 "You should have received a copy of the GNU Lesser General Public\n"
00221 "License along with FFmpeg; if not, write to the Free Software\n"
00222 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
00223 );
00224 #endif
00225 }