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
353 stars 56 forks source link

Crash with Access violation when trying to get info from frame #31

Closed dev-masih closed 3 years ago

dev-masih commented 3 years ago

I'm trying to get data from frames after one or two attempts the program will crash with access violation message. this sample code will crash for me all the time after just one loop.

MediaFile inputFile = MediaFile.Open(@"C:\Work\ConsoleAppTest\input.mp4");
for (int i = 0; i < inputFile.Video.Info.FrameCount; i++)
{
ImagePixelFormat tmpFramePixelFormat = inputFile.Video.ReadFrame(i).PixelFormat;
}

it's not just getting PixelFormat it can happen with getting ImageSize or even Data, is this the library issue? funny thing is the first loop won't get any error and return the correct data but the moment you get another data from the frame it will crash the console output is

The program '[14024] ConsoleAppTest.exe: Program Trace' has exited with code 0 (0x0).
The program '[14024] ConsoleAppTest.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.

I'm using dotnet core 3.1 and avcodec-58.dll, avformat-58.dll, avutil-56.dll, swresample-3.dll, swscale-5.dll 64bit libraries on the latest version of FFMediaToolkit nugget and latest visual studio

dev-masih commented 3 years ago

i tried this again with dotnet framework 4.7 and still get the crash

dev-masih commented 3 years ago

i managed to narrow it down crash happens when in function AVFrameToBitmap, library calls ffmpeg.sws_scale function in FFmpeg.AutoGen library. First call to this function is successful but after that it cases the crash