microsoft / FFmpegInterop

This is a code sample to make it easier to use FFmpeg in Windows applications.
Apache License 2.0
1.27k stars 308 forks source link

WPF Support #290

Closed Pason-Chen closed 2 years ago

Pason-Chen commented 2 years ago

I'm trying to apply this sample on WPF. But the question is I cannot set a MediaStreamSource on the WPF MediaElement. I read about the issues WPF Support #21 and there is a suggestion is that should be able register the MediaStreamSource using the Media Foundation extension so that it can be invoked when setting a source as a URI on the MediaElement.

but the link in that suggestion is dead now. https://code.msdn.microsoft.com/windowsapps/MediaStreamSource-media-dfd55dff

Do anyone know how to convert MediaStreamSource to a URI in WPF? Any suggestion will be help, thanks a lot.

lukasf commented 2 years ago

I think I found the sample here:

https://github.com/microsoft/VCSamples/tree/master/VC2012Samples/Windows%208%20samples/C%2B%2B/Windows%208%20app%20samples/MediaStreamSource%20media%20extension%20sample%20(Windows%208)

The sample targets Windows 8 Apps, not WPF, but the same mechanism should be possible with WPF as well. However, this is really complex stuff, all written in native C++ code. Making it work with WPF, fully featured, with multiple streams and formats would be a very huge task, requiring deep knowledge of both MediaFoundation and native code. The sample only uses a single audio stream if I understand correctly. No video, no multi streams, no dynamic formats, no subtitles. Also, the sample probably won't compile on any recent Visual Studio version, because it targets a totally outdated Windows 8 App framework.

Sorry to say, but personally I think this approach is a dead end.

You might have more luck using the MediaPlayer class from Windows.Media.Playback with FFmpegInterop (or better FFmpegInteropX) and using it in frame server mode. This means manually receiving the decoded D3D video frames from MediaPlayer, and rendering them into your application, in your case probably using a WPF D3DImage as target. But I don't know if anyone has ever tried this. You'd probably have to get down a bit with native D3D or SharpDX, and it probably won't be easy. I know that some people have used the frame server approach successfully with FFmpegInteropX and Unity, rendering video files into their Unity 3D applications with great performance.

brabebhin commented 2 years ago

Frame server mode is the way to go. However, it might be tricky to get CC displayed correctly.

Pason-Chen commented 2 years ago

Thanks a lot for the information. It's seem there is no worthy to try this approach... I will try the other ways, includied FFmpegInteropX or just play the video by native code. Still, thanks again.