首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否有办法在C#中转发RTSP,最好使用LibVLCSharp?

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

Stack Overflow用户
提问于 2019-11-18 12:51:12
回答 1查看 4.7K关注 0票数 1

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

根据我在互联网上发现的,有一种使用VLC库进行流的方法:How to streaming video via VLC api in C#

但是我不知道如何从另一个流而不是一个文件中流。

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

代码语言:javascript
运行
复制
        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背后的代码:

代码语言:javascript
运行
复制
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));
        }
    }
}
EN

Stack Overflow用户

回答已采纳

发布于 2019-11-22 13:18:28

好的,我终于找到了命令列表,并正确地使用了它们。结果我爱上了LibVLC。:D

下面是描述各种命令的链接:https://wiki.videolan.org/Documentation:Streaming_HowTo/Advanced_Streaming_Using_the_Command_Line/#rtp

下面是我所做的代码:

代码语言:javascript
运行
复制
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));
        }
    }
}

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

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58914976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档