0

直接连接 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)”}

4

1 回答 1

0

像这样设置 MediaCaptureInitializationSettings 就足够了:

 MediaCaptureInitializationSettings mcis = new MediaCaptureInitializationSettings()
 {   
     DeviceUri = new Uri("rtsp://login:password@192.168.178.30/axis-media/media.amp", 
     UriKind.RelativeOrAbsolute),
 };
 await mc.InitializeAsync(mcis);

开始结束录制适用于 IP 摄像机,就像任何其他 USB 摄像机一样:

if(_isRecording)
{
    await CE.Source.StopRecordAsync();
    _isRecording = false;
}
else
{
    StorageFile file = await (KnownFolders.CameraRoll).CreateFileAsync("Axis.mp4",
    CreationCollisionOption.GenerateUniqueName);
    
    var encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
    await CE.Source.StartRecordToStorageFileAsync(encodingProfile, file);
    _isRecording = true;
}  

在包装清单中,我检查了:麦克风、图片库、视频库、网络摄像头和互联网(服务器和客户端)

您的特定相机 410(不是 410W)应该使用 rtsp://admin:admin@192.168.1.141/h264Preview_01_sub (来源:https ://www.ispyconnect.com/man.aspx?n=Reolink )

于 2021-02-21T23:23:58.193 回答