我需要使用带有线程的cv2播放视频文件。它适用于第一个文件,但会冻结在第二个文件的第一帧并停在那里。如何解决?
from threading import Thread
import cv2
files = [ 'video_1','video_2']
def player (video):
cap = cv2.VideoCapture(video+'.mp4')
while cap.isOpened() :
time = cap.get(cv2.CAP_PROP_POS_MSEC)
fps = cap.get(cv2.CAP_PROP_FPS)
total_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print(time, fps, total_frames)
ret, frame = cap.read()
if ret == True:
cv2.imshow('frame',frame)
if cv2.waitKey(33) & 0xFF == ord('q'):
break
else:
break
for i in files :
t1 = Thread (target = player , args = (i,))
t1.start()
t1.join()