海思3559AV100实现8k文件编码

        终于到了编码模块。

        VENC接受的输入源有四类:VI、VO、VDEC以及用户态,这里我们要用户态输入。VENC模块的内容很多,包括各种码控、ROI处理等,这边就不写了,太多了,直接分享一下怎么实现用户态编码。

        这份代码是基于venc.c进行二次开发的,由于venc例程中包含了各种编码标准的实现,把后面的几个都删掉(代码少一半),留下一个来改就行。

        之前我改了很久都没有调通,因为我之前的逻辑是,板子数据是从sensor到vi到vpss再到venc,如果我想从vpss截胡,直接给venc传数据的话,就得把前面和sensor等外部输入的代码给注释掉,不然会影响这里,结果是牵一发动全身。后来我琢磨着人家传他的,不管不就行了,我只管把我的数据给编码器,前面爱咋咋地。

        从例程的函数开始,由于我是跑通了4k的例程,所以先以4k的文件编码为目标。

        第一个函数是SAMPLE_VENC_SetDCFInfo,用于捕获拍摄时的一些数据,如焦距、相机型号、制造商等,不用管。

        第二个函数是SAMPLE_VENC_CheckSensor,应该是检查镜头的分辨率支不支持要编的尺寸,这里我们先试的4k,所以也可以不管这个。

        第三个函数是SAMPLE_VENC_VI_Init,这里面需要注意的是SAMPLE_VENC_SYS_Init,SYS_Init里面有一个COMMON_GetPicBufferSize的函数,用来根据size分配buffer,同样我们先试的4k,所以也可以不管这个。

        第四个函数是SAMPLE_VENC_VPSS_Init,这个也是一些初始化的东西,看了下不会影响就也没有管。

        第五个函数是SAMPLE_COMM_VI_Bind_VPSS,这里我们对其解绑,不让vpss的数据给到venc,解绑代码手册是写好了的,在sample_common_sys.c中:

HI_S32 SAMPLE_COMM_VI_UnBind_VPSS(VI_PIPE ViPipe, VI_CHN ViChn, VPSS_GRP VpssGrp)
{
    MPP_CHN_S stSrcChn;
    MPP_CHN_S stDestChn;

    stSrcChn.enModId   = HI_ID_VI;
    stSrcChn.s32DevId  = ViPipe;
    stSrcChn.s32ChnId  = ViChn;

    stDestChn.enModId  = HI_ID_VPSS;
    stDestChn.s32DevId = VpssGrp;
    stDestChn.s32ChnId = 0;

    CHECK_RET(HI_MPI_SYS_UnBind(&stSrcChn, &stDestChn), "HI_MPI_SYS_UnBind(VI-VPSS)");

    return HI_SUCCESS;
}

        直接把bind注释掉好像也可以,我没有尝试,此时再运行时会报错get venc stream time out。

        接下来就是编码部分,首先SAMPLE_COMM_VENC_Start来创建编码通道等,接着原代码在这下面通过SAMPLE_COMM_VPSS_Bind_VENC绑定通道喂数据,把这部分注释掉,新加一个函数,通过这个函数把自己的代码输进去。读取YUV部分的代码参考的下面这篇文章:【Hi3559A 使用HI_MPI_VENC_SendFrame送yuv的例子】_venc_chnvencchns[2] = {0,1}-CSDN博客文章浏览阅读1k次,点赞2次,收藏6次。Hi3559A 使用HI_MPI_VENC_SendFrame送yuv的例子说明:参考mpp中sample_venc.c添加如下代码,自行调用即可。代码是向venc灌入同一帧yuv数据,仅供参考。HI_VOID* SAMPLE_SendVencOneFrameProc(HI_VOID* p){ VENC_CHN VencChn = 0; HI_S32 s32Ret = HI_SUCCESS;HI_U64 u32Cnt = 0; HI_U32 u32Profile = _venc_chnvencchns[2] = {0,1}https://blog.csdn.net/m0_37823030/article/details/124344999?spm=1001.2014.3001.5502        若要改为8k,SAMPLE_VENC_CheckSensor这个函数直接注释了,文件编码不需要check,然后COMMON_GetPicBufferSize要注意尺寸,我这边直接手写了8k的宽高。因为我是改完了才记录的,所以其他哪里有没有改记不清楚了,我把所有代码附上:

/******************************************************************************

  Copyright (C), 2017, Hisilicon Tech. Co., Ltd.

 ******************************************************************************
  File Name     : sample_venc.c
  Version       : Initial Draft
  Author        : Hisilicon multimedia software group
  Created       : 2017
  Description   :
******************************************************************************/

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* End of #ifdef __cplusplus */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>

#include "sample_comm.h"

//#define SUPPORT_PRORES
/******************************************************************************
* function : show usage
******************************************************************************/
void SAMPLE_VENC_Usage(char* sPrgNm)
{
    printf("Usage : %s [index] \n", sPrgNm);
    printf("index:\n");
    printf("\t  0) file-encoding 4k@1frame.\n");
    printf("\t  1) file-encoding 8k@1frame.\n");

    return;
}

/******************************************************************************
* function : to process abnormal case
******************************************************************************/
void SAMPLE_VENC_HandleSig(HI_S32 signo)
{
    if (SIGINT == signo || SIGTERM == signo)
    {
        SAMPLE_COMM_VENC_StopGetStream();
        SAMPLE_COMM_VENC_StopSendQpmapFrame();
        SAMPLE_COMM_All_ISP_Stop();
        SAMPLE_COMM_SYS_Exit();
        printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
    }
    exit(-1);
}

/******************************************************************************
* function : to process abnormal case - the case of stream venc
******************************************************************************/
void SAMPLE_VENC_StreamHandleSig(HI_S32 signo)
{

    if (SIGINT == signo || SIGTERM == signo)
    {
        SAMPLE_COMM_SYS_Exit();
        printf("\033[0;31mprogram exit abnormally!\033[0;39m\n");
    }

    exit(0);
}

VENC_GOP_MODE_E SAMPLE_VENC_GetGopMode(void)
{
    char c;
    VENC_GOP_MODE_E enGopMode = 0;

Begin_Get:

    printf("please input choose gop mode!\n");
    printf("\t 0) NORMALP.\n");
    printf("\t 1) DUALP.\n");
    printf("\t 2) SMARTP.\n");
    printf("\t 3) ADVSMARTP\n");
    printf("\t 4) BIPREDB\n");

    while((c = getchar()) != '\n' && c != EOF)
    switch(c)
    {
        case '0':
            enGopMode = VENC_GOPMODE_NORMALP;
            break;
        case '1':
            enGopMode = VENC_GOPMODE_DUALP;
            break;
        case '2':
            enGopMode = VENC_GOPMODE_SMARTP;
        break;
        case '3':
            enGopMode = VENC_GOPMODE_ADVSMARTP;
            break;
        case '4':
            enGopMode = VENC_GOPMODE_BIPREDB;
            break;
        default:
            SAMPLE_PRT("input rcmode: %c, is invaild!\n",c);
            goto Begin_Get;
    }

    return enGopMode;
}

SAMPLE_RC_E SAMPLE_VENC_GetRcMode(void)
{
    char c;
    SAMPLE_RC_E  enRcMode = 0;

Begin_Get:

    printf("please input choose rc mode!\n");
    printf("\t c) cbr.\n");
    printf("\t v) vbr.\n");
    printf("\t a) avbr.\n");
    printf("\t f) fixQp\n");

    while((c = getchar()) != '\n' && c != EOF)
    switch(c)
    {
        case 'c':
            enRcMode = SAMPLE_RC_CBR;
            break;
        case 'v':
            enRcMode = SAMPLE_RC_VBR;
            break;
        case 'a':
            enRcMode = SAMPLE_RC_AVBR;
        break;
        case 'f':
            enRcMode = SAMPLE_RC_FIXQP;
            break;
        default:
            SAMPLE_PRT("input rcmode: %c, is invaild!\n",c);
            goto Begin_Get;
    }
    return enRcMode;
}


HI_S32 SAMPLE_VENC_SYS_Init(HI_U32 u32SupplementConfig,SAMPLE_SNS_TYPE_E  enSnsType, HI_S32 reso_w)
{
    HI_S32 s32Ret;
    HI_U64 u64BlkSize;
    VB_CONFIG_S stVbConf;
    PIC_SIZE_E enSnsSize;
    SIZE_S     stSnsSize;

    memset(&stVbConf, 0, sizeof(VB_CONFIG_S));

    s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(enSnsType, &enSnsSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed!\n");
        return s32Ret;
    }

    s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSnsSize, &stSnsSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        return s32Ret;
    }


    if(3840 == reso_w)
    {
        u64BlkSize = COMMON_GetPicBufferSize(3840, 2160, PIXEL_FORMAT_YVU_SEMIPLANAR_420, DATA_BITWIDTH_8, COMPRESS_MODE_NONE,DEFAULT_ALIGN);
        stVbConf.astCommPool[0].u64BlkSize   = u64BlkSize;
        stVbConf.astCommPool[0].u32BlkCnt    = 15;
    }
    else if(7680 == reso_w)
    {
        u64BlkSize = COMMON_GetPicBufferSize(7680, 4320, PIXEL_FORMAT_YVU_SEMIPLANAR_420, DATA_BITWIDTH_8, COMPRESS_MODE_NONE,DEFAULT_ALIGN);
        stVbConf.astCommPool[0].u64BlkSize   = u64BlkSize;
        stVbConf.astCommPool[0].u32BlkCnt    = 15;
    }
    else{
        SAMPLE_PRT("Sorry, only support 4k and 8k now \n");
    }
    

    u64BlkSize = COMMON_GetPicBufferSize(1920, 1080, PIXEL_FORMAT_YVU_SEMIPLANAR_422, DATA_BITWIDTH_10, COMPRESS_MODE_NONE,DEFAULT_ALIGN);
    stVbConf.astCommPool[1].u64BlkSize   = u64BlkSize;
    stVbConf.astCommPool[1].u32BlkCnt    = 15;

    SAMPLE_PRT("Pool1 PicBufferSize:  stSnsSize.u32Width:%d   stSnsSize.u32Height:%d\n",stSnsSize.u32Width, stSnsSize.u32Height);

    stVbConf.u32MaxPoolCnt = 2;

    if(0 == u32SupplementConfig)
    {
        s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
    }
    else
    {
        s32Ret = SAMPLE_COMM_SYS_InitWithVbSupplement(&stVbConf,u32SupplementConfig);
    }
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        return s32Ret;
    }

    return HI_SUCCESS;
}


