Commit db724ac2 authored by Anton Mitrofanov's avatar Anton Mitrofanov Committed by Loren Merritt

new API function x264_encoder_delayed_frames.

fix x264cli on streams whose total length is less than the encoder latency.
parent 9179e923
...@@ -2137,3 +2137,20 @@ void x264_encoder_close ( x264_t *h ) ...@@ -2137,3 +2137,20 @@ void x264_encoder_close ( x264_t *h )
x264_free( h->thread[i] ); x264_free( h->thread[i] );
} }
} }
/****************************************************************************
* x264_encoder_delayed_frames:
****************************************************************************/
int x264_encoder_delayed_frames( x264_t *h )
{
int delayed_frames = 0;
int i;
for( i=0; i<h->param.i_threads; i++ )
delayed_frames += h->thread[i]->b_thread_active;
h = h->thread[ h->i_thread_phase % h->param.i_threads ];
for( i=0; h->frames.current[i]; i++ )
delayed_frames++;
for( i=0; h->frames.next[i]; i++ )
delayed_frames++;
return delayed_frames;
}
...@@ -1192,13 +1192,14 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) ...@@ -1192,13 +1192,14 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
fflush( stderr ); // needed in windows fflush( stderr ); // needed in windows
} }
} }
/* Flush delayed B-frames */ /* Flush delayed frames */
do { while( x264_encoder_delayed_frames( h ) )
{
i_frame_size = Encode_frame( h, opt->hout, NULL ); i_frame_size = Encode_frame( h, opt->hout, NULL );
if( i_frame_size < 0 ) if( i_frame_size < 0 )
return -1; return -1;
i_file += i_frame_size; i_file += i_frame_size;
} while( i_frame_size ); }
i_end = x264_mdate(); i_end = x264_mdate();
x264_picture_clean( &pic ); x264_picture_clean( &pic );
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <stdarg.h> #include <stdarg.h>
#define X264_BUILD 70 #define X264_BUILD 71
/* x264_t: /* x264_t:
* opaque handler for encoder */ * opaque handler for encoder */
...@@ -431,5 +431,9 @@ int x264_encoder_encode ( x264_t *, x264_nal_t **, int *, x264_picture_t *, ...@@ -431,5 +431,9 @@ int x264_encoder_encode ( x264_t *, x264_nal_t **, int *, x264_picture_t *,
/* x264_encoder_close: /* x264_encoder_close:
* close an encoder handler */ * close an encoder handler */
void x264_encoder_close ( x264_t * ); void x264_encoder_close ( x264_t * );
/* x264_encoder_delayed_frames:
* return the number of currently delayed (buffered) frames
* this should be used at the end of the stream, to know when you have all the encoded frames. */
int x264_encoder_delayed_frames( x264_t * );
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment