2 * Various utilities for command line tools
3 * Copyright (c) 2000-2003 Fabrice Bellard
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 void show_help_options(const OptionDef *options, const char *msg, int mask, int value)
41 for(po = options; po->name != NULL; po++) {
43 if ((po->flags & mask) == value) {
48 av_strlcpy(buf, po->name, sizeof(buf));
49 if (po->flags & HAS_ARG) {
50 av_strlcat(buf, " ", sizeof(buf));
51 av_strlcat(buf, po->argname, sizeof(buf));
53 printf("-%-17s %s\n", buf, po->help);
58 static const OptionDef* find_option(const OptionDef *po, const char *name){
59 while (po->name != NULL) {
60 if (!strcmp(name, po->name))
67 void parse_options(int argc, char **argv, const OptionDef *options,
68 void (* parse_arg_function)(const char*))
70 const char *opt, *arg;
71 int optindex, handleoptions=1;
76 while (optindex < argc) {
77 opt = argv[optindex++];
79 if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
80 if (opt[1] == '-' && opt[2] == '\0') {
84 po= find_option(options, opt + 1);
86 po= find_option(options, "default");
89 fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
93 if (po->flags & HAS_ARG) {
94 arg = argv[optindex++];
96 fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
100 if (po->flags & OPT_STRING) {
102 str = av_strdup(arg);
103 *po->u.str_arg = str;
104 } else if (po->flags & OPT_BOOL) {
106 } else if (po->flags & OPT_INT) {
107 *po->u.int_arg = atoi(arg);
108 } else if (po->flags & OPT_INT64) {
109 *po->u.int64_arg = strtoll(arg, (char **)NULL, 10);
110 } else if (po->flags & OPT_FLOAT) {
111 *po->u.float_arg = atof(arg);
112 } else if (po->flags & OPT_FUNC2) {
113 if(po->u.func2_arg(opt+1, arg)<0)
119 if (parse_arg_function)
120 parse_arg_function(opt);
125 void print_error(const char *filename, int err)
128 case AVERROR_NUMEXPECTED:
129 fprintf(stderr, "%s: Incorrect image filename syntax.\n"
130 "Use '%%d' to specify the image number:\n"
131 " for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
132 " for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
135 case AVERROR_INVALIDDATA:
136 fprintf(stderr, "%s: Error while parsing header\n", filename);
139 fprintf(stderr, "%s: Unknown format\n", filename);
142 fprintf(stderr, "%s: I/O error occured\n"
143 "Usually that means that input file is truncated and/or corrupted.\n",
146 case AVERROR(ENOMEM):
147 fprintf(stderr, "%s: memory allocation error occured\n", filename);
149 case AVERROR(ENOENT):
150 fprintf(stderr, "%s: no such file or directory\n", filename);
153 fprintf(stderr, "%s: Error while opening file\n", filename);
158 void show_banner(const char *program_name, int program_birth_year)
160 fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-2008 Fabrice Bellard, et al.\n",
161 program_name, program_birth_year);
162 fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n");
163 fprintf(stderr, " libavutil version: " AV_STRINGIFY(LIBAVUTIL_VERSION) "\n");
164 fprintf(stderr, " libavcodec version: " AV_STRINGIFY(LIBAVCODEC_VERSION) "\n");
165 fprintf(stderr, " libavformat version: " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\n");
166 fprintf(stderr, " libavdevice version: " AV_STRINGIFY(LIBAVDEVICE_VERSION) "\n");
167 fprintf(stderr, " built on " __DATE__ " " __TIME__);
169 fprintf(stderr, ", gcc: " __VERSION__ "\n");
171 fprintf(stderr, ", using a non-gcc compiler\n");
175 void show_version(const char *program_name) {
176 /* TODO: add function interface to avutil and avformat avdevice*/
177 printf("%s " FFMPEG_VERSION "\n", program_name);
178 printf("libavutil %d\n"
182 LIBAVUTIL_BUILD, avcodec_build(), LIBAVFORMAT_BUILD, LIBAVDEVICE_BUILD);
185 void show_license(void)
189 "FFmpeg is free software; you can redistribute it and/or modify\n"
190 "it under the terms of the GNU General Public License as published by\n"
191 "the Free Software Foundation; either version 2 of the License, or\n"
192 "(at your option) any later version.\n"
194 "FFmpeg is distributed in the hope that it will be useful,\n"
195 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
196 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
197 "GNU General Public License for more details.\n"
199 "You should have received a copy of the GNU General Public License\n"
200 "along with FFmpeg; if not, write to the Free Software\n"
201 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
205 "FFmpeg is free software; you can redistribute it and/or\n"
206 "modify it under the terms of the GNU Lesser General Public\n"
207 "License as published by the Free Software Foundation; either\n"
208 "version 2.1 of the License, or (at your option) any later version.\n"
210 "FFmpeg is distributed in the hope that it will be useful,\n"
211 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
212 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
213 "Lesser General Public License for more details.\n"
215 "You should have received a copy of the GNU Lesser General Public\n"
216 "License along with FFmpeg; if not, write to the Free Software\n"
217 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"