[x264-devel] MBAFF: Modify ratecontrol to update every two rows
Simon Horlick
git at videolan.org
Thu May 12 08:39:08 CEST 2011
x264 | branch: master | Simon Horlick <simonhorlick at gmail.com> | Fri Mar 25 13:36:21 2011 +0000| [20d9cb8c7b79b29857fe7d92c931efbd65f09df1] | committer: Jason Garrett-Glaser
MBAFF: Modify ratecontrol to update every two rows
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=20d9cb8c7b79b29857fe7d92c931efbd65f09df1
---
encoder/encoder.c | 12 ++++++++++--
encoder/ratecontrol.c | 18 +++++++++++++-----
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/encoder/encoder.c b/encoder/encoder.c
index 9bb40c6..f5d1901 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -2012,6 +2012,7 @@ static int x264_slice_write( x264_t *h )
i_mb_y = h->sh.i_first_mb / h->mb.i_mb_width;
i_mb_x = h->sh.i_first_mb % h->mb.i_mb_width;
i_skip = 0;
+ int mb_size[2];
while( 1 )
{
@@ -2113,7 +2114,7 @@ reencode:
}
int total_bits = bs_pos(&h->out.bs) + x264_cabac_pos(&h->cabac);
- int mb_size = total_bits - mb_spos;
+ mb_size[i_mb_y&1] = total_bits - mb_spos;
if( slice_max_size )
{
@@ -2233,7 +2234,14 @@ reencode:
if( b_deblock )
x264_macroblock_deblock_strength( h );
- x264_ratecontrol_mb( h, mb_size );
+ if( h->sh.b_mbaff )
+ {
+ /* update ratecontrol per-mbpair in MBAFF */
+ if( i_mb_y&1 )
+ x264_ratecontrol_mb( h, mb_size[0]+mb_size[1] );
+ }
+ else
+ x264_ratecontrol_mb( h, mb_size[i_mb_y&1] );
if( mb_xy == h->sh.i_last_mb )
break;
diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index 3dad0c5..5506352 100644
--- a/encoder/ratecontrol.c
+++ b/encoder/ratecontrol.c
@@ -1335,7 +1335,7 @@ static double predict_row_size( x264_t *h, int y, double qp )
static double row_bits_so_far( x264_t *h, int y )
{
double bits = 0;
- for( int i = h->i_threadslice_start; i <= y; i++ )
+ for( int i = h->i_threadslice_start+h->sh.b_mbaff; i <= y; i+=(h->sh.b_mbaff+1) )
bits += h->fdec->i_row_bits[i];
return bits;
}
@@ -1343,7 +1343,7 @@ static double row_bits_so_far( x264_t *h, int y )
static double predict_row_size_sum( x264_t *h, int y, double qp )
{
double bits = row_bits_so_far(h, y);
- for( int i = y+1; i < h->i_threadslice_end; i++ )
+ for( int i = y+1+h->sh.b_mbaff; i < h->i_threadslice_end; i+=(1+h->sh.b_mbaff) )
bits += predict_row_size( h, i, qp );
return bits;
}
@@ -1357,8 +1357,16 @@ void x264_ratecontrol_mb( x264_t *h, int bits )
x264_emms();
h->fdec->i_row_bits[y] += bits;
- rc->qpa_rc += rc->qpm;
- rc->qpa_aq += h->mb.i_qp;
+ if( h->sh.b_mbaff )
+ {
+ rc->qpa_rc += rc->qpm*2.0f;
+ rc->qpa_aq += h->mb.i_qp + h->mb.i_last_qp;
+ }
+ else
+ {
+ rc->qpa_rc += rc->qpm;
+ rc->qpa_aq += h->mb.i_qp;
+ }
if( h->mb.i_mb_x != h->mb.i_mb_width - 1 || !rc->b_vbv )
return;
@@ -1383,7 +1391,7 @@ void x264_ratecontrol_mb( x264_t *h, int bits )
/* B-frames shouldn't use lower QP than their reference frames. */
if( h->sh.i_type == SLICE_TYPE_B )
{
- qp_min = X264_MAX( qp_min, X264_MAX( h->fref[0][0]->f_row_qp[y+1], h->fref[1][0]->f_row_qp[y+1] ) );
+ qp_min = X264_MAX( qp_min, X264_MAX( h->fref[0][0]->f_row_qp[y+1+h->sh.b_mbaff], h->fref[1][0]->f_row_qp[y+1+h->sh.b_mbaff] ) );
rc->qpm = X264_MAX( rc->qpm, qp_min );
}
More information about the x264-devel
mailing list