public static void Main(string[] args) { Parser.Default.ParseArguments<SearchCommandVerb, IndexCommandVerb>(args) .WithParsed<SearchCommandVerb>(search => { var serializationMethod = SerializationMethod.JSON; Enum.TryParse(search.SerializationMethod, out serializationMethod); Maybe<ImageFingerPrint> fingerPrintMaybe = ImageFingerPrinter.TryCalculateFingerPrint(search.PictureFile); if (fingerPrintMaybe.IsSomething()) { var database = new IndexDatabase(search.IndexFile, serializationMethod); IEnumerable<IndexEntry> queryResults = database.TryFindEntries(fingerPrintMaybe.Value); foreach (IndexEntry entry in queryResults) { Console.Error.WriteLine(string.Format("{0} ({1}, {2}) ", entry.VideoFile, entry.StartTime, entry.EndTime)); } } }) .WithParsed<IndexCommandVerb>(index => { var serializationMethod = SerializationMethod.JSON; Enum.TryParse(index.SerializationMethod, out serializationMethod); var database = new IndexDatabase(index.IndexFile, serializationMethod); Indexer.IndexVideo(index.VideoFile, database); database.Flush(); }) .WithNotParsed(errors => { Console.Error.WriteLine("Could not parse arguments"); }); }
private static void IndexEntries(string videoFile, MediaInfo info, IndexDatabase database) { TimeSpan totalDuration = info.GetDuration(); for (var startTime = TimeSpan.FromSeconds(0); startTime < totalDuration; startTime += PlaybackDuration) { IndexEntriesAtIndex(videoFile, startTime, info.GetFramerate(), totalDuration, database); } }
private static void IndexEntriesAtIndex( string videoFile, TimeSpan startTime, Ratio framerate, TimeSpan totalDuration, IndexDatabase database ) { string outputDirectory = Path.GetRandomFileName(); Ratio quarterFramerate = new Ratio(framerate.Numerator, framerate.Denominator * 4); var ffmpegProcessSettings = new FFMPEGProcessSettings( videoFile, outputDirectory, startTime, CalculateFramesToOutputFromFramerate(startTime, quarterFramerate, totalDuration), framerate, FFMPEGOutputFormat.Y4M ); if (Directory.Exists(outputDirectory) == false) { Directory.CreateDirectory(outputDirectory); } using (var ffmpegProcess = new FFMPEGProcess(ffmpegProcessSettings)) { ffmpegProcess.Execute(); IndexFilesInDirectory(videoFile, outputDirectory, startTime, database, quarterFramerate); try { Directory.Delete(outputDirectory, true); } catch (Exception e) { Console.Error.WriteLine(string.Format("Could not clean up images: {0}", e.Message)); } } }
public static void IndexVideo(string videoFile, IndexDatabase database) { MediaInfo info = new MediaInfoProcess(videoFile).Execute(); IndexEntries(videoFile, info, database); }
private static void IndexFilesInDirectory(string originalFileName, string directory, TimeSpan startTime, IndexDatabase database, Ratio frameRate) { foreach (string file in Directory.EnumerateFiles(directory, "*.y4m")) { using (var parser = new VideoFileParser(file)) { Maybe<VideoFile> videoFileMaybe = parser.TryParseVideoFile(); if (videoFileMaybe.IsNothing()) { return; } VideoFile videoFile = videoFileMaybe.Value; int frameNumber = 0; foreach (VideoFrame frame in videoFile.Frames) { database.QueueAddEntry(new IndexEntry { VideoFile = originalFileName, StartTime = startTime, EndTime = CalculateEndTime(startTime, frameRate, frameNumber), FrameHash = ImageFingerPrinter.CalculateFingerPrint(frame), }); frameNumber++; } } } }