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"; } }