HI_VOID SAMPLE_VENC_SetDCFInfo(VI_PIPE ViPipe)
{
    ISP_DCF_INFO_S stIspDCF;

    HI_MPI_ISP_GetDCFInfo(ViPipe, &stIspDCF);

    //description: Thumbnail test
    strncpy((char *)stIspDCF.stIspDCFConstInfo.au8ImageDescription,"Thumbnail test",DCF_DRSCRIPTION_LENGTH);
    //manufacturer: Hisilicon
    strncpy((char *)stIspDCF.stIspDCFConstInfo.au8Make,"Hisilicon",DCF_DRSCRIPTION_LENGTH);
    //model number: Hisilicon IP Camera
    strncpy((char *)stIspDCF.stIspDCFConstInfo.au8Model,"Hisilicon IP Camera",DCF_DRSCRIPTION_LENGTH);
    //firmware version: v.1.1.0
    strncpy((char *)stIspDCF.stIspDCFConstInfo.au8Software,"v.1.1.0",DCF_DRSCRIPTION_LENGTH);


    stIspDCF.stIspDCFConstInfo.u32FocalLength             = 0x00640001;
    stIspDCF.stIspDCFConstInfo.u8Contrast                 = 5;
    stIspDCF.stIspDCFConstInfo.u8CustomRendered           = 0;
    stIspDCF.stIspDCFConstInfo.u8FocalLengthIn35mmFilm    = 1;
    stIspDCF.stIspDCFConstInfo.u8GainControl              = 1;
    stIspDCF.stIspDCFConstInfo.u8LightSource              = 1;
    stIspDCF.stIspDCFConstInfo.u8MeteringMode             = 1;
    stIspDCF.stIspDCFConstInfo.u8Saturation               = 1;
    stIspDCF.stIspDCFConstInfo.u8SceneCaptureType         = 1;
    stIspDCF.stIspDCFConstInfo.u8SceneType                = 0;
    stIspDCF.stIspDCFConstInfo.u8Sharpness                = 5;
    stIspDCF.stIspDCFUpdateInfo.u32ISOSpeedRatings         = 500;
    stIspDCF.stIspDCFUpdateInfo.u32ExposureBiasValue       = 5;
    stIspDCF.stIspDCFUpdateInfo.u32ExposureTime            = 0x00010004;
    stIspDCF.stIspDCFUpdateInfo.u32FNumber                 = 0x0001000f;
    stIspDCF.stIspDCFUpdateInfo.u8WhiteBalance             = 1;
    stIspDCF.stIspDCFUpdateInfo.u8ExposureMode             = 0;
    stIspDCF.stIspDCFUpdateInfo.u8ExposureProgram          = 1;
    stIspDCF.stIspDCFUpdateInfo.u32MaxApertureValue        = 0x00010001;

    HI_MPI_ISP_SetDCFInfo(ViPipe, &stIspDCF);

    return;
}

