コード例 #1
0
        private void AddDBItem(VFPFingerPrint fp)
        {
            var txt = $"{fp.OriginalFilename} [{fp.Width}x{fp.Height}, {fp.OriginalDuration.ToString("g")}]";

            if (fp.IgnoredAreas.Count > 0)
            {
                txt += "(with ignored areas)";
            }

            lbDB.Items.Add(txt);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var options = new CommandLineOptions();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                // Display the default usage information
                //Console.WriteLine(options.GetUsage());
                return;
            }

            if (!File.Exists(options.FragmentFile))
            {
                Console.WriteLine("Fragment file not found: " + options.FragmentFile + ".");
                return;
            }

            if (!File.Exists(options.MainFile))
            {
                Console.WriteLine("Main file not found: " + options.MainFile + ".");
                return;
            }

            VFPAnalyzer.SetLicenseKey(options.LicenseKey);

            Console.WriteLine("Starting analyze.");

            var time = DateTime.Now;

            var fragment = VFPFingerPrint.Load(options.FragmentFile);
            var main     = VFPFingerPrint.Load(options.MainFile);

            double difference;
            var    res = VFPSearch.Search(fragment, 0, main, 0, out difference, options.MaxDifference);

            var elapsed = DateTime.Now - time;

            Console.WriteLine("Analyze finished. Elapsed time: " + elapsed.ToString("g"));

            if (res > 0)
            {
                TimeSpan ts = new TimeSpan(res * TimeSpan.TicksPerSecond);
                Console.WriteLine($"Detected fragment file at {ts:g}, difference level is {difference}");
            }
            else
            {
                Console.WriteLine("Fragment file not found.");
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var options = new CommandLineOptions();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                // Display the default usage information
                //Console.WriteLine(options.GetUsage());
                return;
            }

            if (!File.Exists(options.Input1))
            {
                Console.WriteLine("Input file 1 not found: " + options.Input1 + ".");
                return;
            }

            if (!File.Exists(options.Input2))
            {
                Console.WriteLine("Input file 2 not found: " + options.Input2 + ".");
                return;
            }

            VFPAnalyzer.SetLicenseKey(options.LicenseKey);

            Console.WriteLine("Starting analyze.");

            var time = DateTime.Now;

            var fragment = VFPFingerPrint.Load(options.Input1);
            var main     = VFPFingerPrint.Load(options.Input2);

            double difference;
            var    res = VFPCompare.Compare(fragment, main, options.MaxDifference);

            var elapsed = DateTime.Now - time;

            Console.WriteLine("Analyze finished. Elapsed time: " + elapsed.ToString("g"));

            if (res < 300)
            {
                Console.WriteLine("Input files are similar.");
            }
            else
            {
                Console.WriteLine("Input files are different.");
            }
        }
コード例 #4
0
        private void StopVideoDelegateMethod()
        {
            // done. searching for fingerprints.
            VideoCapture1.Stop();

            long   n;
            IntPtr p = VFPSearch.Build(out n, ref searchLiveData);

            VFPFingerPrint fvp = new VFPFingerPrint()
            {
                Data             = new byte[n],
                OriginalFilename = string.Empty
            };

            Marshal.Copy(p, fvp.Data, 0, (int)n);

            searchLiveData.Free();


            foreach (var ad in adVFPList)
            {
                List <int> positions;
                bool       found = VFPAnalyzer.Search(ad, fvp, ad.Duration, (int)slDifference.Value, out positions, true);

                if (found)
                {
                    foreach (var pos in positions)
                    {
                        results.Add(
                            new ResultsViewModel()
                        {
                            Sample    = ad.OriginalFilename,
                            TimeStamp = DateTime.Now.ToString(CultureInfo.InvariantCulture)
                                        // minutes + ":" + seconds
                        });
                    }
                }
            }

            MessageBox.Show("Analyze completed!");
        }
