python 降低cpu_如何在获取帧的同时降低cpu使用率

这篇博客介绍了一个通过FFmpeg在Python中读取RTSP流并降低CPU使用率的方法。作者创建了一个`ffmpeg_videocapture`类,该类利用FFmpeg将视频流转换为管道输出的原始图像,然后用numpy处理成帧。通过在子进程中运行,实现了从多个RTSP流中同时获取帧,并在读取时有效地管理资源。
摘要由CSDN通过智能技术生成

我通过直接使用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 =

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值