HI_S32 SAMPLE_VENC_VI_Init( SAMPLE_VI_CONFIG_S *pstViConfig, HI_BOOL bLowDelay, HI_U32 u32SupplementConfig, HI_S32 reso_w)
{
    HI_S32              s32Ret;
    SAMPLE_SNS_TYPE_E   enSnsType;
    ISP_CTRL_PARAM_S    stIspCtrlParam;
    HI_U32              u32FrameRate;


    enSnsType = pstViConfig->astViInfo[0].stSnsInfo.enSnsType;

    pstViConfig->as32WorkingViId[0]                           = 0;
    //pstViConfig->s32WorkingViNum                              = 1;

    pstViConfig->astViInfo[0].stSnsInfo.MipiDev            = SAMPLE_COMM_VI_GetComboDevBySensor(pstViConfig->astViInfo[0].stSnsInfo.enSnsType, 0);
    pstViConfig->astViInfo[0].stSnsInfo.s32BusId           = 0;

    //pstViConfig->astViInfo[0].stDevInfo.ViDev              = ViDev0;
    pstViConfig->astViInfo[0].stDevInfo.enWDRMode          = WDR_MODE_NONE;

    if(HI_TRUE == bLowDelay)
    {
        pstViConfig->astViInfo[0].stPipeInfo.enMastPipeMode     = VI_ONLINE_VPSS_ONLINE;
        if(SONY_IMX277_SLVS_8M_120FPS_10BIT == enSnsType)
        {
            pstViConfig->astViInfo[0].stPipeInfo.enMastPipeMode = VI_PARALLEL_VPSS_PARALLEL;
        }
    }
    else
    {
        pstViConfig->astViInfo[0].stPipeInfo.enMastPipeMode     = VI_OFFLINE_VPSS_OFFLINE;
        if(SONY_IMX277_SLVS_8M_120FPS_10BIT == enSnsType)
        {
            pstViConfig->astViInfo[0].stPipeInfo.enMastPipeMode = VI_PARALLEL_VPSS_OFFLINE;
        }
    }

    //if(8k == enSnsType)
    //{
    //    pstViConfig->astViInfo[0].stPipeInfo.enMastPipeMode       = VI_PARALLEL_VPSS_OFFLINE;
    //}

    //pstViConfig->astViInfo[0].stPipeInfo.aPipe[0]          = ViPipe0;
    pstViConfig->astViInfo[0].stPipeInfo.aPipe[1]          = -1;
    pstViConfig->astViInfo[0].stPipeInfo.aPipe[2]          = -1;
    pstViConfig->astViInfo[0].stPipeInfo.aPipe[3]          = -1;

    //pstViConfig->astViInfo[0].stChnInfo.ViChn              = ViChn;
    //pstViConfig->astViInfo[0].stChnInfo.enPixFormat        = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
    //pstViConfig->astViInfo[0].stChnInfo.enDynamicRange     = enDynamicRange;
    pstViConfig->astViInfo[0].stChnInfo.enVideoFormat      = VIDEO_FORMAT_LINEAR;
    pstViConfig->astViInfo[0].stChnInfo.enCompressMode     = COMPRESS_MODE_SEG;//COMPRESS_MODE_SEG;
    s32Ret = SAMPLE_VENC_SYS_Init(u32SupplementConfig,enSnsType,reso_w);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("Init SYS err for %#x!\n", s32Ret);
        return s32Ret;
    }

    SAMPLE_COMM_VI_GetFrameRateBySensor(enSnsType, &u32FrameRate);

    s32Ret = HI_MPI_ISP_GetCtrlParam(pstViConfig->astViInfo[0].stPipeInfo.aPipe[0], &stIspCtrlParam);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("HI_MPI_ISP_GetCtrlParam failed with %d!\n", s32Ret);
        return s32Ret;
    }
    stIspCtrlParam.u32StatIntvl  = u32FrameRate/30;

    s32Ret = HI_MPI_ISP_SetCtrlParam(pstViConfig->astViInfo[0].stPipeInfo.aPipe[0], &stIspCtrlParam);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("HI_MPI_ISP_SetCtrlParam failed with %d!\n", s32Ret);
        return s32Ret;
    }

    s32Ret = SAMPLE_COMM_VI_StartVi(pstViConfig);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_COMM_SYS_Exit();
        SAMPLE_PRT("SAMPLE_COMM_VI_StartVi failed with %d!\n", s32Ret);
        return s32Ret;
    }

    return HI_SUCCESS;
}

