2

I am trying to write a client-server videostreaming app in c# and i am using libvlc. The client is working fine, but i am not sure how can i do the server. It is like the client, with the modification to media AddOptions method? and then play the media?

UPDATE: I have tried this:

    private void button1_Click(object sender, EventArgs e)
    {
        //MyLibVlc vlc = new MyLibVlc();
        string[] args = new string[] { "-I", "dummy", "--ignore-config","" };
        instance = new VlcInstance(args);
        //:sout=#rtp{dst=79.114.124.180,port=5004,mux=ts,ttl=1} :sout-keep
        player = null;
        string source = "D:\\CM.mp4" ;
        VlcMedia media = new VlcMedia(instance, source);
        string[] options=new string[]{":sout=#rtp{dst=79.114.124.180,port=5004,mux=ts,ttl=1} :sout-keep"};
        media.AddOptions(options);
        if (player == null)
        {
            player = new VlcMediaPlayer(media);
        }
        else
        {
            player.Media = media;
        }
        player.Play();

    }

and i have looked in the log file. Could not open file... I passed the arg in a wrong way, or something is missing.

3 Answers 3

3

I knew it is a very long time ago question, but it still has more than 1k views, so maybe someone will need it like me after looking and testing around hours.

"It is like the client, with the modification to media AddOptions method? and then play the media?"

Yes. You just need to modify the media AddOptions.

"and i have looked in the log file. Could not open file... I passed the arg in a wrong way, or something is missing."

This is an example option that I successfully tested. Note that maybe some options could be abundant for your case.

media.AddOption(":sout=#transcode{vcodec=h264,vb=0,scale=0,acodec=mp4a,ab=128,channels=2,samplerate=44100}:rtp{mux=ts,sdp=rtsp://192.168.1.123:554/stream.sdp}");

media.AddOption(":sout-keep");

In creating media, I also need to give the exactly FromType param.

var media = new Media(libVlc, "C:\\foo.avi", FromType.FromPath);

If you want to stream from other sources such as another RTSP source so it will be:

var media = new Media(libVlc, "rtsp://192.168.1.234:555/live/0/MAIN", FromType.FromLocation);
Sign up to request clarification or add additional context in comments.

Comments

1

Here is a full example demonstrating how to stream a video with LibVLCSharp:

using System;
using LibVLCSharp.Shared;

namespace VlcStreaming
{
    class Program
    {
        static void Main(string[] args)
        {
            var serverIpAddress = "192.168.1.101";
            var streamUrl = $"rtsp://{serverIpAddress}:554/stream.sdp";

            LibVLCSharp.Shared.Core.Initialize();

            var libVlc = new LibVLC();
            var media = new Media(libVlc, "fe48f269-4f89-4c58-afd4-04c2e2e3f10f.MP4");

            media.AddOption(
                $":sout=#transcode{{vcodec=h264,vb=0,scale=0,acodec=mp4a,ab=128,channels=2,samplerate=44100}}:rtp{{mux=ts,sdp={streamUrl}}}");
            media.AddOption(":sout-keep");

            var player = new MediaPlayer(media);

            player.Play();

            Console.ReadLine();
        }
    }
}

You need to install the LibVLCSharp library, as well as the LibVlc library for your platform (VideoLAN.LibVlc.Windows in my case).

You can then connect to the stream URL from VLC player (you will need to open port 554 if connecting from another machine etc).

Comments

0

Regards AddOption / Options.. Take a not that you must separate each option, and not use the Vlc-Media-Mplayer given format (can be confusing!), the error received won't help you figure it out!

so, if Vlc-ML options are,

e.g.

":sout=#rtp{dst=127.0.0.1,port=12345,mux=ts} :no-sout-all :sout-keep"

they must be separated to this:

            media = new Media(m_libVlc, p_fileInfo.FullName, FromType.FromPath, 
                @":sout=#rtp{dst=127.0.0.1,port=12345,mux=ts}",
                @":no-sout-all", 
                @":sout-keep");

Hope this helps other (took me quite some time to figure, with the help of #cube45 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.