[FFmpeg-devel] [PATCH] fixed granularity of video quality when encoding with theora codec

Maximilian Seesslen mes at seesslen.net
Fri Jan 4 16:18:11 CET 2013


A floating point version of av_clip has to be used when converting the quality level.

Signed-off-by: Maximilian Seesslen <mes at seesslen.net>
---
 libavcodec/libtheoraenc.c |    2 +-
 libavutil/common.h        |   14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index 1419723..350ac67 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -212,7 +212,7 @@ static av_cold int encode_init(AVCodecContext* avc_context)
                 * 0 <= p <=63
                 * an int value
          */
-        t_info.quality        = av_clip(avc_context->global_quality / (float)FF_QP2LAMBDA, 0, 10) * 6.3;
+        t_info.quality        = av_fclip(avc_context->global_quality / (float)FF_QP2LAMBDA, 0, 10) * 6.3;
         t_info.target_bitrate = 0;
     } else {
         t_info.target_bitrate = avc_context->bit_rate;
diff --git a/libavutil/common.h b/libavutil/common.h
index 0f36309..c9e843b 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -103,6 +103,20 @@ static av_always_inline av_const int av_clip_c(int a, int amin, int amax)
 }
 
 /**
+ * Clips a float value into the amin-amax range.
+ * @param a value to clip
+ * @param amin minimum value of the clip range
+ * @param amax maximum value of the clip range
+ * @return clipped value
+ */
+static inline av_const float av_fclip(float a, float amin, float amax)
+{
+    if      (a < amin) return amin;
+    else if (a > amax) return amax;
+    else               return a;
+}
+
+/**
  * Clip a signed 64bit integer value into the amin-amax range.
  * @param a value to clip
  * @param amin minimum value of the clip range
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list