Help! RTSP Stream with IMX219-160 Camera, not connecting to VLC Player

Here is the python script I run:

import cv2
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
import numpy as np

#initialize GStreamer
Gst.init(None)

#define the pipeline string for capturing the camera feed
pipeline_str = "nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink name=mysink"

#create GStreamer pipeline
pipeline = Gst.parse_launch(pipeline_str)

#start the pipeline
pipeline.set_state(Gst.State.PLAYING)

#define RTSP URL for streaming
rtsp_url = "rtsp://127.0.0.1:8554/live"  # Change the IP address and port as needed

#initialize VideoWriter for RTSP streaming
writer = cv2.VideoWriter(rtsp_url, cv2.CAP_FFMPEG, cv2.VideoWriter_fourcc(*'H264'), 30, (1920, 1080))

#get appsink
sink = pipeline.get_by_name('mysink')

while True:
    #retrieve the captured frame from appsink
    sample = sink.emit('pull-sample')
    buf = sample.get_buffer()
    caps = sample.get_caps()
    arr = buf.extract_dup(0, buf.get_size())
    img_array = np.frombuffer(arr, np.uint8)

    #convert the raw buffer to an image
    frame = cv2.imdecode(img_array, cv2.IMREAD_COLOR)

    #check if frame dimensions are valid
    if frame is not None and frame.shape[0] > 0 and frame.shape[1] > 0:
        # Display the frame
        cv2.imshow("Video Frame", frame)

        #stream the frame over RTSP
        writer.write(frame)

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

#stop the pipeline and clean up
pipeline.set_state(Gst.State.NULL)
writer.release()
cv2.destroyAllWindows()

Here is the output I get in the terminal:

smartdoor@smartdoor-desktop:~/Documents$ python rtsp.py
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected…
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3264 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3264 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1640 x 1232 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 2
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 29.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.

Here is the output I get on VLC player on my windows laptop when this code is running:



Here is the output from running ifconfig in the terminal:
smartdoor@smartdoor-desktop:~$ ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:0c:e3:eb:4c txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.3.17.245 netmask 255.255.0.0 broadcast 10.3.255.255
inet6 fe80::d0e5:84f3:7d0a:8571 prefixlen 64 scopeid 0x20
ether 00:04:4b:e6:76:30 txqueuelen 1000 (Ethernet)
RX packets 492886 bytes 149731508 (149.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2507 bytes 289037 (289.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 151 base 0xb000

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1 (Local Loopback)
RX packets 259 bytes 23133 (23.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 259 bytes 23133 (23.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

rndis0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 56:d6:b1:4f:65:3d txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

usb0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 56:d6:b1:4f:65:3f txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 38:a3:8c:a0:e7:d3 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Hi,
We don’t have experience about launching RTSP sever in python. This would need other users to share experience. And you may try the C sample test-launch:

Jetson Nano FAQ
Q: Is there any example of running RTSP streaming?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.