[x264-devel] Improve slice header QP selection

Jason Garrett-Glaser git at videolan.org
Thu Nov 8 00:55:03 CET 2012


x264 | branch: master | Jason Garrett-Glaser <jason at x264.com> | Wed Sep 26 13:05:00 2012 -0700| [8437d0db5de43cf9cd11e02444c80984935e25dc] | committer: Jason Garrett-Glaser

Improve slice header QP selection
Use the first macroblock of each slice instead of the last of the previous.
Lets us pick a reasonable initial QP for the first slice too.
Slightly improved compression.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=8437d0db5de43cf9cd11e02444c80984935e25dc
---

 encoder/encoder.c |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 2e23d74..8ec9260 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -2236,14 +2236,10 @@ static int x264_slice_write( x264_t *h )
     /* Slice header */
     x264_macroblock_thread_init( h );
 
-    /* If this isn't the first slice in the threadslice, set the slice QP
-     * equal to the last QP in the previous slice for more accurate
-     * CABAC initialization. */
-    if( h->sh.i_first_mb != h->i_threadslice_start * h->mb.i_mb_width )
-    {
-        h->sh.i_qp = h->mb.i_last_qp;
-        h->sh.i_qp_delta = h->sh.i_qp - h->pps->i_pic_init_qp;
-    }
+    /* Set the QP equal to the first QP in the slice for more accurate CABAC initialization. */
+    h->mb.i_mb_xy = h->sh.i_first_mb;
+    h->sh.i_qp = x264_ratecontrol_mb_qp( h );
+    h->sh.i_qp_delta = h->sh.i_qp - h->pps->i_pic_init_qp;
 
     x264_slice_header_write( &h->out.bs, &h->sh, h->i_nal_ref_idc );
     if( h->param.b_cabac )



More information about the x264-devel mailing list