hi3516 mpp venc snap
原文链接: hi3516 mpp venc snap
get venc stream time out
一般出现这个错误一定是配置的问题,
比如 SAMPLE_COMM_IVE_StartViVpssVencVo() 中
if (HI_TRUE == pstSwitch->bVenc)
{
s32Ret = SAMPLE_COMM_VENC_GetGopAttr(VENC_GOPMODE_NORMALP,&stGopAttr);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, END_INIT_5,
"Error(%#x),SAMPLE_COMM_VENC_GetGopAttr failed!\n",s32Ret);
s32Ret = SAMPLE_COMM_VENC_Start(VeH264Chn, enStreamType,aenSize[2],enRcMode,0,bRcnRefShareBuf,&stGopAttr);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, END_INIT_5,
"Error(%#x),SAMPLE_COMM_VENC_Start failed!\n",s32Ret);
// 这里默认是没有进行VPSS 绑定的,所以venc肯定要出问题,就会报 get venc stream time out 错误
s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(VpssGrp, 2,VeH264Chn);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, END_INIT_6,
"Error(%#x),SAMPLE_COMM_VENC_StartGetStream failed!\n",s32Ret);
s32Ret = SAMPLE_COMM_VENC_StartGetStream(&VeH264Chn, 1);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, END_INIT_6,
"Error(%#x),SAMPLE_COMM_VENC_StartGetStream failed!\n",s32Ret);
}
海思3518ev200芯片的sdk中没有专用的抓图接口,在特定场合下需要jpeg图片的情况下,采用将h264数据编码为图片比较麻烦,因此可以采用海思自己的JPEG编码。
不多说直接上代码:
char *pic_addr;
int VencFd, s32Ret;
INT32U maxfd = 0;
struct timeval TimeoutVal;
fd_set read_fds;
VENC_CHN_STAT_S stStat;
VENC_STREAM_S stStream;
VIDEO_FRAME_INFO_S stFrame;
if (HI_MPI_VI_SetFrameDepth(0, 1)) //设置VI通道缓存的视频图像帧数 必须的
{
printf("HI_MPI_VI_SetFrameDepth err, vi chn %d \n", 0);
return -1;
}
usleep(90 * 1000);
VencFd = HI_MPI_VENC_GetFd(1); //JPEG编码通道为1,获取通道句柄
if (VencFd < 0)
{
printf("HI_MPI_VENC_GetFd failed with %#x!\n", VencFd);
return -1;
}
maxfd = VencFd;
s32Ret = HI_MPI_VI_GetFrame(0, &stFrame, VIDEO_GET_FRAME_TIMEOUT); //从VI获取一张原画
if (HI_SUCCESS != s32Ret)
{
printf("HI_MPI_VI_GetFrame ext chn(%d) fail,Error(%#x)\n", 0 ,s32Ret);
return -1;
}
s32Ret = HI_MPI_VENC_SendFrame(1, &stFrame, VIDEO_GET_FRAME_TIMEOUT); //将VI原画发送到JPEG编码器
if (HI_SUCCESS != s32Ret)
{
printf("HI_MPI_VENC_SendFrame ext chn(%d) fail,Error(%#x)\n", 1 ,s32Ret);
return -1;
}
while(1)
{
FD_ZERO(&read_fds);
FD_SET(VencFd, &read_fds);
TimeoutVal.tv_sec = 0;
TimeoutVal.tv_usec = 50 * 1000;
s32Ret = select(maxfd + 1, &read_fds, NULL, NULL, &TimeoutVal); //等待JPEG编码完成
if (s32Ret < 0)
{
printf("select failed!\n");
return -1;
}
else if (s32Ret == 0)
{
printf("get venc stream time out\n");
continue;
}
else
{
if (FD_ISSET(VencFd, &read_fds))
{
memset(&stStream, 0, sizeof(stStream));
s32Ret = HI_MPI_VENC_Query(1, &stStat); //查询编码通道状态,是否创建成功
if (VIDEO_SUCC != s32Ret)
{
printf("HI_MPI_VENC_Query chn[%d] failed with %#x!\n", 1, s32Ret);
return -1;
}
if(0 == stStat.u32CurPacks)
{
printf("NOTE: Current frame is NULL!\n");
return -1;
}
stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == stStream.pstPack)
{
printf("malloc stream pack failed!\n");
return -1;
}
stStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(1, &stStream, VIDEO_GET_FRAME_TIMEOUT); //获取JPEG图片
if (VIDEO_SUCC != s32Ret)
{
free(stStream.pstPack);
stStream.pstPack = NULL;
printf("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
return -1;
}
else
{
printf("\npicture data len is %d\n", stStream.pstPack->u32Len);
pic_addr = (char *)stStream.pstPack[0].pu8Addr + stStream.pstPack[0].u32Offset;
memcpy(picture_data, pic_addr, stStream.pstPack->u32Len);
*data_len = stStream.pstPack->u32Len;
break;
}
}
}
free(stStream.pstPack);
HI_MPI_VI_ReleaseFrame(0, &stFrame); //释放
————————————————
版权声明:本文为CSDN博主「我是诗人不唱歌」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ayuedreamer/article/details/79459309