Emgu Capture plays video super fast

a432511 picture a432511 · Oct 5, 2011 · Viewed 10.7k times · Source

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.

Answer

Chris picture Chris · Oct 6, 2011

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