コード例 #5
0
        private void btSearch_Click(object sender, RoutedEventArgs e)
        {
            btSearch.IsEnabled = false;
            edErrors.Text      = string.Empty;

            // Settings
            VFMediaPlayerSource engine = VFMediaPlayerSource.File_DS;

            switch (cbEngine.SelectedIndex)
            {
            case 0:
                engine = VFMediaPlayerSource.File_DS;
                break;

            case 1:
                engine = VFMediaPlayerSource.File_FFMPEG;
                break;

            case 2:
                engine = VFMediaPlayerSource.File_VLC;
                break;

            case 3:
                engine = VFMediaPlayerSource.LAV;
                break;
            }

            int indexingTime = 5;

            switch (cbIndexingTime.SelectedIndex)
            {
            case 0:
                indexingTime = 3;
                break;

            case 1:
                indexingTime = 5;
                break;

            case 2:
                indexingTime = 10;
                break;

            case 3:
                indexingTime = 30;
                break;
            }

            List <string> extensions = new List <string>();

            if (cbFormatAVI.IsChecked == true)
            {
                extensions.Add("avi");
            }

            if (cbFormatFLV.IsChecked == true)
            {
                extensions.Add("flv");
            }

            if (cbFormatMKV.IsChecked == true)
            {
                extensions.Add("mkv");
            }

            if (cbFormatMOV.IsChecked == true)
            {
                extensions.Add("mov");
            }

            if (cbFormatMP4.IsChecked == true)
            {
                extensions.Add("mp4");
            }

            if (cbFormatMPG.IsChecked == true)
            {
                extensions.Add("mpg");
            }

            if (cbFormatTS.IsChecked == true)
            {
                extensions.Add("ts");
            }

            if (cbFormatWMV.IsChecked == true)
            {
                extensions.Add("wmv");
            }

            lbStatus.Text = "Step 1: Searching video files";

            List <string> filenames = new List <string>();

            List <VFPFingerPrint> fingerPrints = new List <VFPFingerPrint>();

            foreach (string item in lbSourceFolders.Items)
            {
                filenames.AddRange(FileScanner.SearchVideoInFolder(item, extensions));
            }

            lbStatus.Text = "Step 2: Getting fingerprints for video files";

            int progress = 0;

            foreach (string filename in filenames)
            {
                pbProgress.Value = progress;

                VFPFingerPrint fp    = null;
                string         error = null;

                try
                {
                    var source = new VFPFingerprintSource(filename, engine)
                    {
                        StopTime = indexingTime * 1000
                    };

                    fp = VFPAnalyzer.GetComparingFingerprintForVideoFile(source, out error);
                }
                catch (Exception ex)
                {
                    edErrors.Text += ex.Message + Environment.NewLine;
                }

                if (fp != null)
                {
                    fingerPrints.Add(fp);
                }

                if (error != null)
                {
                    edErrors.Text += error + Environment.NewLine;
                }

                progress += 100 / filenames.Count;
            }

            pbProgress.Value = 100;

            List <SearchResult> results = new List <SearchResult>();

            results.Clear();
            lbResults.Items.Clear();
            lbStatus.Text = "Step 3: Analyzing data";
            progress      = 0;
            int foundCount = 0;

            List <string> clonesToIgnore = new List <string>();

            foreach (var first in fingerPrints)
            {
                pbProgress.Value = progress;

                if (first == null)
                {
                    continue;
                }

                if (clonesToIgnore.Contains(first.OriginalFilename))
                {
                    continue;
                }

                foreach (var second in fingerPrints)
                {
                    if (second == null)
                    {
                        continue;
                    }

                    if (first.OriginalFilename == second.OriginalFilename)
                    {
                        continue;
                    }

                    int diff = VFPAnalyzer.Compare(first, second, (int)slMaxShift.Value);

                    if (diff < slSensitivity.Value * 10)
                    {
                        foundCount++;

                        clonesToIgnore.Add(second.OriginalFilename);

                        var result = new SearchResult()
                        {
                            GroupFile = first.OriginalFilename
                        };
                        result.Clones.Add(second.OriginalFilename);

                        results.Add(result);
                    }
                }

                progress += 100 / fingerPrints.Count;
            }

            pbProgress.Value = 0;

            foreach (var result in results)
            {
                ResultItem item = new ResultItem
                {
                    Text = { Text = result.GroupFile },
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Screenshot          = { Source = Helper.GetImageForFile(result.GroupFile) }
                };

                lbResults.Items.Add(item);

                foreach (var clone in result.Clones)
                {
                    ResultItem item2 = new ResultItem
                    {
                        Text                = { Text = clone },
                        Checked             = { IsChecked = true },
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        Screenshot          = { Source = Helper.GetImageForFile(clone) }
                    };

                    lbResults.Items.Add(item2);
                }
            }

            lbStatus.Text = "Step 4: Done. " + foundCount + " copies found.";

            btSearch.IsEnabled = true;
        }
