I am trying to use the openCV VideoWriter class to generate a video from numpy arrays. I am using the following code:
import numpy as np
import cv2
size = 720*16//9, 720
duration = 2
fps = 25
out = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc(*'X264'), fps, size)
for _ in range(fps * duration):
data = np.random.randint(0, 256, size, dtype='uint8')
out.write(data)
out.release()
The codec seems to be installed as ffmpeg can do conversions to the x264 codec and libx264 is installed. The code runs without warnings, however the videos generated seem to contain no data since I always get the following message when trying to read them with mpv:
[ffmpeg/demuxer] avi: Could not find codec parameters for stream 0 (Video: h264 (X264 / 0x34363258), none, 1280x720): unspecified pixel format
What could be the cause of this issue?