HI_S32 SAMPLE_VENC_VPSS_Init(VPSS_GRP VpssGrp, HI_BOOL* pabChnEnable, DYNAMIC_RANGE_E enDynamicRange,PIXEL_FORMAT_E enPixelFormat,SIZE_S stSize[],SAMPLE_SNS_TYPE_E enSnsType)
{
    HI_S32 i;
    HI_S32 s32Ret;
    PIC_SIZE_E      enSnsSize;
    SIZE_S          stSnsSize;
    VPSS_GRP_ATTR_S stVpssGrpAttr;
    VPSS_CHN_ATTR_S stVpssChnAttr[VPSS_MAX_PHY_CHN_NUM];

    s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(enSnsType, &enSnsSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed!\n");
        return s32Ret;
    }

    s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSnsSize, &stSnsSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        return s32Ret;
    }


    stVpssGrpAttr.enDynamicRange = enDynamicRange;
    stVpssGrpAttr.enPixelFormat  = enPixelFormat;
    stVpssGrpAttr.u32MaxW        = stSnsSize.u32Width;
    stVpssGrpAttr.u32MaxH        = stSnsSize.u32Height;
    stVpssGrpAttr.stFrameRate.s32SrcFrameRate = -1;
    stVpssGrpAttr.stFrameRate.s32DstFrameRate = -1;


    for(i=0; i<VPSS_MAX_PHY_CHN_NUM; i++)
    {
        if(HI_TRUE == pabChnEnable[i])
        {
            stVpssChnAttr[i].u32Width                     = stSize[i].u32Width;
            stVpssChnAttr[i].u32Height                    = stSize[i].u32Height;
            stVpssChnAttr[i].enChnMode                    = VPSS_CHN_MODE_USER;
            stVpssChnAttr[i].enCompressMode               = COMPRESS_MODE_NONE;//COMPRESS_MODE_SEG;
            stVpssChnAttr[i].enDynamicRange               = enDynamicRange;
            stVpssChnAttr[i].enPixelFormat                = enPixelFormat;
            stVpssChnAttr[i].stFrameRate.s32SrcFrameRate  = -1;
            stVpssChnAttr[i].stFrameRate.s32DstFrameRate  = -1;
            stVpssChnAttr[i].u32Depth                     = 0;
            stVpssChnAttr[i].bMirror                      = HI_FALSE;
            stVpssChnAttr[i].bFlip                        = HI_FALSE;
            stVpssChnAttr[i].enVideoFormat                = VIDEO_FORMAT_LINEAR;
            stVpssChnAttr[i].stAspectRatio.enMode         = ASPECT_RATIO_NONE;
        }
    }

    s32Ret = SAMPLE_COMM_VPSS_Start(VpssGrp, pabChnEnable,&stVpssGrpAttr,stVpssChnAttr);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("start VPSS fail for %#x!\n", s32Ret);
    }

    return s32Ret;
}


HI_S32 SAMPLE_VENC_CheckSensor(SAMPLE_SNS_TYPE_E   enSnsType,SIZE_S  stSize)
{
    HI_S32 s32Ret;
    SIZE_S          stSnsSize;
    PIC_SIZE_E      enSnsSize;

    s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(enSnsType, &enSnsSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed!\n");
        return s32Ret;
    }
    s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSnsSize, &stSnsSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        return s32Ret;
    }

    if((stSnsSize.u32Width < stSize.u32Width) || (stSnsSize.u32Height < stSize.u32Height))
    {
        SAMPLE_PRT("Sensor size is (%d,%d), but encode chnl is (%d,%d) !\n",
            stSnsSize.u32Width,stSnsSize.u32Height,stSize.u32Width,stSize.u32Height);
        return HI_FAILURE;
    }

    return HI_SUCCESS;
}


HI_VOID* SAMPLE_SendVencOneFrameProc_4k()
{
    VENC_CHN VencChn = 0;
    HI_S32 s32Ret = HI_SUCCESS;
	HI_U64 u32Cnt = 0;
    HI_U32 u32Profile = 0;
	HI_U32 u32PhyAddr;
	HI_U8 *pVirAddr=NULL;	
    HI_S32 milli_sec = 20000;
	HI_U32 u32YSize = 3840*2160;
	HI_U32 u32UVSize = 3840*2160/2;
	HI_U32 u32YUVSize = 3840*2160*3/2;
	VB_POOL poolID;

	HI_U64 u64PhyAddrYuv;
	HI_VOID *ppVirAddrYuv;
	HI_U64 phyYaddr;
	HI_U64* virYaddr;
	FILE *fb = HI_NULL; 
	HI_BOOL isOneFrame = HI_FALSE;
	VIDEO_FRAME_INFO_S stFrmInfo;
	HI_U64 pu64CurPTS;
	
    

	if (fb != HI_NULL)
	{
		fclose(fb);
		fb = HI_NULL;
	}

	fb = fopen("./4k.yuv", "rb" ); 
	if (fb == HI_NULL)
	{
		SAMPLE_PRT("Open yuv file failed!Check if the file %s exit\n","./4k.yuv");
		return;
	}
	
	s32Ret = HI_MPI_SYS_MmzAlloc(&u64PhyAddrYuv, (HI_VOID**)&ppVirAddrYuv,"YUV420SP_3840_2160_FRAME_MEM", NULL, u32YUVSize);

	if(HI_SUCCESS != s32Ret) 
	{
		SAMPLE_PRT("HI_MPI_SYS_MmzAlloc err:0x%x",s32Ret);
        HI_MPI_SYS_MmzFree(u64PhyAddrYuv, ppVirAddrYuv);
		return;
	}
	fread(ppVirAddrYuv, u32YUVSize, 1, fb);

	SAMPLE_PRT("---->>>u64BlkSize=%d\n",u32YUVSize);
    // SAMPLE_PRT("check value of ppVirAddrYuv:  ");
    // for (int i = 10; i < 15; ++i) {
    //     SAMPLE_PRT("%02X ", ((HI_U8*)ppVirAddrYuv)[i]);
    // }
    // SAMPLE_PRT("\n");

    
	
    // while(HI_TRUE)
    // { 
    // create venc buffer
    VB_BLK handleY  = HI_MPI_VB_GetBlock(VB_INVALID_POOLID, u32YUVSize, NULL);
    if( handleY == VB_INVALID_HANDLE)
    {
        usleep(10);
        printf("HI_MPI_VB_GetBlock for Block failed\n");
        // continue;
    }

    poolID =  HI_MPI_VB_Handle2PoolId(handleY);
    //printf("pool id %d\n", poolID);

    phyYaddr = HI_MPI_VB_Handle2PhysAddr(handleY);
    if( phyYaddr == 0)
    {
        printf("HI_MPI_VB_Handle2PhysAddr for handleY failed\n");
        // continue;
    }
    virYaddr = (HI_U64*) HI_MPI_SYS_Mmap(phyYaddr, u32YUVSize);
    
    if(!isOneFrame)
    {
        memset(&stFrmInfo.stVFrame, 0, sizeof(VIDEO_FRAME_S));
        stFrmInfo.enModId = HI_ID_VENC;
        stFrmInfo.u32PoolId = poolID;
        stFrmInfo.stVFrame.u64PhyAddr[0] = phyYaddr;
        stFrmInfo.stVFrame.u64PhyAddr[1] = stFrmInfo.stVFrame.u64PhyAddr[0] + u32YSize;
        stFrmInfo.stVFrame.u64PhyAddr[2] = stFrmInfo.stVFrame.u64PhyAddr[1] + u32YSize;

        stFrmInfo.stVFrame.u64VirAddr[0] = (HI_U64 *)virYaddr;
        stFrmInfo.stVFrame.u64VirAddr[1] = (HI_U64 *)stFrmInfo.stVFrame.u64VirAddr[0] + u32YSize;
        stFrmInfo.stVFrame.u64VirAddr[2] = (HI_U8 *) stFrmInfo.stVFrame.u64VirAddr[1] + u32YSize;

        stFrmInfo.stVFrame.u32Width	   = 3840;
        stFrmInfo.stVFrame.u32Height    = 2160;
        stFrmInfo.stVFrame.u32Stride[0] = 3840;
        stFrmInfo.stVFrame.u32Stride[1] = 3840;
        stFrmInfo.stVFrame.u32Stride[2] = 3840;
        HI_MPI_SYS_GetCurPTS(&pu64CurPTS);
        stFrmInfo.stVFrame.u64PTS	 = pu64CurPTS;
        stFrmInfo.stVFrame.u32TimeRef = (u32Cnt * 2);//timeref need n*2 but you can't get the second frame
        stFrmInfo.stVFrame.enPixelFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
        stFrmInfo.stVFrame.enField = VIDEO_FIELD_FRAME;
        stFrmInfo.stVFrame.enCompressMode = COMPRESS_MODE_NONE;
        stFrmInfo.stVFrame.enVideoFormat  = VIDEO_FORMAT_LINEAR;
        stFrmInfo.stVFrame.enDynamicRange = DYNAMIC_RANGE_SDR8;
        //memcpy 4k about cost 95ms 
        memcpy(stFrmInfo.stVFrame.u64VirAddr[0], ppVirAddrYuv, u32YUVSize);
        isOneFrame = HI_TRUE;
    }
    else
    {	
        HI_MPI_SYS_GetCurPTS(&pu64CurPTS);
        stFrmInfo.u32PoolId = poolID;
        stFrmInfo.stVFrame.u64PTS	 = pu64CurPTS;
        stFrmInfo.stVFrame.u32TimeRef = (u32Cnt * 2);//timeref need n*2 but you can't get the second frame
    }

    s32Ret = HI_MPI_VENC_SendFrame(VencChn, &stFrmInfo, milli_sec);
    
    HI_MPI_SYS_Munmap(virYaddr, u32YUVSize);
    HI_MPI_VB_ReleaseBlock(handleY);
    u32Cnt ++;

    // }
	//before destroy private pool,must stop venc
	HI_MPI_VB_DestroyPool(poolID);
	HI_MPI_SYS_MmzFree(u64PhyAddrYuv, ppVirAddrYuv);
	//close YUV File
	fclose(fb);
	fb=HI_NULL;

}

