AForge.Video.FFMPEG.dll中发生AccessViolationException

Pra*_*h M 5 .net ffmpeg access-violation aforge visual-c++

我有一个相机类,在这个类中我使用了一个计时器,在它的tick事件中我使用AForge.NetC++/Cli中的VideoFileWriter 保存视频(x86,.net framework:v4.6).
这不应该发生,因为这是托管代码.但即使我在try catch块中包装,程序崩溃也是因为AccessViolationException.我已经验证Image不是null.与此有关VideoFileWriter.这种情况发生在应用程序开始到运行30分钟之间.

AForge.Video.FFMPEG.dll中出现未处理的"System.AccessViolationException"类型异常附加信息:尝试读取或写入受保护的内存.这通常表明其他内存已损坏.

在Visual Studio的输出中,我看到了

test.exe中的0x0C4D689F(swscale-2.dll)抛出异常:0xC0000005:访问冲突写入位置0x09F83D80.抛出异常:AForge.Video.FFMPEG.dll中的"System.AccessViolationException"

码:

 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);        
  }
Run Code Online (Sandbox Code Playgroud)

Visual Studio显示的值很少 writer

BitRate 400000
编解码器默认
FrameRate 10
高度480
IsOpen true
宽度640


如果有人需要更多信息,请告诉我.
调用堆栈没有多大帮助

在此输入图像描述

令我惊讶的是,互联网上没有人有这个问题!
代码似乎很直接,可能是什么问题?

Joh*_*ohn 3

将编解码器指定为 AForge.Video.FFMPEG.VideoCodec.MPEG4,该错误就会消失。

  • 这个对我有用,谢谢!就我而言,我从 MemoryStream 获取位图,并将编解码器设置为 H264。您能告诉我们(如果您知道的话)为什么 MPEG4 与其他编解码器相比不会抛出异常吗?再次感谢 (3认同)