diff --git a/x264.c b/x264.c index e9eb91d..770d2d8 100644 --- a/x264.c +++ b/x264.c @@ -1064,6 +1064,8 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) int i_frame_size; int i_update_interval; char buf[200]; + int i_frames_delayed = 0; + int i_frames_delayed_cnt = 0; opt->b_progress &= param->i_log_level < X264_LOG_DEBUG; i_frame_total = p_get_frame_total( opt->hin ); @@ -1111,9 +1113,12 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) pic.i_qpplus1 = 0; } - i_file += Encode_frame( h, opt->hout, &pic ); + i_file += + i_frame_size = Encode_frame( h, opt->hout, &pic ); i_frame++; + i_frames_delayed += !i_frame_size; + i_frames_delayed_cnt += !i_frame_size; /* update status line (up to 1000 times per input file) */ if( opt->b_progress && i_frame % i_update_interval == 0 ) @@ -1137,11 +1142,14 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) fflush( stderr ); // needed in windows } } - /* Flush delayed B-frames */ - do { + /* Flush delayed frames */ + while( i_frames_delayed-- && i_frames_delayed_cnt < X264_BFRAME_MAX * 4 + X264_THREAD_MAX ) + { i_file += i_frame_size = Encode_frame( h, opt->hout, NULL ); - } while( i_frame_size ); + i_frames_delayed += !i_frame_size; + i_frames_delayed_cnt += !i_frame_size; + } i_end = x264_mdate(); x264_picture_clean( &pic );