FFmpeg  1.2.4
cmdutils.h
Go to the documentation of this file.
1 /*
2  * Various utilities for command line tools
3  * copyright (c) 2003 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #ifndef FFMPEG_CMDUTILS_H
23 #define FFMPEG_CMDUTILS_H
24 
25 #include <stdint.h>
26 
27 #include "libavcodec/avcodec.h"
28 #include "libavfilter/avfilter.h"
29 #include "libavformat/avformat.h"
30 #include "libswscale/swscale.h"
31 
32 #ifdef __MINGW32__
33 #undef main /* We don't want SDL to override our main() */
34 #endif
35 
39 extern const char program_name[];
40 
44 extern const int program_birth_year;
45 
49 extern const int this_year;
50 
53 extern struct SwsContext *sws_opts;
54 extern AVDictionary *swr_opts;
56 
61 void init_opts(void);
66 void uninit_opts(void);
67 
72 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
73 
78 int opt_default(void *optctx, const char *opt, const char *arg);
79 
83 int opt_loglevel(void *optctx, const char *opt, const char *arg);
84 
85 int opt_report(const char *opt);
86 
87 int opt_max_alloc(void *optctx, const char *opt, const char *arg);
88 
89 int opt_cpuflags(void *optctx, const char *opt, const char *arg);
90 
91 int opt_codec_debug(void *optctx, const char *opt, const char *arg);
92 
96 int opt_timelimit(void *optctx, const char *opt, const char *arg);
97 
111 double parse_number_or_die(const char *context, const char *numstr, int type,
112  double min, double max);
113 
128 int64_t parse_time_or_die(const char *context, const char *timestr,
129  int is_duration);
130 
131 typedef struct SpecifierOpt {
132  char *specifier;
133  union {
135  int i;
136  int64_t i64;
137  float f;
138  double dbl;
139  } u;
140 } SpecifierOpt;
141 
142 typedef struct OptionDef {
143  const char *name;
144  int flags;
145 #define HAS_ARG 0x0001
146 #define OPT_BOOL 0x0002
147 #define OPT_EXPERT 0x0004
148 #define OPT_STRING 0x0008
149 #define OPT_VIDEO 0x0010
150 #define OPT_AUDIO 0x0020
151 #define OPT_INT 0x0080
152 #define OPT_FLOAT 0x0100
153 #define OPT_SUBTITLE 0x0200
154 #define OPT_INT64 0x0400
155 #define OPT_EXIT 0x0800
156 #define OPT_DATA 0x1000
157 #define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
158  implied by OPT_OFFSET or OPT_SPEC */
159 #define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
160 #define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
161  Implies OPT_OFFSET. Next element after the offset is
162  an int containing element count in the array. */
163 #define OPT_TIME 0x10000
164 #define OPT_DOUBLE 0x20000
165  union {
166  void *dst_ptr;
167  int (*func_arg)(void *, const char *, const char *);
168  size_t off;
169  } u;
170  const char *help;
171  const char *argname;
172 } OptionDef;
173 
183 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
184  int rej_flags, int alt_flags);
185 
190 void show_help_children(const AVClass *class, int flags);
191 
196 void show_help_default(const char *opt, const char *arg);
197 
201 int show_help(void *optctx, const char *opt, const char *arg);
202 
215 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
216  void (* parse_arg_function)(void *optctx, const char*));
217 
223 int parse_option(void *optctx, const char *opt, const char *arg,
224  const OptionDef *options);
225 
231 typedef struct Option {
232  const OptionDef *opt;
233  const char *key;
234  const char *val;
235 } Option;
237 typedef struct OptionGroupDef {
239  const char *name;
244  const char *sep;
247 typedef struct OptionGroup {
249  const char *arg;
250 
252  int nb_opts;
257  struct SwsContext *sws_opts;
259 } OptionGroup;
260 
265 typedef struct OptionGroupList {
267 
271 
272 typedef struct OptionParseContext {
274 
277 
278  /* parsing state */
281 
287 int parse_optgroup(void *optctx, OptionGroup *g);
288 
307 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
308  const OptionDef *options,
309  const OptionGroupDef *groups, int nb_groups);
310 
315 
319 void parse_loglevel(int argc, char **argv, const OptionDef *options);
320 
324 int locate_option(int argc, char **argv, const OptionDef *options,
325  const char *optname);
326 
336 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
337 
353  AVFormatContext *s, AVStream *st, AVCodec *codec);
354 
367  AVDictionary *codec_opts);
368 
378 void print_error(const char *filename, int err);
379 
385 void show_banner(int argc, char **argv, const OptionDef *options);
386 
393 int show_version(void *optctx, const char *opt, const char *arg);
394 
400 int show_license(void *optctx, const char *opt, const char *arg);
401 
407 int show_formats(void *optctx, const char *opt, const char *arg);
408 
414 int show_codecs(void *optctx, const char *opt, const char *arg);
415 
420 int show_decoders(void *optctx, const char *opt, const char *arg);
421 
426 int show_encoders(void *optctx, const char *opt, const char *arg);
427 
433 int show_filters(void *optctx, const char *opt, const char *arg);
434 
440 int show_bsfs(void *optctx, const char *opt, const char *arg);
441 
447 int show_protocols(void *optctx, const char *opt, const char *arg);
448 
454 int show_pix_fmts(void *optctx, const char *opt, const char *arg);
455 
461 int show_layouts(void *optctx, const char *opt, const char *arg);
462 
467 int show_sample_fmts(void *optctx, const char *opt, const char *arg);
468 
473 int read_yesno(void);
474 
485 int cmdutils_read_file(const char *filename, char **bufptr, size_t *size);
486 
505 FILE *get_preset_file(char *filename, size_t filename_size,
506  const char *preset_name, int is_path, const char *codec_name);
507 
518 void *grow_array(void *array, int elem_size, int *size, int new_size);
519 
520 #define GROW_ARRAY(array, nb_elems)\
521  array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
523 typedef struct FrameBuffer {
524  uint8_t *base[4];
526  int linesize[4];
527 
528  int h, w;
531  int refcount;
532  struct FrameBuffer **pool;
533  struct FrameBuffer *next;
534 } FrameBuffer;
535 
546 
552 
559 
565 
566 #define GET_PIX_FMT_NAME(pix_fmt)\
567  const char *name = av_get_pix_fmt_name(pix_fmt);
568 
569 #define GET_SAMPLE_FMT_NAME(sample_fmt)\
570  const char *name = av_get_sample_fmt_name(sample_fmt)
571 
572 #define GET_SAMPLE_RATE_NAME(rate)\
573  char name[16];\
574  snprintf(name, sizeof(name), "%d", rate);
575 
576 #define GET_CH_LAYOUT_NAME(ch_layout)\
577  char name[16];\
578  snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
579 
580 #define GET_CH_LAYOUT_DESC(ch_layout)\
581  char name[128];\
582  av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
583 
584 #endif /* CMDUTILS_H */