下面是我使用多线程池并行播放多个视频的代码。但每个输入仅播放一个视频。我希望每个视频单独打开。未合并
import concurrent.futures
RTSP_URL = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4"
RTSP_List = [RTSP_URL, RTSP_URL, RTSP_URL, RTSP_URL]
def url_to_video(url):
video = cv2.VideoCapture(url)
while True:
_, frame = video.read()
cv2.imshow("RTSP", frame)
k = cv2.waitKey(1)
if k == ord('q'):
break
video.release()
cv2.destroyAllWindows()
while True:
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(url_to_video, RTSP_List)```
how to play each video separately.
Run Code Online (Sandbox Code Playgroud)
您只需要每个线程为 中的窗口使用不同的名称cv2.imshow,以便每个线程都会生成不同的窗口,并且您应该将它们放置在不同的地方,这样它们就不会出现在另一个之上,我只是添加到index它们中这样每个不同的窗口index都会在屏幕上有一个位置和不同的标题,而且当一个窗口完成后,你也不应该销毁所有窗口......
import concurrent.futures
import cv2
RTSP_URL = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4"
RTSP_List = [(RTSP_URL,0), (RTSP_URL,1), (RTSP_URL,2), (RTSP_URL,3)]
def url_to_video(tup):
url,index = tup
video = cv2.VideoCapture(url)
while True:
_, frame = video.read()
cv2.imshow(f"RTSP {index}", frame)
cv2.moveWindow(f"RTSP {index}", index*300, 0)
k = cv2.waitKey(1)
if k == ord('q'):
break
video.release()
while True:
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(url_to_video, RTSP_List)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
901 次 |
| 最近记录: |