/// <summary>获取某通道视频在某时段对应的有效的文件夹列表</summary> public static DateTime[] GetFolderPaths(string videoId, int streamId, DateTime start, DateTime end) { List <DateTime> list = new List <DateTime>(); string path = GlobalData.VideoPath(videoId, streamId); if (Directory.Exists(path)) { DateTime cur = start.Date; while (cur < end) { DirectoryInfo dir = new DirectoryInfo(Path.Combine(path, GlobalProcess.FolderPath(cur))); if (dir.Exists) { list.Add(cur); cur = cur.AddDays(1); } else if (dir.Parent.Exists) { cur = cur.AddDays(1); } else if (dir.Parent.Parent.Exists) { cur = new DateTime(cur.Year, cur.Month, 1).AddMonths(1); } else { cur = new DateTime(cur.Year + 1, 1, 1); } } } return(list.ToArray()); }
/// <summary>读取某通道视频在指定时间内视频流的字节数</summary> public static long GetLength(string videoId, int streamId, DateTime beginTime, DateTime endTime, int headerLength) { string path = GlobalData.VideoPath(videoId, streamId); DateTime[] dates = GetFolderPaths(videoId, streamId, beginTime, endTime); return(getLength(path, dates, beginTime, endTime, headerLength)); }
public VideoTimePeriodsPacket Search(DateTime beginTime, DateTime endTime, IVideoInfo videoInfo) { string path = GlobalData.VideoPath(videoInfo.VideoId, videoInfo.StreamId); DateTime[] dates = VideoStoragerManager.GetFolderPaths(videoInfo.VideoId, videoInfo.StreamId, beginTime, endTime); List <TimePeriodPacket> tis = new List <TimePeriodPacket>(); Parallel.ForEach(dates, date => { string folder = Path.Combine(path, GlobalProcess.FolderPath(date)); var array = FolderManager.GetTimePeriods(folder); if (array.Length > 0) { lock (tis) tis.AddRange(array); } }); if (endTime > DateTime.Now.Date) { tis.AddRange(findTodayLastest(path, endTime)); } var timeCombines = TimePeriodManager.Combine(tis.ToArray()); var validArray = TimePeriodManager.GetIntersections(timeCombines, new TimePeriodPacket(beginTime, endTime)); return(new VideoTimePeriodsPacket(videoInfo, validArray)); }
/// <summary>获取某通道视频在某时段对应文件的首个视频头</summary> public static VideoBasePacket GetVideoBaseInfom(string videoId, int streamId, DateTime beginTime, DateTime endTime) { string path = GlobalData.VideoPath(videoId, streamId); DateTime[] dates = GetFolderPaths(videoId, streamId, beginTime, endTime); foreach (var date in dates) { var header = FolderManager.GetVideoHeader(Path.Combine(path, GlobalProcess.FolderPath(date)), beginTime, endTime); if (header != null && header.Type == DataType.SysHead) { long length = getLength(path, dates, beginTime, endTime, StreamPacket.Encode(header).Length + 4); return(new VideoBasePacket(header.Buffer, header.Time, length)); } } return(null); }
private static string getPath(string videoId, int streamId, DateTime time) { return(Path.Combine(GlobalData.VideoPath(videoId, streamId), GlobalProcess.FolderPath(time))); }