コード例 #6
0
        private void btStart_Click(object sender, RoutedEventArgs e)
        {
            if ((string)btStart.Content == "Stop")
            {
                VideoCapture1.Stop();

                Thread.Sleep(500);

                ProcessVideoDelegateMethod();

                btStart.Content = "Start";

                lbStatus.Content = string.Empty;

                if (_tempBuffer != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(_tempBuffer);
                    _tempBuffer = IntPtr.Zero;
                }
            }
            else
            {
                btStart.IsEnabled = false;

                lbStatus.Content = "Step 1: Searching video files";

                _fragmentCount        = 0;
                _overlapFragmentCount = 0;

                var engine = VFMediaPlayerSource.File_VLC;

                switch (cbEngine.SelectedIndex)
                {
                case 0:
                    engine = VFMediaPlayerSource.File_DS;
                    break;

                case 1:
                    engine = VFMediaPlayerSource.File_FFMPEG;
                    break;

                case 2:
                    engine = VFMediaPlayerSource.File_VLC;
                    break;

                case 3:
                    engine = VFMediaPlayerSource.LAV;
                    break;
                }

                var adList = new List <string>();

                _adVFPList = new List <VFPFingerPrint>();

                foreach (string item in lbAdFolders.Items)
                {
                    adList.AddRange(FileScanner.SearchVideoInFolder(item));
                }

                lbStatus.Content = "Step 2: Getting fingerprints for ads files";

                if (adList.Count == 0)
                {
                    btStart.Content  = "Start";
                    lbStatus.Content = string.Empty;

                    MessageBox.Show("Ads list is empty!");

                    return;
                }

                int progress = 0;
                foreach (string filename in adList)
                {
                    pbProgress.Value = progress;
                    string         error = "";
                    VFPFingerPrint fp;

                    if (File.Exists(filename + ".vfsigx"))
                    {
                        fp = VFPFingerPrint.Load(filename + ".vfsigx");
                    }
                    else
                    {
                        var source = new VFPFingerprintSource(filename, engine);
                        foreach (var area in _ignoredAreas)
                        {
                            source.IgnoredAreas.Add(area);
                        }

                        fp = VFPAnalyzer.GetSearchFingerprintForVideoFile(source, out error);
                    }

                    if (fp == null)
                    {
                        MessageBox.Show("Unable to get fingerpring for video file: " + filename + ". Error: " + error);
                    }
                    else
                    {
                        fp.Save(filename + ".vfsigx", false);
                        _adVFPList.Add(fp);
                    }

                    progress += 100 / adList.Count;
                }

                int fragmentDurationProperty = Convert.ToInt32(edFragmentDuration.Text);
                if (fragmentDurationProperty != 0)
                {
                    _fragmentDuration = fragmentDurationProperty * 1000;
                }
                else
                {
                    var  maxDuration         = _adVFPList.Max((print => print.Duration));
                    long minfragmentDuration = (((maxDuration + 1000) / 1000) + 1) * 1000;
                    _fragmentDuration = minfragmentDuration * 2;
                }

                pbProgress.Value = 100;

                if (_tempBuffer != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(_tempBuffer);
                    _tempBuffer = IntPtr.Zero;
                }

                lbStatus.Content = "Step 3: Starting video preview";

                if (cbSource.SelectedIndex == 0)
                {
                    VideoCapture1.Video_CaptureDevice         = cbVideoSource.Text;
                    VideoCapture1.Video_CaptureFormat         = cbVideoFormat.Text;
                    VideoCapture1.Video_CaptureFormat_UseBest = false;
                    VideoCapture1.Video_FrameRate             = Convert.ToDouble(cbVideoFrameRate.Text);

                    VideoCapture1.Mode = VFVideoCaptureMode.VideoPreview;
                }
                else
                {
                    var ip = new IPCameraSourceSettings
                    {
                        URL      = edNetworkSourceURL.Text,
                        Login    = edNetworkSourceLogin.Text,
                        Password = edNetworkSourcePassword.Text
                    };

                    switch (cbNetworkSourceEngine.SelectedIndex)
                    {
                    case 0:
                        ip.Type = VFIPSource.Auto_LAV;
                        break;

                    case 1:
                        ip.Type = VFIPSource.Auto_VLC;
                        break;

                    case 2:
                        ip.Type = VFIPSource.Auto_FFMPEG;
                        break;
                    }

                    VideoCapture1.IP_Camera_Source = ip;

                    VideoCapture1.Mode = VFVideoCaptureMode.IPPreview;
                }

                VideoCapture1.Audio_PlayAudio   = false;
                VideoCapture1.Audio_RecordAudio = false;

                VideoCapture1.Video_Renderer.Video_Renderer = VFVideoRendererWPF.WPF;

                VideoCapture1.Start();

                lbStatus.Content = "Step 4: Getting data";

                pbProgress.Value = 0;

                lvResults.Items.Refresh();

                btStart.IsEnabled = true;
                btStart.Content   = "Stop";
            }
        }
