x264代码详解——主函数main()

本文详细分析了x264源码中的main函数,包括其如何通过parse函数解析命令行参数及如何通过encode函数进行编码的过程。

作为一个刚入门的小白,语言基础基本为零!记录点滴学习和成长~

今天分享的是x264源码中main函数的分析。读程序对我来说都是困难,所以首先一句一句分析程序。也希望看到我文章的朋友能帮帮我这个新新新人~先行谢过了大笑

x264函数入口为main(),main函数的主要作用是调用了parse和encode两个函数。

  1. /* 
  2. 功能:主要调用了两个函数:parse()和encode()。 
  3.       main()首先调用parse()解析输入的命令行参数,然后调用encode()进行编码。 
  4. */  
  5. int main( int argc, char **argv )  //char **argv表示指针的指针
  6. {  
  7.     x264_param_t param; //参数集  这里暂时还不明白是在干嘛
  8.     cli_opt_t opt = {0}; // 这个感觉和上一句相似,同样不理解难过
  9.     int ret = 0;  
  10.   
  11.     FAIL_IF_ERROR( x264_threading_init(), "unable to initialize threading\n" ) // 还是不理解
  12.   
  13. #ifdef _WIN32  
  14.     FAIL_IF_ERROR( !get_argv_utf8( &argc, &argv ), "unable to convert command line to UTF-8\n" )  //还还还是不理解
  15.   
  16.     GetConsoleTitleW( org_console_title, CONSOLE_TITLE_SIZE );  /*
    org_console_title 指向一个缓冲区 指针 以接收包含标题的字符串.
    CONSOLE_TITLE_SIZE 由lpConsoleTitle指向的缓冲区大小
    返回值
    如果函数成功,则返回值是以 字符为单位的长度控制台窗口的标题。
    如果该函数失败,则返回值为零。要获取 错误信息,请调用GetLastError */
  17.     _setmode( _fileno( stdin ),  _O_BINARY );  //设置文件打开方式
  18.     _setmode( _fileno( stdout ), _O_BINARY );  
  19.     _setmode( _fileno( stderr ), _O_BINARY );  
  20. #endif  
  21.   
  22.     /* Parse command line */  
  23.     if( parse( argc, argv, ¶m, &opt ) < 0 )  ///////////////////解析命令行输入,调用parse()  
  24.         ret = -1;  
  25.   
  26. #ifdef _WIN32  
  27.     /* Restore title; it can be changed by input modules */  
  28.     SetConsoleTitleW( org_console_title );  
  29. #endif  
  30.   
  31.     /* Control-C handler */  
  32.     signal( SIGINT, sigint_handler );  
  33.   
  34.     if( !ret )  
  35.         ret = encode( ¶m, &opt );   ///////////////////编码,调用encode()  
  36.   
  37.     /* clean up handles */  
  38.     if( filter.free )  
  39.         filter.free( opt.hin );  
  40.     else if( opt.hin )  
  41.         cli_input.close_file( opt.hin );  
  42.     if( opt.hout )  
  43.         cli_output.close_file( opt.hout, 0, 0 );  
  44.     if( opt.tcfile_out )  
  45.         fclose( opt.tcfile_out );  
  46.     if( opt.qpfile )  
  47.         fclose( opt.qpfile );  
  48.   
  49. #ifdef _WIN32  
  50.     SetConsoleTitleW( org_console_title );  
  51.     free( argv );  
  52. #endif  
  53.   
  54.     return ret;  
  55. }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值