/* Only do analysis during a normal scenecut check. */
if( real_scenecut && h->param.i_bframe )
{
- int maxp1 = p0 + 1;
+ int origmaxp1 = p0 + 1;
/* Look ahead to avoid coding short flashes as scenecuts. */
if( h->param.i_bframe_adaptive == X264_B_ADAPT_TRELLIS )
/* Don't analyse any more frames than the trellis would have covered. */
- maxp1 += h->param.i_bframe;
+ origmaxp1 += h->param.i_bframe;
else
- maxp1++;
- maxp1 = X264_MIN( maxp1, num_frames );
+ origmaxp1++;
+ int maxp1 = X264_MIN( origmaxp1, num_frames );
/* Where A and B are scenes: AAAAAABBBAAAAAA
* If BBB is shorter than (maxp1-p0), it is detected as a flash
/* Where A-F are scenes: AAAAABBCCDDEEFFFFFF
* If each of BB ... EE are shorter than (maxp1-p0), they are
* detected as flashes and not considered scenecuts.
- * Instead, the first F frame becomes a scenecut. */
- for( int curp0 = p0; curp0 < maxp1; curp0++ )
- if( scenecut_internal( h, a, frames, curp0, maxp1, 0 ) )
+ * Instead, the first F frame becomes a scenecut.
+ * If the video ends before F, no frame becomes a scenecut. */
+ for( int curp0 = p0; curp0 <= maxp1; curp0++ )
+ if( maxp1 != origmaxp1 || (curp0 < maxp1 && scenecut_internal( h, a, frames, curp0, maxp1, 0 )) )
/* If cur_p0 is the p0 of a scenecut, it cannot be the p1 of a scenecut. */
frames[curp0]->b_scenecut = 0;
}