How to convert YUV420 video format input and use in media element (WPF - C#) #334
Replies: 2 comments 13 replies
-
Hi, Unfortunetely WPF media element is quite limited in this regard. Your only hope would be to implement a media source with old MF interfaces. https://learn.microsoft.com/en-us/windows/win32/api/mfidl/nn-mfidl-imfmediasource However, if using MediaElement is not a requirement, you can use the MediaPlayerElement wrapped control for desktop applications https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/mediaplayerelement The MediaPlayerElement is much more extensible. If the above is not good enough, you can use the winRT MediaPlayer in frame server mode, with a custom built MediaStreamSource of your own. You will need to handle rendering to a DirectX surface though https://msdn.microsoft.com/library/windows/apps/windows.media.core.mediastreamsource Windows might be able to render the YUV directly if you provide the proper encoding properties in the sample metadata. However, I stromgly recommend you use ffmpeginteropx instead :) |
Beta Was this translation helpful? Give feedback.
-
If you can use MediaPlayerElement (either by creating a WinUI app, or by hosting WinUI MediaPlayerElement in a WPF XamlIsland), then you should be able to easily render your YUV420 video using MediaStreamSource, without any additional frameworks (also without FFmpegInteropX). You just need to create VideoEncodingProperties with MediaEncodingSubtypes.Iyuv, and create a MSS from that, somehow like this (minimal setup):
In the SampleRequested event handler, create a MediaStreamSample, fill the Sample's Buffer with the raw YUV420 data and set Timestamp, and set the sample to the eventArgs. Now you should be able to assign the mediaPlaybackItem to MediaPlayer.Source (if you want to use MediaPlayerElement with MediaPlayer, which is recommended), or directly to MediaPlayerElement. Note that it is recommended to handle SampleRequested in native code, to avoid delay due to GC. So recommendation would be to do this in a C++/WinRT or C++/CX component, and use that from C#. But you can first try easily in C# to see if it generally works with your data. If you want to use it and want 100% stable frame rates, consider moving to native code. Feel free to check our code for comparison, especially UncompressedVideoSampleProvider and FFmpegMediaSource. |
Beta Was this translation helpful? Give feedback.
-
We are integrating Agora in WPF (C#) - Agora SDK gives use raw video frames - which we need to render on WPF screens.
SDK Documentation Link.
https://docs-preprod.agora.io/en/video-legacy/API%20Reference/csharp/API/rtc_api_data_type.html#enum_videoframetype
We are searching for library which takes YUV420 format and give use stream, which can be used as media element source.
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/how-to-control-a-mediaelement-play-pause-stop-volume-and-speed?view=netframeworkdesktop-4.8
Beta Was this translation helpful? Give feedback.
All reactions