有没有办法在C#中转发RTSP?最好使用LibVLCSharp?
我正在尝试创建一个应用程序,用于在移动应用程序中使用多个RTSP。我的想法是,我在Windows PC上运行一个简单的WPF应用程序,该应用程序连接到家中的IP摄像头,xamarin应用程序连接到它。我希望WPF程序根据请求将所需的RTSP中继到应用程序,但要做到这一点,我不知所措。 我学习了如何在windows和android应用程序上接收流,但我正在寻找一种方法,将windows应用程序接收到的流转发到android应用程序中 根据我在互联网上发现的情况,有一种使用VLC库进行流式传输的方法: 但我不知道如何从另一个流而不是文件流 这就是我得到的-在应用程序上简单显示RTSP:有没有办法在C#中转发RTSP?最好使用LibVLCSharp?,c#,stream,rtsp,libvlcsharp,C#,Stream,Rtsp,Libvlcsharp,我正在尝试创建一个应用程序,用于在移动应用程序中使用多个RTSP。我的想法是,我在Windows PC上运行一个简单的WPF应用程序,该应用程序连接到家中的IP摄像头,xamarin应用程序连接到它。我希望WPF程序根据请求将所需的RTSP中继到应用程序,但要做到这一点,我不知所措。 我学习了如何在windows和android应用程序上接收流,但我正在寻找一种方法,将windows应用程序接收到的流转发到android应用程序中 根据我在互联网上发现的情况,有一种使用VLC库进行流式传输的方法
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>
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命名空间:Serwer”
xmlns:wpf=“clr命名空间:LibVLCSharp.wpf;assembly=LibVLCSharp.wpf”
mc:Ignorable=“d”
Title=“MainWindow”Height=“650”Width=“800”>
设置的占位符
更多流的占位符
这是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));
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间服务器
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
const string VIDEO_URL=”rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
只读libvlcu LibVLC;
公共主窗口()
{
初始化组件();
//这将加载本机libvlc库(如果需要,取决于平台)。
Core.Initialize();
//实例化主libvlc对象
_libvlc=新的libvlc();
VideoView.MediaPlayer=新LibVLCSharp.Shared.MediaPlayer(_libvlc);
VideoView.MediaPlayer.Play(新媒体(_libvlc,VIDEO_URL,FromType.FromLocation));
}
}
}
好的,我终于找到了命令列表并正确使用了它们。原来我爱上了LibVLCD以下是描述各种命令的链接: 下面是我如何编写代码的:
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));
}
}
}
使用LibVLCSharp.Shared;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间服务器
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
const string VIDEO_URL=”rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
只读libvlcu LibVLC;
公共主窗口()
{
InitializeComponent();//这将加载本机libvlc库(如果需要,取决于平台)。
初始化();//实例化主libvlc对象
_libvlc=新的libvlc();
VideoView.MediaPlayer=新LibVLCSharp.Shared.MediaPlayer(_libvlc);
var rtsp1=新媒体(_libvlc,VIDEO_URL,FromType.FromLocation);//创建一个媒体对象,然后将其选项设置为将显示2上的流-1复制为RTSP
rtsp1.AddOption(“:sout=#重复”+
{dst=display{noaudio}+
“dst=rtp{mux=ts,dst=192.168.0.110,端口=8080,sdp=rtsp://192.168.0.110:8080/go.sdp}“”;//地址必须是本地网络适配器地址而不是本地主机
VideoView.MediaPlayer.Play(rtsp1);
VideoView1.MediaPlayer=新的LibVLCSharp.Shared.MediaPlayer(_libvlc);
VideoView1.MediaPlayer.Mute=true;
VideoView1.MediaPlayer.Play(新媒体rtsp://192.168.0.110:8080/go.sdp,FromType.FromLocation));
}
}
}
感谢cube为我指明了正确的方向!我会尝试使用VLC读取流,然后再次将其流式传输到网络。我不确定libvlc/LibVLCSharp是否会有帮助,因为流式传输大部分是一个黑匣子,所以它会增加开销而没有任何好处。我的想法是,如果需要从C#启动/停止,可以使用Process.开始启动VLCI希望让它对用户尽可能简单。这就是我使用VLCSharp的原因。我知道有vlc命令可以帮助我复制流-显示它一次,然后通过http或RTSP转发副本。问题是我在C#中找不到vlc的语法和命令列表。现在我已经找到了找到这个:rtsp1.AddOption(“:sout=#duplicate{dst=display,dst=std{access=udp,mux=ts,dst=}”);问题是,它仍然无法加载,因为上面的这个选项是在不知道如何正确地将其串在一起的情况下编写的。哦,我不知道你的应用程序也需要一个显示器。使用VLC将实时显示和点播流媒体相结合可能会很乏味。但是,你使用的语法似乎是正确的,但我知道不知道详细信息。如果您想要rtsp,您可能需要字符串中的某个sdp。另一个选项是udp多播。这样,您就可以始终使用streamin