From 6b5412cbfa557f7e741293ec69c81eaad5e24def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sat, 24 Oct 2015 15:14:33 +0200 Subject: [PATCH] avutil/opt: print more meaningful default flags values Example: % ./ffmpeg -h encoder=gif [...] GIF encoder AVOptions: -gifflags E..V.... set GIF flags (default offsetting+transdiff) offsetting E..V.... enable picture offsetting transdiff E..V.... enable transparency detection between frames --- libavutil/opt.c | 32 ++++++++++++++++++++++++++++++-- tests/ref/fate/opt | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 36eeeb09e2..da1eb1647f 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -941,6 +941,27 @@ static const char *get_opt_const_name(void *obj, const char *unit, int64_t value return NULL; } +static char *get_opt_flags_string(void *obj, const char *unit, int64_t value) +{ + const AVOption *opt = NULL; + char flags[512]; + + flags[0] = 0; + if (!unit) + return NULL; + while ((opt = av_opt_next(obj, opt))) { + if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) && + opt->default_val.i64 & value) { + if (flags[0]) + av_strlcatf(flags, sizeof(flags), "+"); + av_strlcatf(flags, sizeof(flags), "%s", opt->name); + } + } + if (flags[0]) + return av_strdup(flags); + return NULL; +} + static void opt_list(void *obj, void *av_log_obj, const char *unit, int req_flags, int rej_flags) { @@ -1066,9 +1087,16 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit, case AV_OPT_TYPE_BOOL: av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid")); break; - case AV_OPT_TYPE_FLAGS: - av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64); + case AV_OPT_TYPE_FLAGS: { + char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64); + if (def_flags) { + av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags); + av_freep(&def_flags); + } else { + av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64); + } break; + } case AV_OPT_TYPE_DURATION: log_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64); break; diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt index 307da374ea..e9132a5a1b 100644 --- a/tests/ref/fate/opt +++ b/tests/ref/fate/opt @@ -23,7 +23,7 @@ TestContext AVOptions: -rational E....... set rational (from 0 to 10) (default 1/1) -string E....... set string (default "default") -escape E....... set escape str (default "\=,") - -flags E....... set flags (default 1) + -flags E....... set flags (default cool) cool E....... set cool flag lame E....... set lame flag mu E....... set mu flag