如何诊断AccessViolationException的堆栈跟踪?

问题描述 投票:0回答:1

我正在尝试执行将一部分实时流记录到磁盘的功能。

当将实时流替换为存储在磁盘上的视频文件时,此方法起作用。

将视频文件替换为IP摄像机URL后,我可以查看实时流,但是,当我尝试记录79字节后记录代码中断时,就可以观看实时流。错误是AccessViolationException

这里是完整堆栈跟踪

System.Exception
  HResult=0x80131500
  Message=Capture error
  Source=Emgu.CV.World
  StackTrace:
   at Emgu.CV.VideoCapture.Run(ExceptionHandler eh)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Inner Exception 1:
AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

我尝试使用在此post中找到的命令

netsh winsock reset

但仅能实现相同的错误。

有人可以帮我吗?

这是我使用的方法:

private void ProcessFrame(object sender, EventArgs e)
{
    int fourcc = Convert.ToInt32(_cam1.GetCaptureProperty(CapProp.FourCC));
    string destpath = @"somepath.mp4";
    int Width = Convert.ToInt32(_cam1.GetCaptureProperty(CapProp.FrameWidth));
    int Height = Convert.ToInt32(_cam1.GetCaptureProperty(CapProp.FrameHeight));

    Mat m = new Mat();
    VideoWriter writer = new VideoWriter(destpath, -1, FPS, new Size(Width, Height), true);

    while (FrameNo < 870)
    {
        _cam1.Read(m);
        writer.Write(m);
        cam1Stream.Image = m;
        FrameNo++;

    }
    if (writer.IsOpened)
    {
        writer.Dispose();
        _cam1.Stop();

    }        
}

private void RecordButton_Click(object sender, EventArgs e)
{
    {
        _cam1 = new VideoCapture("udp://someURL", VideoCapture.API.Ffmpeg);
        FPS = _cam1.GetCaptureProperty(CapProp.Fps);
        _cam1.ImageGrabbed += ProcessFrame;
        _cam1.Start();

    }
}
c# .net stack-trace emgucv access-violation
1个回答
0
投票

仔细检查您的代码,我可以看到两个错误。

[首先,每当从捕获中抓取图像(_cam1)时,都会调用ProcessFrame,并在每次调用时重新创建(Video)写入器。确定要这样做吗?

第二,您是否检查了相机上的FPS属性是否可用?我认为不是。

我的建议是,先看看它如何在相机上运行只读循环而不尝试写入。

一旦该部分运行顺利,您可以将其向前迈出一步并尝试编写。

© www.soinside.com 2019 - 2024. All rights reserved.