当前位置 : 主页 > 网络编程 > 其它编程 >

Hi3536视频编解码之视频叠加

来源:互联网 收集:自由互联 发布时间:2023-07-02
通过Hi3536sdk中Hi3536_SDK_V2.0.7.0mpp_mastersamplevo的例程修改而来的视频叠加简单例程。例程实现了打开16个窗口通过按键 通过Hi3536sdk中Hi3536_SDK_V2.0.7.0/mpp_master/sample/vo的例程修改而来的视频叠加
通过Hi3536sdk中Hi3536_SDK_V2.0.7.0mpp_mastersamplevo的例程修改而来的视频叠加简单例程。例程实现了打开16个窗口通过按键

通过Hi3536sdk中Hi3536_SDK_V2.0.7.0/mpp_master/sample/vo的例程修改而来的视频叠加简单例程。 例程实现了打开16个窗口通过按键输入控制每个窗口以规定的大小、位置叠加起来。 效果如下 在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

主要功能函数代码如下注释行为关键部分

HI_S32 SAMPLE_VO_Virtual_HD0(HI_VOID){HI_S32 s32Ret HI_SUCCESS; VB_CONF_S stVbConf; HI_U32 u32BlkSize;VDEC_CHN VdChn 1;PAYLOAD_TYPE_E enType; SIZE_S stSize; HI_S32 s32VpssGrpCnt 6, s32VpssChnCnt 1; HI_S32 i,x,y;HI_U32 u32WndNum;VPSS_GRP_ATTR_S stGrpAttr; VPSS_CHN_MODE_S stVpssChnMode;VENC_CHN VeJpegChn 0;VO_DEV VoDev; VO_LAYER VoLayer;VO_PUB_ATTR_S stVoPubAttr; SAMPLE_VO_MODE_E enVoMode;VO_VIDEO_LAYER_ATTR_S stLayerAttr;HI_CHAR ch;VDEC_CHN_ATTR_S stVdecChnAttr[VDEC_MAX_CHN_NUM];VdecThreadParam stVdecSend[VDEC_MAX_CHN_NUM]; pthread_t VdecThread[2 * VDEC_MAX_CHN_NUM];/******************************************step 1: init variable ******************************************/ memset( u32BlkSize SAMPLE_COMM_SYS_CalcPicVbBlkSize(VIDEO_ENCODING_MODE_PAL,\PIC_HD1080, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);stVbConf.u32MaxPoolCnt 128;stVbConf.astCommPool[0].u32BlkSize u32BlkSize;stVbConf.astCommPool[0].u32BlkCnt 20;s32Ret SAMPLE_COMM_SYS_GetPicSize(VIDEO_ENCODING_MODE_PAL, PIC_HD1080, if (HI_SUCCESS !s32Ret){SAMPLE_PRT("get picture size failed!\n");return HI_FAILURE;}if (704 stSize.u32Width){stSize.u32Width 720;}else if (352 stSize.u32Width){stSize.u32Width 360;}else if (176 stSize.u32Width){stSize.u32Width 180;}/******************************************step 2: mpp system init. ******************************************/s32Ret SAMPLE_COMM_SYS_Init(if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("system init failed with %d!\n", s32Ret);goto END_VIRTUAL_1;}/******************************************step 3: start vdec ******************************************/ enType PT_H264;memset( SAMPLE_COMM_VDEC_ModCommPoolConf(s32Ret SAMPLE_COMM_VDEC_InitModCommVb(if(s32Ret ! HI_SUCCESS){ SAMPLE_PRT("init mod common vb fail for %#x!\n", s32Ret);goto END_VIRTUAL_1;}/**************create vdec chn****************************/ SAMPLE_COMM_VDEC_ChnAttr(VdChn, s32Ret SAMPLE_COMM_VDEC_Start(VdChn, if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("Start Vdec failed!\n");goto END_VIRTUAL_2;} /**************send stream****************************/SAMPLE_COMM_VDEC_ThreadParam(VdChn, SAMPLE_COMM_VDEC_StartSendStream(VdChn, /******************************************step 4: start vpss with vdec bind vpss ******************************************/stGrpAttr.u32MaxW stSize.u32Width;stGrpAttr.u32MaxH stSize.u32Height;stGrpAttr.bIeEn HI_FALSE;stGrpAttr.bNrEn HI_TRUE;stGrpAttr.bHistEn HI_FALSE;stGrpAttr.enDieMode VPSS_DIE_MODE_NODIE;stGrpAttr.enPixFmt SAMPLE_PIXEL_FORMAT;stGrpAttr.bDciEn HI_FALSE;stGrpAttr.bEsEn HI_TRUE;s32Ret SAMPLE_COMM_VPSS_Start(s32VpssGrpCnt, if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("Start Vpss failed!\n");goto END_VIRTUAL_3;}for(i0; i<1; i){s32Ret HI_MPI_VPSS_GetChnMode(i, 0, if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("HI_MPI_VPSS_SetChnMode failed with %x\n",s32Ret);goto END_VIRTUAL_3;}stVpssChnMode.bDouble HI_FALSE;stVpssChnMode.enChnMode VPSS_CHN_MODE_USER;stVpssChnMode.enPixelFormat PIXEL_FORMAT_YUV_SEMIPLANAR_420;stVpssChnMode.u32Width 1920;stVpssChnMode.u32Height 1080;stVpssChnMode.enCompressMode COMPRESS_MODE_NONE; s32Ret HI_MPI_VPSS_SetChnMode(i, 0, if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("HI_MPI_VPSS_SetChnMode failed with %x\n",s32Ret);goto END_VIRTUAL_3;}}for(i 0;i < VdChn; i){s32Ret SAMPLE_COMM_VDEC_BindVpss(i,i);if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("SAMPLE_COMM_VDEC_BindVpss failed!\n");goto END_VIRTUAL_4;}}/***************************************************step 5: start VIRT0 with 4 windows and bind to VENC***************************************************/ /**************start Dev****************************/VoDev SAMPLE_VO_DEV_VIRT0; stVoPubAttr.enIntfSync VO_OUTPUT_1080P30;stVoPubAttr.enIntfType VO_INTF_HDMI;stVoPubAttr.u32BgColor 0x0;s32Ret SAMPLE_COMM_VO_StartDev(VoDev, if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_StartDev failed!\n");goto END_VIRTUAL_4;}/**************start Layer****************************/VoLayer SAMPLE_VO_LAYER_VIRT0;stLayerAttr.bClusterMode HI_FALSE;stLayerAttr.bDoubleFrame HI_FALSE;stLayerAttr.enPixFormat SAMPLE_PIXEL_FORMAT; s32Ret SAMPLE_COMM_VO_GetWH(stVoPubAttr.enIntfSync, \if (s32Ret ! HI_SUCCESS){SAMPLE_PRT("failed with %#x!\n", s32Ret);goto END_VIRTUAL_5;}stLayerAttr.stImageSize.u32Width stLayerAttr.stDispRect.u32Width;stLayerAttr.stImageSize.u32Height stLayerAttr.stDispRect.u32Height;HI_MPI_VO_SetVideoLayerPartitionMode(VoLayer,VO_PART_MODE_SINGLE);s32Ret SAMPLE_COMM_VO_StartLayer(VoLayer, if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_StartLayer failed!\n");goto END_VIRTUAL_5;} /**************start Chn****************************/ enVoMode VO_MODE_16MUX; //16个窗口s32Ret SAMPLE_COMM_VO_StartChn(VoLayer,enVoMode); if (s32Ret ! HI_SUCCESS){SAMPLE_PRT("failed with %#x!\n", s32Ret);goto END_VIRTUAL_6;} /**************vo bind to vpss****************************/u32WndNum 16; //16个窗口for(i 0;i < u32WndNum;i){s32Ret SAMPLE_COMM_VO_BindVpss(VoLayer, i, 0, VPSS_CHN0);if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_BindVpss failed!\n");goto END_VIRTUAL_6;} }sleep(1);/******************************************step 6: start jpege snap.*****************************************/VoDev SAMPLE_VO_DEV_DHD0;VoLayer SAMPLE_VO_LAYER_VHD0;enVoMode VO_MODE_1MUX; //单分屏#ifdef HI_FPGAstVoPubAttr.enIntfSync VO_OUTPUT_1080P30;stVoPubAttr.enIntfType VO_INTF_VGA;#elsestVoPubAttr.enIntfSync VO_OUTPUT_3840x2160_30;stVoPubAttr.enIntfType VO_INTF_HDMI;#endif stVoPubAttr.u32BgColor 0x0;s32Ret SAMPLE_COMM_VO_StartDev(VoDev, if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_StartDev failed!\n");goto END_VIRTUAL_4;}#ifndef HI_FPGAif (HI_SUCCESS ! SAMPLE_COMM_VO_HdmiStart(stVoPubAttr.enIntfSync)){SAMPLE_PRT("Start SAMPLE_COMM_VO_HdmiStart failed!\n");goto END_VIRTUAL_5;}#endif/**************start Layer****************************/ stLayerAttr.bClusterMode HI_FALSE;stLayerAttr.bDoubleFrame HI_FALSE;stLayerAttr.enPixFormat SAMPLE_PIXEL_FORMAT; s32Ret SAMPLE_COMM_VO_GetWH(stVoPubAttr.enIntfSync, \if (s32Ret ! HI_SUCCESS){SAMPLE_PRT("failed with %#x!\n", s32Ret);goto END_VIRTUAL_5;}stLayerAttr.stImageSize.u32Width stLayerAttr.stDispRect.u32Width;stLayerAttr.stImageSize.u32Height stLayerAttr.stDispRect.u32Height;s32Ret SAMPLE_COMM_VO_StartLayer(VoLayer, if (HI_SUCCESS ! s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_StartLayer failed!\n");goto END_VIRTUAL_6;} /**************start Chn****************************/ s32Ret SAMPLE_COMM_VO_StartChn(VoLayer,enVoMode); if (s32Ret ! HI_SUCCESS){SAMPLE_PRT("failed with %#x!\n", s32Ret);goto END_VIRTUAL_6;} SAMPLE_COMM_Vpss_BindVO(SAMPLE_VO_LAYER_VIRT0,0,4,0);/**************vo bind to vpss****************************/s32Ret SAMPLE_COMM_VO_BindVpss(VoLayer, 0, 4, 0);s32Ret SAMPLE_COMM_VO_BindVpss(VoLayer, 6, 5, 0);i 0;while(1){printf("\tpress q to exit this sample.\n");printf("\tpress s to snap one picture\n");ch getchar();if (10 ch){continue;}getchar(); if (q ch){break;}else if(s ch){if(i > 15) //0~1516个窗口goto END_VIRTUAL_1;x 200i*20; //通过X轴坐标定位窗口位置SAMPLE_COMM_VO_SetChn(SAMPLE_VO_LAYER_VIRT0,i,x,x);i;usleep(10);}else{SAMPLE_PRT("the input is invaild! please try again.\n");continue;}}/******************************************step 9: exit process******************************************/ END_VIRTUAL_7: SAMPLE_COMM_VO_SnapStop(VeJpegChn);END_VIRTUAL_6:VoLayer SAMPLE_VO_LAYER_VIRT0;enVoMode VO_MODE_4MUX; SAMPLE_COMM_VO_StopChn(VoLayer,enVoMode); SAMPLE_COMM_VO_StopLayer(VoLayer);u32WndNum 4; for(i 0;i < u32WndNum;i){SAMPLE_COMM_VO_UnBindVpss(VoLayer,i,i,VPSS_CHN0);}END_VIRTUAL_5: VoDev SAMPLE_VO_DEV_VIRT0; SAMPLE_COMM_VO_StopDev(VoDev); END_VIRTUAL_4: for(i 0;i < VdChn;i){SAMPLE_COMM_VDEC_UnBindVpss(i,i);}END_VIRTUAL_3: SAMPLE_COMM_VPSS_Stop(s32VpssGrpCnt, VPSS_MAX_CHN_NUM);END_VIRTUAL_2:SAMPLE_COMM_VDEC_Stop(VdChn); SAMPLE_COMM_VDEC_StopSendStream(VdChn, END_VIRTUAL_1:SAMPLE_COMM_SYS_Exit();return s32Ret;}

完整代码与编译生成文件https://download.csdn.net/download/weixin_43793181/19037437

【来源:国外高防服务器 http://www.558idc.com/stgf.html 欢迎留下您的宝贵建议】
上一篇:js滚动动画和鼠标滚轮操作冲突的问题
下一篇:没有了
网友评论