Search code examples
webrtcmp4vlclibvlclibvlcsharp

Streaming MP4 over WebRTC using .NET and LibVLCSharp


I have a local .mp4 file that I would need to stream over WebRTC. For streaming I believe I first need to get .mp4 file into RTP packets from which I know how to transfer them over WebRTC. I'm looking at library LibVLCSharp with which I can send rtp packets directly to an IP but I am unable to get these packages in code from where I could do stuff with them (send them over with WebRTC)?

My code looks like this:

public void StartStreaming(string filePath)
{
     var rtsp = new Media(mRecorderNode.VlcLib, filePath, FromType.FromPath);
     rtsp.AddOption(":sout=#duplicate" +
                "{dst=display{noaudio}," +
                "dst=rtp{mux=ts,dst=192.168.128.188,port=8080,sdp=rtsp://192.168.128.188:8080/go.sdp}");
     var mediaPlayer = new MediaPlayer(mRecorderNode.VlcLib);
     mediaPlayer.Play(rtsp);
     var mediaPlayer2 = new MediaPlayer(mRecorderNode.VlcLib);
     mediaPlayer2.Mute = true;
     var media = new Media(mRecorderNode.VlcLib, "rtsp://192.168.128.188:8080/go.sdp", FromType.FromLocation);
     mediaPlayer2.Play(media);
}

The library also plays mp4 files locally which is not needed for my use case. I only need to stream them. How could I get around this issue? Can something like this be achieved with VLC?


Solution

  • We have experimented with samples of LibVLCSharp using SIPSorcery, a WebRTC library for .net.

    See https://code.videolan.org/mfkl/libvlcsharp-samples/-/tree/master/WebRTCAndLibVLC Playing a WebRTC stream was the easy part.

    It turns out the current libvlc API shape does not let us stream the video to WebRTC. It should be "hard but doable" in libvlc4, though I didn't test it.

    SIPSorcery has examples of using it with FFMpeg, and it's probably easier to do it that way: https://github.com/sipsorcery-org/sipsorcery/discussions/607