memset( opt, 0, sizeof(cli_opt_t) ),函数元型为void *memset(void *s,int c,size_t n) 将已开辟内存空间 s 的首 n 个字节的值设为值 c。
x264_param_default( ¶m ) ------对编码器的参数进行设定, 包括cpu自动检测、视频序列参量初始化(均为默认值)、编码参量初始化。
int c; c = getopt_long( argc, argv, "hi:I:b:r:cxB:q:f:o:A:m:p:t:vw8", long_options, &long_options_index);
getopt_long() 解析入口地址的向量,最后c 得到的是 运行参数(“-o test.264 foreman.yuv 352x288”)中前面“-o”中“o”的ASCII值 即 c = 111 。可通过VC Debug查看。 getopt_long() 定义在getopt.c中。其中用到 getopt_internal(nargc, nargv, options)也定义在getopt.c中,解析入口地址向量。
atol(optarg) 把string转为long类型,atoi(optarg)类似,参见MSDN.
函数定义:int strncasecmp(const char *s1, const char *s2, size_t n) 用来比较参数s1和s2字符串前n个字符,比较时会自动忽略大小写的差异, 若参数s1和s2字符串相同则返回0; s1若大于s2则返回大于0的值; s1若小于s2则返回小于0的值.
对运行参数(“-o test.264 foreman.yuv 352x288”)由c = 111 ,程序跳转到case 'o',执行p_open_outfile ( optarg, &opt->hout ),即进入函数open_file_bsf(),功能为以二进制写的方式打开输出文件test.264,函数在nuxers.c中,原型如下:
int open_file_bsf( char *psz_filename, hnd_t *p_handle )
{
if ((*p_handle = fopen(psz_filename, "w+b")) == NULL)
return -1;
return 0;
}
然后,再次执行for循环,c = getopt_long( ),得到c=-1, 跳出循环。由psz_filename = argv[optind++]获取输入文件名foreman.yuv,得到文件的尺寸,判断文件格式为avi还是avs还是y4m,如果都不是前面的格式并且输入图片高度或宽度为0,则输出帮助文件。 由函数p_open_infile( psz_filename, &opt->hin, param )打开输入文件。
p_open_infile = open_file_yuv,即进入函数open_file_yuv(),功能为以二进制读的方式打开输入文件foreman.yuv, 函数在nuxers.c中,原型如下:
int open_file_yuv( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
{
yuv_input_t *h = malloc(sizeof(yuv_input_t));
h->width = p_param->i_width;
h->height = p_param->i_height;
h->next_frame = 0;
if( !strcmp(psz_filename, "-") )
h->fh = stdin;
else
h->fh = fopen(psz_filename, "rb");
if( h->fh == NULL )
return -1;
*p_handle = (hnd_t)h;
return 0;
}
评论