private unsafe ImageData Read(bool nextFrame) { var frame = nextFrame ? stream.GetNextFrame() : stream.DecodedFrame; // Reads the next video frame from the stream (usually in YUV pixel format). FramePosition++; // Increments stream position; var targetLayout = GetTargetSize(); // Gets the target size of the frame (it may be set by the MediaOptions.TargetVideoSize). var bitmap = ImageData.CreatePooled(targetLayout, mediaOptions.VideoPixelFormat); // Rents memory for the output bitmap. converter.AVFrameToBitmap(frame, bitmap); // Converts the raw video frame using the given size and pixel format and writes it to the ImageData bitmap. return(bitmap); }