HI_VOID* SAMPLE_SendVencOneFrameProc_8k()
{
    VENC_CHN VencChn = 0;
    HI_S32 s32Ret = HI_SUCCESS;
	HI_U64 u32Cnt = 0;
    HI_U32 u32Profile = 0;
	HI_U32 u32PhyAddr;
	HI_U8 *pVirAddr=NULL;	
    HI_S32 milli_sec = 20000;
	HI_U32 u32YSize = 7680*4320;
	HI_U32 u32UVSize = 7680*4320/2;
	HI_U32 u32YUVSize = 7680*4320*3/2;
	VB_POOL poolID;

	HI_U64 u64PhyAddrYuv;
	HI_VOID *ppVirAddrYuv;
	HI_U64 phyYaddr;
	HI_U64* virYaddr;
	FILE *fb = HI_NULL; 
	HI_BOOL isOneFrame = HI_FALSE;
	VIDEO_FRAME_INFO_S stFrmInfo;
	HI_U64 pu64CurPTS;
	
    

	if (fb != HI_NULL)
	{
		fclose(fb);
		fb = HI_NULL;
	}

	fb = fopen("./8k.yuv", "rb" ); 
	if (fb == HI_NULL)
	{
		SAMPLE_PRT("Open yuv file failed!Check if the file %s exit\n","./4k.yuv");
		return;
	}
	
	s32Ret = HI_MPI_SYS_MmzAlloc(&u64PhyAddrYuv, (HI_VOID**)&ppVirAddrYuv,"YUV420SP_7680_4320_FRAME_MEM", NULL, u32YUVSize);

	if(HI_SUCCESS != s32Ret) 
	{
		SAMPLE_PRT("HI_MPI_SYS_MmzAlloc err:0x%x",s32Ret);
        HI_MPI_SYS_MmzFree(u64PhyAddrYuv, ppVirAddrYuv);
		return;
	}
	fread(ppVirAddrYuv, u32YUVSize, 1, fb);

	SAMPLE_PRT("---->>>u64BlkSize=%d\n",u32YUVSize);
    // SAMPLE_PRT("check value of ppVirAddrYuv:  ");
    // for (int i = 10; i < 15; ++i) {
    //     SAMPLE_PRT("%02X ", ((HI_U8*)ppVirAddrYuv)[i]);
    // }
    // SAMPLE_PRT("\n");

    
	
    // while(HI_TRUE)
    // { 
    // create venc buffer
    VB_BLK handleY  = HI_MPI_VB_GetBlock(VB_INVALID_POOLID, u32YUVSize, NULL);
    if( handleY == VB_INVALID_HANDLE)
    {
        usleep(10);
        printf("HI_MPI_VB_GetBlock for Block failed\n");
        // continue;
    }

    poolID =  HI_MPI_VB_Handle2PoolId(handleY);
    //printf("pool id %d\n", poolID);

    phyYaddr = HI_MPI_VB_Handle2PhysAddr(handleY);
    if( phyYaddr == 0)
    {
        printf("HI_MPI_VB_Handle2PhysAddr for handleY failed\n");
        // continue;
    }
    virYaddr = (HI_U64*) HI_MPI_SYS_Mmap(phyYaddr, u32YUVSize);
    
    if(!isOneFrame)
    {
        memset(&stFrmInfo.stVFrame, 0, sizeof(VIDEO_FRAME_S));
        stFrmInfo.enModId = HI_ID_VENC;
        stFrmInfo.u32PoolId = poolID;
        stFrmInfo.stVFrame.u64PhyAddr[0] = phyYaddr;
        stFrmInfo.stVFrame.u64PhyAddr[1] = stFrmInfo.stVFrame.u64PhyAddr[0] + u32YSize;
        stFrmInfo.stVFrame.u64PhyAddr[2] = stFrmInfo.stVFrame.u64PhyAddr[1] + u32YSize;

        stFrmInfo.stVFrame.u64VirAddr[0] = (HI_U64 *)virYaddr;
        stFrmInfo.stVFrame.u64VirAddr[1] = (HI_U64 *)stFrmInfo.stVFrame.u64VirAddr[0] + u32YSize;
        stFrmInfo.stVFrame.u64VirAddr[2] = (HI_U8 *) stFrmInfo.stVFrame.u64VirAddr[1] + u32YSize;

        stFrmInfo.stVFrame.u32Width	   = 7680;
        stFrmInfo.stVFrame.u32Height    = 4320;
        stFrmInfo.stVFrame.u32Stride[0] = 7680;
        stFrmInfo.stVFrame.u32Stride[1] = 7680;
        stFrmInfo.stVFrame.u32Stride[2] = 7680;
        HI_MPI_SYS_GetCurPTS(&pu64CurPTS);
        stFrmInfo.stVFrame.u64PTS	 = pu64CurPTS;
        stFrmInfo.stVFrame.u32TimeRef = (u32Cnt * 2);//timeref need n*2 but you can't get the second frame
        stFrmInfo.stVFrame.enPixelFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
        stFrmInfo.stVFrame.enField = VIDEO_FIELD_FRAME;
        stFrmInfo.stVFrame.enCompressMode = COMPRESS_MODE_NONE;
        stFrmInfo.stVFrame.enVideoFormat  = VIDEO_FORMAT_LINEAR;
        stFrmInfo.stVFrame.enDynamicRange = DYNAMIC_RANGE_SDR8;
        //memcpy 4k about cost 95ms 
        memcpy(stFrmInfo.stVFrame.u64VirAddr[0], ppVirAddrYuv, u32YUVSize);
        isOneFrame = HI_TRUE;
    }
    else
    {	
        HI_MPI_SYS_GetCurPTS(&pu64CurPTS);
        stFrmInfo.u32PoolId = poolID;
        stFrmInfo.stVFrame.u64PTS	 = pu64CurPTS;
        stFrmInfo.stVFrame.u32TimeRef = (u32Cnt * 2);//timeref need n*2 but you can't get the second frame
    }

    s32Ret = HI_MPI_VENC_SendFrame(VencChn, &stFrmInfo, milli_sec);
    
    HI_MPI_SYS_Munmap(virYaddr, u32YUVSize);
    HI_MPI_VB_ReleaseBlock(handleY);
    u32Cnt ++;

    // }
	//before destroy private pool,must stop venc
	HI_MPI_VB_DestroyPool(poolID);
	HI_MPI_SYS_MmzFree(u64PhyAddrYuv, ppVirAddrYuv);
	//close YUV File
	fclose(fb);
	fb=HI_NULL;

}

