public unsafe bool TryDecode(ref VideoPacket packet, out VideoFrame frame)
        {
            if (_videoDecoder == null)
            {
                _videoDecoder = new VideoDecoder();


                fixed(byte *pData = &packet.Data[0])
                {
                    _avPacket.data = pData;
                    _avPacket.size = packet.Data.Length;
                    frame          = new VideoFrame();
                    if (_videoDecoder.TryDecode(ref _avPacket, ref _avFrame))
                    {
                        if (_videoConverter == null)
                        {
                            _videoConverter = new VideoConverter(_pixelFormat.ToAVPixelFormat());
                        }

                        byte[] data = _videoConverter.ConvertFrame(ref _avFrame);

                        frame.Timestamp   = packet.Timestamp;
                        frame.Number      = packet.FrameNumber;
                        frame.Width       = packet.Width;
                        frame.Height      = packet.Height;
                        frame.Depth       = data.Length / (packet.Width * packet.Height);
                        frame.PixelFormat = _pixelFormat;
                        frame.Data        = data;

                        return(true);
                    }
                }

                return(false);
        }
Esempio n. 2
0
        public unsafe bool TryDecode(ref VideoPacket packet, out VideoFrame frame)
        {
            if (_videoDecoder == null) _videoDecoder = new VideoDecoder();


            fixed (byte* pData = &packet.Data[0])
            {
                _avPacket.data = pData;
                _avPacket.size = packet.Data.Length;
                if (_videoDecoder.TryDecode(ref _avPacket, ref _avFrame))
                {
                    if (_videoConverter == null) _videoConverter = new VideoConverter(_pixelFormat.ToAVPixelFormat());

                    byte[] data = _videoConverter.ConvertFrame(ref _avFrame);

                    frame = new VideoFrame();
                    frame.Timestamp = packet.Timestamp;
                    frame.Number = packet.FrameNumber;
                    frame.Width = packet.Width;
                    frame.Height = packet.Height;
                    frame.Depth = data.Length/(packet.Width*packet.Height);
                    frame.PixelFormat = _pixelFormat;
                    frame.Data = data;
                    return true;
                }
            }
            frame = null;
            return false;
        }