Exemple #1
0
        private void SeekToTime(double seconds, SeekModes seekMode)
        {
            if ((_pendingFrame != null) && (_pendingFrame.Fields != null))
            {
                if (seekMode == SeekModes.Accurate)
                {
                    for (int fieldIndex = 0; fieldIndex < _pendingFrame.Fields.Length; fieldIndex++)
                    {
                        var field = _pendingFrame.Fields[fieldIndex];
                        if ((field.Seconds == seconds))
                        {
                            _pendingFrame.CurrentIndex = fieldIndex;
                            return;
                        }
                    }
                }
                else
                {
                    if (_pendingFrame.IsKeyFrame)
                    {
                        return;
                    }
                }
            }

            long pts = (long)(seconds * _videoCodecContext.pkt_timebase.den / (double)_videoCodecContext.pkt_timebase.num);

            SeekToPTS(pts, seekMode);
        }
Exemple #2
0
 private void SeekToPTS(long pts, SeekModes seekMode)
 {
     if (seekMode == SeekModes.PreviousKeyFrame)
     {
         SeekToPTS(pts, true);
     }
     else if (seekMode == SeekModes.NextKeyFrame)
     {
         SeekToPTS(pts, false);
         while (!_pendingFrame.IsKeyFrame)
         {
             var previousFrame = _pendingFrame;
             _pendingFrame = ReadVideoFrame();
             if (_pendingFrame == null)
             {
                 _pendingFrame = previousFrame;
                 return;
             }
             DisposeFrame(ref previousFrame);
         }
     }
     else
     {
         SeekToPTS(pts, false);
     }
 }
Exemple #3
0
        public FrameField GetVideoFrameField(int fieldNumber, SeekModes seekMode = SeekModes.Accurate)
        {
            FrameField frame = null;

            SeekToField(fieldNumber, seekMode);
            if (_pendingFrame != null)
            {
                frame = _pendingFrame.Fields[_pendingFrame.CurrentIndex];
                //frame.Image.Save(@"D:\temp\image-" + frame.FrameNumber.ToString("00000") + ".png", System.Drawing.Imaging.ImageFormat.Png);
            }
            _pendingFrame.CurrentIndex++;
            if (_pendingFrame.CurrentIndex >= _pendingFrame.Fields.Length)
            {
                _pendingFrame = ReadVideoFrame();
            }
            return(frame);
        }
Exemple #4
0
        private void SeekToField(int fieldNumber, SeekModes seekMode)
        {
            if ((_pendingFrame != null) && (_pendingFrame.Fields != null))
            {
                if ((seekMode == SeekModes.Accurate) || (_pendingFrame.IsKeyFrame))
                {
                    for (int fieldIndex = 0; fieldIndex < _pendingFrame.Fields.Length; fieldIndex++)
                    {
                        var field = _pendingFrame.Fields[fieldIndex];
                        if ((field.FieldNumber == fieldNumber))
                        {
                            _pendingFrame.CurrentIndex = fieldIndex;
                            return;
                        }
                    }
                }
            }

            long pts = PTSPerField * fieldNumber;

            SeekToPTS(pts, seekMode);
        }