x264源代码简单分析:x264命令行工具(x264.exe)(通用2篇)
篇1:x264源代码简单分析:x264命令行工具(x264.exe)
X264命令行工具的源代码在x264中的位置如下图所示。
单击查看更清晰的图片
X264命令行工具的源代码的调用关系如下图所示。
单击查看更清晰的图片
从图中可以看出,X264命令行工具调用了libx264的几个API完成了H.264编码工作。使用libx264的API进行编码可以参考《最简单的视频编码器:基于libx264(编码YUV为H.264)》,这个流程中最关键的API包括:
x264_param_default:设置参数集结构体x264_param_t的缺省值。
x264_encoder_open():打开编码器。
x264_encoder_headers():输出SPS,PPS,SEI等信息。
x264_encoder_encode():编码输出一帧图像。
x264_encoder_close():关闭编码器。
在X264命令行工具中,main()首先调用parse()解析输入的命令行参数,然后调用encode()进行编码。parse()首先调用x264_param_default()为存储参数的结构体x264_param_t赋默认值;然后在一个大循环中调用getopt_long()逐个解析输入的参数,并作相应的处理;最后调用select_input()和select_output()解析输入文件格式(例如yuv,y4m…)和输出文件格式(例如raw,flv,MP4…)。encode()首先调用x264_encoder_open()打开H.264编码器,然后调用x264_encoder_headers()输出H.264码流的头信息(例如SPS、PPS、SEI),接着进入一个循环并且调用encode_frame()逐帧编码视频,最后调用x264_encoder_close()关闭解码器。其中encode_frame()中又调用了x264_encoder_encode()完成了具体的编码工作。下文将会对上述流程展开分析。
篇2:x264源代码简单分析:x264命令行工具(x264.exe)
main()是x264控制台程序的入口函数,定义如下所示。
//主函数int main( int argc, char **argv ){ //参数集 x264_param_t param; cli_opt_t pt = {0}; int ret = 0; FAIL_IF_ERROR( x264_threading_init(), unable to initialize threading )#ifdef _WIN32 FAIL_IF_ERROR( !get_argv_utf8( &argc, &argv ), unable to convert command line to UTF-8 ) 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 */ 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;}
可以看出main()的定义很简单,它主要调用了两个函数:parse()和encode()。main()首先调用parse()解析输入的命令行参数,然后调用encode()进行编码。下面分别分析这两个函数。
【x264源代码简单分析:x264命令行工具(x264.exe)】相关文章:
解析ICMP的ping命令代码05-17
九行代码让windows崩溃原因分析Windows安全04-21
关于软件代码测试工具的广告词05-15
Shell脚本实现的基于SVN的代码提交量统计工具05-18
词法分析设计实验报告(附代码)04-14
教学源代码05-05
开放源代码软件05-25
源代码英语影评英文04-12
用户管理系统源代码05-13
java课程设计带源代码06-20