00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FFMPEG_CMDUTILS_H
00023 #define FFMPEG_CMDUTILS_H
00024
00025 #include <stdint.h>
00026
00027 #include "libavcodec/avcodec.h"
00028 #include "libavfilter/avfilter.h"
00029 #include "libavformat/avformat.h"
00030 #include "libswscale/swscale.h"
00031
00032 #ifdef __MINGW32__
00033 #undef main
00034 #endif
00035
00039 extern const char program_name[];
00040
00044 extern const int program_birth_year;
00045
00049 extern const int this_year;
00050
00051 extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
00052 extern AVFormatContext *avformat_opts;
00053 extern struct SwsContext *sws_opts;
00054 extern struct SwrContext *swr_opts;
00055 extern AVDictionary *format_opts, *codec_opts;
00056
00061 void init_opts(void);
00066 void uninit_opts(void);
00067
00072 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
00073
00078 int opt_default(void *optctx, const char *opt, const char *arg);
00079
00083 int opt_loglevel(void *optctx, const char *opt, const char *arg);
00084
00085 int opt_report(const char *opt);
00086
00087 int opt_max_alloc(void *optctx, const char *opt, const char *arg);
00088
00089 int opt_cpuflags(void *optctx, const char *opt, const char *arg);
00090
00091 int opt_codec_debug(void *optctx, const char *opt, const char *arg);
00092
00096 int opt_timelimit(void *optctx, const char *opt, const char *arg);
00097
00111 double parse_number_or_die(const char *context, const char *numstr, int type,
00112 double min, double max);
00113
00128 int64_t parse_time_or_die(const char *context, const char *timestr,
00129 int is_duration);
00130
00131 typedef struct SpecifierOpt {
00132 char *specifier;
00133 union {
00134 uint8_t *str;
00135 int i;
00136 int64_t i64;
00137 float f;
00138 double dbl;
00139 } u;
00140 } SpecifierOpt;
00141
00142 typedef struct OptionDef {
00143 const char *name;
00144 int flags;
00145 #define HAS_ARG 0x0001
00146 #define OPT_BOOL 0x0002
00147 #define OPT_EXPERT 0x0004
00148 #define OPT_STRING 0x0008
00149 #define OPT_VIDEO 0x0010
00150 #define OPT_AUDIO 0x0020
00151 #define OPT_INT 0x0080
00152 #define OPT_FLOAT 0x0100
00153 #define OPT_SUBTITLE 0x0200
00154 #define OPT_INT64 0x0400
00155 #define OPT_EXIT 0x0800
00156 #define OPT_DATA 0x1000
00157 #define OPT_PERFILE 0x2000
00158
00159 #define OPT_OFFSET 0x4000
00160 #define OPT_SPEC 0x8000
00161
00162
00163 #define OPT_TIME 0x10000
00164 #define OPT_DOUBLE 0x20000
00165 union {
00166 void *dst_ptr;
00167 int (*func_arg)(void *, const char *, const char *);
00168 size_t off;
00169 } u;
00170 const char *help;
00171 const char *argname;
00172 } OptionDef;
00173
00183 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
00184 int rej_flags, int alt_flags);
00185
00190 void show_help_children(const AVClass *class, int flags);
00191
00196 void show_help_default(const char *opt, const char *arg);
00197
00201 int show_help(void *optctx, const char *opt, const char *arg);
00202
00215 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
00216 void (* parse_arg_function)(void *optctx, const char*));
00217
00223 int parse_option(void *optctx, const char *opt, const char *arg,
00224 const OptionDef *options);
00225
00229 void parse_loglevel(int argc, char **argv, const OptionDef *options);
00230
00234 int locate_option(int argc, char **argv, const OptionDef *options,
00235 const char *optname);
00236
00246 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
00247
00262 AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
00263 AVFormatContext *s, AVStream *st, AVCodec *codec);
00264
00276 AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
00277 AVDictionary *codec_opts);
00278
00288 void print_error(const char *filename, int err);
00289
00295 void show_banner(int argc, char **argv, const OptionDef *options);
00296
00303 int show_version(void *optctx, const char *opt, const char *arg);
00304
00310 int show_license(void *optctx, const char *opt, const char *arg);
00311
00317 int show_formats(void *optctx, const char *opt, const char *arg);
00318
00324 int show_codecs(void *optctx, const char *opt, const char *arg);
00325
00330 int show_decoders(void *optctx, const char *opt, const char *arg);
00331
00336 int show_encoders(void *optctx, const char *opt, const char *arg);
00337
00343 int show_filters(void *optctx, const char *opt, const char *arg);
00344
00350 int show_bsfs(void *optctx, const char *opt, const char *arg);
00351
00357 int show_protocols(void *optctx, const char *opt, const char *arg);
00358
00364 int show_pix_fmts(void *optctx, const char *opt, const char *arg);
00365
00371 int show_layouts(void *optctx, const char *opt, const char *arg);
00372
00377 int show_sample_fmts(void *optctx, const char *opt, const char *arg);
00378
00383 int read_yesno(void);
00384
00395 int cmdutils_read_file(const char *filename, char **bufptr, size_t *size);
00396
00415 FILE *get_preset_file(char *filename, size_t filename_size,
00416 const char *preset_name, int is_path, const char *codec_name);
00417
00428 void *grow_array(void *array, int elem_size, int *size, int new_size);
00429
00430 typedef struct FrameBuffer {
00431 uint8_t *base[4];
00432 uint8_t *data[4];
00433 int linesize[4];
00434
00435 int h, w;
00436 enum AVPixelFormat pix_fmt;
00437
00438 int refcount;
00439 struct FrameBuffer **pool;
00440 struct FrameBuffer *next;
00441 } FrameBuffer;
00442
00452 int codec_get_buffer(AVCodecContext *s, AVFrame *frame);
00453
00458 void codec_release_buffer(AVCodecContext *s, AVFrame *frame);
00459
00465 void filter_release_buffer(AVFilterBuffer *fb);
00466
00471 void free_buffer_pool(FrameBuffer **pool);
00472
00473 #define GET_PIX_FMT_NAME(pix_fmt)\
00474 const char *name = av_get_pix_fmt_name(pix_fmt);
00475
00476 #define GET_SAMPLE_FMT_NAME(sample_fmt)\
00477 const char *name = av_get_sample_fmt_name(sample_fmt)
00478
00479 #define GET_SAMPLE_RATE_NAME(rate)\
00480 char name[16];\
00481 snprintf(name, sizeof(name), "%d", rate);
00482
00483 #define GET_CH_LAYOUT_NAME(ch_layout)\
00484 char name[16];\
00485 snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
00486
00487 #define GET_CH_LAYOUT_DESC(ch_layout)\
00488 char name[128];\
00489 av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
00490
00491 #endif