/******************************************************************************
* function :  H.265e@4K@120fps + H264e@1080p@30fps
******************************************************************************/
HI_S32 SAMPLE_VENC_4K(void)
{
    HI_S32 i;
    HI_S32 reso_w = 3840;
    HI_S32 s32Ret;
    SIZE_S          stSize[2];
    PIC_SIZE_E      enSize[2]     = {PIC_3840x2160, PIC_1080P};
    HI_S32          s32ChnNum     = 1;
    VENC_CHN        VencChn[2]    = {0,1};
    HI_U32          u32Profile[2] = {0,1};
    PAYLOAD_TYPE_E  enPayLoad[2]  = {PT_H265, PT_H264};
    VENC_GOP_MODE_E enGopMode;
    VENC_GOP_ATTR_S stGopAttr;
    SAMPLE_RC_E     enRcMode;

    VI_DEV          ViDev        = 0;
    VI_PIPE         ViPipe       = 0;
    VI_CHN          ViChn        = 0;
    SAMPLE_VI_CONFIG_S stViConfig;

    VPSS_GRP        VpssGrp        = 0;
    VPSS_CHN        VpssChn[2]     = {0,1};
    HI_BOOL         abChnEnable[4] = {1,0,0,0};

    HI_U32 u32SupplementConfig = HI_FALSE;

    for(i=0; i<s32ChnNum; i++)
    {
        s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSize[i], &stSize[i]);
        if (HI_SUCCESS != s32Ret)
        {
            SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
            return s32Ret;
        }
    }

    SAMPLE_COMM_VI_GetSensorInfo(&stViConfig);

    if(SAMPLE_SNS_TYPE_BUTT == stViConfig.astViInfo[0].stSnsInfo.enSnsType)
    {
        SAMPLE_PRT("Not set SENSOR%d_TYPE !\n",0);
        return HI_FAILURE;
    }

    s32Ret = SAMPLE_VENC_CheckSensor(stViConfig.astViInfo[0].stSnsInfo.enSnsType,stSize[0]);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("Check Sensor err!\n");
        return HI_FAILURE;
    }

    stViConfig.s32WorkingViNum       = 1;
    stViConfig.astViInfo[0].stDevInfo.ViDev     = ViDev;
    stViConfig.astViInfo[0].stPipeInfo.aPipe[0] = ViPipe;
    stViConfig.astViInfo[0].stChnInfo.ViChn     = ViChn;
    stViConfig.astViInfo[0].stChnInfo.enDynamicRange = DYNAMIC_RANGE_SDR8;
    stViConfig.astViInfo[0].stChnInfo.enPixFormat    = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
    s32Ret = SAMPLE_VENC_VI_Init(&stViConfig, HI_FALSE,u32SupplementConfig, reso_w);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("Init VI err for %#x!\n", s32Ret);
        return HI_FAILURE;
    }

    s32Ret = SAMPLE_VENC_VPSS_Init(VpssGrp,abChnEnable,DYNAMIC_RANGE_SDR8,PIXEL_FORMAT_YVU_SEMIPLANAR_420,stSize,stViConfig.astViInfo[0].stSnsInfo.enSnsType);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Init VPSS err for %#x!\n", s32Ret);
        goto EXIT_VI_STOP;
    }

    s32Ret = SAMPLE_COMM_VI_Bind_VPSS(ViPipe, ViChn, VpssGrp);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("VI Bind VPSS err for %#x!\n", s32Ret);
        goto EXIT_VPSS_STOP;
    }
    s32Ret = SAMPLE_COMM_VI_UnBind_VPSS(ViPipe, ViChn, VpssGrp);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("VI UnBind VPSS err for %#x!\n", s32Ret);
        goto EXIT_VPSS_STOP;
    }


   /******************************************
    start stream venc
    ******************************************/

    enRcMode = SAMPLE_VENC_GetRcMode();

    enGopMode = SAMPLE_VENC_GetGopMode();
    s32Ret = SAMPLE_COMM_VENC_GetGopAttr(enGopMode,&stGopAttr);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Venc Get GopAttr for %#x!\n", s32Ret);
        goto EXIT_VI_VPSS_UNBIND;
    }

   /***encode h.265 **/
    s32Ret = SAMPLE_COMM_VENC_Start(VencChn[0], enPayLoad[0],enSize[0], enRcMode,u32Profile[0],&stGopAttr);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Venc Start failed for %#x!\n", s32Ret);
        goto EXIT_VI_VPSS_UNBIND;
    }

    s32Ret = SAMPLE_SendVencOneFrameProc_4k();

    // s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(VpssGrp, VpssChn[0],VencChn[0]);
    // if (HI_SUCCESS != s32Ret)
    // {
    //     SAMPLE_PRT("Venc Get GopAttr failed for %#x!\n", s32Ret);
    //     goto EXIT_VENC_H265_STOP;
    // }

    // /***encode h.264 **/
    // s32Ret = SAMPLE_COMM_VENC_Start(VencChn[1], enPayLoad[1], enSize[1], enRcMode,u32Profile[1],&stGopAttr);
    // if (HI_SUCCESS != s32Ret)
    // {
    //     SAMPLE_PRT("Venc Start failed for %#x!\n", s32Ret);
    //     goto EXIT_VENC_H265_UnBind;
    // }

    // s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(VpssGrp, VpssChn[1],VencChn[1]);
    // if (HI_SUCCESS != s32Ret)
    // {
    //     SAMPLE_PRT("Venc bind Vpss failed for %#x!\n", s32Ret);
    //     goto EXIT_VENC_H264_STOP;
    // }

    /******************************************
     stream save process
    ******************************************/
    s32Ret = SAMPLE_COMM_VENC_StartGetStream(VencChn,s32ChnNum);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto EXIT_VENC_H264_UnBind;
    }

    printf("please press twice ENTER to exit this sample\n");
    getchar();
    getchar();

    /******************************************
     exit process
    ******************************************/
    SAMPLE_COMM_VENC_StopGetStream();

