a432511
a432511

Reputation: 1905

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.

Upvotes: 6

Views: 11863

Answers (2)

Nuwan
Nuwan

Reputation: 123

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 :)

Upvotes: 0

Chris
Chris

Reputation: 3482

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

Upvotes: 11

Related Questions