I'm using mss, numpy, and OpenCV to make my own recording software, but when I record, all of my videos end up with a 258 bytes file size (no matter the length of the video), and I can't view the video. No frames seem to be in my videos. What am I doing wrong?
Here's my code, any help would be greatly appreciated:
import datetime
import numpy as np
import cv2
import mss
import mss.tools
time_stamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
fourcc = cv2.VideoWriter_fourcc("m", "p", "4", "v")
captured_video = cv2.VideoWriter(f"{time_stamp}.mp4", fourcc, 20.0, (1080, 720))
with mss.mss() as sct:
monitor = {"top": 0, "left": 0, "width": 1080, "height": 720}
while True:
img = np.array(sct.grab(monitor))
img_final0 = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
img_final = cv2.cvtColor(img_final0, cv2.COLOR_BGR2RGB)
cv2.imshow('LevelRecorder', img_final)
capture = captured_video.write(img_final)
print(capture)
if cv2.waitKey(10) == ord("q"):
break