jetson中python使用GStreamer解码rtsp视频流


import cv2
import time


image_width = 1280
image_height = 720
rtsp_latency = 0
framerate = 5

# Define multiple URI's for each video stream
uri_list = [
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            "rtsp://admin:[email protected]:554/Streaming/Channels/101",
            ]

# Create a list to store the GStreamer pipeline for each stream
pipeline_list = []

# Create a GStreamer pipeline for each stream
for uri in uri_list:
    #gst_str = ("rtspsrc location={} latency={}  ! rtph264depay ! avdec_h264  ! videorate ! video/x-raw, framerate={}/1 ! videoconvert ! appsink sync=false").format(uri, rtsp_latency,framerate)
    #可以控制帧率
    gst_str = ("rtspsrc location={} latency={} " 
               "! rtph264depay "
               "! avdec_h264 "
               "! videorate "
               "! video/x-raw,width=(int){}, height=(int){}, framerate={}/1 "
               "! videoconvert"  
               "! appsink sync=true").format(uri, rtsp_latency,image_width,image_height,framerate)

	# 不可以控制帧率
    # gst_str = ('rtspsrc location={} latency={} ! '
    #             'rtph264depay ! h264parse ! omxh264dec ! videoconvert !'
    #             'video/x-raw, width=(int){}, height=(int){},framerate={}/1  '
    #             'x264enc tune=zerolatency bitrate=10 speed-preset=superfast '
    #             'format=(string)BGRx !'
    #             'videoconvert ! fpsdisplaysink appsink sync=false').format(uri, rtsp_latency, image_width, image_height,framerate)


    pipeline = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
    pipeline_list.append(pipeline)

# Read frames from each pipeline and display them
while True:
    for i, pipeline in enumerate(pipeline_list):
        ret, frame = pipeline.read()
        cv2.namedWindow(f"frame{i}", cv2.WINDOW_NORMAL)
        cv2.resizeWindow(f"frame{i}", 300, 300)
        cv2.imshow(f"frame{i}", frame)
        #cv2.imwrite('/home/admins/kaifa/image/'+str(i)+'.jpg',frame)

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

# Release all pipelines and destroy windows
for pipeline in pipeline_list:
    pipeline.release()

cv2.destroyAllWindows()

控制比特率但是性能会消耗更多

gst_str = ("rtspsrc location={} latency={} "
           "! rtph264depay "
           "! h264parse "
           "! avdec_h264 "
           "! videorate "
           "! video/x-raw,width=(int){},height=(int){},framerate={}/1 "
           "! x264enc bitrate=1000 speed-preset=ultrafast tune=zerolatency "
           "! queue "
           "! videoconvert "
           "! appsink sync=true").format(uri, rtsp_latency, image_width, image_height, framerate)
           

jetson中python使用GStreamer解码rtsp视频流_第1张图片

你可能感兴趣的:(GStreamr专栏,python)