I am using OpenCV to extract frames from a video. It opened sucessfully but failed to capture any frames. Anyone knows what the problem might be? Thanks. I used the codes below, not sure if it helps with anything but just in case it does:
import cv2
video_path = "input.mp4"
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print("Error: Could not open video.")
exit()
while True:
ret, frame = cap.read()
if not ret:
print("Reached the end of the video.")
break
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Tried changing the format to .mov and .mp4. Did not help
New contributor
Orange Capybara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.