[FFmpeg-devel] [PATCH] Make global_quality a float

Nicolas George nicolas.george
Sat Oct 11 12:40:34 CEST 2008


Hi.

The gloal_quality field in AVCodecContext is currently an integer, but IMHO
it should be a float: a lot of codecs treat it as a float, it is scaled by a
118 factor which leads to odd rounding errors, it is sometimes stored to or
from other float fields, etc.

The attached patch turns it into a float.

As it changes the binary interface of the library, I understand it requires
a major version bump. I could also make the change conditional to the next
bump, if this is the preferred way.

Regards,

-- 
  Nicolas George
-------------- next part --------------
Index: libavcodec/asv1.c
===================================================================
--- libavcodec/asv1.c	(revision 15594)
+++ libavcodec/asv1.c	(working copy)
@@ -579,7 +579,7 @@
 
     if(avctx->global_quality == 0) avctx->global_quality= 4*FF_QUALITY_SCALE;
 
-    a->inv_qscale= (32*scale*FF_QUALITY_SCALE +  avctx->global_quality/2) / avctx->global_quality;
+    a->inv_qscale= (32*scale*FF_QUALITY_SCALE + (int)avctx->global_quality/2) / (int)avctx->global_quality;
 
     avctx->extradata= av_mallocz(8);
     avctx->extradata_size=8;
Index: libavcodec/utils.c
===================================================================
--- libavcodec/utils.c	(revision 15594)
+++ libavcodec/utils.c	(working copy)
@@ -633,7 +633,7 @@
 {"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
 {"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
 {"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_FLOAT, DEFAULT, INT_MIN, INT_MAX},
 {"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
 {"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
 {"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
Index: libavcodec/mpegvideo_enc.c
===================================================================
--- libavcodec/mpegvideo_enc.c	(revision 15594)
+++ libavcodec/mpegvideo_enc.c	(working copy)
@@ -2703,7 +2703,7 @@
         //FIXME broken
     }else
         s->lambda= s->current_picture.quality;
-//printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality);
+//printf("%f %d\n", s->avctx->global_quality, s->current_picture.quality);
     update_qscale(s);
     return 0;
 }
Index: libavcodec/avcodec.h
===================================================================
--- libavcodec/avcodec.h	(revision 15594)
+++ libavcodec/avcodec.h	(working copy)
@@ -29,7 +29,7 @@
 
 #include "libavutil/avutil.h"
 
-#define LIBAVCODEC_VERSION_MAJOR 52
+#define LIBAVCODEC_VERSION_MAJOR 53
 #define LIBAVCODEC_VERSION_MINOR  0
 #define LIBAVCODEC_VERSION_MICRO  0
 
@@ -1651,7 +1651,7 @@
      * - encoding: Set by user.
      * - decoding: unused
      */
-    int global_quality;
+    float global_quality;
 
 #define FF_CODER_TYPE_VLC       0
 #define FF_CODER_TYPE_AC        1
Index: libavcodec/libschroedingerenc.c
===================================================================
--- libavcodec/libschroedingerenc.c	(revision 15594)
+++ libavcodec/libschroedingerenc.c	(working copy)
@@ -170,7 +170,7 @@
                                           "rate_control",
                                           SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
         } else {
-            int noise_threshold;
+            double noise_threshold;
             schro_encoder_setting_set_double (p_schro_params->encoder,
                           "rate_control",
                           SCHRO_ENCODER_RATE_CONTROL_CONSTANT_NOISE_THRESHOLD);
Index: ffserver.c
===================================================================
--- ffserver.c	(revision 15594)
+++ ffserver.c	(working copy)
@@ -4200,7 +4200,7 @@
             get_arg(arg, sizeof(arg), &p);
             if (stream) {
                 video_enc.flags |= CODEC_FLAG_QSCALE;
-                video_enc.global_quality = FF_QP2LAMBDA * atoi(arg);
+                video_enc.global_quality = FF_QP2LAMBDA * strtof(arg, NULL);
             }
         } else if (!strcasecmp(cmd, "VideoQDiff")) {
             get_arg(arg, sizeof(arg), &p);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081011/ac5ad6a8/attachment.pgp>



More information about the ffmpeg-devel mailing list