有没有办法在 C# 中转发 RTSP,最好使用 LibVLCSharp?

Is there a way to forward RTSP in C# preferably using LibVLCSharp?

我正在尝试创建一个应用程序来加重多个 RTSP 在移动应用程序中的使用。这个想法是我 运行 Windows PC 上的一个简单的 WPF 应用程序连接到家里的 IP 摄像头,一个 xamarin 应用程序连接到它。我希望 WPF 程序根据请求将所需的 RTSP 中继到应用程序,但为此我不知所措。 我学会了如何在 windows 和 android 应用程序上接收流,但我正在寻找一种方法将 windows 应用程序接收到的流转发到 android 应用程序.

根据我在互联网上发现的潜伏信息,有一种使用 VLC 库进行流式传输的方法:

但我不知道如何从另一个流而不是文件进行流式传输。

这就是我得到的 - 在应用程序上简单显示 RTSP:

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Serwer"
        xmlns:wpf="clr-namespace:LibVLCSharp.WPF;assembly=LibVLCSharp.WPF"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition  Width="*"/>
            <ColumnDefinition  Width="*"/>
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0">Placeholder for settings</Label>
        <Label Grid.Row="0" Grid.Column="1">Placeholder for more streams</Label>
        <Label Grid.Row="1" Grid.Column="1"></Label>
        <wpf:VideoView x:Name="VideoView" Grid.Row="1" Grid.Column="0"/>
    </Grid>
</Window>

这是XAML背后的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Serwer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        const string VIDEO_URL = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
        readonly LibVLC _libvlc;

        public MainWindow()
        {
            InitializeComponent();
            // this will load the native libvlc library (if needed, depending on the platform). 
            Core.Initialize();

            // instantiate the main libvlc object
            _libvlc = new LibVLC();
            VideoView.MediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libvlc);
            VideoView.MediaPlayer.Play(new Media(_libvlc, VIDEO_URL, FromType.FromLocation));
        }
    }
}

好的,我终于找到命令列表并正确使用它们了。结果我爱上了 LibVLC。 :D
这是描述各种命令的 link:https://wiki.videolan.org/Documentation:Streaming_HowTo/Advanced_Streaming_Using_the_Command_Line/#rtp

这是我完成代码的方式:

using LibVLCSharp.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Serwer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        const string VIDEO_URL = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
        readonly LibVLC _libvlc;

        public MainWindow()
        {
            InitializeComponent();            // this will load the native libvlc library (if needed, depending on the platform). 
            Core.Initialize();                // instantiate the main libvlc object
            _libvlc = new LibVLC();
            VideoView.MediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libvlc);
            var rtsp1 = new Media(_libvlc, VIDEO_URL, FromType.FromLocation);       //Create a media object and then set its options to duplicate streams - 1 on display 2 as RTSP
            rtsp1.AddOption(":sout=#duplicate" +
                "{dst=display{noaudio}," +
                "dst=rtp{mux=ts,dst=192.168.0.110,port=8080,sdp=rtsp://192.168.0.110:8080/go.sdp}");  //The address has to be your local network adapters addres not localhost
            VideoView.MediaPlayer.Play(rtsp1);
            VideoView1.MediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libvlc);
            VideoView1.MediaPlayer.Mute=true;
            VideoView1.MediaPlayer.Play(new Media(_libvlc, "rtsp://192.168.0.110:8080/go.sdp", FromType.FromLocation));
        }
    }
}

感谢立方体为我指明了正确的方向!