Linux · 2021-11-17

GStreamer UDP stream examples

MJPEG

Server (Ubuntu 16.04)

gst-launch-1.0 -v filesrc location= /home/rein/Videos/big_buck_bunny_720p_30mb_0_0.mp4 ! decodebin ! videoconvert ! jpegenc ! rtpjpegpay ! udpsink host=localhost port=5000

Client (Ubuntu 16.04)

gst-launch-1.0 udpsrc  port=5000 ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink

H264

Server (Ubuntu 16.04)

gst-launch-1.0 -v filesrc location=abc.mp4 ! decodebin ! videoconvert ! x264enc speed-preset=superfast tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=5000

gst-launch-1.0 -vv avfvideosrc device-index=0 ! ‘video/x-raw,format=UYVY,width=320,height=240’ ! decodebin ! videoconvert ! x264enc speed-preset=superfast tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=5000

gst-launch-1.0 -vv avfvideosrc device-index=0 ! ‘video/x-raw,format=UYVY,width=320,height=240′ ! decodebin ! videoconvert ! x264enc ! h264parse ! flvmux ! rtmpsink location=’rtmp://pili-publish.livedev.abc.com/abc’

gst-launch-1.0 -v libcamerasrc ! video/x-raw,width=640,height=480,framerate=30/1 ! decodebin ! videoconvert ! x264enc speed-preset=superfast tune=zerolatency ! rtph264pay ! udpsink host=192.168.31.188 port=5000

gstlaud libcamerasrc ! video/x-raw,width=640,height=480,framerate=30/1 ! decodebin ! v4l2convert ! video/x-raw,format=I420 ! v4l2h264enc ! “video/x-h264,level=(string)4” ! rtph264pay ! udpsink host=192.168.31.188 port=5000

 

gstlaud v4l2src device=/dev/video2 ! rawvideoparse format=uyvy width=1024 height=760 framerate=30/1 ! v4l2convert ! video/x-raw,format=I420 ! timeoverlay ! v4l2h264enc extra-controls=”controls,h264_level=12,h264_profile=1″ capture-io-mode=dmabuf bitrate=700 ! “video/x-h264,level=(string)4,bitrate=800” ! rtph264pay ! udpsink host=192.168.31.51 port=5000

gstlaud v4l2src device=/dev/video2 ! video/x-raw,width=640,height=480,framerate=30/1 ! decodebin ! videoconvert ! timeoverlay ! x264enc speed-preset=superfast tune=zerolatency ! h264parse ! flvmux ! rtmpsink location=


Client (Ubuntu 16.04)

gst-launch-1.0 udpsrc port=5000 ! application/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! autovideosink


 

Try these (You may have to install gstreamer-ugly plugins for this one)

UDP streaming from Webcam (stream over the network)

gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv,width=640,height=480' !  x264enc pass=qual quantizer=20 tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=1234

UDP Streaming received from webcam (receive over the network)

gst-launch udpsrc port=1234 ! "application/x-rtp, payload=127" ! rtph264depay ! ffdec_h264 ! xvimagesink sync=false

v4l2-ctl –list-formats-ext -d /dev/video0

vcgencmd get_camera

 

# server libcamera-vid -t 0 –width 1920 –height 1080 –codec h264 -n -l -o tcp://0.0.0.0:5001

# client gst-launch-1.0 -v tcpclientsrc host=xxx.xxx.xxx.xxx port=5001 ! decodebin ! fpsdisplaysink sync=false text-overlay=false

sudo rpi-update to get the latest kernel and firmware
- download the kernel module from https://github.com/6by9/RPiTest/blob/ma ... 35-v4l2.ko
- copy it to /lib/modules/3.12.20+/kernel/drivers/media/platform/bcm2835/ on your Pi
- amend your modprobe line to read modprobe bcm2835-v4l2 gst_v4l2src_is_broken=1
(no longer need steps 2 and 3 as the fix is in the main kernel)

sudo modprobe bcm2835-v4l2 gst_v4l2src_is_broken=1

We have 2 worlds for the camera - one GPU centric (MMAL and bcm2835_v4l2), and one ARM centric (bcm2835_unicam).

There is a full camera stack with AGC/AE/AWB control algorithms, sensor drivers, ISP drivers, residing solely within the GPU. The RPC transport layer to get to this is VCHIQ, with MMAL being the multimedia protocol on top of that.
MMAL is available either from the kernel or userspace. raspistill/raspivid do it from userspace and therefore require no additional kernel modules. bcm2835_v4l2 does it from the kernel to implement a V4L2 device.

bcm2835_unicam totally ignores all the GPU stuff, and gives you direct access to the raw CSI2 receiver peripheral. You then need a sensor driver to be able to configure the sensor - there is one for the V1.3 sensor (ov5647), but not currently for the V2.1 (imx219).
That gives you the raw Bayer image data with no control algorithms running (those are totally up to you). You also need to do a load of processing to convert from Bayer into YUV or RGB domains.

Most people want world 1, but world 2 is there for those who want the lowest level of control.

VideoCore is a bundle of peripherals connected to the system AXI busses. There are blocks for JPEG, H264, CSI2 receiver, 3D, HDMI, HVS, ISP, SPI, I2C, I2S, and a bundle of other things. Generally all of these can be accessed by anything else on the AXI bus.
One of those peripherals is a dual-core 16way SIMD processor, normally referred to as the VPU. This is what the firmware runs on, and it is the thing that often gets termed the GPU.

