I am using FFMPEG + x264 on Android to encode YUV420 frames to a video file. I use the following code on each frame to encode them:
avcodec_encode_video2(gVideoWriteCodecCtx, &packet, pCurrentFrame, &gotPacket);
On the first few calls, the frame buffer gets filled and nothing is encoded. When the first encoding happens, a call is made to x264_lookahead_get_frames. I can see there that my frame array is correctly populated, but the first item is NULL. As a consequence, in x264_weights_analyse the reference frame gotten as frames[p0] is NULL and I get an exception there.
slicetype.c, the first frame in "frames" is NULL
if( h->param.analyse.i_weighted_pred && b == p1 )
{
x264_emms();
x264_weights_analyse( h, fenc, frames[p0], 1 );
w = fenc->weight[0];
}
And the exception happens there, ref is NULL
static void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int b_lookahead )
{
int i_delta_index = fenc->i_frame - ref->i_frame - 1;
I surely am missing something as I am sure this encoder works for most people :) Does anyone have an idea why this first frame in the "frames" array is null?
Many thanks