import numpy as np
import cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'): break
else: break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
它使用python正确记录但是当我使用pyinstaller转换它时,视频会生成一个没有内容的输出.avi(0字节)。我也试过cx_freeze但结果是一样的。
答案 0 :(得分:-1)
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
您可以尝试将其更改为
out = cv2.VideoWriter('output.mp4',fourcc, 20.0, (640,480))
除了在编程中更改为mp4或wav之外,基本上我什么都不知道。但是一旦你从程序中获取文件,你可以保存文件并更改它的编码。您可以通过重命名在Windows上执行此操作。但我不了解Macs。或者,如果你想,你可以根据需要制作.exe。