Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AccessViolationException occurred in AForge.Video.FFMPEG.dll

I have a camera class, in this class I used a timer and in its tick event I am saving video using AForge.Net's VideoFileWriter in C++/Cli (x86, .net framework: v4.6).
This is not supposed to happen, as this is managed code. But even if I wrap in try catch block, program crashes because of AccessViolationException. I have verified that Image is not null. Something to do with VideoFileWriter. This happens anytime between app start to 30 minutes of running.

An unhandled exception of type 'System.AccessViolationException' occurred in AForge.Video.FFMPEG.dll Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

In Visual Studio's output I see

Exception thrown at 0x0C4D689F (swscale-2.dll) in test.exe: 0xC0000005: Access violation writing location 0x09F83D80. Exception thrown: 'System.AccessViolationException' in AForge.Video.FFMPEG.dll

code:

 private: System::Void Video_Recorder_Tick(System::Object^  sender, System::Timers::ElapsedEventArgs^  e)
  {
      Bitmap^ save = ConvertMatToBitmap(image); //function to convert opencv's Mat to .net's Bitmap        
      if(writer!= nullptr)
       writer->WriteVideoFrame(save);
       delete save;
   }

  VideoFileWriter ^writer = gcnew VideoFileWriter();

  private: Void load_VideoWriter()
  {
    writer->Open("C:/video.avi", 640, 480, 10, VideoCodec::Default);        
  }

Visual Studio showed few values for writer

BitRate 400000
Codec Default
FrameRate 10
Height 480
IsOpen true
Width 640


Let me know if anybody needs more info.
call stack didn't help much

enter image description here

To my surprise no one on internet is having this issue!
Code seems straight forward, what could possibly be the issue?

like image 561
Prakash M Avatar asked Oct 30 '22 07:10

Prakash M


1 Answers

Specify the codec as AForge.Video.FFMPEG.VideoCodec.MPEG4 and that error should go away.

like image 64
John Avatar answered Nov 11 '22 08:11

John