Egor. L
Egor. L

Reputation: 169

Python OpenCv how do I detect when a video finishes playing?

I am using Python 3.5 and Opencv for an interactive video. However I can't figure out how to detect when my video finishes playing. Any ideas how I can detect when the video ends?

Thanks a bunch.

Upvotes: 4

Views: 15046

Answers (3)

Nitesh B
Nitesh B

Reputation: 1

May be this will help

with OpenCV 3

cv2.CAP_PROP_FRAME_COUNT

with OpenCV 2.4

cv2.cv.CV_CAP_PROP_FRAME_COUNT

Upvotes: 0

user8995972
user8995972

Reputation:

When ret is False, it means that the video is in the last frame.

Here is my code.You can try it.

import cv2

video_capture = cv2.VideoCapture("huge.mp4")
while True:
    ret, frame = video_capture.read()
    if ret:
        cv2.imshow('Video', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break
video_capture.release()
cv2.destroyAllWindows()

Upvotes: 8

Blue
Blue

Reputation: 663

check this link out. You can use the identifier CV_CAP_PROP_FRAME_COUNT to get the Number of frames in the video file.

Upvotes: 1

Related Questions