x265探索与研究(六):main()函数

本文详细探讨了x265编码器的入口函数main(),包括其功能、代码结构和主要调用的子功能。main()负责参数解析、编码器初始化、NAL设置、编码过程及关闭编码器。重点分析了cliopt.parse()、encoder_open()、encoder_headers()、encoder_encode()和encoder_close()等关键函数的作用。
摘要由CSDN通过智能技术生成

x265探索与研究(六):main()函数

 

        x265源码的入口函数是main(),本文分析main()的主要功能。首先给出main()函数的功能及其代码结构;其次给出main()函数源码以及分析;最后给出main()函数中的主要功能函数的具体功能。

 

1main()函数的功能及其代码结构

 

        main()函数的主要功能是解析参数并进行编码的一些准备工作,调用了如下几个重要的函数:

1cliopt.parse()函数:解析参数

2api->encoder_open()函数:打开编码器配置

3api->encoder_headers()函数:设置NAL相关信息

4api->encoder_encode()函数:进入编码函数

5api->encoder_close()函数:结束编码并进行总结

 

注:encoder_open()函数、encoder_headers()函数、encoder_encode()函数与encoder_close()函数均位于api.app中。

 

        对应的函数关系图如下图所示:




2main()函数源码以及分析

        

        main()函数的源码分析如下代码中的注释,代码如下:

/*=============================================================*/
/*
 ====== Analysed by: RuiDong Fang 
 ====== Csdn Blog:	 http://blog.csdn.net/frd2009041510 
 ====== Date:		 2016.04.10
 ====== Funtion:	 x265的入口main()函数
 */
/*=============================================================*/
/* CLI return codes:
 *
 * 0 - encode successful
 * 1 - unable to parse command line
 * 2 - unable to open encoder
 * 3 - unable to generate stream headers
 * 4 - encoder abort
 * 5 - unable to open csv file
 *
 */
int main(int argc, char **argv)	//主函数入口
{
#if HAVE_VLD
    // This uses Microsoft's proprietary WCHAR type, but this only builds on Windows to start with
    VLDSetReportOptions(VLD_OPT_REPORT_TO_DEBUGGER | VLD_OPT_REPORT_TO_FILE, L"x265_leaks.txt");
#endif
    PROFILE_INIT();
    THREAD_NAME("API", 0);

    GetConsoleTitle(orgConsoleTitle, CONSOLE_TITLE_SIZE);	//获取控制台窗口
    SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);

    ReconPlay* reconPlay = NULL;
    CLIOptions cliopt;

    if (cliopt.parse(argc, argv))	//==========分析参数,对编码器的参数进行设定,打开文件
    {
        cliopt.destroy();
        if (cliopt.api)
            cliopt.api->param_free(cliopt.param);
        exit(1);
    }

    x265_param* param = cliopt.param;
    const x265_api* api = cliopt.api;

    /* This allows muxers to modify bitstream format */
    cliopt.output->setParam(param);

    if (cliopt.reconPlayCmd)
        reconPlay = new ReconPlay(cliopt.reconPlayCmd, *param);

    /* note: we could try to acquire a different libx265 API here based on
     * the profile found during option parsing, but it must be done before
     * opening an encoder */

    x265_encoder *encoder = api->encoder_open(param);	//==========encoder_open()函数,打印编码器配置
    if (!encoder)	//若打不开编码器配置,提示错误
    {
        x265_log(param, X265_LOG_ERROR, "failed to open encoder\n");
        cliopt.destroy();
        api->param_free(param);
        api->cleanup();
        exit(2);
    }

    /* get the encoder parameters post-initialization */
    api->encoder_parameters(encoder, param);

    if (cliopt.csvfn)
    {
        cliopt.csvfpt = x265_csvlog_open(*api, *param, cliopt.csvfn, cliopt.csvLogLevel);
        if (!cliopt.csvfpt)
        {
            x265_log(param, X265_LOG_ERROR, "Unable to open CSV log file <%s>, aborting\n", cliopt.csvfn);
            cliopt.destroy();
            if (cliopt.api)
                cliopt.api->param_free(cliopt.param);
            exit(5);
        }
    }

    /* Contr
编译好的x265,带y4m文件 Syntax: x265 [options] infile [-o] outfile infile can be YUV or Y4M outfile is raw HEVC bitstream Executable Options: -h/--help Show this help text and exit -V/--version Show version info and exit Output Options: -o/--output Bitstream output file name --log-level Logging level: none error warning info debug full. Default info --no-progress Disable CLI progress reports --[no-]cu-stats Enable logging stats about distribution of cu across all modes. Default disabled Input Options: --input Raw YUV or Y4M input file name. `-` for stdin --fps Source frame rate (float or num/denom), auto-detected if Y4M --input-res WxH Source picture size [w x h], auto-detected if Y4M -f/--frames Maximum number of frames to encode. Default all --seek First frame to encode Quality reporting metrics: --[no-]ssim Enable reporting SSIM metric scores. Default disabled --[no-]psnr Enable reporting PSNR metric scores. Default disabled Profile, Level, Tier: --profile Enforce an encode profile: main, main10, mainstillpicture --level-idc Force a minumum required decoder level (as '5.0' or '50') --[no-]high-tier If a decoder level is specified, this modifier selects High tier of that level Threading, performance: --threads Number of threads for thread pool (0: detect CPU core count, default) -F/--frame-threads Number of concurrently encoded frames. 0: auto-determined by core count --[no-]wpp Enable Wavefront Parallel Processing. Default enabled --[no-]pmode Parallel mode analysis. Default disabled --[no-]pme Parallel motion estimation. De
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值