/// <summary> /// Converts this video frame to the <see cref="ImageData"/> with the specified pixel format. /// </summary> /// <param name="scaler">A <see cref="ImageConverter"/> object, used for caching the FFMpeg <see cref="SwsContext"/> when converting many frames of the same video.</param> /// <param name="targetFormat">The output bitmap pixel format.</param> /// <returns>A <see cref="ImageData"/> instance containg converted bitmap data.</returns> public ImageData ToBitmap(ImageConverter scaler, ImagePixelFormat targetFormat) { var bitmap = ImageData.CreatePooled(Layout, targetFormat); scaler.AVFrameToBitmap(this, bitmap); return(bitmap); }
/// <summary> /// Converts this video frame to the <see cref="ImageData"/> with the specified pixel format. /// </summary> /// <param name="converter">A <see cref="ImageConverter"/> object, used for caching the FFMpeg <see cref="SwsContext"/> when converting many frames of the same video.</param> /// <param name="targetFormat">The output bitmap pixel format.</param> /// /// <param name="targetSize">The output bitmap size.</param> /// <returns>A <see cref="ImageData"/> instance containing converted bitmap data.</returns> public ImageData ToBitmap(ImageConverter converter, ImagePixelFormat targetFormat, Size targetSize) { var bitmap = ImageData.CreatePooled(targetSize, targetFormat); // Rents memory for the output bitmap. fixed(byte *ptr = bitmap.Data) { // Converts the raw video frame using the given size and pixel format and writes it to the ImageData bitmap. converter.AVFrameToBitmap(this, ptr, bitmap.Stride); } return(bitmap); }