[Python] Opencv saving empty video Python

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

  1. Stack

    Stack Membro Participativo

    I am facing a problem in recording a video from camera. I am using python and opencv to do so. I have my images in QImage format, I convert them to numpy array in order to display to stream it when video capturing of the cam (using VideoCapture of opencv), everything works fine.
    When I try to record a video and save it in the folder (using VideoWriter_fourcc of opencv), I get no errors but I get an empty video. I did a lot of searching to find the problem but I couldn't.

    Here's the code that I use to record a video:

    import cv2

    fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
    #img is a numpy array
    videoWriter = cv2.VideoWriter('video.avi', fourcc, 20, (img.shape[0],img.shape[1]))
    while True:
    videoWriter.write(img)
    videoWriter.release()


    I tried to change the Framerate, the frameSize, the extension of the video and the code of codec but nothing worked.

    Any suggestion ?

    Continue reading...

Compartilhe esta Página