If you mean the number of frames, then that question has already been answered here:
http://lovelace.augustana.edu/q2a/index.php/126/how-to-use-the-slider-to-change-frames
If you want the duration in seconds, then you can take the number of frames (see previous answer) and divide the number of frames by the framerate (in frames per second), which I think you can get by doing:
vidCap.get(Videoio.CV_CAP_PROP_FPS);
where vidCap is an opencv VideoCapture object.