diff --git a/encoder/slicetype.c b/encoder/slicetype.c index fff7bc4..b318560 100644 --- a/encoder/slicetype.c +++ b/encoder/slicetype.c @@ -311,7 +311,7 @@ int x264_slicetype_frame_cost( x264_t *h, x264_mb_analysis_t *a, x264_emms(); } - if( b_intra_penalty ) + if( b_intra_penalty && h->sps->i_mb_width > 2 && h->sps->i_mb_height > 2 ) { // arbitrary penalty for I-blocks after B-frames int nmb = (h->sps->i_mb_width - 2) * (h->sps->i_mb_height - 2); @@ -350,7 +350,11 @@ static int scenecut( x264_t *h, x264_frame_t *frame, int pdist ) if( res ) { int imb = frame->i_intra_mbs[pdist]; - int pmb = (h->sps->i_mb_width - 2) * (h->sps->i_mb_height - 2) - imb; + int pmb; + if( h->sps->i_mb_width > 2 && h->sps->i_mb_height > 2 ) + pmb = (h->sps->i_mb_width - 2) * (h->sps->i_mb_height - 2) - imb; + else + pmb = -imb; x264_log( h, X264_LOG_DEBUG, "scene cut at %d Icost:%d Pcost:%d ratio:%.4f bias:%.4f gop:%d (imb:%d pmb:%d)\n", frame->i_frame, icost, pcost, 1. - (double)pcost / icost, @@ -366,10 +370,15 @@ void x264_slicetype_analyse( x264_t *h ) int num_frames; int keyint_limit; int j; - int i_mb_count = (h->sps->i_mb_width - 2) * (h->sps->i_mb_height - 2); + int i_mb_count; int cost1p0, cost2p0, cost1b1, cost2p1; int idr_frame_type; + if( h->sps->i_mb_width > 2 && h->sps->i_mb_height > 2 ) + i_mb_count = (h->sps->i_mb_width - 2) * (h->sps->i_mb_height - 2); + else + i_mb_count = 0; + assert( h->frames.b_have_lowres ); if( !h->frames.last_nonb ) @@ -419,9 +428,14 @@ no_b_frames: { int pthresh = X264_MAX(INTER_THRESH - P_SENS_BIAS * (j-1), INTER_THRESH/10); int pcost = x264_slicetype_frame_cost( h, &a, frames, 0, j+1, j+1, 1 ); -// fprintf( stderr, "frm%d+%d: %d <=> %d, I:%d/%d \n", -// frames[0]->i_frame, j-1, pthresh, pcost/i_mb_count, -// frames[j+1]->i_intra_mbs[j+1], i_mb_count ); +// if( i_mb_count ) +// fprintf( stderr, "frm%d+%d: %d <=> %d, I:%d/%d \n", +// frames[0]->i_frame, j-1, pthresh, pcost/i_mb_count, +// frames[j+1]->i_intra_mbs[j+1], i_mb_count ); +// else +// fprintf( stderr, "frm%d+%d: %d <=> %d, I:%d/%d \n", +// frames[0]->i_frame, j-1, pthresh, pcost, +// frames[j+1]->i_intra_mbs[j+1], i_mb_count ); if( pcost > pthresh*i_mb_count || frames[j+1]->i_intra_mbs[j+1] > i_mb_count/3 ) { frames[j]->i_type = X264_TYPE_P;