我通过直接使用FFmpeg读取帧来提高速度。也许有更好的方法来做到这一点,但这是一种认可。我想你已经在不同的过程中开始了视频捕获,对吗?否则,这也是明智的一步。在import numpy
from subprocess import Popen, PIPE
import cv2
class ffmpeg_videocapture:
def __init__(self, stream, width=640, height=360, scale=1, fps=15):
self.command = 'ffmpeg -rtsp_transport udp -i {i} -pix_fmt bgr24 -s {w}x{h} -vcodec rawvideo ' \
'-an -sn -r {fps} -f image2pipe pipe:1'
self.stream = stream
self.width = width
self.height = height
self.scale = scale
self.fps = fps
self.errors = []
self.start()
def start(self):
width = int(self.width * self.scale)
height = int(self.height * self.scale)
command = self.command.format(i=self.stream, w=width, h=height, fps=self.fps)
self.capture =