Do you want to implement a video player with OpenCV?
Let's say the fps of a normal video is 24, a interval of diplaying a frame is around 41 milliseconds.
Then you should measure the execution time of the code above waitKey, denotes as exeTime, the paraemter of waitKey should be (41 - exeTime).