[FFmpeg-devel] [PATCH] avutil/opt: handle whole range of int64_t in av_opt_get_int

Zhao Zhili quinkblack at foxmail.com
Wed Nov 10 14:46:26 EET 2021


Make get_int/set_int symetric. The int64_t to double to int64_t
conversion is unprecise for large value.
---
 libavutil/opt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index c7001dbcd3..b2be63828d 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -920,7 +920,10 @@ int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_v
 
     if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
         return ret;
-    *out_val = num * intnum / den;
+    if (num / den == 1.0)
+        *out_val = intnum;
+    else
+        *out_val = num * intnum / den;
     return 0;
 }
 
-- 
2.31.1



More information about the ffmpeg-devel mailing list