将ffmpeg d3dva纹理资源复制到共享渲染纹理

将ffmpeg d3dva纹理资源复制到共享渲染纹理,ffmpeg,rendering,textures,directx-11,render-to-texture,Ffmpeg,Rendering,Textures,Directx 11,Render To Texture,基于这个例子,我使用ffmpeg通过d3dva对视频进行解码。我能成功地解码视频。我接下来需要做的是渲染解码的NV12帧。我已经基于此示例创建了directx渲染纹理,并将其设置为共享 D3D11_TEXTURE2D_DESC texDesc; texDesc.Format = DXGI_FORMAT_NV12; // Pixel format texDesc.Width = width; //

基于这个例子,我使用ffmpeg通过d3dva对视频进行解码。我能成功地解码视频。我接下来需要做的是渲染解码的NV12帧。我已经基于此示例创建了directx渲染纹理,并将其设置为共享

    D3D11_TEXTURE2D_DESC texDesc;
    texDesc.Format = DXGI_FORMAT_NV12;              // Pixel format
    texDesc.Width = width;                          // Width of the video frames
    texDesc.Height = height;                        // Height of the video frames
    texDesc.ArraySize = 1;                          // Number of textures in the array
    texDesc.MipLevels = 1;                          // Number of miplevels in each texture
    texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; // We read from this texture in the shader
    texDesc.Usage = D3D11_USAGE_DEFAULT;
    texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
    texDesc.CPUAccessFlags = 0;

    hr = device.CreateTexture2D(&texDesc, null, &nv12Texture);
    if (FAILED(hr))
    {
        error("Failed to create NV12 texture (hr: %s)", hr);
        return false;
    }

    // QI IDXGIResource interface to synchronized shared surface.
    IDXGIResource dxgiResource;
    nv12Texture.QueryInterface(&IID_IDXGIResource, cast(void**)&dxgiResource);

    // obtain handle to IDXGIResource object.
    hr = dxgiResource.GetSharedHandle(&sharedHandle);
    dxgiResource.Release();
    dxgiResource = null;

    if (FAILED(hr))
    {
        error("Failed to create NV12 texture shared handle (hr: %s)", hr);
        return false;
    }
然后我尝试将nv12从ffmpeg纹理复制到我的渲染纹理。与ffmpeg在功能上完全相同

但是渲染窗口只是绿色的没有错误没有失败的hr结果什么都没有。当我使用sw解码器时,我可以渲染帧,我只需使用D3D11_使用情况_动态和D3D11_CPU_访问_写入创建纹理

下面是每个纹理的描述

hwTexture desc D3D11_TEXTURE2D_DESC(1280, 720, 1, 20, 103, DXGI_SAMPLE_DESC(1, 0), 0, 512, 0, 0)
nv12Texture desc D3D11_TEXTURE2D_DESC(1280, 720, 1, 1, 103, DXGI_SAMPLE_DESC(1, 0), 0, 8, 0, 2)
sharedTexture desc D3D11_TEXTURE2D_DESC(1280, 720, 1, 1, 103, DXGI_SAMPLE_DESC(1, 0), 0, 8, 0, 2)

知道我遗漏了什么吗?

所以我终于找出了问题所在,问题是OpenSharedResource是从设备而不是hwDevice调用的。

尝试使用AVD3D11VADeviceContext*device\uHWCTX=ctx->device\uCTX->hwctx;(使用适当的强制转换)而不是从纹理中获取设备上下文。ctx是由avcodec_alloc_context3创建的avcodec上下文。另外,尝试为nv12Texture设置D3D11_BIND_RENDER_TARGET|D3D11_BIND_SHADER_资源。您好,非常感谢您的评论,但这没有帮助。
hwTexture desc D3D11_TEXTURE2D_DESC(1280, 720, 1, 20, 103, DXGI_SAMPLE_DESC(1, 0), 0, 512, 0, 0)
nv12Texture desc D3D11_TEXTURE2D_DESC(1280, 720, 1, 1, 103, DXGI_SAMPLE_DESC(1, 0), 0, 8, 0, 2)
sharedTexture desc D3D11_TEXTURE2D_DESC(1280, 720, 1, 1, 103, DXGI_SAMPLE_DESC(1, 0), 0, 8, 0, 2)