cap = cv.VideoCapture(videoFile)
print(cap.get(cv.CAP_PROP_FRAME_WIDTH))
print(cap.get(cv.CAP_PROP_FRAME_HEIGHT))
# 重新定义视频大小,并将其保存到指定路径中
fourcc = cv.VideoWriter_fourcc(*'XVID')
videoFile = os.path.join("..\\demoDatasets\\videos4", "test.avi")
out = cv.VideoWriter(videoFile, fourcc, 20, (640, 368))
assert out.isOpened(), "重塑后的视频读取失败"
while out.isOpened():
ret, frame = cap.read()
if ret:
out.write(frame)
cv.imshow('frame',frame)
if cv.waitKey(2) == ord('q'):
break
else:
break
out.release()
原因,out.wirte设置的画布大小必须和待写入的帧的大小保持一致
|