コード例 #7
0
        private void ProcessVideoDelegateMethod()
        {
            lock (_processingLock)
            {
                //if (VideoCapture1.Status == VFVideoCaptureStatus.Free)
                //{
                //    return;
                //}

                //// done. searching for fingerprints.
                //VideoCapture1.Stop();

                long n;
                FingerprintLiveData fingerprint = null;

                if (_fingerprintQueue.TryDequeue(out fingerprint))
                {
                    IntPtr p = VFPSearch.Build(out n, ref fingerprint.Data);

                    VFPFingerPrint fvp = new VFPFingerPrint()
                    {
                        Data             = new byte[n],
                        OriginalFilename = string.Empty
                    };

                    Marshal.Copy(p, fvp.Data, 0, (int)n);

                    foreach (var ad in _adVFPList)
                    {
                        List <int> positions;
                        bool       found = VFPAnalyzer.Search(ad, fvp, ad.Duration, (int)slDifference.Value, out positions, true);

                        if (found)
                        {
                            foreach (var pos in positions)
                            {
                                DateTime tm = fingerprint.StartTime.AddMilliseconds(pos * 1000);

                                bool duplicate = false;
                                foreach (var detectedAd in _results)
                                {
                                    long time = 0;

                                    if (detectedAd.Timestamp > tm)
                                    {
                                        time = (long)(detectedAd.Timestamp - tm).TotalMilliseconds;
                                    }
                                    else
                                    {
                                        time = (long)(tm - detectedAd.Timestamp).TotalMilliseconds;
                                    }

                                    if (time < 1000)
                                    {
                                        // duplicate
                                        duplicate = true;
                                        break;
                                    }
                                }

                                if (duplicate)
                                {
                                    break;
                                }

                                _results.Add(new DetectedAd(tm));
                                resultsView.Add(
                                    new ResultsViewModel()
                                {
                                    Sample      = ad.OriginalFilename,
                                    TimeStamp   = tm.ToString("HH:mm:ss.fff"),
                                    TimeStampMS = tm - new DateTime(1970, 1, 1)
                                });
                            }
                        }
                    }

                    fingerprint.Data.Free();
                    fingerprint.Dispose();
                }
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            var options = new CommandLineOptions();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                // Display the default usage information
                //Console.WriteLine(options.GetUsage());
                return;
            }

            if (!File.Exists(options.InputFile))
            {
                Console.WriteLine("Source file not found: " + options.InputFile + ".");
                return;
            }

            VFPAnalyzer.SetLicenseKey(options.LicenseKey);

            var engine = VFSimplePlayerEngine.LAV;

            if (!string.IsNullOrEmpty(options.Engine))
            {
                switch (options.Engine.Trim())
                {
                case "directshow":
                    engine = VFSimplePlayerEngine.DirectShow;
                    break;

                case "ffmpeg":
                    engine = VFSimplePlayerEngine.FFMPEG;
                    break;

                case "lav":
                    engine = VFSimplePlayerEngine.LAV;
                    break;
                }
            }

            Console.WriteLine("Analyzing...");

            var time        = DateTime.Now;
            var mediaPlayer = new SimplePlayer(null)
            {
                Filename       = options.InputFile,
                Video_Renderer = VFVideoRendererInternal.None
            };

            if (Path.GetExtension(options.InputFile)?.ToLowerInvariant() == ".wmv")
            {
                engine = VFSimplePlayerEngine.DirectShow;
            }

            mediaPlayer.Engine = engine;
            mediaPlayer.MaximalSpeedPlayback = true;

            //if (!string.IsNullOrEmpty(DebugDir))
            //{
            //    mediaPlayer.Debug_Dir = DebugDir;
            //    mediaPlayer.Debug_Mode = true;
            //}

            var mediaInfo = new MediaInfoReader
            {
                Filename = options.InputFile
            };

            mediaInfo.ReadFileInfo(true);


            VFPSearchData[] dataList = new VFPSearchData[options.Count];

            string error1 = string.Empty;
            bool   inUse  = true;
            bool   error  = false;

            // check for hang or something
            long frameNumber = 0;

            int sourceWidth  = 0;
            int sourceHeight = 0;

            int  index     = 0;
            long minusTime = 0;

            mediaPlayer.OnVideoFrame += delegate(object sender, SampleGrabberBufferCBEventArgs e)
            {
                if (!inUse)
                {
                    return;
                }

                long timestamp = (long)(e.SampleTime * 1000);
                timestamp -= minusTime;

                if (timestamp >= options.Duration)
                {
                    Console.WriteLine($"Started new fragment at {minusTime}");
                    index++;
                    minusTime  = (long)(e.SampleTime * 1000);
                    timestamp -= minusTime;
                }

                if (index >= options.Count)
                {
                    inUse = false;
                    return;
                }

                if (e.SampleTime < options.Duration * options.Count)
                {
                    frameNumber++;

                    sourceWidth  = e.Width;
                    sourceHeight = e.Height;

                    if (dataList[index] == null)
                    {
                        dataList[index] = new VFPSearchData(TimeSpan.FromMilliseconds(options.Duration));
                    }

                    VFPSearch.Process(
                        e.Buffer,
                        e.Width,
                        e.Height,
                        ImageHelper.GetStrideRGB24(e.Width),
                        TimeSpan.FromMilliseconds(timestamp),
                        ref dataList[index]);
                }
                else
                {
                    inUse = false;
                }
            };

            mediaPlayer.OnStop += delegate
            {
                inUse = false;
            };

            mediaPlayer.OnError += delegate(object sender, ErrorsEventArgs e)
            {
                if (e.Message.Contains("FULL"))
                {
                    return;
                }

                if (e.Level == DebugLevel.Error)
                {
                    error = true;
                    inUse = false;

                    error1 = e.Message + " | " + e.CallSite;
                }
            };

            mediaPlayer.Start();

            while (inUse && !error)
            {
                Thread.Sleep(100);
                Application.DoEvents();
            }

            mediaPlayer.Stop();

            Debug.WriteLine($"Processed {frameNumber} frame for file {options.InputFile}.");

            if (!error)
            {
                for (var i = 0; i < dataList.Length; i++)
                {
                    var data = dataList[i];
                    if (data == null)
                    {
                        break;
                    }

                    IntPtr p = VFPSearch.Build(out var n, ref data);

                    VFPFingerPrint fvp = new VFPFingerPrint()
                    {
                        // ReSharper disable once ExceptionNotDocumented
                        Data             = new byte[n],
                        OriginalFilename = options.InputFile,
                        OriginalDuration = TimeSpan.FromMilliseconds(options.Duration),
                        Duration         = TimeSpan.FromMilliseconds(options.Duration),
                        ID        = Guid.NewGuid(),
                        Width     = sourceWidth,
                        Height    = sourceHeight,
                        FrameRate = mediaInfo.Video_FrameRate(0)
                    };

                    Marshal.Copy(p, fvp.Data, 0, (int)n);

                    data.Free();

                    var newFilename = $"{options.InputFile}_segment{i}.vfsigx";
                    fvp.Save(newFilename);
                }
            }
            else
            {
                Debug.WriteLine($"Error: {error1}.");
            }

            mediaPlayer.Dispose();

            var elapsed = DateTime.Now - time;

            Console.WriteLine("Analyze finished. Elapsed time: " + elapsed.ToString("g"));
        }
