public interface IVideoStorage : IStorage<Mat>
{
string Camera { get; }
string Path { get; }
}
internal class VideoStorage : IVideoStorage, IDisposable
{
public string Camera { get; private set; }
public string Path { get; private set; }
private readonly FourCC fourCC = FourCC.MP4V;
private readonly double fps;
private readonly Size size;
public VideoStorage(string camera, double fps, Size size)
{
this.Camera = camera;
this.fps = fps;
this.size = size;
}
private VideoWriter writer = new VideoWriter();
public bool Append(string path, Mat content)
{
this.Path = path;
if (this.writer.FileName != path)
{
this.writer.Release();
this.writer = new VideoWriter(path, this.fourCC, this.fps, this.size);
}
this.writer.Write(content);
return true;
}
private bool disposedValue;
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
this.writer.Dispose();
this.writer = null;
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
public bool Append(string path, List<Mat> contents)
{
foreach (var item in contents)
{
this.Append(path, item);
}
return true;
}
}
C# OpenCV存储视频
最新推荐文章于 2024-07-18 17:22:51 发布