Пример #1
0
        private void SetupPlayer()
        {
            if (_decoder != null)
            {
                _decoder.Stop();
                _decoder.ClearBuffer();
                _decoder.Dispose();
                _decoder = null;
            }

            string file = "";

            Dispatcher.Invoke(() => file = txtFileName.Text);

            _decoder = new VideoDecoder();
            _decoder.Open(file);
            _decoder.PlayerOutputWidth  = _decoder.VideoInfo.Width;
            _decoder.PlayerOutputHeight = _decoder.VideoInfo.Height;

            Dispatcher.Invoke(() =>
            {
                sliderTime.Minimum = 0;
                sliderTime.Maximum = _decoder.VideoInfo.TotalFrames - 1;
            });

            if (iterator == null)
            {
                iterator = new FrameIterator(_decoder.VideoInfo.TotalFrames,
                                             templateView.TemplatePaths.Keys.Count,
                                             AppSettings.Default.BurstSize
                                             );

                var startFrame = (int)Math.Round(AppSettings.Default.StartTime * _decoder.VideoInfo.FPS);
                var endFrame   = (int)Math.Round(AppSettings.Default.EndTime * _decoder.VideoInfo.FPS);

                if (AppSettings.Default.UseRandom)
                {
                    iterator.InitRandomSequence(
                        AppSettings.Default.MaxFrames,
                        Math.Max(0, startFrame),
                        Math.Min(_decoder.VideoInfo.TotalFrames, endFrame) - 1,
                        AppSettings.Default.UseSeed ? AppSettings.Default.Seed : (int?)null
                        );
                }
                else
                {
                    iterator.InitLinearSequence(
                        AppSettings.Default.EveryNth,
                        Math.Max(0, startFrame),
                        Math.Min(_decoder.VideoInfo.TotalFrames - 1, endFrame)
                        );
                }
            }

            _decoder.SeekTo(iterator.BurstBeginFrameIndex);
            _decoder.Start();
            _decoder.FrameDecoder.FrameBufferCapacity  = 1;
            _decoder.FrameDecoder.MinimumWorkingFrames = 1;
        }
Пример #2
0
        public void SeekTo(double percentLocation)
        {
            MostRecentFrameIndex = (int)(Math.Round(VD.VideoInfo.TotalFrames * percentLocation, 0));

            VD.SeekTo((float)(VD.VideoInfo.Duration.TotalSeconds * percentLocation));
        }
Пример #3
0
        private void StartStopMarking(object sender, RoutedEventArgs e)
        {
            IsMarking = true;

            SetupPlayer();

            videoCanvas.Focus();

            Thread.Sleep(50);
            HideInstructions();


            new Thread(() =>
            {
                while (IsMarking)
                {
                    //for(var i = 0; i < 500; i++)
                    {
                        if (_decoder == null)
                        {
                            SetupPlayer();
                        }

                        lock (_decoder)
                        {
                            _decoder.Stop();
                            _decoder.ClearBuffer();
                            _decoder.SeekTo(iterator.FrameIndex);
                            _decoder.Start(true);

                            while (!_decoder.FramesInBuffer)
                            {
                                Thread.Sleep(5);
                            }

                            if (nextFrame != null)
                            {
                                nextFrame.Dispose();
                            }

                            nextFrame = _decoder.PlayNextFrame();
                        }
                    }

                    if (currentFrame != null)
                    {
                        currentFrame.Dispose();
                    }

                    currentFrame = nextFrame;

                    Dispatcher.Invoke(() =>
                    {
                        lblActivePartName.Text = TemplateView.Current.CurrentPartName;
                        ShowFrame(currentFrame);

                        GC.Collect();
                    });



                    ReadyForNextFrame = false;

                    while (!ReadyForNextFrame && IsMarking)
                    {
                        Thread.Sleep(5); //Wait for position data (use value < smallest inter-click interval)
                    }

                    //Store the position data
                    if (!FrameData.ContainsKey(currentFrame.FrameIndex))
                    {
                        FrameData[currentFrame.FrameIndex] = new Dictionary <string, System.Drawing.Point?>();
                    }

                    if (_capturedMousePosition != null)
                    {
                        FrameData[currentFrame.FrameIndex][TemplateView.Current.CurrentPartName] = _capturedMousePosition;
                    }

                    UpdateReward();

                    if (iterator.IsAtEndOfBurstOrSequenceOrVideo && iterator.IsAtEndOfBatch)
                    {
                        iterator.AdvanceBurst();
                        templateView.CurrentPartIndex = iterator.BatchPartIndex;
                        IsMarking = false;
                        ShowInstructions();
                        return;
                    }

                    if (iterator.IsAtEndOfBurstOrSequenceOrVideo)
                    {
                        iterator.AdvanceBurst();
                        templateView.CurrentPartIndex = iterator.BatchPartIndex;
                        SetupPlayer(); //Rewind to first frame
                        IsMarking = false;
                        ShowInstructions();
                        return;
                    }

                    iterator.AdvanceBurst();

                    Thread.Sleep(10);
                }
            }).Start();
        }