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

Fix System.AccessViolationException in InputContainer.OnDisposing #71

Closed jrz371 closed 3 years ago

jrz371 commented 3 years ago

I get a random System.AccessViolationException in the InputContainer.OnDisposing. I have a media file I open and close semi frequently to grab a single frame from.

I see you're getting around avformat_close_input setting the input to null by passing it a copy of the pointer and not a real one. This is so you can free those other resources in the section I'm removing with this commit.

The FFmpeg docs say that avformat_close_input frees the AVFormatContext and all its contents. Those pointers are dangling and should be set null in FFmpeg but are not. This crash pops up because that memory has already been freed.

avformat_close_input calls avio_close at the end which in turns frees the buffer and pb which are you attempting to delete.

By removing this bit I fix my crash and resolves the issues with deleting the AVFormatContext