Skip to content

ONVIF snapshot

ONVIF snapshots

To get just a JPEG image from an IP camera, instead of starting the camera live stream, it is possible to request a JPEG snapshot, which is returned as a JPEG file or as a pointer to the JPEG memory buffer, or both.

Sample code to get a JPEG file:

VideoGrabber.VideoSource = vs_IPCamera
VideoGrabber.OpenURLAsync = true; // so the connection does not block the main thread (it's the default anyway)
VideoGrabber.IPCameraURL = "onvif://192.168.0.25:80" // if the port is not specified the default port 80 is used
VideoGrabber.SetAuthentication (at_IPCamera, "root", "admin")
VideoGrabber.ONVIFSnapShot (false, true, "c:/folder/snapshot.jpg")

Sample code to get access to the JPEG snapshot buffer in memory:

VideoGrabber.VideoSource = vs_IPCamera
VideoGrabber.OpenURLAsync = true; // default, so the connection does not block the main thread
VideoGrabber.IPCameraURL = "onvif://192.168.0.25:80" // if the port is not specified the default port 80 is used
VideoGrabber.SetAuthentication (at_IPCamera, "root", "admin")
VideoGrabber.OnRawVideoSample = OnRawVideoSampleCallback
VideoGrabber.ONVIFSnapShot (true, false, "")

in the OnRawVideoSampleCallback event callback, the pSampleBuffer parameter returns a pointer to the JPEG snapshot in memory, whose size is given by SampleBufferSize.

Note: it is possible to get both the memory callback and the JPEG file as follows:

VideoGrabber.ONVIFSnapShot (true, true, "c:/folder/snapshot.jpg")