Simple example of writing color imagery using VideoWriter in python
I want to be able to write out a color raster for each video from in python. However, when I pass a 3d array to video writer, it generates a bad output. What am I doing wrong?
Sampled code below....
h,w = raster.shape
cmap = hot()
writer = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc('P','I','M','1'), 25, (h,w), True)
for i in range(len(images)):
x = np.transpose((dsp.normalize(images[i]**(0.5))*255).astype('uint8'))
x = (cmap(x)*255).astype('uint8')
for k in range(25):
writer.write(x)
del writer
EDIT 1: Here is a simplier, stand alone version of the problem. This hangs VLC.
import cv2
import numpy as np
x = np.random.randint(0,255,(100,100,3)).astype('uint8')
writer = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc('P','I','M','1'), 25, (100,100), True)
for k in range(100):
writer.write(x)
del writer
"it generates a bad output" -- meaning what, exactly ?
ohh, btw, it should be (w,h), not (h,w)
The avi file has size to it on disk, but VLC player wont play it. VLC doesnt give me an error, it simply hangs.