I'm attempting to read decoded video frames in a .NET5 console app using the new WinRT Projection APIs.
I've spent many hours trying to piece it together using the following without success:
- https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/use-opencv-with-mediaframereader
- https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/play-audio-and-video-with-mediaplayer
- https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/custom-video-effects
- https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/process-media-frames-with-mediaframereader
- https://blogs.windows.com/windowsdeveloper/2020/09/03/calling-windows-apis-in-net5/
This does open and start to decode frames, but I am unable to get access to them in the FrameAvailable event.
MediaPlayer player = new MediaPlayer
{
Source = mediaSource,
IsVideoFrameServerEnabled = true,
IsMuted = true,
IsLoopingEnabled = false,
AudioDevice = default,
};
player.VideoFrameAvailable += FrameAvailable;
private void FrameAvailable(MediaPlayer sender, object args)
{
var frame = VideoFrame.CreateWithSoftwareBitmap(bitmap);
sender.CopyFrameToVideoSurface(frame.Direct3DSurface);//this Direct3DSurface is null
using (var buffer = bitmap.LockBuffer(BitmapBufferAccessMode.Write))
{
BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0);
using (var reference = buffer.CreateReference())
{
IntPtr start;
uint capacity;//bytes
((IMemoryBufferByteAccess)reference).GetBuffer(out start, out capacity);
//process the pixels here
...
How can I get access to the decoded frames so that I can process the pixels?