Error in Writing Video

Hi,

I am building a video classification model same as in this video: Video Classification using Deep Learning Python Project - Classification Process - AI Course 2020 - YouTube

The model predicts which sport is being shown in the video: Tennis, swimming or Boxing.

I already built my model and has a 96% accuracy.
Now, I have a sample video to test my model.

from keras.models import load_model
from collections import deque
import numpy as np
import pickle
import cv2
model = load_model(r"C:\Users\yudishteer.c\Desktop\VideoClassification\video_classification_model\videoclassificationModel")
lb = pickle.loads(open(r"C:\Users\yudishteer.c\Desktop\VideoClassification\video_classification_model\videoclassificationBinarizer.pickle", "rb").read())
outputvideo = r"C:\Users\yudishteer.c\Desktop\VideoClassification\video_classification_model\outputvideo\demo_output.avi"
mean = np.array([123.68, 116.779, 103.939], dtype = "float32")
Queue = deque(maxlen=128)
capture_video = cv2.VideoCapture(r"C:\Users\yudishteer.c\Desktop\VideoClassification\video_classification_model\demo_video.mp4")
writer = None
(Width, Height) = (None, None)

while True:
    (taken, frame) = capture_video.read()
    if not taken:
        break
    if Width is None or Height is None:
        (Width, Height) = frame.shape[:2]
        
    output = frame.copy()
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    frame = cv2.resize(frame, (224,224)).astype("float32")
    frame -= mean
    preds = model.predict(np.expand_dims(frame, axis=0))[0]
    Queue.append(preds)
    results = np.array(Queue).mean(axis = 0)
    i = np.argmax(results)
    label = lb.classes_[i]
    text = "The game is {}".format(label)
    cv2.putText(output, text, (45,60), cv2.FONT_HERSHEY_SIMPLEX, 1.25, (255,0,0),5)
    
    if writer is None:
        fourcc = cv2.VideoWriter_fourcc(*'MJPG')
        writer = cv2.VideoWriter('demo_output.mp4', fourcc, 10, (Width, Height), True)
    writer.write(output)
    cv2.imshow("In progress", output)
    key = cv2.waitKey(1) & 0xFF
    
    if key == ord("q"):
        break
        
print("Finalizing.......")
writer.release()
capture_video.release()
# Closes all the frames
cv2.destroyAllWindows()

When I run the above code, I can see it being classified correctly.
That is the demo video(demo_video.mp4) is opened and I can see either Swimming, Tennis or Boxing being displayed at the top of the video depending on the sport being shown.

However, since I have a:
writer = cv2.VideoWriter(‘demo_output.mp4’, fourcc, 10, (Width, Height), True)

when I open my demo_output.mp4 or even avi, I get:

Can someone help what is wrong?
thanks!

print(cv2.getBuildInformation())
assert writer.isOpened()

an mp4 container might not allow MJPEG content. try “avi”, which is built into OpenCV, or “mov” or “mkv”.

cross-post: