1

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?

Mr Squidr
  • 143
  • 1
  • 8

2 Answers2

2

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

cube45
  • 3,429
  • 2
  • 24
  • 35
  • First, thank you for your answer. I have seen you being active in similar topics in other answers also. If I understand you correctly the code posted above does not work? Reading the code over it seems like code for streaming video over webrtc with SipSorcery and LibVLC which is exactly what I need but in your next paragraph you state it does not let us stream the video to WebRTC. Will be testing with FFMpeg. – Mr Squidr Mar 15 '23 at 18:24
  • The sample is for playing a WebRTC stream, for example a camera captured from a web page, not producing a WebRTC stream from a VLC source. – cube45 Mar 15 '23 at 22:03
2

We use FFMpeg to do this in one of our applications. FFMpeg generates the RTP which we read and forward over WebRTC. While the code is written for our WebRTC SDK (LiveSwitch), it should be pretty easy to modify it for whichever SDK you want to use.