首先从main还是开始,该函数在x264.c文件中。
int main( int argc, char **argv )
{
x264_param_t param;
cli_opt_t opt = {0};
int ret = 0;
FAIL_IF_ERROR( x264_threading_init(), "unable to initialize threading\n" )
#ifdef _WIN32
FAIL_IF_ERROR( !get_argv_utf8( &argc, &argv ), "unable to convert command line to UTF-8\n" )
GetConsoleTitleW( org_console_title, CONSOLE_TITLE_SIZE );
_setmode( _fileno( stdin ), _O_BINARY );
_setmode( _fileno( stdout ), _O_BINARY );
_setmode( _fileno( stderr ), _O_BINARY );
#endif
/* Parse command line */
//分析参数,对编码器的参数进行设定,打开文件
if( parse( argc, argv, ¶m, &opt ) < 0 )
ret = -1;
#ifdef _WIN32
/* Restore title; it can be changed by input modules */
SetConsoleTitleW( org_console_title );
#endif
/* Control-C handler */
//当键入Ctrl-C的时候,当前执行程序调用指针函数sigint_handler 执行完后,再返回原来执行的地方接着往下走。
signal( SIGINT, sigint_handler );
//开始编码
if( !ret )
ret = encode( ¶m, &opt );
/* clean up handles */
//清理,关闭文件
if( filter.free )
filter.free( opt.hin );
else if( opt.hin )
cli_input.close_file( opt.hin );
if( opt.hout )
cli_output.close_file( opt.hout, 0, 0 );
if( opt.tcfile_out )
fclose( opt.tcfile_out );
if( opt.qpfile )
fclose( opt.qpfile );
#ifdef _WIN32
SetConsoleTitleW( org_console_title );
free( argv );
#endif
return ret;
}
static int encode( x264_param_t *param, cli_opt_t *opt )
{
x264_t *h = NULL; //x264关键数据结构
x264_picture_t pic; //一幅图像数据
cli_pic_t cli_pic;
const cli_pulldown_t *pulldown = NULL; // shut up gcc
int i_frame = 0;
int i_