コード例 #1
0
        public unsafe IDecodedVideoFrame GetDecodedFrame(ArraySegment <byte> bufferSegment,
                                                         PostVideoDecodingParameters parameters)
        {
            if (!_scalersMap.TryGetValue(parameters, out FFmpegDecodedVideoScaler videoScaler))
            {
                videoScaler = FFmpegDecodedVideoScaler.Create(_currentFrameParameters, parameters);
                _scalersMap.Add(parameters, videoScaler);
            }

            int resultCode;

            Debug.Assert(bufferSegment.Array != null, "bufferSegment.Array != null");

            fixed(byte *scaledBuffer = &bufferSegment.Array[bufferSegment.Offset])
            resultCode = FFmpegVideoPInvoke.ScaleDecodedVideoFrame(_decoderHandle, videoScaler.Handle,
                                                                   (IntPtr)scaledBuffer, videoScaler.ScaledStride);

            if (resultCode != 0)
            {
                throw new DecoderException(
                          $"An error occurred while converting decoding video frame, {_videoCodecId} codec, code: {resultCode}");
            }

            return(new DecodedVideoFrame(_currentDecodedFrameTimestamp, bufferSegment, _currentFrameParameters.Width,
                                         _currentFrameParameters.Height,
                                         videoScaler.ScaledWidth, videoScaler.ScaledHeight, videoScaler.ScaledPixelFormat,
                                         videoScaler.ScaledStride));
        }
コード例 #2
0
        public unsafe IDecodedVideoFrame GetDecodedFrame(PostVideoDecodingParameters parameters)
        {
            if (!_scalersMap.TryGetValue(parameters, out FFmpegDecodedVideoScaler videoScaler))
            {
                videoScaler = FFmpegDecodedVideoScaler.Create(_currentFrameParameters, parameters);
                _scalersMap.Add(parameters, videoScaler);
            }

            int resultCode;

            int bufferSize = parameters.TargetFrameSize.Height *
                             ImageUtils.GetStride(parameters.TargetFrameSize.Width, parameters.TargetFormat);

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

                fixed(byte *scaledBuffer = _decodedFrameBuffer)
                resultCode = FFmpegVideoPInvoke.ScaleDecodedVideoFrame(_decoderHandle, videoScaler.Handle, (IntPtr)scaledBuffer, videoScaler.ScaledStride);

                if (resultCode != 0)
                {
                    throw new DecoderException(
                              $"An error occurred while converting decoding video frame, {_videoCodecId} codec, code: {resultCode}");
                }

                return(new DecodedVideoFrame(_currentDecodedFrameTimestamp, new ArraySegment <byte>(_decodedFrameBuffer, 0, bufferSize), _currentFrameParameters.Width,
                                             _currentFrameParameters.Height,
                                             videoScaler.ScaledWidth, videoScaler.ScaledHeight, videoScaler.ScaledPixelFormat,
                                             videoScaler.ScaledStride));
        }
コード例 #3
0
        private void TransformTo(IntPtr buffer, int bufferStride, TransformParameters parameters)
        {
            if (!_scalersMap.TryGetValue(parameters, out FFmpegDecodedVideoScaler videoScaler))
            {
                videoScaler = FFmpegDecodedVideoScaler.Create(_currentFrameParameters, parameters);
                _scalersMap.Add(parameters, videoScaler);
            }

            int resultCode = FFmpegVideoPInvoke.ScaleDecodedVideoFrame(_decoderHandle, videoScaler.Handle, buffer, bufferStride);

            if (resultCode != 0)
            {
                throw new DecoderException($"An error occurred while converting decoding video frame, {_videoCodecId} codec, code: {resultCode}");
            }
        }
コード例 #4
0
        private void TransformTo(IntPtr buffer, int bufferStride, TransformParameters parameters)
        {
            if (!_scalersMap.TryGetValue(parameters, out FFmpegDecodedVideoScaler videoScaler))
            {
                videoScaler = FFmpegDecodedVideoScaler.Create(_currentFrameParameters, parameters);
                _scalersMap.Add(parameters, videoScaler);
            }

            lock (disposalLock) {
                if (_disposed)
                {
                    Console.WriteLine("Skipped scaling video frame, as decoder was disposed. (Therefore the frame probably wasn't wanted)");
                    return;
                }

                int resultCode = FFmpegVideoPInvoke.ScaleDecodedVideoFrame(_decoderHandle, videoScaler.Handle, buffer, bufferStride);

                if (resultCode != 0)
                {
                    throw new DecoderException($"An error occurred while converting decoding video frame, {_videoCodecId} codec, code: {resultCode}");
                }
            }
        }