int get_frame_total_yuv( hnd_t handle )
{
yuv_input_t *h = handle;
int i_frame_total = 0;
if( !fseek( h->fh, 0, SEEK_END ) )
{
uint64_t i_size = ftell( h->fh ); //计算出文件的大小
fseek( h->fh, 0, SEEK_SET ); //作用是将文件指针放到文件开始位置
i_frame_total = (int)(i_size / ( h->width * h->height * 3 / 2 ));
//计算总的帧数, 这里乘以1.5是因为一个编码单位是一个亮度块加2个色度块,大小上等于1.5个亮度块
}
return i_frame_total;
}
其中fseek中第一个参数为文件指针,第二个参数为偏移量,起始位置,SEEK_END 表示文件尾,SEEK_SET 表示文件头。fseek作用是将定位文件指针,用于随机访问。ftell函数返回h->fh的指针偏移位值.
2. i_frame_total -= opt->i_seek;
if( ( i_frame_total == 0 || param->i_frame_total < i_frame_total )
&& param->i_frame_total > 0 )
i_frame_total = param->i_frame_total;
param->i_frame_total = i_frame_total;
//获取要求编码的帧数param->i_frame_total。
3. x264_t *x264_encoder_open ( x264_param_t *param ), 在文件encoder.c中,对不正确的264_t结构体(h的类型是264_t * )参数进行修改,并对各结构体参数、编码、预测等需要的参数进行初始化。
x264_t *x264_encoder_open ( x264_param_t *param )
{
x264_t *h = x264_malloc( sizeof( x264_t ) ); //分配空间并进行初始化,x264_malloc( )在common.c中。
int i;
memset( h, 0, sizeof( x264_t ) );
/* Create a copy of param */
memcpy( &h->param, param, sizeof( x264_param_t ) ); //创建param的副本
//memcpy原型:extern void *memcpy(void *dest, void *src, unsigned int count);
//用法:#include <string.h>, 功能:由src所指内存区域复制count个字节到dest所指内存区域。
//说明:src和dest所指内存区域不能重叠,函数返回指向dest的指针。
if( x264_validate_parameters( h ) < 0 ) // 函数x264_validate_parameters( h )在encoder.c中,
// 功能为判断参数是否有效,并对不合适的参数进行修改
{
x264_free( h );
return NULL;
}
if( h->param.psz_cqm_file )
if( x264_cqm_parse_file( h, h->param.psz_cqm_file ) < 0 )
{
x264_free( h );
return NULL;
}
............
}