GStreamer - stream video to IP

Hello, I have a problem with streaming my webcam video to IP, I have no idea how to do it
I’m working on Jetson Nano 2GB

My camera works just fine if I use :

gst-launch-1.0 v4l2src device=\"/dev/video0\" ! xvimagesink 

I tried variety of combinations from all around internet D:

#gst-launch-1.0 v4l2src device=\"/dev/video0\" ! xvimagesink 
#gst-launch-1.0 -vv -e videotestsrc ! queue ! x264enc bitrate=5000 ! mpegtsmux alignment=7 ! rndbuffersize max=1316 min=1316 ! udpsink host=127.0.0.1 port=5000
#gst-launch-1.0 v4l2src device=/dev/video0 ! qtdemux ! h264parse config-interval=-1 ! rtpmp2tpay ! udpsink host=127.0.0.1 port=9001 sync=true
#gst-launch-1.0 -v v4l2src device=/dev/video0 ! rtpvrawpay ! udpsink host=127.0.0.1 port=5000
#gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoscale ! videoconvert ! x264enc ! rtph264pay config-interval=10 pt=96 ! udpsink host=127.0.0.1 port=5000
#gst-launch-1.0 v4l2src device=/dev/video1 io-mode=2 ! image/jpeg,width=3840,height=2160,framerate=30/1 ! nvjpegdec ! video/x-raw ! omxh265enc ! rtph265pay name=pay0 pt=96
#ffmpeg -i rtsp://user:password@192.168.18.209:554 -framerate 15 -s 720x480 -c:v libx264 -preset slower -crf 17 -async 1 -vsync 1 -f mpegts udp://192.168.18.178:5006
#ffmpeg -i /dev/video0 -f matroska -vcodec libx264 pipe:1|ffplay -i pipe:0
#gst-launch-1.0 uvch264src device=/dev/video0 initial-bitrate=4000000 average-bitrate=4000000 iframe-period=3000 name=src auto-start=true \
 #        src.vidsrc ! queue ! video/x-h264,width=1280,height=720,framerate=30/1 ! h264parse ! rtph264pay ! udpsink host=127.0.0.1 port=5602
# gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoscale ! videoconvert ! x264enc ! rtph264pay config-interval=10 pt=96 ! udpsink host=127.0.0.1 port=5000
# gst-launch-1.0 v4l2src device=/dev/video0 ! rndbuffersize max=1316 min=1316 ! udpsink host=127.0.0.1 port=5000
#gst-launch-1.0 v4l2src device=/dev/video0 ! h264parse config-interval=-1 ! rtph264pay pt=96 ! udpsink host=192.168.10.153 port=9001
#gst-launch-1.0 -vv -e v4l2src device=/dev/video0 ! "video/x-raw,width=1280,height=720,framerate=10/1"\ ! queue ! x264enc speed-preset=1 ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=192.255.10.41 port=5004
# gst-launch-1.0 -vv -e v4l2src device=/dev/video0  \
# ! videoscale \
# ! "video/x-raw,width=352,height=288,framerate=10/1" \
# ! queue  \
# ! x264enc speed-preset=1 \
# ! h264parse \
# ! mpegtsmux ! rtpmp2tpay ! udpsink host=239.255.12.42 port=5004
# gst-launch-1.0 -ve v4l2src \
# ! video/x-raw, framerate=30/1 \
# ! videoconvert \
# ! x264enc noise-reduction=10000 speed-preset=fast tune=zerolatency byte-stream=true threads=4 key-int-max=15 intra-refresh=true  \
# ! rtph264pay pt=96 \
# ! udpsink host=localhost port=5000

For each one I tried to open the given IP and Port via VLC Player - Connect via Network
Only this one execute without terminal errors :

gst-launch-1.0 v4l2src device=/dev/video0 ! rndbuffersize max=1316 min=1316 ! udpsink host=127.0.0.1 port=5000

image
But I still can’t get vision from camera in VLC

Simplest solution would be to build test-launch RTSP minimal server and try : Is there any example of running RTSP streaming? in https://forums.developer.nvidia.com/t/jetson-nano-faq/82953. You may aslo check this topic in case of trouble.

When done, you would be able to test with:

test-launch "v4l2src device=/dev/video0 ! nvvidconv ! nvvh264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0"

# EDIT: Typo above. Should be :
test-launch "v4l2src device=/dev/video0 ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0"

Hi,
It seems not easy to receive/decode UDP stream in VLC. Please try RTSP as Honey Patouceul has suggested.

If other users know the tip of receiving UDP stream, please kindly share the method. Thanks.

For reading RTP/UDP stream from vlc, you would need a sdp file on receiver side.
You may look at this example using multicast:

Ok, so I followed the FAQ example, and with “videotestsrc” lunch, and if I open it by

$ gst-launch-1.0 uridecodebin uri=rtsp://127.0.0.1:8554/test ! nvoverlaysink

from example, it successfully shows a test screen (that colors and noise :P ), but If I try to open it by VLC then the program close itself, on another device I just get an error that it can’t connect (I’m I the same network on all devices)

