Preview and recording of IP cameras and URL sources
Note
With IP cameras supporting the ONVIF protocol, there is no need to know the RTSP URL syntax: the RTSP URL can be opened by specifying the onvif:// protocol followed by the IP address or domain name and the port.
Preview only:
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.AudioDeviceRendering = true; // optional, if audio rendering is needed
VideoGrabber.FrameGrabber = fg_Disabled; // if no overlay or frame capture is required, saves CPU
VideoGrabber.StartPreview ();
Preview and recording:
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.FrameGrabber = fg_Disabled; // if no overlay or frame capture is required, saves CPU
VideoGrabber.RecordingInNativeFormat = true;
VideoGrabber.RecordingMethod = rm_MP4;
VideoGrabber.AudioRecording = true; // optional, if the URL has audio and audio recording is needed
VideoGrabber.StartRecording ();
Recording only (no decoding, saves CPU):
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.RecordingInNativeFormat = true;
VideoGrabber.RecordingMethod = rm_MP4;
VideoGrabber.FrameGrabber = fg_Disabled;
VideoGrabber.VideoRenderer = vr_None;
VideoGrabber.StartRecording ();
To close the current file and start recording to a new file while the recording is running, invoke RecordToNewFileNow: it generates a new file on the fly without losing frames.
Alternatively, enable the RecordingTimer to periodically close the current file and generate a new file. In this case the file name is generated automatically; however, the files can be renamed on the fly from the OnRecordingCompleted event.
RTSP, RTMP, HTTP, UDP, MMS, RTP sources and other streaming protocols
The sample code is the same, e.g.:
IPCameraURL = "rtsp://192.168.5.25/axis-media/media.amp?videocodec=h264&audio=1"
IPCameraURL = "udp://192.168.0.25"
IPCameraURL = "mmsh://192.168.0.25"
IPCameraURL = "rtmp://192.168.0.25/live"
IPCameraURL = "rtp://192.168.0.25"
IPCameraURL = "http://192.168.0.25/url"
etc.