Streaming video to VLC via RTSP

Hi, I want to stream my video from python in Xavier NX.
I did some image processing and I want to stream the processed images via RTSP, so users can see it using VLC.

I have follow the instruction here:
https://forums.developer.nvidia.com/t/making-a-720p-live-video-monitoring/45228/5

I can stream videotestsrc and usb camera /dev/video0 in VLC.
Then, I try to stream my file using this command:

./test-launch “filesrc location=input.mp4 ! qtdemux ! h264parse ! rtph264pay name=pay0 pt=96”

But, when I try to open it in VLC it didn’t work.

What gives:

gst-launch-1.0 -v filesrc location=/input.mp4 ! qtdemux ! h264parse ! rtph264pay name=pay0 pt=96 ! fakesink

Be sure your file is located at /. If the file is in current directory, you would use ./input.mp4 instead.

Hi, sorry, that’s typo.

I try:

gst-launch-1.0 -v filesrc location=/home/xavier/input.mp4 ! qtdemux ! h264parse ! rtph264pay name=pay0 pt=96 ! fakesink

I got this error:

Setting pipeline to PAUSED …
Pipeline is PREROLLING …
WARNING: from element /GstPipeline:pipeline0/GstQTDemux:qtdemux0: Delayed linking failed.
Additional debug info:
./grammar.y(510): gst_parse_no_more_pads (): /GstPipeline:pipeline0/GstQTDemux:qtdemux0:
failed delayed linking some pad of GstQTDemux named qtdemux0 to some pad of GstH264Parse named h264parse0
ERROR: from element /GstPipeline:pipeline0/GstQTDemux:qtdemux0: Internal data stream error.
Additional debug info:
qtdemux.c(6073): gst_qtdemux_loop (): /GstPipeline:pipeline0/GstQTDemux:qtdemux0:
streaming stopped, reason not-linked (-1)
ERROR: pipeline doesn’t want to preroll.
Setting pipeline to NULL …
Freeing pipeline …

Thanks

Maybe it’s confused if your file has more than video stream.
Does this works ?

gst-launch-1.0 -ev filesrc location=/home/xavier/input.mp4 ! video/quicktime ! qtdemux ! h264parse ! nvv4l2decoder ! nvvidconv! xvimagesink

#Or:
gst-launch-1.0 -ev filesrc location=/home/xavier/input.mp4 ! qtdemux name=demux      demux.video_0 ! h264parse ! nvv4l2decoder ! nvvidconv! xvimagesink

Thank you for reply, but both didn’t works.
I got this error:

WARNING: erroneous pipeline: no element “qtdemux”

I try your suggestion here:
https://forums.developer.nvidia.com/t/how-to-stream-video-to-network-from-python/128732/2

My code:

import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

gst_out = “appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw,format=BGRx ! nvvidconv ! omxh264enc insert-sps-pps=true ! h264parse ! rtph264pay pt=96 ! queue ! application/x-rtp, media=video, encoding-name=H264 ! udpsink host=127.0.0.1 port=5000”

out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 20, (640, 480))

if not out.isOpened() :
print(“Writer failed”)
exit()
print(‘Writer opened’)

while True:
ret,frame = cap.read()

if not ret:
    break
#cv2.imshow("Image", frame)
out.write(frame)
cv2.waitKey(1)

out.release()
cap.release()

And try to open in VLC with sdp vlc -vvv test.sdp:

c=IN IP4 127.0.0.1
m=video 5000 RTP/AVP 96
a=rtpmap:96 H264/90000

I got error:

[0000007f58c16f40] omxil decoder debug: - OMX.Nvidia.h264.decode.secure
Bus error (core dumped)

And I try this command:

gst-launch-1.0 -ev udpsrc port=5000 ! application/x-rtp, media=video, encoding-name=H264, clock-rate=90000 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! xvimagesink

I got error:

(gst-plugin-scanner:18484): GStreamer-WARNING **: 14:01:26.427: Failed to load plugin ‘/usr/lib/arm-linux-gnueabihf/gstreamer-1.0/libgstgio.so’: /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0: undefined symbol: gst_element_foreach_sink_pad
ERROR: pipeline could not be constructed: no element “udpsrc”.

