aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorZdenek Kabelac <kabi@informatics.muni.cz>2003-01-06 18:06:51 +0000
committerZdenek Kabelac <kabi@informatics.muni.cz>2003-01-06 18:06:51 +0000
commit628d601b56a8057ea0963878b59ba12ba223a38f (patch)
tree236691ede07857ef4a0ac4e9e9abeca9850e394b /libavcodec
parentc296f66b54e58d8f02763bfc7553aa4cf8debd16 (diff)
downloadffmpeg-628d601b56a8057ea0963878b59ba12ba223a38f.tar.gz
* first shot for generaly usable option parser for codecs
Originally committed as revision 1402 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/avcodec.h37
-rw-r--r--libavcodec/opts.c77
2 files changed, 113 insertions, 1 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ae96558c95..fd7eafbd4f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1109,6 +1109,41 @@ void avcodec_register_all(void);
void avcodec_flush_buffers(AVCodecContext *avctx);
+typedef struct {
+ /** options' name with default value*/
+ const char* name;
+ /** English text help */
+ const char* help;
+ /** type of variable */
+ int type;
+#define FF_CONF_TYPE_BOOL 1 // boolean - true,1,on (or simply presence)
+#define FF_CONF_TYPE_DOUBLE 2 // double
+#define FF_CONF_TYPE_INT 3 // integer
+#define FF_CONF_TYPE_STRING 4 // string (finished with \0)
+#define FF_CONF_TYPE_MASK 0x1f // mask for types - upper bits are various flags
+#define FF_CONF_TYPE_EXPERT 0x20 // flag for expert option
+#define FF_CONF_TYPE_FLAG (FF_CONF_TYPE_BOOL | 0x40)
+#define FF_CONF_TYPE_RCOVERIDE (FF_CONF_TYPE_STRING | 0x80)
+ /** where the parsed value should be stored */
+ void* val;
+ /** min value (min == max -> no limits) */
+ double min;
+ /** maximum value for double/int */
+ double max;
+ /** default boo [0,1]l/double/int value */
+ double defval;
+ /**
+ * default string value (with optional semicolon delimited extra option-list
+ * i.e. option1;option2;option3
+ * defval might select other then first argument as default
+ */
+ const char* defstr;
+ /** char* list of supported codecs (i.e. ",msmpeg4,h263," NULL - everything */
+ const char* supported;
+} avc_config_t;
+
+void avcodec_getopt(AVCodecContext* avctx, char* str, avc_config_t** config);
+
/**
* Interface for 0.5.0 version
*
@@ -1193,7 +1228,7 @@ void __av_freep(void **ptr);
#define av_freep(p) __av_freep((void **)(p))
/* for static data only */
/* call av_free_static to release all staticaly allocated tables */
-void av_free_static();
+void av_free_static(void);
void *__av_mallocz_static(void** location, unsigned int size);
#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
diff --git a/libavcodec/opts.c b/libavcodec/opts.c
new file mode 100644
index 0000000000..bcefc40a3b
--- /dev/null
+++ b/libavcodec/opts.c
@@ -0,0 +1,77 @@
+/*
+ * LGPL
+ */
+
+/*
+ * typical parsed command line:
+ * msmpeg4:bitrate=720000:qmax=16
+ *
+ */
+
+#include "avcodec.h"
+
+/*
+ * possible extension - use for decoder options
+ * - for given codec names filter only correct
+ * options given (could be passed with 'str')
+ */
+
+/**
+ * \param avctx where to store parsed results
+ * \param str string with options for parsing
+ * \param config allocated avc_config_t for external parsing
+ * i.e. external program might learn about all available
+ * options for given codec
+ **/
+void avcodec_getopt(AVCodecContext* avctx, char* str, avc_config_t** config)
+{
+ AVCodecContext avctx_tmp;
+ AVCodecContext* ctx = (avctx) ? avctx : &avctx_tmp;
+ static const char* class_h263 = ",msmpeg4,";
+ //"huffyuv,wmv1,msmpeg4v2,msmpeg4,mpeg4,mpeg1,mpeg1video,mjpeg,rv10,h263,h263p"
+
+ avc_config_t cnf[] =
+ {
+ // FIXME: sorted by importance!!!
+ // expert option should follow more common ones
+ {
+ "bitrate", "desired video bitrate",
+ FF_CONF_TYPE_INT, &ctx->bit_rate, 4, 240000000, 800000, NULL, class_h263
+ }, {
+ "vhq", "very high quality",
+ FF_CONF_TYPE_FLAG, &ctx->flags, 0, CODEC_FLAG_HQ, 0, NULL, class_h263
+ }, {
+ "ratetol", "number of bits the bitstream is allowed to diverge from the reference"
+ "the reference can be CBR (for CBR pass1) or VBR (for pass2)",
+ FF_CONF_TYPE_INT, &ctx->bit_rate_tolerance, 4, 240000000, 8000, NULL, class_h263
+ }, {
+ "qmin", "minimum quantizer", FF_CONF_TYPE_INT, &ctx->qmin, 1, 31, 2, NULL, class_h263
+ }, {
+ "qmax", "maximum qunatizer", FF_CONF_TYPE_INT, &ctx->qmax, 1, 31, 31, NULL, class_h263
+ }, {
+ "rc_eq", "rate control equation",
+ FF_CONF_TYPE_STRING, &ctx->rc_eq, 0, 0, 0, "tex^qComp" /* FILLME options */, class_h263
+ }, {
+ "rc_minrate", "rate control minimum bitrate",
+ FF_CONF_TYPE_INT, &ctx->rc_min_rate, 4, 24000000, 0, NULL, class_h263
+ }, {
+ "rc_maxrate", "rate control maximum bitrate",
+ FF_CONF_TYPE_INT, &ctx->rc_max_rate, 4, 24000000, 0, NULL, class_h263
+ }, {
+ "psnr", "calculate PSNR of compressed frames",
+ FF_CONF_TYPE_FLAG, &ctx->flags, 0, CODEC_FLAG_PSNR, 0, NULL, class_h263
+ }, {
+ "rc_override", "ratecontrol override (=startframe,endframe,qscale,quality_factor)",
+ FF_CONF_TYPE_RCOVERIDE, &ctx->rc_override, 0, 0, 0, NULL, class_h263
+ },
+
+ { NULL, NULL, 0, NULL, 0, 0, 0, NULL, NULL }
+ };
+
+ if (config)
+ {
+ *config = malloc(sizeof(cnf));
+ if (*config)
+ memcpy(*config, cnf, sizeof(cnf));
+ }
+}