static void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qscale )
{
int i, ch;
+ int b_decimate = b_inter && (h->sh.i_type == SLICE_TYPE_B || h->param.analyse.b_dct_decimate);
for( ch = 0; ch < 2; ch++ )
{
quant_4x4( h, dct4x4[i], h->quant4_mf[CQM_4IC + b_inter], i_qscale, !b_inter );
scan_zigzag_4x4( h->dct.block[16+i+ch*4].residual_ac, dct4x4[i] );
- if( b_inter )
+ if( b_decimate )
{
i_decimate_score += x264_mb_decimate_score( h->dct.block[16+i+ch*4].residual_ac, 15 );
}
h->dctf.idct2x2dc( dct2x2 );
x264_mb_dequant_2x2_dc( dct2x2, h->dequant4_mf[CQM_4IC + b_inter], i_qscale ); /* XXX not inversed */
- if( b_inter && i_decimate_score < 7 )
+ if( b_decimate && i_decimate_score < 7 )
{
/* Near null chroma 8x8 block so make it null (bits saving) */
- memset( dct4x4, 0, sizeof( dct4x4 ) );
memset( &h->dct.block[16+ch*4], 0, 4 * sizeof( *h->dct.block ) );
+ if( !array_non_zero( (int*)dct2x2, sizeof(dct2x2)/sizeof(int) ) )
+ continue;
+ memset( dct4x4, 0, sizeof( dct4x4 ) );
}
else
{
h->quantf.dequant_4x4( dct4x4[i], h->dequant4_mf[CQM_4IC + b_inter], i_qscale );
}
- /* calculate dct coeffs */
for( i = 0; i < 4; i++ )
- {
- /* copy dc coeff */
dct4x4[i][0][0] = dct2x2[0][i];
- }
h->dctf.add8x8_idct( p_dst, dct4x4 );
}
}
{
int i_cbp_dc = 0;
int i_qp = h->mb.i_qp;
+ int b_decimate = h->sh.i_type == SLICE_TYPE_B || h->param.analyse.b_dct_decimate;
int i;
if( h->mb.i_type == P_SKIP )
{
int16_t dct8x8[4][8][8];
int nnz8x8[4] = {1,1,1,1};
+ b_decimate &= !h->mb.b_trellis; // 8x8 trellis is inherently optimal decimation
h->dctf.sub16x16_dct8( dct8x8, h->mb.pic.p_fenc[0], h->mb.pic.p_fdec[0] );
for( idx = 0; idx < 4; idx++ )
scan_zigzag_8x8full( h->dct.luma8x8[idx], dct8x8[idx] );
- if( !h->mb.b_trellis )
+ if( b_decimate )
{
int i_decimate_8x8 = x264_mb_decimate_score( h->dct.luma8x8[idx], 64 );
i_decimate_mb += i_decimate_8x8;
nnz8x8[idx] = 0;
}
}
+ else
+ nnz8x8[idx] = array_non_zero( (int*)dct8x8[idx], sizeof(*dct8x8)/sizeof(int) );
}
- if( i_decimate_mb < 6 && !h->mb.b_trellis )
+ if( i_decimate_mb < 6 && b_decimate )
memset( h->dct.luma8x8, 0, sizeof( h->dct.luma8x8 ) );
else
{
quant_4x4( h, dct4x4[idx], h->quant4_mf[CQM_4PY], i_qp, 0 );
scan_zigzag_4x4full( h->dct.block[idx].luma4x4, dct4x4[idx] );
-
- i_decimate_8x8 += x264_mb_decimate_score( h->dct.block[idx].luma4x4, 16 );
+
+ if( b_decimate )
+ i_decimate_8x8 += x264_mb_decimate_score( h->dct.block[idx].luma4x4, 16 );
}
/* decimate this 8x8 block */
i_decimate_mb += i_decimate_8x8;
- if( i_decimate_8x8 < 4 )
+ if( i_decimate_8x8 < 4 && b_decimate )
{
memset( &dct4x4[i8x8*4], 0, 4 * sizeof( *dct4x4 ) );
memset( &h->dct.block[i8x8*4], 0, 4 * sizeof( *h->dct.block ) );
}
}
- if( i_decimate_mb < 6 )
+ if( i_decimate_mb < 6 && b_decimate )
memset( h->dct.block, 0, 16 * sizeof( *h->dct.block ) );
else
{
int i_qp = h->mb.i_qp;
uint8_t *p_fenc = h->mb.pic.p_fenc[0] + (i8&1)*8 + (i8>>1)*8*FENC_STRIDE;
uint8_t *p_fdec = h->mb.pic.p_fdec[0] + (i8&1)*8 + (i8>>1)*8*FDEC_STRIDE;
- int i_decimate_8x8 = 0;
- int nnz8x8 = 1;
+ int b_decimate = h->sh.i_type == SLICE_TYPE_B || h->param.analyse.b_dct_decimate;
+ int nnz8x8;
int ch;
x264_mb_mc_8x8( h, i8 );
{
int16_t dct8x8[8][8];
h->dctf.sub8x8_dct8( dct8x8, p_fenc, p_fdec );
-
quant_8x8( h, dct8x8, h->quant8_mf[CQM_8PY], i_qp, 0 );
scan_zigzag_8x8full( h->dct.luma8x8[i8], dct8x8 );
- i_decimate_8x8 = x264_mb_decimate_score( h->dct.luma8x8[i8], 64 );
- if( i_decimate_8x8 < 4 )
- {
- memset( h->dct.luma8x8[i8], 0, sizeof(h->dct.luma8x8[i8]) );
- nnz8x8 = 0;
- }
+ if( b_decimate )
+ nnz8x8 = 4 <= x264_mb_decimate_score( h->dct.luma8x8[i8], 64 );
+ else
+ nnz8x8 = array_non_zero( (int*)dct8x8, sizeof(dct8x8)/sizeof(int) );
+
if( nnz8x8 )
{
h->quantf.dequant_8x8( dct8x8, h->dequant8_mf[CQM_8PY], i_qp );
}
else
{
- int i4, idx;
+ int i4;
int16_t dct4x4[4][4][4];
h->dctf.sub8x8_dct( dct4x4, p_fenc, p_fdec );
-
+ quant_4x4( h, dct4x4[0], h->quant4_mf[CQM_4PY], i_qp, 0 );
+ quant_4x4( h, dct4x4[1], h->quant4_mf[CQM_4PY], i_qp, 0 );
+ quant_4x4( h, dct4x4[2], h->quant4_mf[CQM_4PY], i_qp, 0 );
+ quant_4x4( h, dct4x4[3], h->quant4_mf[CQM_4PY], i_qp, 0 );
for( i4 = 0; i4 < 4; i4++ )
- {
- idx = i8 * 4 + i4;
-
- quant_4x4( h, dct4x4[i4], h->quant4_mf[CQM_4PY], i_qp, 0 );
- scan_zigzag_4x4full( h->dct.block[idx].luma4x4, dct4x4[i4] );
- i_decimate_8x8 += x264_mb_decimate_score( h->dct.block[idx].luma4x4, 16 );
- }
+ scan_zigzag_4x4full( h->dct.block[i8*4+i4].luma4x4, dct4x4[i4] );
- if( i_decimate_8x8 < 4 )
+ if( b_decimate )
{
- memset( &h->dct.block[i8*4], 0, 4 * sizeof(*h->dct.block) );
- nnz8x8 = 0;
+ int i_decimate_8x8 = 0;
+ for( i4 = 0; i4 < 4 && i_decimate_8x8 < 4; i4++ )
+ i_decimate_8x8 += x264_mb_decimate_score( h->dct.block[i8*4+i4].luma4x4, 16 );
+ nnz8x8 = 4 <= i_decimate_8x8;
}
+ else
+ nnz8x8 = array_non_zero( (int*)dct4x4, sizeof(dct4x4)/sizeof(int) );
+
if( nnz8x8 )
{
for( i4 = 0; i4 < 4; i4++ )
- h->quantf.dequant_4x4( dct4x4[i4], h->dequant4_mf[CQM_4PY], i_qp );
+ h->quantf.dequant_4x4( dct4x4[i4], h->dequant4_mf[CQM_4PY], i_qp );
h->dctf.add8x8_idct( p_fdec, dct4x4 );
}
}
h->dctf.sub4x4_dct( dct4x4, p_fenc, p_fdec );
quant_4x4( h, dct4x4, h->quant4_mf[CQM_4PC], i_qp, 0 );
scan_zigzag_4x4( h->dct.block[16+i8+ch*4].residual_ac, dct4x4 );
- h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4PC], i_qp );
- h->dctf.add4x4_idct( p_fdec, dct4x4 );
+ if( array_non_zero( (int*)dct4x4, sizeof(dct4x4)/sizeof(int) ) )
+ {
+ h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4PC], i_qp );
+ h->dctf.add4x4_idct( p_fdec, dct4x4 );
+ }
}
if( nnz8x8 )
" - 1: enabled only on the final encode of a MB\n"
" - 2: enabled on all mode decisions\n"
" --no-fast-pskip Disables early SKIP detection on P-frames\n"
+ " --no-dct-decimate Disables coefficient thresholding on P-frames\n"
" --nr <integer> Noise reduction [%d]\n"
"\n"
" --cqm <string> Preset quant matrices [\"flat\"]\n"
#define OPT_BIME 318
#define OPT_NR 319
#define OPT_THREAD_INPUT 320
+#define OPT_NO_DCT_DECIMATE 321
static struct option long_options[] =
{
{ "8x8dct", no_argument, NULL, '8' },
{ "trellis", required_argument, NULL, 't' },
{ "no-fast-pskip", no_argument, NULL, OPT_NO_FAST_PSKIP },
+ { "no-dct-decimate", no_argument, NULL, OPT_NO_DCT_DECIMATE },
{ "level", required_argument, NULL, OPT_LEVEL },
{ "ratetol", required_argument, NULL, OPT_RATETOL },
{ "vbv-maxrate", required_argument, NULL, OPT_VBVMAXRATE },
case OPT_NO_FAST_PSKIP:
param->analyse.b_fast_pskip = 0;
break;
+ case OPT_NO_DCT_DECIMATE:
+ param->analyse.b_dct_decimate = 0;
+ break;
case OPT_LEVEL:
if( atof(optarg) < 6 )
param->i_level_idc = (int)(10*atof(optarg)+.5);