C#读取RTSP流并切录制视频
下载Nuget包:EMGU.CV(测试用版本:4.0.1.3373) ;
public void InitVideo()
{
VideoCapture _capture = new VideoCapture("rtsp://admin:123456@192.168.1.237:554");
Thread.Sleep(100);
VideoWriter videoWriter = null;
Mat fram = new Mat();
Task.Run(() => {
while (true)
{
try
{
_capture.Read(fram);
var item=_capture.QueryFrame();
if (videoWriter == null)
{
videoWriter = new VideoWriter("out.mp4", 0, 24, fram.Size, false);
videoWriter.Set(WriterProperty.Framebytes, 10);
}
videoWriter.Write(fram);
}
catch (Exception ex)
{
break;
}
Thread.Sleep(10);
}
});
}