diff options
author | Paul B Mahol <onemda@gmail.com> | 2013-03-17 10:49:56 +0000 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2013-03-20 12:29:54 +0000 |
commit | 7aa9af51db84ec4d2c143fa5adca4da1d3c28bd0 (patch) | |
tree | 845cb53152f340aa587272e8a83f8f5131cc04f7 | |
parent | 7d29c6eebc428741004071f7a92ea37d8d1d2cce (diff) | |
download | ffmpeg-streaming-7aa9af51db84ec4d2c143fa5adca4da1d3c28bd0.zip ffmpeg-streaming-7aa9af51db84ec4d2c143fa5adca4da1d3c28bd0.tar.gz |
lavu/opt: add AV_OPT_VIDEO_RATE option
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r-- | doc/APIchanges | 3 | ||||
-rw-r--r-- | libavutil/opt.c | 61 | ||||
-rw-r--r-- | libavutil/opt.h | 3 | ||||
-rw-r--r-- | libavutil/version.h | 2 |
4 files changed, 67 insertions, 2 deletions
diff --git a/doc/APIchanges b/doc/APIchanges index 2c1358f..41552aa 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..04e33ce 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; @@ -436,6 +445,23 @@ int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_ return 0; } +int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags) +{ + void *target_obj; + const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + + if (!o || !target_obj) + return AVERROR_OPTION_NOT_FOUND; + if (o->type != AV_OPT_TYPE_VIDEO_RATE) { + av_log(obj, AV_LOG_ERROR, + "The value set by option '%s' is not a video rate.\n", o->name); + return AVERROR(EINVAL); + } + if (val.num <= 0 || val.den <= 0) + return AVERROR(EINVAL); + return set_number(obj, name, val.num, val.den, 1, search_flags); +} + static int set_format(void *obj, const char *name, int fmt, int search_flags, enum AVOptionType type, const char *desc, int nb_fmts) { @@ -543,6 +569,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: @@ -695,6 +722,22 @@ int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_ return 0; } +int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val) +{ + int64_t intnum = 1; + double num = 1; + int ret, den = 1; + + if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0) + return ret; + + if (num == 1.0 && (int)intnum == intnum) + *out_val = (AVRational){intnum, den}; + else + *out_val = av_d2q(num*intnum/den, 1<<24); + return 0; +} + static int get_format(void *obj, const char *name, int search_flags, int *out_fmt, enum AVOptionType type, const char *desc) { @@ -809,6 +852,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 +954,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 +1317,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 +1384,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 +1435,11 @@ int main(void) "sample_fmt=s16", "sample_fmt=2", "sample_fmt=bogus", + "video_rate=pal", + "video_rate=25", + "video_rate=30000/1001", + "video_rate=30/1.001", + "video_rate=bogus", }; test_ctx.class = &test_class; diff --git a/libavutil/opt.h b/libavutil/opt.h index baf1b82..b36aebe 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('V','R','A','T'), ///< offset must point to AVRational #if FF_API_OLD_AVOPTIONS FF_OPT_TYPE_FLAGS = 0, FF_OPT_TYPE_INT, @@ -653,6 +654,7 @@ int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags); int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags); int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags); +int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags); /** * @} */ @@ -679,6 +681,7 @@ int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out); int av_opt_get_pixel_fmt (void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt); int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt); +int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val); /** * @} */ diff --git a/libavutil/version.h b/libavutil/version.h index 1ff9ffe..0619eb9 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -75,7 +75,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 52 -#define LIBAVUTIL_VERSION_MINOR 20 +#define LIBAVUTIL_VERSION_MINOR 21 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |