Waqas
Waqas

Reputation: 92

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

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:[email protected]: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)"}

Upvotes: 0

Views: 1305

Answers (2)

Hawke
Hawke

Reputation: 34

I had the same problem (with a normal webcam). If you don't have a microphone, it might cause that exception you're getting. Try to handle it, or attach a microphone and see how it works.

Upvotes: 0

Visualcoach
Visualcoach

Reputation: 111

It should be enough to set the MediaCaptureInitializationSettings like this:

 MediaCaptureInitializationSettings mcis = new MediaCaptureInitializationSettings()
 {   
     DeviceUri = new Uri("rtsp://login:[email protected]/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:[email protected]/h264Preview_01_sub (source: https://www.ispyconnect.com/man.aspx?n=Reolink)

Upvotes: 0

Related Questions