nvEncDXGIOutputDuplicationSample - Using YUV420 instead of NV12 causes error

I have the nvEncDXGIOutputDuplicationSample sample from NVIDIA’s GitHub. What I want to do seems like it should be relatively simple. I want to change the color conversion to convert to YUV420/I420 instead of NV12.

I changed this line from NV_ENC_BUFFER_FORMAT_NV12 to NV_ENC_BUFFER_FORMAT_IYUV, and then added

case NV_ENC_BUFFER_FORMAT_IYUV:
        return DXGI_FORMAT_420_OPAQUE;

to this switch block

Unfortunately, when I try and run the code now, I get Error 0x80070057 E_INVALIDARG in CreateVideoProcessorOutputView at this line

github.
com/NVIDIA/video-sdk-samples/blob/master/nvEncDXGIOutputDuplicationSample/Preproc.cpp#L141

Any ideas why? The modifications I made were so small so I can’t imagine why it would be causing a problem.

For D3D12 video, RTX 3070 only supports encoding NV12 format.
It’s probably just not supported on hardware level to use DXGI_FORMAT_420_OPAQUE directly, you must convert your textures to NV12 manually.