EXIT_VENC_H264_UnBind:
    SAMPLE_COMM_VPSS_UnBind_VENC(VpssGrp,VpssChn[1],VencChn[1]);
EXIT_VENC_H264_STOP:
    SAMPLE_COMM_VENC_Stop(VencChn[1]);
EXIT_VENC_H265_UnBind:
    SAMPLE_COMM_VPSS_UnBind_VENC(VpssGrp,VpssChn[0],VencChn[0]);
EXIT_VENC_H265_STOP:
    SAMPLE_COMM_VENC_Stop(VencChn[0]);
EXIT_VI_VPSS_UNBIND:
    SAMPLE_COMM_VI_UnBind_VPSS(ViPipe,ViChn,VpssGrp);
EXIT_VPSS_STOP:
    SAMPLE_COMM_VPSS_Stop(VpssGrp,abChnEnable);
EXIT_VI_STOP:
    SAMPLE_COMM_VI_StopVi(&stViConfig);
    SAMPLE_COMM_SYS_Exit();

    return s32Ret;
}

HI_S32 SAMPLE_VENC_8K(void)
{
    HI_S32 i;
    HI_S32 reso_w = 7680;
    HI_S32 s32Ret;
    SIZE_S          stSize[2];
    PIC_SIZE_E      enSize[2]     = {PIC_7680x4320, PIC_1080P};
    HI_S32          s32ChnNum     = 1;
    VENC_CHN        VencChn[2]    = {0,1};
    HI_U32          u32Profile[2] = {0,1};
    PAYLOAD_TYPE_E  enPayLoad[2]  = {PT_H265, PT_H264};
    VENC_GOP_MODE_E enGopMode;
    VENC_GOP_ATTR_S stGopAttr;
    SAMPLE_RC_E     enRcMode;

    VI_DEV          ViDev        = 0;
    VI_PIPE         ViPipe       = 0;
    VI_CHN          ViChn        = 0;
    SAMPLE_VI_CONFIG_S stViConfig;

    VPSS_GRP        VpssGrp        = 0;
    VPSS_CHN        VpssChn[2]     = {0,1};
    HI_BOOL         abChnEnable[4] = {1,0,0,0};

    HI_U32 u32SupplementConfig = HI_FALSE;

    for(i=0; i<s32ChnNum; i++)
    {
        s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSize[i], &stSize[i]);
        if (HI_SUCCESS != s32Ret)
        {
            SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
            return s32Ret;
        }
    }

    SAMPLE_COMM_VI_GetSensorInfo(&stViConfig);

    if(SAMPLE_SNS_TYPE_BUTT == stViConfig.astViInfo[0].stSnsInfo.enSnsType)
    {
        SAMPLE_PRT("Not set SENSOR%d_TYPE !\n",0);
        return HI_FAILURE;
    }

    // s32Ret = SAMPLE_VENC_CheckSensor(stViConfig.astViInfo[0].stSnsInfo.enSnsType,stSize[0]);
    // if(s32Ret != HI_SUCCESS)
    // {
    //     SAMPLE_PRT("Check Sensor err!\n");
    //     return HI_FAILURE;
    // }

    stViConfig.s32WorkingViNum       = 1;
    stViConfig.astViInfo[0].stDevInfo.ViDev     = ViDev;
    stViConfig.astViInfo[0].stPipeInfo.aPipe[0] = ViPipe;
    stViConfig.astViInfo[0].stChnInfo.ViChn     = ViChn;
    stViConfig.astViInfo[0].stChnInfo.enDynamicRange = DYNAMIC_RANGE_SDR8;
    stViConfig.astViInfo[0].stChnInfo.enPixFormat    = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
    s32Ret = SAMPLE_VENC_VI_Init(&stViConfig, HI_FALSE,u32SupplementConfig, reso_w);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("Init VI err for %#x!\n", s32Ret);
        return HI_FAILURE;
    }

    s32Ret = SAMPLE_VENC_VPSS_Init(VpssGrp,abChnEnable,DYNAMIC_RANGE_SDR8,PIXEL_FORMAT_YVU_SEMIPLANAR_420,stSize,stViConfig.astViInfo[0].stSnsInfo.enSnsType);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Init VPSS err for %#x!\n", s32Ret);
        goto EXIT_VI_STOP;
    }

    s32Ret = SAMPLE_COMM_VI_Bind_VPSS(ViPipe, ViChn, VpssGrp);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("VI Bind VPSS err for %#x!\n", s32Ret);
        goto EXIT_VPSS_STOP;
    }
    s32Ret = SAMPLE_COMM_VI_UnBind_VPSS(ViPipe, ViChn, VpssGrp);
    if(s32Ret != HI_SUCCESS)
    {
        SAMPLE_PRT("VI UnBind VPSS err for %#x!\n", s32Ret);
        goto EXIT_VPSS_STOP;
    }


   /******************************************
    start stream venc
    ******************************************/

    enRcMode = SAMPLE_VENC_GetRcMode();

    enGopMode = SAMPLE_VENC_GetGopMode();
    s32Ret = SAMPLE_COMM_VENC_GetGopAttr(enGopMode,&stGopAttr);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Venc Get GopAttr for %#x!\n", s32Ret);
        goto EXIT_VI_VPSS_UNBIND;
    }

   /***encode h.265 **/
    s32Ret = SAMPLE_COMM_VENC_Start(VencChn[0], enPayLoad[0],enSize[0], enRcMode,u32Profile[0],&stGopAttr);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Venc Start failed for %#x!\n", s32Ret);
        goto EXIT_VI_VPSS_UNBIND;
    }

    s32Ret = SAMPLE_SendVencOneFrameProc_8k();

    // s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(VpssGrp, VpssChn[0],VencChn[0]);
    // if (HI_SUCCESS != s32Ret)
    // {
    //     SAMPLE_PRT("Venc Get GopAttr failed for %#x!\n", s32Ret);
    //     goto EXIT_VENC_H265_STOP;
    // }

    // /***encode h.264 **/
    // s32Ret = SAMPLE_COMM_VENC_Start(VencChn[1], enPayLoad[1], enSize[1], enRcMode,u32Profile[1],&stGopAttr);
    // if (HI_SUCCESS != s32Ret)
    // {
    //     SAMPLE_PRT("Venc Start failed for %#x!\n", s32Ret);
    //     goto EXIT_VENC_H265_UnBind;
    // }

    // s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(VpssGrp, VpssChn[1],VencChn[1]);
    // if (HI_SUCCESS != s32Ret)
    // {
    //     SAMPLE_PRT("Venc bind Vpss failed for %#x!\n", s32Ret);
    //     goto EXIT_VENC_H264_STOP;
    // }

    /******************************************
     stream save process
    ******************************************/
    s32Ret = SAMPLE_COMM_VENC_StartGetStream(VencChn,s32ChnNum);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto EXIT_VENC_H264_UnBind;
    }

    printf("please press twice ENTER to exit this sample\n");
    getchar();
    getchar();

    /******************************************
     exit process
    ******************************************/
    SAMPLE_COMM_VENC_StopGetStream();

