[Python] OpenCV_Python - Write Code for Read the Saved Video (cv2.VideoWriter())

Discussão em 'Python' iniciado por Stack, Agosto 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am a newbie in OpenCV using Python. I am currently working with a project related OpenCV using Python language. I would like to read a saved video from a frame sequence. However, I am getting an error when I execute the program to read the video. What might be wrong?

    import cv2
    import numpy as np
    import os
    import glob as gb

    filename = "VideoDataSet/dynamicBackground/canoe/input"

    img_path = gb.glob(filename)

    videoWriter = cv2.VideoWriter('test.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 25,(640,480))

    for path in img_path:
    img = cv2.imread(path)
    img = cv2.resize(img,(640,480))
    videoWriter.write(img)
    print(path)
    print ("you are success create.")


    Note: The saved video named 'test.avi' is not problem and able to play at the saved file location. The problem now is I would like to write a program code to read the video and play it. However I am getting an error.

    inputVideoName = 'test.avi'
    cap = cv2.VideoCapture(inputVideoName)

    if (cap.isOpened() == False):
    print("Error opening video stream or file!")

    while(True):
    ret, frame = cap.read()

    if ret == True:
    cv2.imshow('Display Video Clip',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):break


    This is the error:

    Error: OpenCV(3.4.1) Error: Assertion failed (chunk.m_size <= 0xFFFF) in
    cv::AVIReadContainer::readFrame, file D:\Build\OpenCV\opencv-
    3.4.1\modules\videoio\src\container_avi.cpp, line 514

    Continue reading...

Compartilhe esta Página