Beispiel #1
0
        public int DecodeFrame(Surface output, ReadOnlySpan <byte> bitstream)
        {
            FFmpegApi.av_frame_unref(output.Frame);

            int result;
            int gotFrame;

            fixed(byte *ptr = bitstream)
            {
                _packet->Data = ptr;
                _packet->Size = bitstream.Length;
                result        = _decodeFrame(_context, output.Frame, &gotFrame, _packet);
            }

            if (gotFrame == 0)
            {
                FFmpegApi.av_frame_unref(output.Frame);

                // If the frame was not delivered, it was probably delayed.
                // Get the next delayed frame by passing a 0 length packet.
                _packet->Data = null;
                _packet->Size = 0;
                result        = _decodeFrame(_context, output.Frame, &gotFrame, _packet);

                // We need to set B frames to 0 as we already consumed all delayed frames.
                // This prevents the decoder from trying to return a delayed frame next time.
                _context->HasBFrames = 0;
            }

            FFmpegApi.av_packet_unref(_packet);

            if (gotFrame == 0)
            {
                FFmpegApi.av_frame_unref(output.Frame);

                return(-1);
            }

            return(result < 0 ? result : 0);
        }
Beispiel #2
0
 public void Dispose()
 {
     FFmpegApi.av_frame_unref(Frame);
     FFmpegApi.av_free(Frame);
 }