i use OpenCvSharp to record video,10 minute per file,but the code i wrote must be somewhere wrong, when i see the video,the video takes 12 minutes 29 seconds.here is the code.
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YCamera
{
public class CameraRecoding
{
public static void run()
{
VideoCapture video = new VideoCapture(0);
string last_dstr = "";
VideoWriter videoWriter = null;
while (true)
{
string dstr = DateTime.Now.ToString("yyyyMMddHHmm");
string new_dir = Global_Vals.save_dir;
//record a file per 10 minutes
if (last_dstr==""||dstr.Substring(0,11) != last_dstr.Substring(0,11))
{
if(videoWriter != null)
{
videoWriter.Dispose();
videoWriter = null;
}
string new_file = System.IO.Path.Combine(new_dir, "video" + dstr + ".avi");
videoWriter = new VideoWriter(new_file,
VideoWriter.FourCC(@"XVID"), 20, new Size(640, 480), true);
if (!video.IsOpened())
{
Console.WriteLine("camera open failed");
return;
}
}
Mat Camera = new Mat();
video.Read(Camera);
if (Camera.Empty())//
{
break;
}
videoWriter.Write(Camera);
last_dstr = dstr;
}
}
}
}
i consider if
video.Read(Camera);
take a very long time, and i cannot find a way to change the code,i cannot find similar questions,can any one know how to do so?
New contributor
ying is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.