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

Error: "BC30668" ImageData is outdated, Type with embedded references are not supported #51

Closed smartelligence closed 3 years ago

smartelligence commented 3 years ago

I'm working with

I just downloaded/installed FFMediatoolkit and got this error message directly within my editor.

I guess using VB# is the problem since you guys use C#.

Any suggestions?

smartelligence commented 3 years ago

Others have the same issue... https://stackoverflow.com/questions/65074332/ignore-compiler-error-bc30668-types-with-embedded-references-are-not-supported

smartelligence commented 3 years ago

This seems unsolvable since this is "by design"... In the documentation is noted: FFMediaToolkit will also work with any other graphics library that supports creating images from Span, byte array or memory pointer

Is there any change to circumvent the use of the ImageData data structure?

radek-k commented 3 years ago

With the latest release, you can write the decoded bitmap directly to the WPF WriteableBitmap buffer using the TryReadFrameToPointer method

Dim file As FileStream = New FileStream("path to the video file", FileMode.Open, FileAccess.Read)
Dim media As MediaFile = MediaFile.Load(file)
Dim bmp As WriteableBimap = New WriteableBitmap(media.Video.Info.FrameSize.Width, media.Video.Info.FrameSize.Height, 96, 96, PixelFormats.Bgr24, Nothing)
bmp.Lock()
Dim decoded As Boolean = media.Video.TryReadFrameToPointer(TimeSpan.FromMinutes(1), bmp.BackBuffer, bmp.BackBufferStride)
If decoded Then
    bmp.AddDirtyRect(New Int32Rect(0, 0, media.Video.Info.FrameSize.Width, media.Video.Info.FrameSize.Height))
End If
bmp.Unlock()
imageBox.Source = bmp

You can also convert ImageData to a byte array:

Dim data() As Byte = media.Video.ReadNextFrame().Data.ToArray()