1
爲什麼下面的代碼不能保存視頻? 網絡攝像頭的幀速率是否與VideoWriter幀大小完全匹配也是強制性的?Opencv2:Python:cv2.VideoWriter
import numpy as np`enter code here
import cv2
import time
def videoaufzeichnung(video_wdth,video_hight,video_fps,seconds):
cap = cv2.VideoCapture(6)
cap.set(3,video_wdth) # wdth
cap.set(4,video_hight) #hight
cap.set(5,video_fps) #hight
# Define the codec and create VideoWriter object
fps = cap.get(5)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc,video_fps, (video_wdth,video_hight))
#out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
start=time.time()
zeitdauer=0
while(zeitdauer<seconds):
end=time.time()
zeitdauer=end-start
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,180)
# 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()`
videoaufzeichnung.videoaufzeichnung(1024,720,10,30)
在此先感謝您的幫助。
您的系統上是否安裝了'Xvid'編解碼器? – zindarod
是的,但我仍然有同樣的問題 – user8495738