[FFmpeg-cvslog] avutil/opt: display a better default value for int/int64 options

Clément Bœsch git at videolan.org
Mon Oct 19 00:31:01 CEST 2015


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Sat Oct 17 14:54:31 2015 +0200| [ce0a117ed4f99c5eac2fd365cbdebba568a0ead8] | committer: Clément Bœsch

avutil/opt: display a better default value for int/int64 options

Example:

% ./ffmpeg -h encoder=aac
  -aac_coder         <int>        E...A... Coding algorithm (from -1 to 3) (default twoloop)
     faac                         E...A... FAAC-inspired method
     anmr                         E...A... ANMR method
     twoloop                      E...A... Two loop searching method
     fast                         E...A... Constant quantizer
[...]

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ce0a117ed4f99c5eac2fd365cbdebba568a0ead8
---

 libavutil/opt.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 03160c7..36eeeb0 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -928,6 +928,19 @@ static void log_value(void *av_log_obj, int level, double d)
     }
 }
 
+static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
+{
+    const AVOption *opt = NULL;
+
+    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)
+            return opt->name;
+    return NULL;
+}
+
 static void opt_list(void *obj, void *av_log_obj, const char *unit,
                      int req_flags, int rej_flags)
 {
@@ -1057,10 +1070,17 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
                 av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
                 break;
             case AV_OPT_TYPE_DURATION:
-            case AV_OPT_TYPE_INT:
-            case AV_OPT_TYPE_INT64:
                 log_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
                 break;
+            case AV_OPT_TYPE_INT:
+            case AV_OPT_TYPE_INT64: {
+                const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
+                if (def_const)
+                    av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
+                else
+                    log_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
+                break;
+            }
             case AV_OPT_TYPE_DOUBLE:
             case AV_OPT_TYPE_FLOAT:
                 log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);



More information about the ffmpeg-cvslog mailing list