AVI file created using XVID but video not playing

After running the code, the webcam opens but the saved video cannot be played, it says it’s corrupted and it’s size is 6kb everytime. I’m guessing it happens because pycharm keeps giving an error under *“XVID” saying unexpected argument. I’ve tried other codecs and tried saving it as mp4 but nothing works. My opencv is also updated. How do I fix this?
Here’s the code:

import cv2

vid = cv2.VideoCapture(0, cv2.CAP_DSHOW)

fourcc = cv2.VideoWriter_fourcc(*"XVID")
output = cv2.VideoWriter("G:/output.avi", int(fourcc), 20.0, (600, 480), True)

while vid.isOpened():
    ret, frame = vid.read()
    if ret == True:
        # frame = cv2.resize(frame,(600,500))
        cv2.imshow('frame', frame)
        k = cv2.waitKey(10)
        if k == ord('q'):

so, your output expects images of size 600x480, and will reject misfits on write() , so you end up with an empty movie !

(600, 480), again …

1 Like

i tried to fix it as you said and it actually works now, thank you so much!!

1 Like