[FFmpeg-devel] [PATCH 1/2] lavu: add av_gcd_q().
Nicolas George
george at nsup.org
Thu Apr 16 22:38:54 EEST 2020
TODO APIchanges and minor bump.
Signed-off-by: Nicolas George <george at nsup.org>
---
libavutil/rational.c | 9 +++++++++
libavutil/rational.h | 6 ++++++
2 files changed, 15 insertions(+)
This one too, I need for the code I am writing.
And lavfi/avf_concat could use it too to choose a better time base.
diff --git a/libavutil/rational.c b/libavutil/rational.c
index 35ee08877f..eb148ddb12 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -182,3 +182,12 @@ uint32_t av_q2intfloat(AVRational q) {
return sign<<31 | (150-shift)<<23 | (n - (1<<23));
}
+
+AVRational av_gcd_q(AVRational a, AVRational b, int max_den, AVRational def)
+{
+ int64_t gcd, lcm;
+
+ gcd = av_gcd(a.den, b.den);
+ lcm = (a.den / gcd) * b.den;
+ return lcm < max_den ? av_make_q(av_gcd(a.num, b.num), lcm) : def;
+}
diff --git a/libavutil/rational.h b/libavutil/rational.h
index 5c6b67b4e9..cbb08a0baf 100644
--- a/libavutil/rational.h
+++ b/libavutil/rational.h
@@ -207,6 +207,12 @@ int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
*/
uint32_t av_q2intfloat(AVRational q);
+/**
+ * Return the best rational so that a and b are multiple of it.
+ * If the resulting denominator is larger than max_den, return def.
+ */
+AVRational av_gcd_q(AVRational a, AVRational b, int max_den, AVRational def);
+
/**
* @}
*/
--
2.25.1
More information about the ffmpeg-devel
mailing list