Using Uri connected IP camera to take pictures and record video with Windows UWP app

0

Connecting directly IP cameras is a new UWP feature. On this page: https://blogs.windows.com/windowsdeveloper/2019/10/10/connecting-network-cameras-to-windows-10-devices/

It says: "For streaming from a URI through the MediaCapture class, assign the desired URI to MediaCaptureInitializationSettings::DeviceUri. If credentials are required, they can be set through MediaCaptureInitializationSettings::DeviceUriPasswordCredential. The API supports ONVIF and generic RTSP server URIs. This allows applications to use the standard Windows Media APIs to capture video from generic cameras that do not conform to the ONVIF standards, or from an arbitrary URI without pairing."

Update: Now I am able to connect to the camera successfully. The problem was with the format of the URI. I have Reolink-410 Camera

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);

After this I can take pictures successfully

....
await _app.VM.MediaCapture.CapturePhotoToStorageFileAsync(GetImageEncodingProperties(), file);

But When I try to record video it throws exception: {"The specified object or value does not exist. (Exception from 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(); 

I also have tried await _mediaRecording.StartAsync(); which throws same exception. {"The specified object or value does not exist. (Exception from HRESULT: 0xC00D36D5)"}

uwp
camera
ip
onvif
mediacapture
asked on Stack Overflow Feb 16, 2021 by Waqas • edited Mar 1, 2021 by Waqas

1 Answer

0

It should be enough to set the MediaCaptureInitializationSettings like this:

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

Start end stop recording is for the IP camera just like any other USB camera:

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;
}  

In the package manifest I have check: Microphone, Pictureslibrary,VideoLibrary, WebCam and internet(server&client)

your specific camera the 410 (not 410W) should use rtsp://admin:admin@192.168.1.141/h264Preview_01_sub (source: https://www.ispyconnect.com/man.aspx?n=Reolink)

answered on Stack Overflow Feb 21, 2021 by Visualcoach • edited Feb 21, 2021 by Visualcoach

User contributions licensed under CC BY-SA 3.0