radek-k / FFMediaToolkit

FFMediaToolkit is a cross-platform video decoder/encoder library for .NET that uses FFmpeg native libraries. It supports video frames extraction, reading stream metadata and creating videos from bitmaps in any format supported by FFmpeg.
MIT License
352 stars 56 forks source link

ImageSharp image -> ImageData ? #119

Closed NnWinter closed 2 years ago

NnWinter commented 2 years ago

An ImageSharp image as var img = new Image(size.Width, size.Height); file.Video.AddFrame() need ImageData

How does it convert?

hey-red commented 2 years ago

As I don't know how you load image and which pixel format it has, but here is example for Rgba32:

using var image = Image.Load<Rgba32>(@"/path/to/image.jpg");

// Copy to bytes
byte[] pixelBytes = new byte[image.Width * image.Height * Unsafe.SizeOf<Rgba32>()];
image.CopyPixelDataTo(pixelBytes);

var imageData = ImageData.FromArray(pixelBytes, ImagePixelFormat.Rgba32, image.Width, image.Height);

// Do something with ImageData

Replace Rgba32 with Rgb32 or another px format.

NnWinter commented 2 years ago

Thanks!that's exactly what I needed!