bcm2835_unicam ignores the VPU, and uses the ARM to talk direct to the peripheral over the AXI bus.

Using Raspberry Pi Camera

This RTSP server works with Raspberry Pi camera using :

  • the opensource V4L2 driver bcm2835-v4l2

    sudo modprobe -v bcm2835-v4l2

  • the closed source V4L2 driver for the Raspberry Pi Camera Module http://www.linux-projects.org/uv4l/

    sudo uv4l –driver raspicam –auto-video_nr –encoding h264

 

The source for the bcm2835-v4l2 kernel module is in the linux staging tree at linux/drivers/staging/vc04_services/bcm2835-camera/

You can find it e.g. in the RPF Linux repository at https://github.com/raspberrypi/linux For the current RPF Linux kernel (4.14.y) it’s at https://github.com/raspberrypi/linux/tree/rpi-4.14.y/drivers/staging/vc04_services/bcm2835-camera

It is also available in the upstream Linux repositories.

You need a version 1.0 or later of v4l2-ctl, available from:
git://git.linuxtv.org/v4l-utils.git

$ sudo modprobe bcm2835-v4l2

Turn on the overlay:

$ v4l2-ctl –overlay=1

Turn off the overlay:

$ v4l2-ctl –overlay=0

Set the capture format for video:

$ v4l2-ctl –set-fmt-video=width=1920,height=1088,pixelformat=4

(Note: 1088 not 1080).

Capture:

$ v4l2-ctl –stream-mmap=3 –stream-count=100 –stream-to=somefile.h264

Stills capture:

$ v4l2-ctl –set-fmt-video=width=2592,height=1944,pixelformat=3
$ v4l2-ctl –stream-mmap=3 –stream-count=1 –stream-to=somefile.jpg

List of available formats:

$ v4l2-ctl –list-formats

 

 

install rpicamsrc in 1.14.4
$ git clone https://github.com/thaytan/gst-rpicamsrc.git
$ cd gst-rpicamsrc
$ ./autogen.sh
$ make
$ sudo make install
$ sudo ldconfig
ONLY Raspberry Pi 32-bit OS with rpicamsrc
UDP
# get the IP address of therecievingRPi first
$ hostname -I
# start the sender, the one with the Raspicam
$gst-launch-1.0 -v rpicamsrc num-buffers=-1 ! video/x-raw, width=640, height=480, framerate=30/1clockoverlay time-format=”%D %H:%M:%S” ! videoconvert ! jpegenc !rtpjpegpay !udpsink host=192.168.178.84 port=5200
# start the reciever, the one with IP 192.168.178.84
$gst-launch-1.0 -v udpsrc port=5200 ! application/x-rtp, media=video, clock-rate=90000, payload=96 ! rtpjpegdepay ! jpegdec ! videoconvert ! autovideosink
TCP
# get the IP address of the sending RPi first
$ hostname -I
# start the sender, the one with the Raspicam and IP 192.168.178.32
gst-launch-1.0 -v rpicamsrc vflip=true awb-mode=tungsten preview=false num-buffers=-1 ! video/x-raw,width=640,height=480, framerate=30/1 ! timeoverlay time-mode=”buffer-time” ! videoconvert ! jpegenc ! tcpserversink  host=192.168.178.32 port=5000
# start the reciever and connect to the server with IP 192.168.178.32
gst-launch-1.0 tcpclientsrc host=192.168.178.32 port=5000 ! jpegdec ! videoconvert ! autovideosink

 had the same problem with on a raspberrypi 4 with gstreamer and solved it by enabling the kernel side support (often referenced as “v4l2m2m”).

You can check it is activated because you get new /dev/video character device files in addition to /dev/video0. (for me it’s 3 new files /dev/video[10,11,12]).

Check that the kernel module is loaded or load it with:

modprobe bcm2835-codec

Then gst-inspect-1.0 video4linux2 should show you the elements you are looking for, such as v4l2h264dec, v4l2h264enc, v4l2vp8dec, …. (sometimes gst-inspect-1.0 does not really retry but relies on a cache which might not reflect recent changes: removing the cache can be helpful. In my install I do rm ~/.cache/gstreamer-1.0/registry.armv8-a.bin)

 

v4l2-ctl –get-fmt-video -d /dev/video2

modprobe v4l2loopback video_nr=5 card_label=”vcam” exclusive_caps=1

 

https://www.highvoltagecode.com/post/webrtc-on-raspberry-pi-live-hd-video-and-audio-streaming

 

gpu_info.sh

vcgencmd version
echo “#########################################”
echo “memory info:”
vcgencmd get_mem arm && vcgencmd get_mem gpu

echo “#########################################”
echo “gpu temperature info:”
vcgencmd measure_temp

echo “#########################################”
echo “gpu clock info:”
for src in arm core h264 hevc isp v3d uart pwm emmc pixel vec hdmi dpi ; do
echo -e “$src:\t$(vcgencmd measure_clock $src)” ;
done

echo “#########################################”
echo “gpu volts info:”
for id in core sdram_c sdram_i sdram_p ; do
echo -e “$id:\t$(vcgencmd measure_volts $id)” ;
done

echo “#########################################”
echo “code info:”
for codec in H264 H265 HEVC MPG2 WVC1 MPG4 MJPG WMV9 ; do
echo -e “$codec:\t$(vcgencmd codec_enabled $codec)” ;
done