如何将视频文件拆分为图像?
问题描述:
我正在尝试使用Aforge.Video.DirectShow从视频文件中捕获帧,但是当我到达此行时它无法正常工作
I am trying to capture frames from a video file using Aforge.Video.DirectShow but it doesn't work properly as when I reach on this line
filesource.NewFrame += filesource_NewFrame;
它给出了一个错误线程0x2094已退出代码259(0x103)。当我尝试stepinto
it gives me an error "The thread 0x2094 has exited with code 259 (0x103)." also when i try to stepinto
filesource_NewFrame
时,它表示代码没有运行,而
it says code is not running whereas
filesource.IsRunning
为true且收到的帧数是$
is true and frames received are 0.
FileVideoSource filesource = new FileVideoSource();
filesource.Source = "C:\\Users\\Zam\\Videos\\akcent 1-cut.avi";
Console.WriteLine("Start ");
source.Start();
int i=0;
if (filesource.IsRunning)
{
Console.WriteLine("it is running and source is: "+source.Source);
while (i <= filesource.FramesReceived)
{
filesource.NewFrame += filesource_NewFrame;
Console.WriteLine("Start and execute ");
i++;
}
}
else Console.WriteLine("File is not running");
}
void filesource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
mypic.Image = new Bitmap(eventArgs.Frame, 300, 300);
Console.WriteLine("Working.....");
}
答
尝试在while循环外注册事件处理程序。
filesource.NewFrame + = filesource_NewFrame;
我还建议你创建一个表单应用程序而不是控制台应用程序来活动线程。
try registering the event handler outside the while loop.
filesource.NewFrame += filesource_NewFrame;
Also i will suggest you to create a forms application instead of console application to alive the thread.