コード例 #9
0
        private async void btStart_Click(object sender, RoutedEventArgs e)
        {
            if (cbDebug.IsChecked == true)
            {
                VFPAnalyzer.DebugDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\VisioForge\\MMT\\";
            }

            btStart.IsEnabled = false;

            results.Clear();
            lvResults.Items.Refresh();

            lbStatus.Content = "Step 1: Searching video files";

            VFSimplePlayerEngine engine = VFSimplePlayerEngine.LAV;

            switch (cbEngine.SelectedIndex)
            {
            case 0:
                engine = VFSimplePlayerEngine.DirectShow;
                break;

            case 1:
                engine = VFSimplePlayerEngine.FFMPEG;
                break;

            case 2:
                engine = VFSimplePlayerEngine.LAV;
                break;
            }

            List <string> adList        = new List <string>();
            List <string> broadcastList = new List <string>();

            List <VFPFingerPrint> adVFPList        = new List <VFPFingerPrint>();
            List <VFPFingerPrint> broadcastVFPList = new List <VFPFingerPrint>();

            foreach (string item in lbAdFolders.Items)
            {
                bool isDir = (File.GetAttributes(item) & FileAttributes.Directory) == FileAttributes.Directory;
                if (isDir)
                {
                    adList.AddRange(FileScanner.SearchVideoInFolder(item));
                }
                else
                {
                    adList.Add(item);
                }
            }

            foreach (string item in lbBroadcastFolders.Items)
            {
                bool isDir = (File.GetAttributes(item) & FileAttributes.Directory) == FileAttributes.Directory;
                if (isDir)
                {
                    broadcastList.AddRange(FileScanner.SearchVideoInFolder(item));
                }
                else
                {
                    broadcastList.Add(item);
                }
            }

            lbStatus.Content = "Step 2: Getting fingerprints for ads files";

            int progress = 0;

            foreach (string filename in adList)
            {
                pbProgress.Value = progress;

                var source = new VFPFingerprintSource(filename, engine);
                foreach (var area in _ignoredAreas)
                {
                    source.IgnoredAreas.Add(area);
                }

                VFPFingerPrint fp = _db.GetFingerprint(source);

                if (fp == null)
                {
                    fp = await VFPAnalyzer.GetSearchFingerprintForVideoFileAsync(source, errorDelegate);

                    if (fp == null)
                    {
                        MessageBox.Show("Unable to get fingerprint for the video file: " + filename);
                    }
                    else
                    {
                        _db.Items.Add(fp);
                        AddDBItem(fp);
                    }
                }

                adVFPList.Add(fp);

                progress += 100 / adList.Count;
            }

            pbProgress.Value = 100;

            lbStatus.Content = "Step 3: Getting fingerprints for broadcast files";
            progress         = 0;
            foreach (string filename in broadcastList)
            {
                pbProgress.Value = progress;

                var source = new VFPFingerprintSource(filename, engine);
                foreach (var area in _ignoredAreas)
                {
                    source.IgnoredAreas.Add(area);
                }

                VFPFingerPrint fp = _db.GetFingerprint(source);
                if (fp == null)
                {
                    fp = await VFPAnalyzer.GetSearchFingerprintForVideoFileAsync(source, errorDelegate);

                    if (fp == null)
                    {
                        MessageBox.Show("Unable to get fingerprint for the video file: " + filename);
                        return;
                    }
                    else
                    {
                        _db.Items.Add(fp);
                        AddDBItem(fp);
                    }
                }

                broadcastVFPList.Add(fp);

                progress += 100 / broadcastList.Count;
            }

            pbProgress.Value = 100;

            lbStatus.Content = "Step 4: Analyzing data";
            progress         = 0;
            int foundCount = 0;

            foreach (var broadcast in broadcastVFPList)
            {
                pbProgress.Value = progress;

                foreach (var ad in adVFPList)
                {
                    var positions = await VFPAnalyzer.SearchAsync(ad, broadcast, ad.Duration, (int)slDifference.Value, true);

                    if (positions.Count > 0)
                    {
                        foreach (var pos in positions)
                        {
                            foundCount++;
                            int minutes = (int)(pos.TotalSeconds / 60);
                            int seconds = (int)(pos.TotalSeconds % 60);

                            results.Add(
                                new ResultsViewModel()
                            {
                                Sample   = ad.OriginalFilename,
                                DumpFile = broadcast.OriginalFilename,
                                Position = minutes + ":" + seconds
                            });
                        }
                    }
                }

                progress += 100 / broadcastList.Count;
            }

            pbProgress.Value = 0;

            lvResults.Items.Refresh();

            lbStatus.Content = "Step 5: Done. " + foundCount + " ads found.";

            btStart.IsEnabled = true;
        }
