encode()函数中循环调用encode_frame()函数进行逐帧编码:
static int encode_frame( x264_t *h, hnd_t hout, x264_picture_t *pic, int64_t *last_dts )
{
x264_picture_t pic_out; // 编码后输出帧
x264_nal_t *nal; // NAL数据包
int i_nal;
int i_frame_size = 0;
i_frame_size = x264_encoder_encode( h, &nal, &i_nal, pic, &pic_out ); // 编码单帧
FAIL_IF_ERROR( i_frame_size < 0, "x264_encoder_encode failed\n" );
if( i_frame_size )
{
i_frame_size = cli_output.write_frame( hout, nal[0].p_payload, i_frame_size, &pic_out ); // 将编码后的图片装入输出视频流
*last_dts = pic_out.i_dts; // 显示时间戳
}
return i_frame_size;
}
x264_encoder_encode()函数,x264中一个十分重要的函数,理解此函数对后面算法函数的深入十分关键: