]> git.videolan.org Git - x264.git/commitdiff
Automatically restrict QPs to avoid quantization (under|over)flow
authorJason Garrett-Glaser <darkshikari@gmail.com>
Fri, 26 Nov 2010 06:12:07 +0000 (22:12 -0800)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Tue, 7 Dec 2010 02:56:59 +0000 (18:56 -0800)
--cqm jvt and similar should now work "out of the box" instead of requiring futzing with --qpmin.

common/set.c

index 92b6b7a64450eb7a6efe9f2501acdf7487658a7e..ecdc750deb317b91f2318a0669eb48a01775d3ec 100644 (file)
@@ -185,23 +185,19 @@ int x264_cqm_init( x264_t *h )
                 }
     }
 
-    if( !h->mb.b_lossless && max_qp_err >= h->param.rc.i_qp_min )
+    if( !h->mb.b_lossless )
     {
-        x264_log( h, X264_LOG_ERROR, "Quantization overflow.  Your CQM is incompatible with QP < %d,\n", max_qp_err+1 );
-        x264_log( h, X264_LOG_ERROR, "but min QP is set to %d.\n", h->param.rc.i_qp_min );
-        return -1;
-    }
-    if( !h->mb.b_lossless && max_chroma_qp_err >= h->chroma_qp_table[h->param.rc.i_qp_min] )
-    {
-        x264_log( h, X264_LOG_ERROR, "Quantization overflow.  Your CQM is incompatible with QP < %d,\n", max_chroma_qp_err+1 );
-        x264_log( h, X264_LOG_ERROR, "but min chroma QP is implied to be %d.\n", h->chroma_qp_table[h->param.rc.i_qp_min] );
-        return -1;
-    }
-    if( !h->mb.b_lossless && min_qp_err <= h->param.rc.i_qp_max )
-    {
-        x264_log( h, X264_LOG_ERROR, "Quantization underflow.  Your CQM is incompatible with QP > %d,\n", min_qp_err-1 );
-        x264_log( h, X264_LOG_ERROR, "but max QP is implied to be %d.\n", h->param.rc.i_qp_max );
-        return -1;
+        while( h->chroma_qp_table[h->param.rc.i_qp_min] <= max_chroma_qp_err )
+            h->param.rc.i_qp_min++;
+        if( min_qp_err <= h->param.rc.i_qp_max )
+            h->param.rc.i_qp_max = min_qp_err-1;
+        if( max_qp_err >= h->param.rc.i_qp_min )
+            h->param.rc.i_qp_min = max_qp_err+1;
+        if( h->param.rc.i_qp_min > h->param.rc.i_qp_max )
+        {
+            x264_log( h, X264_LOG_ERROR, "Impossible QP constraints for CQM (min=%d, max=%d)\n", h->param.rc.i_qp_min, h->param.rc.i_qp_max );
+            return -1;
+        }
     }
     return 0;
 fail: