when I use dxva2 decode h264 in ffmpeg,the output format in surface sometimes is nv12,and sometime is nv21,how can I know which format is .D3DSURFACE_DESC Format is same.
when I use dxva2 decode h264 in ffmpeg,the output format in surface sometimes is nv12,and sometime is nv21,how can I know which format is .D3DSURFACE_DESC Format is same.
Since you use dxva2 together with ffmpeg, I want to confirm which API generate the output format? And can this issue be reproduced without ffmpeg?
ffmpeg call dxva2 APIs like this:
LoadLibrary("d3d9.dll");
LoadLibrary("dxva2.dll");
IDirect3D9_CreateDevice
.......................
after decode h264 frame,get decoded data from D3D surface,
hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, D3DLOCK_READONLY);
I found that the decoded frame format is nv12 if the stream encoded in avc1 h264,and format is nv21 if the stream encoed in mpeg4 h264。
Hello,
There is a need to convert NV12 / NV21 to D3D supported surface format like D3DFMT_R8G8B8.
NV21 is same as NV12, except that Cb and Cr samples are swapped. All you need to do, is to reverse the order.
More references: "Recommended 8-Bit YUV Formats for Video Rendering", "Color Converter DSP" and "DirectXMath Library color functions ( XMColorYUVToRGB )"
Thank you!
FFMPEG call dxva2 APIs decode h264 and return D3D surface,D3DSURFACE_DESC Format is same while decoed frame is NV12 or NV21,if I scale and convert the source frame(include format convert) to NV12,output format and frame data are right.but this will Increase CPU consumption.
Please check MFMapDXGIFormatToDX9Format(DXGI_FORMAT_NV12) or MAKEFOURCC('N', 'V', '1', '2') to see if it helps. Or maybe you can check DXGI which supports DXGI_FORMAT_NV12. DXGI is used by Direct3D 10, Direct3D 11 and Direct3D 12.
1 Person is following this question.