开发者

Emgu Capture plays video super fast

When I am playing back a video using Emgu, it plays back开发者_如何学编程 way faster than it should. Here is the relevant code.

public Form1()
{
    InitializeComponent();

    _capture = new Capture("test.avi");
    Application.Idle += RefreshFrames;
}

protected void RefreshFrames(object sender, EventArgs e)
{
    imageBox.Image = _capture.QueryFrame();
}

I tried to set the FPS using the SetCaptureProperty method on the Capture object, but it still plays in super fast motion.


The Application.Idle handle is called when no other function is being called by you program and you computer has free resources. It is not designed to be called at set periods. Instead set a timer up and use it's tick function to set the playback speed.

Timer My_Time = new Timer();
int FPS = 30;

public Form1()
{
    InitializeComponent();

    //Frame Rate
    My_Timer.Interval = 1000 / FPS;
    My_Timer.Tick += new EventHandler(My_Timer_Tick);
    My_Timer.Start();
    _capture = new Capture("test.avi");   
}

private void My_Timer_Tick(object sender, EventArgs e)
{
    imageBox.Image = _capture.QueryFrame();
}

The above code should do what you wish, Adjust FPS to get the desired playback speed. If you need anything else let me know,

Cheers

Chris


public Form1()
{
    InitializeComponent();

    _capture = new Capture("test.avi");
    Application.Idle += RefreshFrames;
}

protected void RefreshFrames(object sender, EventArgs e)
{
    imageBox.Image = _capture.QueryFrame();

    Thread.sleep(1000/FrameRate);
}

Use thread.sleep to set the play back speed to real time. you can easily achieve that using this :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