Problem:
I'm having issues correctly rendering/playing a video created by OpenCV's videowriter.
Details:
Python does not spit out any errors and sucessfully runs through/creates the video. When I try to play the video with VLC, it looks like VLC is trying to play an empty video (it looks like it has time length 00:00). Furthermore, the video size is a mere 5kbs. I've used this function with other NumPy image arrays, and they have worked.
My NumPy Array Preparation Code:
for i in range(len(frames)-1):
fig = PIV.runPIV(frames[i].astype(np.int32),frames[i+1].astype(np.int32),dt = self.context.attrs.dt)
agg = fig.canvas.switch_backends(FigureCanvasAgg)
agg.draw() #This produces a successful image. Simple Quiver plot.
image = np.fromstring(agg.tostring_rgb(),dtype = np.uint8)
image.shape = agg.get_width_height() + (3,)
images.append(image)
self._render(images)
Images Array:
[[[191 191 191]
[191 191 191]
[191 191 191]
...,
[191 191 191]
[191 191 191]
[191 191 191]]]
Note:
This array has a shape of (640,480,3) which was what other arrays previously that worked similarly had. The only difference between this and other past successes is that before I loaded images and did processing on them before rendering, but this stack is from matplotlib.pyplot with a switched backend to FigureCanvasAgg; however, when I save the image prior to its NumPy conversion, the image looks perfectly fine.
My OpenCV VideoWriter Code:
def writeMovie(self, fileName, fps=20):
isColor = len(self[0].shape) == 3
writer = cv2.VideoWriter(fileName,
fps=fps,
fourcc=cv2.cv.CV_FOURCC(*"PIM1"),
frameSize=self[0].shape[0:2],
isColor=isColor)
for image in self:
if image.dtype == np.bool:
image = image.astype(np.uint8)*255
writer.write(image)
I will gladly provide more information to the best of my abilities to clarify and help answer this question. Any advice/suggestions will be greatly appreciated.