YOLOv8, opencv и h.264

Hello. Wrote a code in python using YOLOv8 and cv2. The video plays for a couple minutes and the model detects objects. After that the window closes itself and writes that the problem is in h.264 decoding/encoding. Could you please help to solve the problem!