我正在使用以下代码关注有关视频保存的OpenCV文档 .
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
height = int(cap.get(4))
width = int(cap.get(3))
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (width, height))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
当我运行它时,它工作正常,但保存的视频文件无法通过VLC /快速时间等打开 .
从openCV video saving in python i 've noticed you can change fourcc to -1 allowing you to pick your codec if you are on a windows machine. But I can' t在Mac上执行此操作(OSX 10.11.12) .
我也尝试了一些其他的四个选项,但似乎没有一个在Mac上工作 .
有什么建议?