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

Fatal error. System.AccessViolationException when trying to dispose video stream #114

Closed ggolda closed 2 years ago

ggolda commented 2 years ago

Error with library version 4.4.0, happens when I try to dispose a video stream:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at FFMediaToolkit.Decoding.Internal.Decoder.DiscardBufferedData()
   at FFMediaToolkit.Decoding.MediaStream.Dispose()
   at FFMediaToolkit.Decoding.VideoStream.Dispose()

Video stream is created using code sample below:

          MediaOptions options = new MediaOptions()
          {
              StreamsToLoad = MediaMode.Video,
              VideoPixelFormat = ImagePixelFormat.Rgba32,
          };

          _file = MediaFile.Open(filePath, options);
          if (!_file.HasVideo)
          {
              throw new Exception($"Can't create video resource. Source file of resource {id} doesn't have video stream.");
          }

          _videoStream = _file.Video;

Works fine with version 4.1.1

radek-k commented 2 years ago

Fixed in v4.4.1

ggolda commented 2 years ago

Thanks!

tghanem commented 2 years ago

Not sure if it's related to this thread but I got it when disposing the MediaOutput object in the latest version (i.e., 4.4.1).

It happens rarely, so it's very hard to repro and capture more information but I have a screenshot.

AccessViolationOnDispose