First time here? Check out the FAQ!
answered 2016-01-23 10:27:04 -0600
the answer is in your code:
ret, frame = cap.read()
if ret is False or frame == None, you reached the end of the video file, so all you need is:
ret, frame = cap.read() if not ret: break