3108
- 收藏
- 点赞
- 分享
- 举报
Hi3516D venc读取本地YUV文件
新手一枚,目前sample_venc已经能够实现读取摄像头视频并进行编码,但如何读取本地YUV420文件呀。我想把视频流存入Buffer,但一直提示
[SAMPLE_COMM_VENC_GetVencStreamProc]-1118: get venc stream time out, exit thread 错误。
希望各位大神能给我解答一下,越详细越好,不胜感激。
下面是我的一部分源码:
/******************************************************************************
* function : 1D1 User send pictures for H264 encode
******************************************************************************/
HI_S32 SAMPLE_VENC_1_D1_YUVFiles(HI_VOID)//by lyx
{
VB_CONF_S stVbConf;
// VENC_GRP VencGrp = 0; //delete
HI_U32 u32Profile = 0;//ADD by lyx
VENC_CHN VencChn = 0;
PIC_SIZE_E enSize = PIC_HD1080;
HI_S32 s32Ret = HI_SUCCESS;
HI_U32 u32BlkSize;
SIZE_S stSize;
VB_POOL hPool = VB_INVALID_POOLID;
FILE *pfp_img = HI_NULL;
HI_U32 u32PicLStride = 0;
HI_U32 u32PicCStride = 0;
HI_U32 u32LumaSize = 0;
HI_U32 u32ChrmSize = 0;
HI_U32 u32Cnt = 0;
HI_U32 u32ChnCnt = 1;
typedef struct hisample_MEMBUF_S
{
VB_BLK hBlock;
VB_POOL hPool;
HI_U32 u32PoolId;
HI_U32 u32PhyAddr;
HI_U8 *pVirAddr;
HI_S32 s32Mdev;
}SAMPLE_MEMBUF_S;
/******************************************
step 1: init variable
******************************************/
memset(&stVbConf,0,sizeof(VB_CONF_S));
//SAMPLE_COMM_VI_GetSizeBySensor 未添加
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.u32MaxPoolCnt = 128;
/*ddr0 video buffer*/
stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
stVbConf.astCommPool[0].u32BlkCnt = 10;
memset(stVbConf.astCommPool[0].acMmzName,0,sizeof(stVbConf.astCommPool[0].acMmzName));
/******************************************
step 2: mpp system init.
******************************************/
s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("system init failed with %d!\n", s32Ret);
goto END_VENC_1_D1_YUVFiles_0;
}
/******************************************
step 3: open yuv file
******************************************/
if (pfp_img != HI_NULL)
{
fclose(pfp_img);
pfp_img = HI_NULL;
}
pfp_img = fopen("5_1920x1080_2.yuv", "rb" );
if (pfp_img == HI_NULL)
{
SAMPLE_PRT("Open yuv file failed!Check if the file %s exit\n","5_704x576.yuv");
goto END_VENC_1_D1_YUVFiles_0;
}
/******************************************
step 4: create private pool on ddr0
******************************************/
hPool = HI_MPI_VB_CreatePool( u32BlkSize, 10,NULL );
if (hPool == VB_INVALID_POOLID)
{
SAMPLE_PRT("HI_MPI_VB_CreatePool failed! \n");
goto END_VENC_1_D1_YUVFiles_1;
}
/******************************************
step 5: encode process
******************************************/
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_1_D1_YUVFiles_2;
}
s32Ret = SAMPLE_COMM_VENC_Start(VencChn, PT_H264, gs_enNorm, enSize, SAMPLE_RC_CBR,u32Profile);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start snap failed!\n");
goto END_VENC_1_D1_YUVFiles_2;
}
/******************************************
step 6: stream venc process -- get stream, then save it to file.
******************************************/
s32Ret = SAMPLE_COMM_VENC_StartGetStream(u32ChnCnt);//u32ChnCnt==1;
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("StartGetStream failed!\n");
goto END_VENC_1_D1_YUVFiles_3;
}
u32PicLStride = CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH);
u32PicCStride = CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH);
u32LumaSize = (u32PicLStride * stSize.u32Height);
u32ChrmSize = (u32PicCStride * stSize.u32Height) >> 2;
while(0 == feof(pfp_img))
{
SAMPLE_MEMBUF_S stMem = {0};
VIDEO_FRAME_INFO_S stFrmInfo;
stMem.hPool = hPool;
u32Cnt ++;
while((stMem.hBlock = HI_MPI_VB_GetBlock(stMem.hPool, u32BlkSize,NULL)) == VB_INVALID_HANDLE)
{
;
}
stMem.pVirAddr = (HI_U8 *) HI_MPI_SYS_Mmap( stMem.u32PhyAddr, u32BlkSize );
if(stMem.pVirAddr == NULL)
{
SAMPLE_PRT("Mem dev may not open\n");
goto END_VENC_1_D1_YUVFiles_4;
}
memset(&stFrmInfo.stVFrame, 0, sizeof(VIDEO_FRAME_S));
stFrmInfo.stVFrame.u32PhyAddr[0] = stMem.u32PhyAddr;
stFrmInfo.stVFrame.u32PhyAddr[1] = stFrmInfo.stVFrame.u32PhyAddr[0] + u32LumaSize;
stFrmInfo.stVFrame.u32PhyAddr[2] = stFrmInfo.stVFrame.u32PhyAddr[1] + u32ChrmSize;
stFrmInfo.stVFrame.pVirAddr[0] = stMem.pVirAddr;
stFrmInfo.stVFrame.pVirAddr[1] = (HI_U8 *) stFrmInfo.stVFrame.pVirAddr[0] + u32LumaSize;
stFrmInfo.stVFrame.pVirAddr[2] = (HI_U8 *) stFrmInfo.stVFrame.pVirAddr[1] + u32ChrmSize;
stFrmInfo.stVFrame.u32Width = stSize.u32Width;
stFrmInfo.stVFrame.u32Height = stSize.u32Height;
stFrmInfo.stVFrame.u32Stride[0] = u32PicLStride;
stFrmInfo.stVFrame.u32Stride[1] = u32PicLStride;
stFrmInfo.stVFrame.u32Stride[2] = u32PicLStride;
stFrmInfo.stVFrame.u64pts = (u32Cnt * 40);
stFrmInfo.stVFrame.u32TimeRef = (u32Cnt * 2);
/* Different channsel with different picture sequence */
SAMPLE_COMM_VENC_ReadOneFrame( pfp_img, stFrmInfo.stVFrame.pVirAddr[0],
stFrmInfo.stVFrame.pVirAddr[1], stFrmInfo.stVFrame.pVirAddr[2],
stFrmInfo.stVFrame.u32Width, stFrmInfo.stVFrame.u32Height,
stFrmInfo.stVFrame.u32Stride[0], stFrmInfo.stVFrame.u32Stride[1] >> 1 );
if(0 != feof(pfp_img))
{
break;
}
SAMPLE_COMM_VENC_PlanToSemi( stFrmInfo.stVFrame.pVirAddr[0], stFrmInfo.stVFrame.u32Stride[0],
stFrmInfo.stVFrame.pVirAddr[1], stFrmInfo.stVFrame.u32Stride[1],
stFrmInfo.stVFrame.pVirAddr[2], stFrmInfo.stVFrame.u32Stride[1],
stFrmInfo.stVFrame.u32Width, stFrmInfo.stVFrame.u32Height );
stFrmInfo.stVFrame.enPixelFormat = SAMPLE_PIXEL_FORMAT;
stFrmInfo.stVFrame.u32Field = VIDEO_FIELD_FRAME;
stMem.u32PoolId = HI_MPI_VB_Handle2PoolId( stMem.hBlock );
stFrmInfo.u32PoolId = stMem.u32PoolId;
s32Ret = HI_MPI_VENC_SendFrame(VencChn, &stFrmInfo,-1);
HI_MPI_SYS_Munmap( stMem.pVirAddr, u32BlkSize );
HI_MPI_VB_ReleaseBlock(stMem.hBlock);
}
/******************************************
step 7: exit process
******************************************/
END_VENC_1_D1_YUVFiles_4:
SAMPLE_COMM_VENC_StopGetStream();
END_VENC_1_D1_YUVFiles_3:
s32Ret=SAMPLE_COMM_VENC_Stop(VencChn);
if(HI_SUCCESS!=s32Ret)
{
SAMPLE_PRT("Stop encode failed ! \n");
goto END_VENC_1_D1_YUVFiles_2;
}
END_VENC_1_D1_YUVFiles_2:
//before destroy private pool,must stop venc
HI_MPI_VB_DestroyPool(hPool);
END_VENC_1_D1_YUVFiles_1:
//close YUV File
fclose(pfp_img);
pfp_img=HI_NULL;
END_VENC_1_D1_YUVFiles_0:
//system exit
SAMPLE_COMM_SYS_Exit();
}
[SAMPLE_COMM_VENC_GetVencStreamProc]-1118: get venc stream time out, exit thread 错误。
希望各位大神能给我解答一下,越详细越好,不胜感激。
下面是我的一部分源码:
/******************************************************************************
* function : 1D1 User send pictures for H264 encode
******************************************************************************/
HI_S32 SAMPLE_VENC_1_D1_YUVFiles(HI_VOID)//by lyx
{
VB_CONF_S stVbConf;
// VENC_GRP VencGrp = 0; //delete
HI_U32 u32Profile = 0;//ADD by lyx
VENC_CHN VencChn = 0;
PIC_SIZE_E enSize = PIC_HD1080;
HI_S32 s32Ret = HI_SUCCESS;
HI_U32 u32BlkSize;
SIZE_S stSize;
VB_POOL hPool = VB_INVALID_POOLID;
FILE *pfp_img = HI_NULL;
HI_U32 u32PicLStride = 0;
HI_U32 u32PicCStride = 0;
HI_U32 u32LumaSize = 0;
HI_U32 u32ChrmSize = 0;
HI_U32 u32Cnt = 0;
HI_U32 u32ChnCnt = 1;
typedef struct hisample_MEMBUF_S
{
VB_BLK hBlock;
VB_POOL hPool;
HI_U32 u32PoolId;
HI_U32 u32PhyAddr;
HI_U8 *pVirAddr;
HI_S32 s32Mdev;
}SAMPLE_MEMBUF_S;
/******************************************
step 1: init variable
******************************************/
memset(&stVbConf,0,sizeof(VB_CONF_S));
//SAMPLE_COMM_VI_GetSizeBySensor 未添加
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.u32MaxPoolCnt = 128;
/*ddr0 video buffer*/
stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
stVbConf.astCommPool[0].u32BlkCnt = 10;
memset(stVbConf.astCommPool[0].acMmzName,0,sizeof(stVbConf.astCommPool[0].acMmzName));
/******************************************
step 2: mpp system init.
******************************************/
s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("system init failed with %d!\n", s32Ret);
goto END_VENC_1_D1_YUVFiles_0;
}
/******************************************
step 3: open yuv file
******************************************/
if (pfp_img != HI_NULL)
{
fclose(pfp_img);
pfp_img = HI_NULL;
}
pfp_img = fopen("5_1920x1080_2.yuv", "rb" );
if (pfp_img == HI_NULL)
{
SAMPLE_PRT("Open yuv file failed!Check if the file %s exit\n","5_704x576.yuv");
goto END_VENC_1_D1_YUVFiles_0;
}
/******************************************
step 4: create private pool on ddr0
******************************************/
hPool = HI_MPI_VB_CreatePool( u32BlkSize, 10,NULL );
if (hPool == VB_INVALID_POOLID)
{
SAMPLE_PRT("HI_MPI_VB_CreatePool failed! \n");
goto END_VENC_1_D1_YUVFiles_1;
}
/******************************************
step 5: encode process
******************************************/
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_1_D1_YUVFiles_2;
}
s32Ret = SAMPLE_COMM_VENC_Start(VencChn, PT_H264, gs_enNorm, enSize, SAMPLE_RC_CBR,u32Profile);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start snap failed!\n");
goto END_VENC_1_D1_YUVFiles_2;
}
/******************************************
step 6: stream venc process -- get stream, then save it to file.
******************************************/
s32Ret = SAMPLE_COMM_VENC_StartGetStream(u32ChnCnt);//u32ChnCnt==1;
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("StartGetStream failed!\n");
goto END_VENC_1_D1_YUVFiles_3;
}
u32PicLStride = CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH);
u32PicCStride = CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH);
u32LumaSize = (u32PicLStride * stSize.u32Height);
u32ChrmSize = (u32PicCStride * stSize.u32Height) >> 2;
while(0 == feof(pfp_img))
{
SAMPLE_MEMBUF_S stMem = {0};
VIDEO_FRAME_INFO_S stFrmInfo;
stMem.hPool = hPool;
u32Cnt ++;
while((stMem.hBlock = HI_MPI_VB_GetBlock(stMem.hPool, u32BlkSize,NULL)) == VB_INVALID_HANDLE)
{
;
}
stMem.pVirAddr = (HI_U8 *) HI_MPI_SYS_Mmap( stMem.u32PhyAddr, u32BlkSize );
if(stMem.pVirAddr == NULL)
{
SAMPLE_PRT("Mem dev may not open\n");
goto END_VENC_1_D1_YUVFiles_4;
}
memset(&stFrmInfo.stVFrame, 0, sizeof(VIDEO_FRAME_S));
stFrmInfo.stVFrame.u32PhyAddr[0] = stMem.u32PhyAddr;
stFrmInfo.stVFrame.u32PhyAddr[1] = stFrmInfo.stVFrame.u32PhyAddr[0] + u32LumaSize;
stFrmInfo.stVFrame.u32PhyAddr[2] = stFrmInfo.stVFrame.u32PhyAddr[1] + u32ChrmSize;
stFrmInfo.stVFrame.pVirAddr[0] = stMem.pVirAddr;
stFrmInfo.stVFrame.pVirAddr[1] = (HI_U8 *) stFrmInfo.stVFrame.pVirAddr[0] + u32LumaSize;
stFrmInfo.stVFrame.pVirAddr[2] = (HI_U8 *) stFrmInfo.stVFrame.pVirAddr[1] + u32ChrmSize;
stFrmInfo.stVFrame.u32Width = stSize.u32Width;
stFrmInfo.stVFrame.u32Height = stSize.u32Height;
stFrmInfo.stVFrame.u32Stride[0] = u32PicLStride;
stFrmInfo.stVFrame.u32Stride[1] = u32PicLStride;
stFrmInfo.stVFrame.u32Stride[2] = u32PicLStride;
stFrmInfo.stVFrame.u64pts = (u32Cnt * 40);
stFrmInfo.stVFrame.u32TimeRef = (u32Cnt * 2);
/* Different channsel with different picture sequence */
SAMPLE_COMM_VENC_ReadOneFrame( pfp_img, stFrmInfo.stVFrame.pVirAddr[0],
stFrmInfo.stVFrame.pVirAddr[1], stFrmInfo.stVFrame.pVirAddr[2],
stFrmInfo.stVFrame.u32Width, stFrmInfo.stVFrame.u32Height,
stFrmInfo.stVFrame.u32Stride[0], stFrmInfo.stVFrame.u32Stride[1] >> 1 );
if(0 != feof(pfp_img))
{
break;
}
SAMPLE_COMM_VENC_PlanToSemi( stFrmInfo.stVFrame.pVirAddr[0], stFrmInfo.stVFrame.u32Stride[0],
stFrmInfo.stVFrame.pVirAddr[1], stFrmInfo.stVFrame.u32Stride[1],
stFrmInfo.stVFrame.pVirAddr[2], stFrmInfo.stVFrame.u32Stride[1],
stFrmInfo.stVFrame.u32Width, stFrmInfo.stVFrame.u32Height );
stFrmInfo.stVFrame.enPixelFormat = SAMPLE_PIXEL_FORMAT;
stFrmInfo.stVFrame.u32Field = VIDEO_FIELD_FRAME;
stMem.u32PoolId = HI_MPI_VB_Handle2PoolId( stMem.hBlock );
stFrmInfo.u32PoolId = stMem.u32PoolId;
s32Ret = HI_MPI_VENC_SendFrame(VencChn, &stFrmInfo,-1);
HI_MPI_SYS_Munmap( stMem.pVirAddr, u32BlkSize );
HI_MPI_VB_ReleaseBlock(stMem.hBlock);
}
/******************************************
step 7: exit process
******************************************/
END_VENC_1_D1_YUVFiles_4:
SAMPLE_COMM_VENC_StopGetStream();
END_VENC_1_D1_YUVFiles_3:
s32Ret=SAMPLE_COMM_VENC_Stop(VencChn);
if(HI_SUCCESS!=s32Ret)
{
SAMPLE_PRT("Stop encode failed ! \n");
goto END_VENC_1_D1_YUVFiles_2;
}
END_VENC_1_D1_YUVFiles_2:
//before destroy private pool,must stop venc
HI_MPI_VB_DestroyPool(hPool);
END_VENC_1_D1_YUVFiles_1:
//close YUV File
fclose(pfp_img);
pfp_img=HI_NULL;
END_VENC_1_D1_YUVFiles_0:
//system exit
SAMPLE_COMM_SYS_Exit();
}
我来回答
回答3个
时间排序
认可量排序
认可0
认可0
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2023-03-07 16:04:27
-
252015-01-23 01:53:02
-
2016-11-04 16:56:42
-
2018-01-12 09:31:18
-
2016-07-12 14:11:11
-
2017-08-15 22:55:23
-
2019-07-12 18:29:38
-
2016-09-29 20:25:44
-
2016-12-12 11:07:53
-
2016-10-10 09:41:04
-
2018-12-26 15:19:51
-
2017-08-01 18:05:50
-
2019-05-27 20:49:31
-
2016-03-14 14:53:55
-
2018-04-12 16:03:21
-
2018-03-15 17:12:39
-
2016-10-10 17:04:26
-
2017-05-26 17:40:53
-
2016-08-04 15:12:21
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5Hi3516CV610 如何使用SD卡升级固件
-
5cat /dev/logmpp 报错 <3>[ vi] [func]:vi_send_frame_node [line]:99 [info]:vi pic queue is full!
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认