我正在进行一个小型家庭视频广播项目。我找到了一些示例,但它们不起作用,因为需要旧版本库0.8.6。所以我找到了它,但在尝试从API获取组件时,出现了未受管理代码的异常。也许有人在使用VLC进行视频广播,如果您能够提供任何示例,那就太好了。
我找到了一个解决方案,并使用了Vlc.DotNet包装器。 我安装了NuGet包并编写了控制台应用程序:
class Program
{
static void Main(string[] args)
{
FileInfo file = new FileInfo(@"C:\Users\Jman\VideoMaker.avi");
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://192.168.1.162:8008/test}",
":sout-keep"
};
//mediaPlayer.SetMedia(new Uri("http://hls1.addictradio.net/addictrock_aac_hls/playlist.m3u8"),
// mediaOptions);
mediaPlayer.SetMedia(file, mediaOptions);
mediaPlayer.Play();
Console.WriteLine("Streaming on rtsp://192.168.1.162:8008/test");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}
你可以在我的GitHub存储库中查看我的测试应用程序:VideoBroadcast。rtsp://192.168.1.162:8008/test