Ask Your Question

Revision history [back]

Use WaitKey or Sleep Problem in MFC

We use MFC to play a video.

Question:

1.We can not use waitkey and sleep in main(UI) thread.waitkey and sleep will block main(UI) thread.

2.If we not use waitkey and sleep,how can i control video playing with different FPS?

Possible solution:

1.Can we update UI and video output in other thread(I think it is not a good idea)?

2.Waitkey or sleep in main(UI) (I think it is not a good idea)?

3.Should we PostMessage from other thread to UI thread(is it the best solution)?Can message guarantee the refresh interval?

4.Use timer to refresh UI,problem:We can not check timer is stop when stop video playing. Error example:(begin kill Timer => stop video playing => update video UI thread background=> timer update UI thread background => timer end)=>(I worry but not testing this case in my app,is it possible?)

Reference:

The function waitKey() waits for a key event infinitely (when delay <= 0) or for delay milliseconds, when it is positive. If the FPS is equal to 20, then you should wait 0,05 seconds between the consecutive frames. So put waitKey(50) after imshow() and it will be displayed at normal speed.