i'm trying to record a video clip. I have an object "observer" that created frames.
When i "imshow" images - i can see everything OK. I have an "avi" file being generated. But when i try to view it - it is empty. clip is 0 seconds of black screen.
What am i missing?
frames_count = 0
fourcc = cv2.VideoWriter_fourcc(*'XVID')
writer = cv2.VideoWriter('output.avi', fourcc, 15.0, frame_size)
while True:
img_pil = observer.get()
draw = ImageDraw.Draw(img_pil)
frame = cv2.cvtColor(np.array(img_pil), cv2.COLOR_BGR2GRAY)
writer.write(frame)
cv2.imshow(f"frame (q: {observer.q.qsize()})", frame)
frames_count = 1
if cv2.waitKey(1) & 0Xff == ord('q'):
break
if frames_count > 30:
break
writer.release()
CodePudding user response:
The issue is that the image is grayscale. This line:
writer = cv2.VideoWriter('output.avi', fourcc, 15.0, frame_size)
Should be replaced with:
writer = cv2.VideoWriter('output.avi', fourcc, 15.0, frame_size,0)