Example #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.");
            }
        }
Example #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.");
            }
        }
        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"));
        }
Example #4
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;
            }

            if (File.Exists(options.OutputFile))
            {
                try
                {
                    File.Delete(options.OutputFile);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to delete output file: " + options.OutputFile + ". Exception: " + e.Message + ".");
                    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("Starting analyze.");

            var time = DateTime.Now;

            var source = new VFPFingerprintSource(options.InputFile, engine);

            if (options.Duration > 0)
            {
                source.StopTime = TimeSpan.FromMilliseconds(options.Duration);
            }

            VFPFingerPrint fp;

            if (options.Type == "search")
            {
                fp = VFPAnalyzer.GetSearchFingerprintForVideoFile(source, ErrorCallback);
            }
            else
            {
                fp = VFPAnalyzer.GetComparingFingerprintForVideoFile(source, ErrorCallback);
            }

            if (fp == null)
            {
                Console.WriteLine("Unable to get fingerprint.");
                return;
            }

            var elapsed = DateTime.Now - time;

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

            fp.Save(options.OutputFile);
        }