/// <summary>
        ///
        /// </summary>
        /// <param name="databaseHashes">Dictionary: Key=Hash of anchorFreq, targetFreq, offsetTime; Value=List of hash fingerprints</param>
        /// <returns></returns>
        public int IdentifyEpisodeForAudioMatch(Dictionary <int, List <Fingerprint> > databaseHashes)
        {
            var episodeFingerprintMatches = new Dictionary <int, Dictionary <long, int> >();  //Key is fingerprint hash. Value is dictionary where each entry's key is the timestamp delta between two samples and value is count of samples with the same timestamp delta

            //Generate fingerprints for audio capture  //TODO: Use window into episode
            string path = Directory.GetCurrentDirectory() + "\\SampleVideo2Capture2.mp4";
            //string path = Directory.GetCurrentDirectory() + "\\Sample1KHz.mp4";
            var fingerprinter = new AudioFileFingerprinter();
            var fingerprintsForCaptureFile = new Dictionary <int, List <Fingerprint> >(1000);

            fingerprinter.GenerateFingerprintsForFile(path, 0, fingerprintsForCaptureFile);
            SaveToJson(Directory.GetCurrentDirectory() + "\\MatchFingerprints.json", fingerprintsForCaptureFile);

            //Count number of matching hashes at the same sample time delta for each possibly matching episode.
            //  . ForEach group of fingerprints for capture file with the same hash
            //  . . For each fingerprint for this file in the group
            //  . . . If fingerprint's hash is in another file in the database
            //  . . . . Create histogram of deltas between capture sample's sample time and the sample time for samples with matching fingerprints in the database
            foreach (var hashGroup in fingerprintsForCaptureFile)
            {
                var fingerprintHash          = hashGroup.Key;
                var fingerprintsWithSameHash = hashGroup.Value;
                foreach (var captureFingerprint in fingerprintsWithSameHash)
                {
                    if (databaseHashes.ContainsKey(captureFingerprint.Hash))
                    {
                        ProcessMatchingHash(captureFingerprint, databaseHashes[captureFingerprint.Hash], episodeFingerprintMatches);
                    }
                }
            }

            return(GetEpisodeIdForMatchingEpisode(episodeFingerprintMatches));
        }
示例#2
0
        public Dictionary <int, List <Fingerprint> > GenerateFingerprintsForAllShows()
        {
            if (LOAD_FROM_JSON)
            {
                databaseFingerprintHashes = LoadFromJson(JSON_FILE_PATH);
            }
            else
            {
                databaseFingerprintHashes = new Dictionary <int, List <Fingerprint> >(20000);
                AudioFileFingerprinter fingerprinter;

                //fingerprinter = new AudioFileFingerprinter();
                //fingerprinter.GenerateFingerprintsForFile(Directory.GetCurrentDirectory() + "\\SampleVideo.mp4", 1, databaseFingerprintHashes);

                fingerprinter = new AudioFileFingerprinter();
                fingerprinter.GenerateFingerprintsForFile(Directory.GetCurrentDirectory() + "\\SampleVideo2.mp4", 2, databaseFingerprintHashes);

                //fingerprinter = new AudioFileFingerprinter();
                //fingerprinter.GenerateFingerprintsForFile(Directory.GetCurrentDirectory() + "\\SampleVideo2Capture1.mp4", 1, databaseFingerprintHashes);

                //fingerprinter = new AudioFileFingerprinter();
                //fingerprinter.GenerateFingerprintsForFile(Directory.GetCurrentDirectory() + "\\SampleVideo2Capture2.mp4", 1, databaseFingerprintHashes);

                //TODO
                var maxFileToProcess = -1;  //TODO REMOVE
                var fileList         = Directory.GetFiles(Directory.GetCurrentDirectory() + "\\TestFiles", "*.mp4");
                var episodeId        = 3;
                foreach (var filePath in fileList)
                {
                    if (maxFileToProcess-- <= 0)  //TODO REMOVE
                    {
                        break;
                    }
                    fingerprinter = new AudioFileFingerprinter();
                    fingerprinter.GenerateFingerprintsForFile(filePath, episodeId++, databaseFingerprintHashes);
                }

                SaveToJson(JSON_FILE_PATH);
            }

            return(databaseFingerprintHashes);
        }