コード例 #10
0
        private void btStart_Click(object sender, RoutedEventArgs e)
        {
            if ((string)btStart.Content == "Stop")
            {
                _stopFlag = true;

                Thread.Sleep(500);

                _videoCapture?.Stop();
                _videoPlayer?.Stop();

                Thread.Sleep(500);

                ProcessVideoDelegateMethod();

                btStart.Content = "Start";

                lbStatus.Content = string.Empty;

                if (_tempBuffer != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(_tempBuffer);
                    _tempBuffer = IntPtr.Zero;
                }

                pnScreen.BeginInit();
                pnScreen.Source = null;
                pnScreen.EndInit();
            }
            else
            {
                _stopFlag = false;

                btStart.IsEnabled = false;

                lbStatus.Content = "Step 1: Searching video files";

                _fragmentCount        = 0;
                _overlapFragmentCount = 0;

                var engine = VFSimplePlayerEngine.LAV;

                switch (cbEngine.SelectedIndex)
                {
                case 0:
                    engine = VFSimplePlayerEngine.DirectShow;
                    break;

                case 1:
                    engine = VFSimplePlayerEngine.FFMPEG;
                    break;

                case 2:
                    engine = VFSimplePlayerEngine.LAV;
                    break;
                }

                var adList = new List <string>();

                _adVFPList = new List <VFPFingerPrint>();

                foreach (string item in lbAdFiles.Items)
                {
                    adList.Add(item);
                }

                lbStatus.Content = "Step 2: Getting fingerprints for ads files";

                if (adList.Count == 0)
                {
                    btStart.Content   = "Start";
                    lbStatus.Content  = string.Empty;
                    btStart.IsEnabled = true;

                    MessageBox.Show("Ads list is empty!");

                    return;
                }

                int progress = 0;
                foreach (string filename in adList)
                {
                    pbProgress.Value = progress;
                    string         error = "";
                    VFPFingerPrint fp;

                    if (File.Exists(filename + ".vfsigx"))
                    {
                        fp = VFPFingerPrint.Load(filename + ".vfsigx");
                    }
                    else
                    {
                        var source = new VFPFingerprintSource(filename, engine);
                        foreach (var area in _ignoredAreas)
                        {
                            source.IgnoredAreas.Add(area);
                        }

                        fp = VFPAnalyzer.GetSearchFingerprintForVideoFile(source, ErrorCallback);
                    }

                    if (fp == null)
                    {
                        MessageBox.Show("Unable to get fingerprint for video file: " + filename + ". Error: " + error);
                    }
                    else
                    {
                        fp.Save(filename + ".vfsigx");
                        _adVFPList.Add(fp);
                    }

                    progress += 100 / adList.Count;
                }

                int fragmentDurationProperty = Convert.ToInt32(edFragmentDuration.Text);
                if (fragmentDurationProperty != 0)
                {
                    _fragmentDuration = fragmentDurationProperty * 1000;
                }
                else
                {
                    var  maxDuration         = _adVFPList.Max((print => print.Duration));
                    long minfragmentDuration = ((((long)maxDuration.TotalMilliseconds + 1000) / 1000) + 1) * 1000;
                    _fragmentDuration = minfragmentDuration * 2;
                }

                pbProgress.Value = 100;

                if (_tempBuffer != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(_tempBuffer);
                    _tempBuffer = IntPtr.Zero;
                }

                lbStatus.Content = "Step 3: Starting video preview";

                if (cbSource.SelectedIndex == 0)
                {
                    _videoCapture.Video_CaptureDevice_Name      = cbVideoSource.Text;
                    _videoCapture.Video_CaptureDevice_Format    = cbVideoFormat.Text;
                    _videoCapture.Video_CaptureDevice_FrameRate = Convert.ToDouble(cbVideoFrameRate.Text);

                    _videoCapture.Start();
                }
                else
                {
                    string url = edNetworkSourceURL.Text;
                    //var ip = new IPCameraSourceSettings
                    //             {
                    //                 URL =,
                    //                 Login = edNetworkSourceLogin.Text,
                    //                 Password = edNetworkSourcePassword.Text
                    //             };
                    _videoPlayer.Filename             = url;
                    _videoPlayer.MaximalSpeedPlayback = false;


                    switch (cbNetworkSourceEngine.SelectedIndex)
                    {
                    case 0:
                        _videoPlayer.Engine = VFSimplePlayerEngine.LAV;
                        break;

                    case 2:
                        _videoPlayer.Engine = VFSimplePlayerEngine.FFMPEG;
                        break;
                    }

                    _videoPlayer.Start();
                }

                lbStatus.Content = "Step 4: Getting data";

                pbProgress.Value = 0;

                lvResults.Items.Refresh();

                btStart.IsEnabled = true;
                btStart.Content   = "Stop";
            }
        }