问题是:VideoWriter的size与frame不一致,解决方案是:把Size调一致。
官方文档的教程包括网上大部分教程都是这样创建fourcc的:
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
然后我的文件就打不开了,后来把’XVID’改成"MJPG"就可以了:
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))