python 多线程调用同一个视频_如何在python中使用OpenCV、多线程、队列同时运行多个视频?...

我尝试使用opencv、多线程和队列同时运行两个视频。然而,两个队列都被帧填满,但是视频不会同时运行,而是一个接一个地运行。有没有什么方法可以让我们使用多线程或多处理队列同时制作多个视频?在import os

import threading

import queue as Queue

import cv2

video_path_1 = '/home/big_buck_bunny.mp4'

video_path_2 = '/home/cup.mp4'

class MyThread (threading.Thread):

maxRetries = 22

def __init__(self, thread_id, name, video_url, thread_lock):

threading.Thread.__init__(self)

self.thread_id = thread_id

self.name = name

self.video_url = video_url

self.thread_lock = thread_lock

self.Q = Queue.Queue(maxsize=128)

def run(self):

print("Starting " + self.name)

cap = cv2.VideoCapture(self.video_url)

while True:

ret, frame = cap.read()

if ret == True:

self.Q.put(frame)

def view(self):

print('start view')

while self.Q.qsize()>0:

print('true')

cv2.imshow('self.1', self.Q.get())

if cv2.waitKey(1) & 0xFF == ord('q'):

break

else:

print('false')

def main():

thread_lock = threading.Lock()

thread1 = MyThread(1, "Thread 1", video_path_1, thread_lock)

thread2 = MyThread(2, "Thread 2", video_path_2, thread_lock)

thread1.start()

thread2.start()

cv2.imshow('1', thread2.Q.get())

cv2.imshow('23', thread1.Q.get())

print("Exiting Main Thread")

thread1.view()

thread2.view()

if __name__ == '__main__':

main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值