Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
is possible convert YUV surface to CanvasBitmap ? #198
I'm developing a video streaming app via Win2D and FFmpeg,
cus Win2D just work in D2D format, so I have to do sws_scale,
a worst case like a big resolution 4000 x 3000 h264 streaming
it's really too slow if convert it from yuv to bgra in FFmpeg
I just noticed a test "Direct3DSurfaceInteropTests",
so I don't know the detail, but is possible that I bind yuv data to a d3d surface, and convert yuv to bgra in GPU or even better if Win2D can draw the surface directly
Win2D does not directly support YUV data formats. If you are willing to interop and include some native C++ code, you have several options:
I just finish the interop, but the image which be drawn is not incorrect.
I guess the UV is wrong, I'm confused, since I have to interop Win2D & Direct2D
I should use the CanvasDrawSession and send it into C++ to do interop it to D2D1Context to do CreateImageSourceFromDxgi
or I should use the D2D1Device which I created in C++ and send it to C# , interop it to CanvasDevice ?
this sample is what I done for now, https://github.com/PatrickSCLin/YUVSample
maybe you give me some hint from the code
Great to hear you got this working! How is the performance?
The incoming surfaces for CreateImageSourceFromDxgi don't have to be NV12. https://msdn.microsoft.com/en-us/library/windows/desktop/dn890791%28v=vs.85%29.aspx has a table documenting the various options - input can either be a single planar format texture, or a pair of textures containing separate Y and UV data.
sorry, I'm trying to put yuv420p frame data directly to a CanvasVirturalBitmap by CreateImageSourceFromDxgi
since yuv420p is a planlar format, so in this case, I should create 3 textures for Y, U, V, all of them are R8 format, right ?
also I saw the document said
If multiple surfaces are provided, this method infers whether chroma planes are subsampled (by 2x) from the relative sizes of each corresponding source rectangle (or if the source rectangles parameter is NULL, the bounds of each surface). The second and third rectangle must each be equal in size to the first rectangle, or to the first rectangle with one or both dimensions scaled by 0.5 (while rounding up).
the problem is, I can not see the argument sourceRectagles in my ID2D1DeviceContext2 interface
the function in my VisualStudio 2015 Update 1 is looks like this, and no other overload function:
what should I do ?