我一直试图通过谷歌搜索解决这个问题一个月。但是现在我必须在这里寻求帮助。
我想使用ffmpeg解码帧进行渲染。并使用框架(它转换为RGB32格式),我……
没有人回复。我解决了我的问题。 我修改了一些代码,我不确定它是否解决了这个问题。黑屏原因的问题是我的矩阵。
D3D11_TEXTURE2D_DESC TextureDesc; D3D11_RENDER_TARGET_VIEW_DESC RenderTargetViewDesc; D3D11_SHADER_RESOURCE_VIEW_DESC ShaderResourceViewDesc; ZeroMemory(&TextureDesc, sizeof(TextureDesc)); TextureDesc.Height = pFrame->height; TextureDesc.Width = pFrame->width; TextureDesc.MipLevels = 1; TextureDesc.ArraySize = 1; TextureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;/*DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;*/ //size 32bit TextureDesc.SampleDesc.Count = 1; TextureDesc.SampleDesc.Quality = 0; TextureDesc.Usage = D3D11_USAGE_DYNAMIC; TextureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; TextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; TextureDesc.MiscFlags = 0; DWORD* pInitImage = new DWORD[pFrame->width*pFrame->height]; memset(pInitImage, 0, sizeof(DWORD)*pFrame->width*pFrame->height); D3D11_SUBRESOURCE_DATA InitData; InitData.pSysMem = pInitImage; InitData.SysMemPitch = pFrame->width*sizeof(DWORD); InitData.SysMemSlicePitch = 0; result = m_device->CreateTexture2D(&TextureDesc, &InitData, &m_2DTex); if (FAILED(result)) return false; ShaderResourceViewDesc.Format = TextureDesc.Format; ShaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; ShaderResourceViewDesc.Texture2D.MostDetailedMip = 0; ShaderResourceViewDesc.Texture2D.MipLevels = 1; result = m_device->CreateShaderResourceView(m_2DTex, &ShaderResourceViewDesc, &m_ShaderResourceView); if (FAILED(result)) return false; D3D11_MAPPED_SUBRESOURCE S_mappedResource_tt; ZeroMemory(&S_mappedResource_tt, sizeof(S_mappedResource_tt)); DWORD Stride = pFrame->linesize[0]; result = m_deviceContext->Map(m_2DTex, 0, D3D11_MAP_WRITE_DISCARD, 0, &S_mappedResource_tt); if (FAILED(result)) return false; BYTE * pFrameData = pFrame->data[0]; // now we have a pointer that points to begin of the destination buffer BYTE* mappedData = (BYTE *)S_mappedResource_tt.pData;// +S_mappedResource_tt.RowPitch; for (auto i = 0; i < pFrame->height; i++) { memcpy(mappedData, pFrameData, Stride); mappedData += S_mappedResource_tt.RowPitch; pFrameData += Stride; } m_deviceContext->Unmap(m_2DTex, 0);
它很有效。我希望那对我做同样事情的人会有所帮助。