For using VLC on Jetson, you have to disable omxil plugin.

For other errors, my guess is that you’ve installed arm32 bits (I see arm-linux-gnueabihf) packages, and gstreamer gets confused with the mix. The gstreamer packages in standard JetPack installation should be enough.

1 Like

Hi, thank you very much.
I disable omxil plugin and it works in Jetson.

But, still didn’t works in PC when I run the sdp file.

Is there something missing?
Many thanks

If you want to stream to that PC only, provide its IP address in host option of udpsink, and on that PC use jetson IP address in the sdp file.

Otherwise, use multicast (example here).

Note that this is RTP/UDP streaming, not RTSP.

Hi, I try your suggestion and the multicast also.
It only works in the same Jetson.
When I try to open the sdp file using another board or PC, it didn’t works.

I try to change the cv2.VideoCapture(0) to:

gst_cap = “v4l2src device=/dev/video0 ! video/x-raw, format=(string)YUY2, width=(int)640, height=(int)480, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw(memory:NVMM), format=(string)NV12 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink”
cap = cv2.VideoCapture(gst_cap, cv2.CAP_GSTREAMER)

is this correct for usb webcam?
Thank you

The complete python:

import cv2

gst_cap = “v4l2src device=/dev/video0 ! video/x-raw, format=(string)YUY2, width=(int)640, height=(int)480, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw(memory:NVMM), format=(string)NV12 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink”

cap = cv2.VideoCapture(gst_cap, cv2.CAP_GSTREAMER)

gst_out = “appsrc ! video/x-raw, format=BGR, pixel-aspect-ratio=1/1 ! queue ! videoconvert ! video/x-raw, format=BGRx ! nvvidconv ! nvv4l2h264enc insert-vui=1 ! video/x-h264, stream-format=byte-stream, alignment=au ! h264parse ! video/x-h264, stream-format=byte-stream ! rtph264pay pt=96 config-interval=1 ! application/x-rtp, media=video, encoding-name=H264 ! udpsink host=224.1.1.1 port=5000 auto-multicast=true”

out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 20, (640, 480))
if not out.isOpened() :
print(“Writer failed”)
exit()
print(‘Writer opened’)

while True:
ret,frame = cap.read()

if not ret:
    break
#cv2.imshow("Image", frame)
out.write(frame)
cv2.waitKey(5)

out.release()
cap.release()

The sdp file:

c=IN IP4 224.1.1.1
m=video 5000 RTP/AVP 96
a=rtpmap:96 H264/90000

It works in the same board only.

Seems unexpected. Check this post if not already seen.
Check if firewall rules in host allow incoming connection from jetson into host port 5000, or check with network admin if multcast address is valid.

Hi, I try your suggestion here:
https://forums.developer.nvidia.com/t/jetson-tx2-rtsp-streaming-ffmpeg-or-gstreamer/153907/5

Run the streaming via RTSP:

./test-launch "shmsrc socket-path=/tmp/my_h264_sock ! video/x-h264, stream-format=byte-stream, width=640, height=480, framerate=30/1 ! h264parse ! video/x-h264, stream-format=byte-stream ! rtph264pay pt=96 name=pay0 "

And it works.
Thank you very much

Hi, may I ask something again?

When I try to stream the code via RTSP, I just get 1 frame only.
And, when I try to stop my python code using ctrl+c, the program won’t exit.
Then, I try to close the terminal.

If I try to run it again, I will get this error:

gst_poll_remove_fd: assertion ‘fd->fd >= 0’ failed

Many thanks

You would check again that post about managing the named socket. Be sure to clean up, otherwise another socket with slightly different name would be created and it wouldn’t work out. Check;

watch -n 1 'ls /tmp/my_h264_sock*'

I see, I can stream it again after clean up the socket file.

But, I just get 1 frame image and not a video.
I stream to PC via VLC using the jetson ip address and port rtsp://192.168.1.177:8554/test.
Do you have any idea?

Thank you

You may try adding option do-timestamp=true to shmsrc options.

Oh, you are right. It works.
Thank you.