直接连接 IP 摄像机是 UWP 的一项新功能。在此页面上:https ://blogs.windows.com/windowsdeveloper/2019/10/10/connecting-network-cameras-to-windows-10-devices/
它说:“对于通过 MediaCapture 类从 URI 流式传输,将所需的 URI 分配给 MediaCaptureInitializationSettings::DeviceUri。如果需要凭据,可以通过 MediaCaptureInitializationSettings::DeviceUriPasswordCredential 设置它们。API 支持 ONVIF 和通用 RTSP 服务器 URI。这允许应用程序使用标准的 Windows Media API 从不符合 ONVIF 标准的通用摄像机或未配对的任意 URI 捕获视频。”
更新: 现在我可以成功连接到相机了。问题在于 URI 的格式。我有 Reolink-410 相机
MediaCapture = new MediaCapture();
MediaCaptureInitializationSettings captureInitSettings = new MediaCaptureInitializationSettings();
captureInitSettings.DeviceUri = new
Uri("rtsp://admin:password@192.168.1.241:554//h264Preview_01_main");
captureInitSettings.DeviceUriPasswordCredential = new Windows.Security.Credentials.PasswordCredential
{
UserName = "admin",
Password = "password"
};
MediaCapture.Failed += MediaCapture_Failed;
MediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded;
await MediaCapture.InitializeAsync(captureInitSettings);
之后我可以成功拍照
....
await _app.VM.MediaCapture.CapturePhotoToStorageFileAsync(GetImageEncodingProperties(), file);
但是当我尝试录制视频时,它会抛出异常:{“指定的对象或值不存在。(来自 HRESULT 的异常:0xC00D36D5)”}
...
var _mediaRecording = await _app.VM.MediaCapture.PrepareLowLagRecordToStorageFileAsync(MediaEncodingProfile.CreateHevc(VideoEncodingQuality.Auto), file);// Exception here {"The specified object or value does not exist. (Exception from HRESULT: 0xC00D36D5)"}
//also tried with CreateMP4
await _mediaRecording.StartAsync();
我也尝试过await _mediaRecording.StartAsync();
抛出相同的异常。{“指定的对象或值不存在。(来自 HRESULT 的异常:0xC00D36D5)”}