作为一个刚入门的小白,语言基础基本为零!记录点滴学习和成长~
今天分享的是x264源码中main函数的分析。读程序对我来说都是困难,所以首先一句一句分析程序。也希望看到我文章的朋友能帮帮我这个新新新人~先行谢过了
x264函数入口为main(),main函数的主要作用是调用了parse和encode两个函数。
- /*
- 功能:主要调用了两个函数:parse()和encode()。
- main()首先调用parse()解析输入的命令行参数,然后调用encode()进行编码。
- */
- int main( int argc, char **argv ) //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 ); /*
CONSOLE_TITLE_SIZE 由lpConsoleTitle指向的缓冲区大小返回值如果函数成功,则返回值是以 字符为单位的长度控制台窗口的标题。如果该函数失败,则返回值为零。要获取 错误信息,请调用GetLastError */
- _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 ) ///////////////////解析命令行输入,调用parse()
- 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 ); ///////////////////编码,调用encode()
- /* 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;
- }
本文详细分析了x264源码中的main函数,包括其如何通过parse函数解析命令行参数及如何通过encode函数进行编码的过程。
6159

被折叠的 条评论
为什么被折叠?



