How to get decoded video frames using WinRT in .NET5

Viewed 219

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:

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?

0 Answers
Related