How to stream webcam video over rtsp on jetson nano using python

Note that with Jetson, you would have to disable a VLC plugin, OMXIL.

Also note about corrupted frames that first 10 seconds may be trying to adjust.
You may also check with gstreamer:

gst-play-1.0 rtsp://127.0.0.1:8554/test

If this doesn’t correctly display the stream after 10 or 15s with videotestsrc, there is a problem with your system or software.

Now let’s try using your camera just reading and displaying with gstreamer:

# 640x480@30fps Raw video YUYV 4:2:2, aka YUY2 in gstreamer
gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! xvimagesink

# 640x480@30fps MJPG decoded by nvjpegdec, nvvidconv will convert and copy to system memory
gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg,format=MJPG,width=640,height=480,framerate=30/1 ! nvjpegdec ! 'video/x-raw(memory:NVMM),format=I420' ! nvvidconv ! xvimagesink

# 640x480@30fps MJPG decoded by nvv4l2decoder, nvvidconv will convert and copy to system memory
gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg,format=MJPG,width=640,height=480,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! 'video/x-raw(memory:NVMM),format=NV12' ! nvvidconv ! xvimagesink

If some of these work, you would try the respective pipelines for rtsp server:

# 640x480@30fps Raw video YUYV 4:2:2, aka YUY2 in gstreamer, encoded into H264 and sent to RTPH264
factory.set_launch('( v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 idrinterval=30 insert-vui=1 ! rtph264pay name=pay0 )')

# 640x480@30fps MJPG decoded by nvjpegdec, then encoded into H264 and sent to RTPH264
factory.set_launch('( v4l2src device=/dev/video0 ! image/jpeg,format=MJPG,width=640,height=480,framerate=30/1 ! nvjpegdec ! video/x-raw(memory:NVMM),format=I420 ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 idrinterval=30 insert-vui=1 ! rtph264pay name=pay0 )')

# 640x480@30fps MJPG decoded by nvv4l2decoder, nvvidconv will convert and copy to system memory
factory.set_launch('( v4l2src device=/dev/video0 ! image/jpeg,format=MJPG,width=640,height=480,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! video/x-raw(memory:NVMM),format=NV12 ! nvv4l2h264enc insert-sps-pps=1 idrinterval=30 insert-vui=1 ! rtph264pay name=pay0 )')

If reading from camera in MJPG works, the simplest would just be to stream in MPJG (no H264 transcoding):

factory.set_launch('( v4l2src device=/dev/video0 ! image/jpeg,format=MJPG,width=640,height=480,framerate=30/1 ! rtpjpegpay name=pay0 )')
1 Like