示例#1
0
        private void OnFrameReceived(object sender, RawFrame rawFrame)
        {
            if (!(rawFrame is RawVideoFrame rawVideoFrame))
            {
                return;
            }

            FFmpegVideoDecoder decoder = GetDecoderForFrame(rawVideoFrame);

            if (!decoder.TryDecode(rawVideoFrame, out DecodedVideoFrameParameters decodedFrameParameters))
            {
                return;
            }

            //long desiredSize = (long)rawFrame. << 32 | (uint)height;

            //long desiredSize = Interlocked.Read(ref _desiredSize);

            int targetWidth;
            int targetHeight;

            int bufferSize;

            //if (desiredSize == 0)
            //{
            targetWidth  = decodedFrameParameters.Width;
            targetHeight = decodedFrameParameters.Height;

            bufferSize = decodedFrameParameters.Height *
                         ImageUtils.GetStride(decodedFrameParameters.Width, PixelFormat.Bgr24);
            //}
            //else
            //{
            //    targetWidth = (int)(desiredSize >> 32);
            //    targetHeight = (int)desiredSize;

            //    bufferSize = targetHeight *
            //                 ImageUtils.GetStride(targetWidth, PixelFormat.Bgr24);
            //}


            if (_decodedFrameBuffer.Length != bufferSize)
            {
                _decodedFrameBuffer = new byte[bufferSize];
            }

            var bufferSegment = new ArraySegment <byte>(_decodedFrameBuffer);

            var postVideoDecodingParameters = new PostVideoDecodingParameters(RectangleF.Empty,
                                                                              new Size(targetWidth, targetHeight),
                                                                              ScalingPolicy.Stretch, PixelFormat.Bgr24, ScalingQuality.Bicubic);

            IDecodedVideoFrame decodedFrame = decoder.GetDecodedFrame(bufferSegment, postVideoDecodingParameters);

            FrameReceived?.Invoke(this, decodedFrame);
        }
示例#2
0
        private void OnFrameReceived(object sender, RawFrame rawFrame)
        {
            if (!(rawFrame is RawVideoFrame rawVideoFrame))
            {
                return;
            }

            FFmpegVideoDecoder decoder = GetDecoderForFrame(rawVideoFrame);

            if (!decoder.TryDecode(rawVideoFrame, out DecodedVideoFrameParameters decodedFrameParameters))
            {
                return;
            }

            int targetWidth  = decodedFrameParameters.Width;
            int targetHeight = decodedFrameParameters.Height;

            int bufferSize = decodedFrameParameters.Height *
                             ImageUtils.GetStride(decodedFrameParameters.Width, PixelFormat.Bgr24);

            if (_decodedFrameBuffer.Length != bufferSize)
            {
                _decodedFrameBuffer = new byte[bufferSize];
            }

            var bufferSegment = new ArraySegment <byte>(_decodedFrameBuffer);

            if (_postVideoDecodingParameters.TargetFrameSize.Width != targetWidth ||
                _postVideoDecodingParameters.TargetFrameSize.Height != targetHeight)
            {
                _postVideoDecodingParameters = new PostVideoDecodingParameters(RectangleF.Empty,
                                                                               new Size(targetWidth, targetHeight),
                                                                               ScalingPolicy.Stretch, PixelFormat.Bgr24, ScalingQuality.Nearest);
            }

            IDecodedVideoFrame decodedFrame = decoder.GetDecodedFrame(bufferSegment, _postVideoDecodingParameters);

            FrameReceived?.Invoke(this, decodedFrame);
        }
示例#3
0
        private void OnFrameReceived(object sender, RawFrame rawFrame)
        {
            if (!(rawFrame is RawVideoFrame rawVideoFrame))
            {
                return;
            }

            FFmpegVideoDecoder decoder = GetDecoderForFrame(rawVideoFrame);

            if (!decoder.TryDecode(rawVideoFrame, out DecodedVideoFrameParameters decodedFrameParameters))
            {
                return;
            }

            long desiredSize = Interlocked.Read(ref _desiredSize);

            int targetWidth;
            int targetHeight;

            if (desiredSize == 0)
            {
                targetWidth  = decodedFrameParameters.Width;
                targetHeight = decodedFrameParameters.Height;
            }
            else
            {
                targetWidth  = (int)(desiredSize >> 32);
                targetHeight = (int)desiredSize;
            }

            var postVideoDecodingParameters = new PostVideoDecodingParameters(RectangleF.Empty,
                                                                              new Size(targetWidth, targetHeight),
                                                                              ScalingPolicy.Stretch, PixelFormat.Bgr24, ScalingQuality.Bicubic);

            IDecodedVideoFrame decodedFrame = decoder.GetDecodedFrame(postVideoDecodingParameters);

            FrameReceived?.Invoke(this, decodedFrame);
        }