7

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.

a432511
  • 1,907
  • 4
  • 26
  • 48

2 Answers2

11

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

Chris
  • 3,462
  • 20
  • 32
  • Awesome! Thanks. The only think you are missing is My_Timer.Start() – a432511 Oct 06 '11 at 00:25
  • @Chris Does this timer have adequate resolution? – gonzobrains Jul 19 '13 at 21:48
  • 1
    @gonzobrains yes it has millisecond accuracy of which resolutions is entirely processor dependant but it means you can have playback of 1000 FPS if you have a requirement for greater speed you can use the stopwatch class. Timer: http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx Stopwatch: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx http://stackoverflow.com/questions/7137121/c-sharp-high-resolution-timer – Chris Jul 30 '13 at 10:19
0
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 :)

Nuwan
  • 121
  • 1
  • 2
  • 8