0

I need to stream a webcam to an ip address. After days of googling I decided that the easiest way was to embed Vlc. That said I am also still open to other solutions.


Step1 - OK!: I can see my webcam in a form by using that code:

vlcPlayer.MediaPlayer.VlcLibDirectory = new DirectoryInfo(@"c:\Program Files (x86)\VideoLAN\VLC\");
vlcPlayer.MediaPlayer.EndInit();
vlcPlayer.MediaPlayer.Play(new Uri(@"dshow://");

Step2 - OK!: Now trying to make a step forward and using this tutorial I can send a video locally 127.0.0.1:5004 using 2 instances of Vlc: one to transmit and one to receive.


Step 3 - NOT OK: it should seem simple to configure vlc for changing the source from file to webcam and to transmit it via ip. So what I do is to operate as before only changing the source: 1. Menu "Media" --> Stream. That opens the "open media" window.

Here I click the tab capture device --> video device name --> I choose "integrated webcam"

Then all the rest is as before. But nothing happens. The receiver is black with nothing inside. Also If I try to save the flow from the receiver I only get a few bytes. The afore mentioned settings for the transmitter are the following:

Capture device tab --> integrated webcam. Then the stream button --> the window opens correctly with dshow:\ --> next --> new destination RTP,MPEG transport stream ---> add button --> address = 127.0.0.1 port = 5004 StreamNAme=test

So the strange is that when I stream a file with whatever name from the transmitter, it immediately is recognized by the receiver. Instead try as I might, nothing happens when the webcam is the source.


That being said the problem above is not crucial to the solution. What I care for is not how to use vlc stand alone but how to use it from my wpf application in order to send the webcam stream.

Thanks for any help

Patrick

mfkl
  • 1,914
  • 1
  • 11
  • 21
Patrick
  • 3,073
  • 2
  • 22
  • 60

1 Answers1

0

I believe this sample should help you achieve your goal:

static void Main()
{
    var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
    // Default installation path of VideoLAN.LibVLC.Windows
    var libDirectory =
        new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));

    using (var mediaPlayer = new Vlc.DotNet.Core.VlcMediaPlayer(libDirectory))
    {

        var mediaOptions = new[]
        {
            ":sout=#rtp{sdp=rtsp://127.0.0.1:554/}",
            ":sout-keep"
        };

        mediaPlayer.SetMedia(new Uri("http://hls1.addictradio.net/addictrock_aac_hls/playlist.m3u8"),
            mediaOptions);

        mediaPlayer.Play();

        Console.WriteLine("Streaming on rtsp://127.0.0.1:554/");
        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
    }
}

You will need 2 nuget packages: Vlc.DotNet (C# wrapper) and VideoLAN.LibVLC.Windows (LibVLC library for Windows).

mfkl
  • 1,914
  • 1
  • 11
  • 21