由查得的方法总结,可能存在的问题包括几方面:
1.编码方式不对
2.视频写入的图像尺寸与画布尺寸不对应
转载 https://blog.csdn.net/weixin_48994268/article/details/114458138
import numpy as np
import cv2
cap = cv2.VideoCapture('test.mp4')
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print("width:",width, "height:", height)
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (width, height))
while (cap.isOpened()):
ret, frame = cap.read()
if ret == True:
out.write(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()