示例#1
0
        public void StartDecoder(FfmpegPackage package)
        {
            if (!_ffmpegHeaderInit)
            {
                throw new InvalidOperationException("没有初始化FFMPEG视频流包头。");
            }
            var frame = _ffmpegDecoder.Decode(package.Type, package.Pts, package.Data);

            completeFfmpegDecode(frame);
        }
示例#2
0
 public bool Update(StreamPacket packet)
 {
     FfmpegDecoder.VideoFrame frame = _decoder?.Decode(1, (ulong)packet.Time.Ticks / 10000, packet.Buffer);
     if (frame != null)
     {
         onDisplay(new VideoFrame(frame.Width, frame.Height, packet.Time.Ticks, frame.Data));
     }
     return(true);
 }
        void run()
        {
            FfmpegDecoder decoder = new FfmpegDecoder();
            int           index   = 0;

            int wait = 0;

            while (!_disposeEvent.WaitOne(wait))
            {
                wait = 1;
                if (_records.Length > 0)
                {
                    bool     reposed = false;
                    DateTime startRealTime;
                    DateTime startPlayTime;
                    lock (_playTimeLockObj)
                    {
                        startRealTime = _startRealTime;
                        startPlayTime = _startPlayTime;
                        reposed       = _reposed;
                        _reposed      = false;
                    }

                    if (_playing || reposed)
                    {
                        DateTime curPlayTime = startPlayTime + new TimeSpan((long)Math.Round((DateTime.Now - startRealTime).Ticks * _speed));
                        if (curPlayTime > EndTime)
                        {
                            curPlayTime = EndTime;
                        }

                        Record <FfmpegPackage> record = null;
                        if (reposed)
                        {
                            for (index = 0; index < _records.Length; index++)
                            {
                                if (_records[index].Time >= curPlayTime)
                                {
                                    break;
                                }
                            }
                            if (index < _records.Length)
                            {
                                record = _records[index];
                            }
                        }
                        else
                        {
                            int next = index + 1;
                            if (next < _records.Length && _records[next].Time < curPlayTime)
                            {
                                index  = next;
                                record = _records[index];
                            }
                        }

                        if (record != null)
                        {
                            _currentTime = record.Time;
                            decoder.Init(record.Package.CodecID, record.Package.Width, record.Package.Height);
                            var frame = decoder.Decode(record.Package.Type, record.Package.Pts, record.Package.Data);
                            if (frame != null)
                            {
                                var videoFrame = new VideoFrame()
                                {
                                    Width     = frame.Width,
                                    Height    = frame.Height,
                                    Timestamp = (int)frame.Pts,
                                    Data      = frame.Data,
                                };
                                fireVideoFrameEvent(videoFrame);
                            }
                            wait = 0;
                        }
                    }
                }
            }
        }