static void Main(string[] args) { var sw = new Stopwatch(); sw.Start(); var file = args.Length != 0 ? args[0] : @"2018030321470048.mp4"; var video = new VideoCapture(file); var srcFrame = new Mat(); var binFrame = new Mat(); var list = new System.Collections.Generic.List <Tuple <TimeSpan, TimeSpan> >(); var prevStart = new TimeSpan(); var pos = TimeSpan.Zero; while (true) { var nextPos = pos + Params.giantStep; CvUtil.GetFrame(video, pos, srcFrame); if (srcFrame.Empty()) { break; } CvUtil.Binarize(srcFrame, 7, binFrame); if (Params.GameStartTemplate.Match(binFrame)) { var se = Params.GameStartTemplate.FindMatchBoundary(video, pos); var start = se.Item1; var end = se.Item2; Console.WriteLine($"{start}: game starts"); nextPos = end + Params.babyStep; prevStart = start; } else if (Params.GameEndTemlate.Match(binFrame)) { var se = Params.GameEndTemlate.FindMatchBoundary(video, pos); var end = se.Item2; Console.WriteLine($"${end}: game ends"); nextPos = end + Params.babyStep; FfMpegUtil.Cut(prevStart, end, "out"); prevStart = new TimeSpan(); } pos = nextPos; } Console.WriteLine(sw.Elapsed); }
private TimeSpan FindMatchEnd(VideoCapture video, TimeSpan from) { var m = from; while (true) { var tryTime = m + Params.babyStep; if (tryTime >= TimeSpan.FromSeconds(video.FrameCount / video.Fps)) { break; } CvUtil.GetFrame(video, tryTime, searchFrame); CvUtil.Binarize(searchFrame, 7, searchBinFrame); if (!Match(searchBinFrame)) { break; } m = tryTime; } return(m); }
private TimeSpan FindMatchStart(VideoCapture video, TimeSpan from) { var m = from; while (true) { var tryTime = m - Params.babyStep; if (tryTime < TimeSpan.Zero) { break; } CvUtil.GetFrame(video, tryTime, searchFrame); CvUtil.Binarize(searchFrame, 7, searchBinFrame); if (!Match(searchBinFrame)) { break; } m = tryTime; } return(m); }