2

all. I'm a beginner of programming and I met some difficulties on video decoding/playing.

I have raw h264 data stream from tcpsocket, and I want to show the video on a WPF usercontrol.

Since I have few knowledge of C++ & video decoding/encoding, it will be hard to use ffmpeg for me. So I'm considering if VLC can do this.

The background is: I want to use Scrcpy server build my own "Android screen cast & remote control" WPF application.

So far, I've implemented:

  • Push server to device and start the server
  • Establish TCP connection between PC and Android device
  • Can see h264 raw data streaming in the socket

Then the next step is: show video on a WPF usercontrol

Actually I've tried another solution before and can get what I want

  • Use MPV as a media player
  • Start mpv.exe process in my app with specific arguments
  • Embed mpv window in a WPF host element

But I think <WindowsFormsHost/> is not perfect for a WPF application, So I'm trying to find a WPF-style way.

When I searching the Github, I found it is easier if I want to play a media file from disc or internet, I just need to pass the file location (e.g. D:/MyFolder/mySampleVideo.mp4 or http://somesite/aSampleVideo.flv) and no need to care about how the component/element work. Like this project and this project

If I use the VLC, how can I directly play the raw h264 data stream? Is there a method like VlcPlayer.Play(NetworkStream myh264stram) {...} ?

Vveeb
  • 23
  • 6
  • Thanks for your interest in Vlc.DotNet, but please make sure you have read the warning messages on the Readme: - The project has gone into maintenance mode - This part where I regret having made a true WPF video control : https://github.com/ZeBobo5/Vlc.DotNet#writing-a-wpf-app--migrating-wpf-control-from-2x – cube45 Jul 24 '20 at 09:31
  • The mentioning of MPV is especially useful. Thanks for that! – minghua Oct 15 '21 at 15:51

1 Answers1

2

But I think is not perfect for a WPF application, So I'm trying to find a WPF-style way.

The solution of using a WindowsFormsHost in a WPF application is the best we've found for WPF, because implementing a true-WPF solution doesn't have great perfs: https://github.com/ZeBobo5/Vlc.DotNet#writing-a-wpf-app--migrating-wpf-control-from-2x

That said, if you still want to go ahead with Vlc.DotNet (which has been placed in maintenance mode), you will probably need to specify the demux you want libvlc to be using with "--demux", "h264" in the VlcMediaPlayerOptions

Then, you could indeed call

   mediaPlayer.Play(stream);

With LibVLCSharp, the procedure is quite the same, but we are using a MediaInput class to hold the reference to the Stream, see : https://github.com/mfkl/lvst/blob/master/LVST/Program.cs#L72

using var mediaInput = new StreamMediaInput(stream);
using var media = new Media(libVLC, mediaInput);
using var mediaPlayer = new MediaPlayer(media);

see also : C# LibVLCSharp player direct feed media

cube45
  • 3,429
  • 2
  • 24
  • 35
  • Many thanks to your post, now I can easily build a sample project to play local media file follwing the start guide (although this takes me half a day) in LibVLCSharp! Next step I'll try out "stream playback". – Vveeb Jul 27 '20 at 09:05
  • And this [airspace issue](https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/docs/getting_started.md#the-airspace-issue) was exactly what I met before when using `WindowsFormsHost`. Hence, I said that : `WindowsFormsHost` way is not perfect. – Vveeb Jul 27 '20 at 09:08
  • Can you imagine, my application is just a part of the whole project(like the text editor in visual studio), and my text editor (my video element) always blocks other views(popup + float). And then I saw in the [guide](https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/docs/getting_started.md#the-airspace-issue): "We decided to implement the WPF control with the third solution". So, a question in advance: will `` behave as I expected if I use LibVLCSarp ? – Vveeb Jul 27 '20 at 09:10
  • Read the LVS WPF doc. In short, if you want to place content over the video, place that inside the control tag, and it will be rendered in an invisible window over the video. – cube45 Jul 27 '20 at 17:07