编码300帧的视频,发现read_frame_yuv函数被调用300次. 函数read_frame_yuv的功能是从yuv文件中读取一帧的数据,具体函数定义如下:

int read_frame_yuv( x264_picture_t *p_pic, hnd_t handle, int i_frame )
{
    yuv_input_t *h = handle;

    if( i_frame != h->next_frame )
        if( fseek( h->fh, (uint64_t)i_frame * h->width * h->height * 3 / 2, SEEK_SET ) )  yuv420
            return -1;

    if( fread( p_pic->img.plane[0], 1, h->width * h->height, h->fh ) <= 0  // Y分量
            || fread( p_pic->img.plane[1], 1, h->width * h->height / 4, h->fh ) <= 0  // U分量
            || fread( p_pic->img.plane[2], 1, h->width * h->height / 4, h->fh ) <= 0 )  // V分量
        return -1;

    h->next_frame = i_frame + 1;

    return 0;
}


     对于每一帧而言,p_pic->img.plane[0][i]表示Y分量,p_pic->img.plane[1][i]表示U分量,p_pic->img.plane[2][i]表示V分量. 所以,通过调用read_frame_yuv函数后,yuv视频文件的像素值就读到程序中了.


本文转载:CSDN博客