Home > Net >  cv2.VideoWriter() returns strange video
cv2.VideoWriter() returns strange video

Time:11-23

I am using this function (inside a class) to save an array of images into a video. Despite the program running with no errors, the video I got, in the end, is not what was expected. It has a stripy effect even though when I print the images individually everything is ok.

def saveVideo(self):
        import cv2
        out = cv2.VideoWriter("output.mp4", cv2.VideoWriter_fourcc(*'mp4v'), self.fps, (160, 122), 0)
        for i in range(0, len(self.images)):
            out.write(self.images[i])
        out.release()

The video I get

Update: What happens is that the image in the video looks like the original image stretched, flipped, and with the black bars in the middle. There must be a problem with the video shape but I cannot manage to solve it.

CodePudding user response:

Have you tried casting the images to uint8? Try:

np.uint8(self.images[i])

CodePudding user response:

I'd say try

fourcc = cv2.VideoWriter_fourcc(*'XVID')

instead of

cv2.VideoWriter_fourcc(*'mp4v')

so like this

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter("output.mp4", fourcc, self.fps, (160, 122), 0)
  • Related