ONVIF JPEG snapshot
It is possible to get a JPEG snapshot synchronously or asynchronously, by just adding the filter to the graph and loading the URL (without running the graph).
The snapshot can be returned as a JPEG file and/or as a pointer to a memory buffer containing the JPEG image.
Configuration steps to capture a JPEG snapshot of the IP camera 192.168.5.22 (sample code in the C# "DatasteadRTSPSource_ONVIF_Snapshot" demo project):
- add the filter to the graph,
- set the user name and password:
DatasteadRTSPSourceConfig.SetStr(RTSP_Source_AuthUser_str, "username")
DatasteadRTSPSourceConfig.SetStr(RTSP_Source_AuthPassword_str, "password")
- set a non-default connection timeout if needed, e.g. for 5 seconds:
DatasteadRTSPSourceConfig.SetInt (RTSP_Source_ConnectionTimeOut_int, 5000)
- if a JPEG file is needed, set also the recording file name:
DatasteadRTSPSourceConfig.SetStr(RTSP_Source_RecordingFileName_str, "c:\folder\shot.jpg")
A) to capture the snapshot synchronously, invoke:
int hr = DatasteadRTSPSourceConfig.Action(RTSP_Action_GetONVIFSnapshot, "onvif://192.168.5.22")
if (hr == 0) {
byte *pJPEGBuffer;
DatasteadRTSPSourceConfig2.GetIntPtr (RTSP_ONVIF_LastJPEGSnapshotBuffer_intptr, &pJPEGBuffer)
int JpegSize;
DatasteadRTSPSourceConfig.GetInt (RTSP_ONVIF_LastJPEGSnapshotSize_int, &JpegSize)
}
B) to capture the snapshot asynchronously, invoke:
DatasteadRTSPSourceConfig.Action(RTSP_Action_GetONVIFSnapshotAsync, "onvif://192.168.5.22");
The connection and download will run in a separate thread, then IMediaEvent will return one of the following events:
- upon failure:
EC_RTSPNOTIFYwith Param1 =EC_RTSP_PARAM1_ONVIF_SNAPSHOT_FAILED, - upon success:
EC_RTSPNOTIFYwith Param1 =EC_RTSP_PARAM1_ONVIF_SNAPSHOT_SUCCEEDED.
Upon success, if needed, access the memory JPEG buffer as follows:
byte *pJPEGBuffer;
DatasteadRTSPSourceConfig2.GetIntPtr (RTSP_ONVIF_LastJPEGSnapshotBuffer_intptr, &pJPEGBuffer)
int JpegSize;
DatasteadRTSPSourceConfig.GetInt (RTSP_ONVIF_LastJPEGSnapshotSize_int, &JpegSize)
Note: NO NEED TO RUN THE GRAPH FOR THE SNAPSHOT CAPTURE.