D3D显示YUV420视频

么特里亚 2015-08-21 09:36:40
请问下,上个接口已经将视频分别分成Y,U,V,请问下怎么将视频用D3D显示出来
int D3DOffscreenRender::render(unsigned char *py, unsigned char *pu, unsigned char *pv, int width, int height,RECT*srcRect)
希望大家给点经验,首次用D3D替换DDRAW,不懂
...全文
306 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dong364 2015-08-26
  • 打赏
  • 举报
回复
检查下pu、py、pv,这几个变量每次for都没有递增
么特里亚 2015-08-21
  • 打赏
  • 举报
回复
#if 1
	BYTE * pTextureBuffer = NULL;
	LONG  lTexturePitch;     
	D3DLOCKED_RECT d3d_rect;  
    lRet=m_pDirect3DSurfaceRender->LockRect(&d3d_rect,NULL,D3DLOCK_DONOTWAIT);  
    if(FAILED(lRet))  
        return -1;  

	lTexturePitch = d3d_rect.Pitch;
	BYTE *pDest = (BYTE*)d3d_rect.pBits ;
	int i = 0;
	for(i = 0;i < m_height;i ++){
		memcpy(pDest + i * lTexturePitch,py, m_width);
	}
	for(i = 0;i < m_height/2;i ++){
		memcpy(pDest + lTexturePitch * m_height + i * lTexturePitch / 2,pu, m_width / 2);
	}
	for(i = 0;i < m_height/2;i ++){
		memcpy(pDest + lTexturePitch * m_height + lTexturePitch * m_height / 4 + i * lTexturePitch / 2,pv, m_width / 2);
	}

// 	for(int i = 0;i < surfaceDesc.Height;i ++){  
//         memcpy(pTextureBuffer + i * lTexturePitch,py, surfaceDesc.Width);  
//     }  
//     for(int j = 0;j < (surfaceDesc.Height)/2;j ++){  
//         memcpy(pTextureBuffer + lTexturePitch * (surfaceDesc.Height) + j * lTexturePitch / 2,pu, (surfaceDesc.Width) / 2);  
//     }  
//     for(int k = 0;k < (surfaceDesc.Height)/2;k ++){  
//         memcpy(pTextureBuffer + lTexturePitch * (surfaceDesc.Height) + lTexturePitch * (surfaceDesc.Height) / 4 + k * lTexturePitch / 2,pv, (surfaceDesc.Width) / 2);  
//     }  
#endif
    lRet=m_pDirect3DSurfaceRender->UnlockRect(); 
我试过这样,显示不出来
赵4老师 2015-08-21
  • 打赏
  • 举报
回复
先弄清楚图像每行到底多少个字节,每个像素到底对应几个字节以及这几个字节分别代表什么量还有其取值范围。
么特里亚 2015-08-21
  • 打赏
  • 举报
回复
#if 1
BYTE * pTextureBuffer = NULL;
LONG lTexturePitch;
D3DLOCKED_RECT d3d_rect;
lRet=m_pDirect3DSurfaceRender->LockRect(&d3d_rect,NULL,D3DLOCK_DONOTWAIT);
if(FAILED(lRet))
return -1;

lTexturePitch = d3d_rect.Pitch;
BYTE *pDest = (BYTE*)d3d_rect.pBits ;
int i = 0;
for(i = 0;i < m_height;i ++){
memcpy(pDest + i * lTexturePitch,py, m_width);
}
for(i = 0;i < m_height/2;i ++){
memcpy(pDest + lTexturePitch * m_height + i * lTexturePitch / 2,pu, m_width / 2);
}
for(i = 0;i < m_height/2;i ++){
memcpy(pDest + lTexturePitch * m_height + lTexturePitch * m_height / 4 + i * lTexturePitch / 2,pv, m_width / 2);
}
#endif

么特里亚 2015-08-21
  • 打赏
  • 举报
回复
引用 2 楼 dong364 的回复:
你的问题可以从这里解决:http://blog.csdn.net/leixiaohua1020/article/details/40279297

我借鉴了这篇文章,并且作了修改
#if 1
BYTE * pTextureBuffer = NULL;
LONG lTexturePitch;
D3DLOCKED_RECT d3d_rect;
lRet=m_pDirect3DSurfaceRender->LockRect(&d3d_rect,NULL,D3DLOCK_DONOTWAIT);
if(FAILED(lRet))
return -1;

lTexturePitch = d3d_rect.Pitch;
BYTE *pDest = (BYTE*)d3d_rect.pBits ;
int i = 0;
for(i = 0;i < m_height;i ++){
memcpy(pDest + i * lTexturePitch,py, m_width);
}
for(i = 0;i < m_height/2;i ++){
memcpy(pDest + lTexturePitch * m_height + i * lTexturePitch / 2,pu, m_width / 2);
}
for(i = 0;i < m_height/2;i ++){
memcpy(pDest + lTexturePitch * m_height + lTexturePitch * m_height / 4 + i * lTexturePitch / 2,pv, m_width / 2);
}
#endif

但是显示的图像不对
赵4老师 2015-08-21
  • 打赏
  • 举报
回复
顶楼上!
dong364 2015-08-21
  • 打赏
  • 举报
回复
你的问题可以从这里解决:http://blog.csdn.net/leixiaohua1020/article/details/40279297

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