如何使用硬件解码器在python中解码RTSP流?(NVidia JetSon Nano)

本文介绍了一种使用NVIDIA Jetson Nano与Full HD IP相机的RTSP/h264流进行GPU加速解码的方法。通过GStreamer后端与OpenCV结合实现高效视频流处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我有NVIDIA Jetson Nano和FullHD Ip相机。摄像机流RTSP / h264。我想从这台相机的python脚本中解码帧以进行分析。

CPU 解码

因此,我尝试使用类似的方法:

# import the necessary packages
from imutils.video import VideoStream
import imutils
import time
import cv2
# grab a reference to the webcam
print("[INFO] starting video stream...")
#vs = VideoStream(src=0).start()
vs = VideoStream(src="rtsp://login:password@192.168.1.180").start()
time.sleep(2.0)

# loop over frames
while True:
    # grab the next frame
    frame = vs.read()
    # resize the frame to have a maximum width of 500 pixels
    frame = imutils.resize(frame, width=500)
    # show the output frame
    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF
    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break
# release the video stream and close open windows
vs.stop()
cv2.destroyAllWindows()

那是可行的,但是以这种方式在CPU上解码帧。如何使用GPU解码器?

GPU解码

cv2.VideoCapture与GStreamer后端一起使用:

import cv2
pipeline = "rtspsrc location=\"rtsp://login:password@host:port/\" ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, format=(string)BGRx! videoconvert ! appsink"
capture = cv2.VideoCaputure(pipeline, cv2.CAP_GSTREAMER)

while capture.isOpened():
    res, frame = capture.read()
    cv2.imshow("Video", frame)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break
capture.release()
cv2.destroyAllWindows()

转载说明

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值