I’m facing a strange issue while writing a set of frames as a video to disk by using the cv2.VideoWriter. In some occasions the output is rendered like this image:
This is basically the code:
out = cv2.VideoWriter(video_path, fourcc, 25, (420, 420)) for i in range(len(frames)): # Convert RGB to BGR, OpenCV expects BGR frame = frames[i][...,::-1] * 255 frame = cv2.resize(env_frame, (420, 420), interpolation=cv2.INTER_AREA) out.write(frame) out.release()
The frames are sourced from different Reinforcement Learning environments like CartPole, Minigrid or Obstacle Tower. I’ve got no issues if I record videos based on CartPole. Initially I had issues with Minigrid, but resolved these by grabbing freshly rendered frames. I did not get it to work for Obstacle Tower.
Because of Minigrid I figured that using references might be the issue as the frames may also be used elsewhere. So I used deepcopy for retrieving the frames. However, that did not resolve my problem for Obstacle Tower.
I ensured that the frames feature np.int32 values in the range 0 to 255.
I’m not sure if this is somewhat a scaling or aspect ratio issue. The Obstacle Tower frames’ dimensions are 84x84. Minigrid and Cartpole exceed my target video resolution of 420x420. Well, I can decrease Minigrid to 84x84 as well and get a good result. It remains unclear to me why this issue persists on the other source.
Does anybody have an idea on how to debug this problem? What other information could I provide?
edit: I tried varius codecs like MP4V, DIVX or MJPG.
edit2: I also plotted each image before calling write() to verify that they appear like expected.