If I use this command :

$ ./test-launch "v4l2src device=/dev/video0 ! nvvidconv ! nvvh264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0"

It seems to work (“stream ready …”), but when I try to open it :
VLC behaves as previously, and

$ gst-launch-1.0 uridecodebin uri=rtsp://127.0.0.1:8554/test ! nvoverlaysink

is no longer working :

gst-launch-1.0 uridecodebin uri=rtsp://127.0.0.1:8554/test ! nvoverlaysink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://127.0.0.1:8554/test
Progress: (open) Retrieving server options
Progress: (open) Retrieving media info
ERROR: from element /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source: Unhandled error
Additional debug info:
gstrtspsrc.c(6161): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source:
Service Unavailable (503)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

Seems the pipeline in test-launch failed to run.
It’s hard to tell more for now, it would help to know the camera capabilities:

# v4l2-ctl is provided by apt package v4l-utils
v4l2-ctl -d0 --list-formats-ext

# Your working case with some details
gst-launch-1.0 -v v4l2src device=/dev/video0 ! xvimagesink 

Maybe it sends a format that is not accepted by nvvidconv. First try with gst-launch-1.0 just adding fakesink at the end of the pipeline:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! nvvidconv ! nvvh264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0 ! fakesink

What the errors ?

You may try to add videoconvert:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! nvvidconv ! nvvh264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0 ! fakesink

If this works, you would try with test-launch, removing fakesink.

Here what I got.
My camera:

$ v4l2-ctl -d0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'MJPG' (compressed)
	Name        : Motion-JPEG
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
	Index       : 1
	Type        : Video Capture
	Pixel Format: 'YUYV'
	Name        : YUYV 4:2:2
		Size: Discrete 1280x720
			Interval: Discrete 0.100s (10.000 fps)
		Size: Discrete 640x480
			Interval: Discrete 0.040s (25.000 fps)

Working case :

$ gst-launch-1.0 -v v4l2src device=/dev/video0 ! xvimagesink 
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720, framerate=(fraction)10/1, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstXvImageSink:xvimagesink0.GstPad:sink: caps = video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720, framerate=(fraction)10/1, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:06.155449338
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

Commands from you :

$ gst-launch-1.0 -v v4l2src device=/dev/video0 ! nvvidconv ! nvvh264enc insert-sps-pps=1 insert-vui=1 ! h264parse !     rtph264pay name=pay0 ! fakesink
WARNING: erroneous pipeline: no element "nvvh264enc"
$ gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! nvvidconv ! nvvh264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0 ! fakesink
WARNING: erroneous pipeline: no element "nvvh264enc"

Sorry…the encoder is nvv4l2h264enc:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0 ! fakesink

gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0 ! fakesink
legion@legion-desktop:~$ gst-launch-1.0 -v v4l2src device=/dev/video0 ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0 ! fakesink
Setting pipeline to PAUSED ...
Opening in BLOCKING MODE 
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = video/x-raw, width=(int)1280, height=(int)720, framerate=(fraction)10/1, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
/GstPipeline:pipeline0/Gstnvvconv:nvvconv0.GstPad:src: caps = video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, framerate=(fraction)10/1, pixel-aspect-ratio=(fraction)1/1, format=(string)I420, interlace-mode=(string)progressive
/GstPipeline:pipeline0/nvv4l2h264enc:nvv4l2h264enc0.GstPad:src: caps = video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)NULL, level=(string)NULL, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)10/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:sink: caps = video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)NULL, level=(string)NULL, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)10/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2
Redistribute latency...
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
/GstPipeline:pipeline0/nvv4l2h264enc:nvv4l2h264enc0.GstPad:sink: caps = video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, framerate=(fraction)10/1, pixel-aspect-ratio=(fraction)1/1, format=(string)I420, interlace-mode=(string)progressive
/GstPipeline:pipeline0/Gstnvvconv:nvvconv0.GstPad:sink: caps = video/x-raw, width=(int)1280, height=(int)720, framerate=(fraction)10/1, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
H264: Profile = 66, Level = 0 
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:src: caps = video/x-h264, stream-format=(string)avc, alignment=(string)au, profile=(string)constrained-baseline, level=(string)3.1, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)10/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true, codec_data=(buffer)0142401fffe1001c6742401f965402802dd350000054000003000400000300523c2211a801000468ce3c80
/GstPipeline:pipeline0/GstRtpH264Pay:pay0.GstPad:src: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)42401f, sprop-parameter-sets=(string)"Z0JAH5ZUAoAt01AAAFQAAAMABAAAAwBSPCIRqA\=\=\,aM48gA\=\=", payload=(int)96, ssrc=(uint)2515986560, timestamp-offset=(uint)2128799388, seqnum-offset=(uint)7648, a-framerate=(string)10
/GstPipeline:pipeline0/GstFakeSink:fakesink0.GstPad:sink: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)42401f, sprop-parameter-sets=(string)"Z0JAH5ZUAoAt01AAAFQAAAMABAAAAwBSPCIRqA\=\=\,aM48gA\=\=", payload=(int)96, ssrc=(uint)2515986560, timestamp-offset=(uint)2128799388, seqnum-offset=(uint)7648, a-framerate=(string)10
/GstPipeline:pipeline0/GstRtpH264Pay:pay0.GstPad:sink: caps = video/x-h264, stream-format=(string)avc, alignment=(string)au, profile=(string)constrained-baseline, level=(string)3.1, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)10/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true, codec_data=(buffer)0142401fffe1001c6742401f965402802dd350000054000003000400000300523c2211a801000468ce3c80
/GstPipeline:pipeline0/GstRtpH264Pay:pay0: timestamp = 2128802837
/GstPipeline:pipeline0/GstRtpH264Pay:pay0: seqnum = 7648
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:02.596071539
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
legion@legion-desktop:~$ gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0 ! fakesink
Setting pipeline to PAUSED ...
Opening in BLOCKING MODE 
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = video/x-raw, width=(int)1280, height=(int)720, framerate=(fraction)10/1, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:src: caps = video/x-raw, width=(int)1280, height=(int)720, framerate=(fraction)10/1, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
/GstPipeline:pipeline0/Gstnvvconv:nvvconv0.GstPad:src: caps = video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, framerate=(fraction)10/1, pixel-aspect-ratio=(fraction)1/1, format=(string)I420, interlace-mode=(string)progressive
/GstPipeline:pipeline0/nvv4l2h264enc:nvv4l2h264enc0.GstPad:src: caps = video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)NULL, level=(string)NULL, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)10/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:sink: caps = video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)NULL, level=(string)NULL, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)10/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2
Redistribute latency...
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
/GstPipeline:pipeline0/nvv4l2h264enc:nvv4l2h264enc0.GstPad:sink: caps = video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, framerate=(fraction)10/1, pixel-aspect-ratio=(fraction)1/1, format=(string)I420, interlace-mode=(string)progressive
/GstPipeline:pipeline0/Gstnvvconv:nvvconv0.GstPad:sink: caps = video/x-raw, width=(int)1280, height=(int)720, framerate=(fraction)10/1, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:sink: caps = video/x-raw, width=(int)1280, height=(int)720, framerate=(fraction)10/1, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
H264: Profile = 66, Level = 0 
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:src: caps = video/x-h264, stream-format=(string)avc, alignment=(string)au, profile=(string)constrained-baseline, level=(string)3.1, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)10/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true, codec_data=(buffer)0142401fffe1001c6742401f965402802dd350000054000003000400000300523c2211a801000468ce3c80
/GstPipeline:pipeline0/GstRtpH264Pay:pay0.GstPad:src: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)42401f, sprop-parameter-sets=(string)"Z0JAH5ZUAoAt01AAAFQAAAMABAAAAwBSPCIRqA\=\=\,aM48gA\=\=", payload=(int)96, ssrc=(uint)4227956481, timestamp-offset=(uint)2721908892, seqnum-offset=(uint)20077, a-framerate=(string)10
/GstPipeline:pipeline0/GstFakeSink:fakesink0.GstPad:sink: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)42401f, sprop-parameter-sets=(string)"Z0JAH5ZUAoAt01AAAFQAAAMABAAAAwBSPCIRqA\=\=\,aM48gA\=\=", payload=(int)96, ssrc=(uint)4227956481, timestamp-offset=(uint)2721908892, seqnum-offset=(uint)20077, a-framerate=(string)10
/GstPipeline:pipeline0/GstRtpH264Pay:pay0.GstPad:sink: caps = video/x-h264, stream-format=(string)avc, alignment=(string)au, profile=(string)constrained-baseline, level=(string)3.1, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)10/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true, codec_data=(buffer)0142401fffe1001c6742401f965402802dd350000054000003000400000300523c2211a801000468ce3c80
/GstPipeline:pipeline0/GstRtpH264Pay:pay0: timestamp = 2721912552
/GstPipeline:pipeline0/GstRtpH264Pay:pay0: seqnum = 20077
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:03.651083881
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

It’s running - nothing is happening, but the process is running and I need to end it with Ctrl+C

Yes, it’s normal you don’t see more, but good news, seems working, so you can try with test-launch:

test-launch "v4l2src device=/dev/video0 ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 insert-vui=1 ! h264parse ! rtph264pay name=pay0"

Unfortunately, I still can’t receive the video :(

$ gst-launch-1.0 uridecodebin uri=rtsp://127.0.0.1:8554/test ! nvoverlaysink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://127.0.0.1:8554/test
Progress: (open) Retrieving server options
Progress: (open) Retrieving media info
ERROR: from element /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source: Unhandled error
Additional debug info:
gstrtspsrc.c(6161): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source:
Service Unavailable (503)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

VLC can’t open as well

Hi,
Please check if you can run this:

The steps work on all Jetson platforms, although the topic is about TX2.