We have a small windows forms c# app that captures a frame on intervals (ex: 1 frame per 5 minutes). The provided code snippet is suppose to capture a single frame be calling the “HandleNewCameraFrame” function. The issue is that liveVideo.stop does not seem to stop the stream as “HandleNewCameraFrame” keeps getting called. Client’s Milestone server has recording disabled.
var videoParams = new VideoParams()
{
CameraId = cameraId,
DestWidth = CaptureUtility.Properties.Settings.Default.resolutionwidth,
DestHeight = CaptureUtility.Properties.Settings.Default.resolutionheight,
CompressionLvl = 50,
FPS = 1, // Set FPS to 1 to reduce frame rate and save bandwidth
MethodType = StreamParamsHelper.MethodType.Push,
SignalType = StreamParamsHelper.SignalType.Live,
StreamType = StreamParamsHelper.StreamType.Transcoded,
};
var response = Program.Connection.Video.RequestStream(videoParams, null, TimeSpan.FromSeconds(10));
if (response.ErrorCode != ErrorCodes.Ok)
{
// Log the error when the video stream cannot be requested
Console.WriteLine($"Error requesting stream for camera {cameraId}: {response.ErrorCode}");
return;
}
var liveVideo = Program.Connection.VideoFactory.CreateLiveVideo(new RequestStreamResponseLive(response));
\_liveVideo.Add(liveVideo); // Add to the live video list
// Assign the NewFrame handler to process the frame when received
liveVideo.NewFrame = (VideoFrame frame) => HandleNewCameraFrame(indexId, frame);
// Start the live video to capture a frame
//liveVideo.Start();
Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - Successfully started video stream for camera {cameraId}.");
// Stop the live video to save bandwidth after capturing the first frame
//liveVideo.Stop();
Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - Stopped video stream for camera {cameraId} to save bandwidth.");