Python 上次OpenCV更新(3.3.1)使我的视频速度更快
我有下面的代码,它只是从一个摄像头制作视频 例如,用户编写“python record_video.py 20”,其中20是以秒为单位的长度。在3.3.0中,以下脚本运行良好,在3.3.1中,它可以使视频速度提高33%Python 上次OpenCV更新(3.3.1)使我的视频速度更快,python,python-3.x,opencv,Python,Python 3.x,Opencv,我有下面的代码,它只是从一个摄像头制作视频 例如,用户编写“python record_video.py 20”,其中20是以秒为单位的长度。在3.3.0中,以下脚本运行良好,在3.3.1中,它可以使视频速度提高33% def kill_video(event, time_to_wait): '''Waits for time_wait time. Then sets and event so that the timeout is marked and the video re
def kill_video(event, time_to_wait):
'''Waits for time_wait time.
Then sets and event so that the timeout is marked and the video recording
stops'''
time.sleep(time_to_wait+1) # cam always takes around 1s to warm up
event.set()
if __name__ == "__main__":
if len(sys.argv) > 1:
user_time = float(sys.argv[1])
else:
user_time = 0
vc = cv2.VideoCapture(0)
vc.set(cv2.CAP_PROP_FRAME_WIDTH, 800)
vc.set(cv2.CAP_PROP_FRAME_HEIGHT, 600)
cv2.namedWindow("video")
fourcc = cv2.VideoWriter_fourcc(*'XVID')
random_name = random_filename(5)
out = cv2.VideoWriter(random_name,fourcc, 30.0, (800,600))
event = threading.Event()
if user_time > 0:
timer = threading.Thread(target=kill_video, args=(event,user_time))
timer.start()
while(1):
start_time = time.clock() * 1000 # seconds to ms
ret,frame = vc.read()
out.write(frame)
cv2.imshow("video",frame)
end_time = time.clock() * 1000
wait_time = 33333 - (end_time - start_time)*1000
key = cv2.waitKey(int(wait_time/1000))
if key == ord('q') or event.is_set():
break
vc.release()
out.release()
cv2.destroyAllWindows()
如前所述,在当前版本3.3.1中,它使视频速度提高了33%,但我刚刚降级到3.3.0,它使视频的时间长度正确