[Python] cv2 cap.read() returns FALSE when reading a mp4 file

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am running this on Google Colab.

    cap = cv2.VideoCapture(INPUT_VIDEO_PATH)
    if not cap.isOpened():
    print(f"Error: Could not open video file: {INPUT_VIDEO_PATH}")
    else:
    print(f"Processing video: {INPUT_VIDEO_PATH}")

    count = cap.get(cv2.CAP_PROP_FRAME_COUNT)
    print(f"Total number of frames: {count}")
    while True:
    ret, frame = cap.read()
    print(ret,frame)
    if not ret:
    print("End of video reached.")
    break
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
    break
    cap.release()


    Expecting frames but getting this instead:

    Processing video: /content/input.mp4 Total number of frames: 13075.0 False None End of video reached.

    since it gives me frame count it means I have successfully read the file, but I can not get any frame, any ideas ?

    Continue reading...

Compartilhe esta Página