public void TestVideoIndexerSerialization() { var frameFingerPrint = new FrameFingerPrintWrapper { FrameNumber = 0, PHashCode = 0x1010, EdgeGrayScaleThumb = new byte[] { 0, 1, 0 }, }; var videoFingerPrint = new VideoFingerPrintWrapper { FilePath = "test.mkv", FingerPrints = new[] { frameFingerPrint }, }; var database = new VideoFingerPrintDatabaseWrapper { VideoFingerPrints = new[] { videoFingerPrint }, }; using (var memoryStream = new MemoryStream()) { VideoFingerPrintDatabaseSaver.Save(database, memoryStream); byte[] savedDatabase = memoryStream.ToArray(); VideoFingerPrintDatabaseWrapper reloadedDatabase = VideoFingerPrintDatabaseLoader.Load(savedDatabase); Assert.AreEqual(database, reloadedDatabase); } }
private static VideoFingerPrintDatabaseMetaTableEntryWrapper CoalesceDatabases(IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> coalescedEntries) { // Load each database IEnumerable <VideoFingerPrintDatabaseWrapper> databases = from entry in coalescedEntries select VideoFingerPrintDatabaseLoader.Load(entry.FileName); // Merge fingerprints IEnumerable <VideoFingerPrintWrapper> allVideoFingerPrints = from database in databases from videoFingerPrint in database.VideoFingerPrints select videoFingerPrint; // Create a new database var freshDatabase = new VideoFingerPrintDatabaseWrapper { VideoFingerPrints = allVideoFingerPrints.ToArray(), }; // Save the database string databaseFileName = Path.GetRandomFileName() + ".bin"; VideoFingerPrintDatabaseSaver.Save(freshDatabase, databaseFileName); FileInfo databaseFileInfo = new FileInfo(databaseFileName); return(new VideoFingerPrintDatabaseMetaTableEntryWrapper { FileName = databaseFileName, FileSize = (ulong)databaseFileInfo.Length, }); }
private static void ExecuteCheckDatabase(string[] args) { string maxMemoryArg = GetMaxMemory(args); string databaseMetaTablePath = GetDatabaseMetaTable(args); if (string.IsNullOrWhiteSpace(databaseMetaTablePath)) { PrintHelp("Database metatable path not provided"); return; } if (File.Exists(databaseMetaTablePath) == false) { PrintHelp("Database MetaTable does not exist"); return; } if (string.IsNullOrWhiteSpace(maxMemoryArg)) { PrintHelp("--max-memory must be set"); return; } long maxMemory = 0; if (long.TryParse(maxMemoryArg, out maxMemory) == false) { PrintHelp("--max-memory could not be parsed"); return; } VideoFingerPrintDatabaseMetaTableWrapper metaTable = VideoFingerPrintDatabaseMetaTableLoader.Load(databaseMetaTablePath); var random = new Random(); foreach (string databasePath in metaTable.DatabaseMetaTableEntries.Select(e => e.FileName)) { VideoFingerPrintDatabaseWrapper database = VideoFingerPrintDatabaseLoader.Load(databasePath); int videoFingerPrintSampleCount = (int)Math.Round(database.VideoFingerPrints.Length / 3.0); IEnumerable <VideoFingerPrintWrapper> videoFingerPrints = from fingerPrint in database.VideoFingerPrints where random.Next() % 2 == 0 select fingerPrint; foreach (VideoFingerPrintWrapper videoFingerPrint in videoFingerPrints.Take(videoFingerPrintSampleCount)) { VideoFingerPrintWrapper actualVideoFingerPrint = Video.VideoIndexer.IndexVideo(videoFingerPrint.FilePath, maxMemory); if (Equals(videoFingerPrint, actualVideoFingerPrint) == false) { Console.WriteLine("{0} Fingerprint does not match", Path.GetFileName(videoFingerPrint.FilePath)); } } } }
private static IEnumerable <string> GetKnownDatabaseEntries(string databaseMetaTablePath) { if (File.Exists(databaseMetaTablePath) == false) { return(Enumerable.Empty <string>()); } var knownDatabaseEntries = new HashSet <string>(); VideoFingerPrintDatabaseMetaTableWrapper metatable = VideoFingerPrintDatabaseMetaTableLoader.Load(databaseMetaTablePath); foreach (VideoFingerPrintDatabaseMetaTableEntryWrapper entry in metatable.DatabaseMetaTableEntries) { VideoFingerPrintDatabaseWrapper database = VideoFingerPrintDatabaseLoader.Load(entry.FileName); foreach (VideoFingerPrintWrapper fingerprint in database.VideoFingerPrints) { knownDatabaseEntries.Add(fingerprint.FilePath); } } return(knownDatabaseEntries); }
private Tuple <VideoFingerPrintDatabaseWrapper, string> GetNextEligibleDatabase() { VideoFingerPrintDatabaseMetaTableWrapper metatable = CreateOrLoadMetatable(_metatablePath); Tuple <VideoFingerPrintDatabaseWrapper, string> eligibleDatabase = (from entry in metatable.DatabaseMetaTableEntries where entry.FileSize < MaxDatabaseSize select Tuple.Create(VideoFingerPrintDatabaseLoader.Load(entry.FileName), entry.FileName)).FirstOrDefault(); // If we can't find an eligible database, then we need to create one and send it back return(eligibleDatabase ?? CreateNewDatabaseAndAddToMetatable()); }
/// <summary> /// Enumerate all databases in the metatable /// </summary> /// <param name="metatable">The metatable</param> /// <returns>An enumeration of all of the databases</returns> public static IEnumerable <VideoFingerPrintDatabaseWrapper> EnumerateDatabases(VideoFingerPrintDatabaseMetaTableWrapper metatable) { return(from entry in metatable.DatabaseMetaTableEntries select VideoFingerPrintDatabaseLoader.Load(entry.FileName)); }