[FFmpeg-devel] [PATCH 1/2] lavu/opt: add AV_OPT_VIDEO_RATE option
Paul B Mahol
onemda at gmail.com
Sun Mar 17 12:07:15 CET 2013
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
doc/APIchanges | 3 +++
libavutil/opt.c | 26 +++++++++++++++++++++++++-
libavutil/opt.h | 1 +
libavutil/version.h | 4 ++--
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 2bde666..797d558 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2012-10-22
API changes, most recent first:
+2013-03-17 - xxxxxx - lavu 52.20.100 - opt.h
+ Add AV_OPT_TYPE_VIDEO_RATE value to AVOptionType enum.
+
2013-03-07 - xxxxxx - lavu 52.18.100 - avstring.h,bprint.h
Add av_escape() and av_bprint_escape() API.
diff --git a/libavutil/opt.c b/libavutil/opt.c
index e138402..24029e6 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -256,7 +256,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
return AVERROR_OPTION_NOT_FOUND;
if (!val && (o->type != AV_OPT_TYPE_STRING &&
o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT &&
- o->type != AV_OPT_TYPE_IMAGE_SIZE))
+ o->type != AV_OPT_TYPE_IMAGE_SIZE && o->type != AV_OPT_TYPE_VIDEO_RATE))
return AVERROR(EINVAL);
dst = ((uint8_t*)target_obj) + o->offset;
@@ -278,6 +278,15 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
if (ret < 0)
av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val);
return ret;
+ case AV_OPT_TYPE_VIDEO_RATE:
+ if (!val) {
+ ret = AVERROR(EINVAL);
+ } else {
+ ret = av_parse_video_rate(dst, val);
+ }
+ if (ret < 0)
+ av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as video rate\n", val);
+ return ret;
case AV_OPT_TYPE_PIXEL_FMT:
if (!val || !strcmp(val, "none")) {
ret = AV_PIX_FMT_NONE;
@@ -543,6 +552,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
case AV_OPT_TYPE_INT64: ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;
case AV_OPT_TYPE_FLOAT: ret = snprintf(buf, sizeof(buf), "%f" , *(float *)dst);break;
case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf, sizeof(buf), "%f" , *(double *)dst);break;
+ case AV_OPT_TYPE_VIDEO_RATE:
case AV_OPT_TYPE_RATIONAL: ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
case AV_OPT_TYPE_CONST: ret = snprintf(buf, sizeof(buf), "%f" , o->default_val.dbl);break;
case AV_OPT_TYPE_STRING:
@@ -809,6 +819,9 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
case AV_OPT_TYPE_IMAGE_SIZE:
av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<image_size>");
break;
+ case AV_OPT_TYPE_VIDEO_RATE:
+ av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<video_rate>");
+ break;
case AV_OPT_TYPE_PIXEL_FMT:
av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<pix_fmt>");
break;
@@ -908,6 +921,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
break;
case AV_OPT_TYPE_STRING:
case AV_OPT_TYPE_IMAGE_SIZE:
+ case AV_OPT_TYPE_VIDEO_RATE:
av_opt_set(s, opt->name, opt->default_val.str, 0);
break;
case AV_OPT_TYPE_PIXEL_FMT:
@@ -1270,6 +1284,12 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch
range->value_min = 0;
range->value_max = INT_MAX/8;
break;
+ case AV_OPT_TYPE_VIDEO_RATE:
+ range->component_min = 1;
+ range->component_max = INT_MAX;
+ range->value_min = 1;
+ range->value_max = INT_MAX;
+ break;
default:
ret = AVERROR(ENOSYS);
goto fail;
@@ -1331,6 +1351,7 @@ static const AVOption test_options[]= {
{"size", "set size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE,{0}, 0, 0 },
{"pix_fmt", "set pixfmt", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_NONE}, -1, AV_PIX_FMT_NB-1},
{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64 = AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_NB-1},
+{"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0 },
{NULL},
};
@@ -1381,6 +1402,9 @@ int main(void)
"sample_fmt=s16",
"sample_fmt=2",
"sample_fmt=bogus",
+ "video_rate=pal",
+ "video_rate=25",
+ "video_rate=bogus",
};
test_ctx.class = &test_class;
diff --git a/libavutil/opt.h b/libavutil/opt.h
index baf1b82..bd7839c 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -230,6 +230,7 @@ enum AVOptionType{
AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S','I','Z','E'), ///< offset must point to two consecutive integers
AV_OPT_TYPE_PIXEL_FMT = MKBETAG('P','F','M','T'),
AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S','F','M','T'),
+ AV_OPT_TYPE_VIDEO_RATE = MKBETAG('R','A','T','E'), ///< offset must point to AVRational
#if FF_API_OLD_AVOPTIONS
FF_OPT_TYPE_FLAGS = 0,
FF_OPT_TYPE_INT,
diff --git a/libavutil/version.h b/libavutil/version.h
index b8f814f..1ff9ffe 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,8 +75,8 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 19
-#define LIBAVUTIL_VERSION_MICRO 101
+#define LIBAVUTIL_VERSION_MINOR 20
+#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
--
1.7.11.4
More information about the ffmpeg-devel
mailing list