Exemple #1
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.");
            }
        }
Exemple #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.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.");
            }
        }
        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";
            }
        }
        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";
            }
        }