Let say I have made a program to detect a green ball in a video. Whenever there is a green ball detected, I want to print out the duration of video at the time the green ball is detected. Is it possible?
Asked
Active
Viewed 6,806 times
2 Answers
6
In this answer, you will find a solution to determine the frames per second.
so you'd want to use:
fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
and count the number of frames you're at. Then you can compute the video time with
videotime = current_frame_number / fps.
EDIT:
@Miki suggested to use CAP_PROP_POS_MSEC
which should result in the same time (in [ms])
Corrected my typo as pointed out by @Swiper-CCCVI

DomTomCat
- 8,189
- 1
- 49
- 64
-
2wouldn't be easier to use `CAP_PROP_POS_MSEC` (_Current position of the video file in milliseconds_)? – Miki Jun 08 '16 at 09:02
-
1Wouldn't that be the inverted measure of the video time? Shouldn't it actually be current_frame_number / fps instead? – BigBerger Sep 28 '17 at 22:25
2
You can simply measure a certain position in the video in milliseconds using
time_milli = cap.get(cv2.CAP_PROP_POS_MSEC)
and then divide time_milli
by 1000 to get the time in seconds.

Krishna Ojha
- 91
- 4