EXIT_VENC_H264_UnBind:
    SAMPLE_COMM_VPSS_UnBind_VENC(VpssGrp,VpssChn[1],VencChn[1]);
EXIT_VENC_H264_STOP:
    SAMPLE_COMM_VENC_Stop(VencChn[1]);
EXIT_VENC_H265_UnBind:
    SAMPLE_COMM_VPSS_UnBind_VENC(VpssGrp,VpssChn[0],VencChn[0]);
EXIT_VENC_H265_STOP:
    SAMPLE_COMM_VENC_Stop(VencChn[0]);
EXIT_VI_VPSS_UNBIND:
    SAMPLE_COMM_VI_UnBind_VPSS(ViPipe,ViChn,VpssGrp);
EXIT_VPSS_STOP:
    SAMPLE_COMM_VPSS_Stop(VpssGrp,abChnEnable);
EXIT_VI_STOP:
    SAMPLE_COMM_VI_StopVi(&stViConfig);
    SAMPLE_COMM_SYS_Exit();

    return s32Ret;
}

/******************************************************************************
* function    : main()
* Description : video venc sample
******************************************************************************/
#ifdef __HuaweiLite__
    int app_main(int argc, char *argv[])
#else
    int main(int argc, char *argv[])
#endif
{
    HI_S32 s32Ret;
    HI_U32 u32Index;

    if (argc < 2)
    {
        SAMPLE_VENC_Usage(argv[0]);
        return HI_FAILURE;
    }
    u32Index = atoi(argv[1]);

#ifndef __HuaweiLite__
    signal(SIGINT, SAMPLE_VENC_HandleSig);
    signal(SIGTERM, SAMPLE_VENC_HandleSig);
#endif

    switch (u32Index)
    {
        case 0:
            s32Ret = SAMPLE_VENC_4K();
            break;
        case 1:
            s32Ret = SAMPLE_VENC_8K();
            break;

        default:
            printf("the index is invaild!\n");
            SAMPLE_VENC_Usage(argv[0]);
            return HI_FAILURE;
    }

    if (HI_SUCCESS == s32Ret)
    { printf("program exit normally!\n"); }
    else
    { printf("program exit abnormally!\n"); }

#ifdef __HuaweiLite__
    return s32Ret;
#else
    exit(s32Ret);
#endif
}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */

       有些小改动需要在common中改,都很简单就不写了,看一下就知道,另外我这边只测试了8k的一帧编码,如需连续编码视频需要再扩展一下,我这边由于公司项目安排就没再继续做了,测试出来8k文件编码的结果如下,颜色偏差是因为我的YUV和板子支持的YUV的存储顺序不一致,这里时间关系也就不调了,也算是顺利实现了芯片的8k文件编码。

        祝大家平安健康。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值