﻿{"id":2190,"date":"2021-11-17T10:51:13","date_gmt":"2021-11-17T02:51:13","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=2190"},"modified":"2021-11-25T16:54:44","modified_gmt":"2021-11-25T08:54:44","slug":"%e7%94%a8%e6%a0%91%e8%8e%93%e6%b4%be%e5%81%9a-rtmp-%e6%b5%81%e7%9b%b4%e6%92%ad%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%8c%e5%8f%af%e6%8e%a8%e9%80%81%e8%87%b3%e6%96%97%e9%b1%bc%e7%9b%b4%e6%92%ad","status":"publish","type":"post","link":"https:\/\/nick.txtcc.com\/index.php\/linux\/2190","title":{"rendered":"GStreamer UDP stream examples"},"content":{"rendered":"<h1 dir=\"auto\">MJPEG<\/h1>\n<h2 dir=\"auto\">Server (Ubuntu 16.04)<\/h2>\n<pre><code>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\n<\/code><\/pre>\n<h2 dir=\"auto\">Client (Ubuntu 16.04)<\/h2>\n<pre><code>gst-launch-1.0 udpsrc  port=5000 ! application\/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink\n<\/code><\/pre>\n<h1 dir=\"auto\">H264<\/h1>\n<h2 dir=\"auto\">Server (Ubuntu 16.04)<\/h2>\n<pre><code>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\n<\/code><\/pre>\n<p class=\"p1\"><span class=\"s1\">gst-launch-1.0 -vv avfvideosrc device-index=0 ! &#8216;video\/x-raw,format=UYVY,width=320,height=240&#8217; ! decodebin ! videoconvert ! x264enc speed-preset=superfast tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=5000<\/span>\n<code><\/code><\/p>\n<p class=\"p1\"><span class=\"s1\">gst-launch-1.0 -vv avfvideosrc device-index=0 ! &#8216;video\/x-raw,format=UYVY,width=320,height=240&#8242; ! decodebin ! videoconvert ! x264enc ! h264parse ! flvmux ! rtmpsink location=&#8217;rtmp:\/\/pili-publish.livedev.abc.com\/abc&#8217;<\/span><\/p>\n<pre><code><\/code><\/pre>\n<p class=\"p1\"><span class=\"s1\">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<\/span><\/p>\n<pre><code><\/code><\/pre>\n<p class=\"p1\"><span class=\"s1\">gstlaud libcamerasrc ! video\/x-raw,width=640,height=480,framerate=30\/1 ! decodebin ! v4l2convert ! video\/x-raw,format=I420 ! v4l2h264enc ! &#8220;video\/x-h264,level=(string)4&#8221; ! rtph264pay ! udpsink host=192.168.31.188 port=5000<\/span><\/p>\n<p>&nbsp;<\/p>\n<p class=\"p1\"><span class=\"s1\">gstlaud v4l2src device=\/dev\/video2 ! rawvideoparse format=uyvy width=1024 height=760 framerate=30\/1 ! v4l2convert ! video\/x-raw,format=I420 ! <\/span>\n<span class=\"s1\">timeoverlay <\/span>\n<span class=\"s1\">! v4l2h264enc extra-controls=&#8221;controls,h264_level=12,h264_profile=1&#8243; capture-io-mode=dmabuf <\/span>\n<span class=\"s1\">bitrate=700 <\/span>\n<span class=\"s1\">! &#8220;video\/x-h264,level=(string)4,bitrate=800&#8221; ! rtph264pay ! udpsink host=192.168.3<\/span>\n<span class=\"s1\">1.51 port=5000<\/span><\/p>\n<pre><code><\/code><\/pre>\n<p class=\"p1\"><span class=\"s1\">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=<\/span><\/p>\n<pre><code>\n<\/code><\/pre>\n<h2 dir=\"auto\">Client (Ubuntu 16.04)<\/h2>\n<pre><code>gst-launch-1.0 udpsrc port=5000 ! application\/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! autovideosink\n\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>Try these (You may have to install gstreamer-ugly plugins for this one)<\/p>\n<pre><code><\/code><\/pre>\n<p><strong>UDP streaming from Webcam (stream over the network)<\/strong><\/p>\n<pre><code><\/code><\/pre>\n<pre><code>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\n<\/code><\/pre>\n<pre><code><\/code><\/pre>\n<p><strong>UDP Streaming received from webcam (receive over the network)<\/strong><\/p>\n<pre><code><\/code><\/pre>\n<pre><code>gst-launch udpsrc port=1234 ! &quot;application\/x-rtp, payload=127&quot; ! rtph264depay ! ffdec_h264 ! xvimagesink sync=false\n<\/code><\/pre>\n<pre><code><\/code><\/pre>\n<p class=\"p1\"><span class=\"s1\">v4l2-ctl &#8211;list-formats-ext -d \/dev\/video0<\/span><\/p>\n<p>vcgencmd get_camera<\/p>\n<p>&nbsp;<\/p>\n<h1>server libcamera-vid -t 0 &#8211;width 1920 &#8211;height 1080 &#8211;codec h264 -n -l -o tcp:\/\/0.0.0.0:5001<\/h1>\n<h1>client gst-launch-1.0 -v tcpclientsrc host=xxx.xxx.xxx.xxx port=5001 ! decodebin ! fpsdisplaysink sync=false text-overlay=false<\/h1>\n<pre><code>sudo rpi-update to get the latest kernel and firmware\n- download the kernel module from&nbsp;&lt;a class=&quot;postlink&quot; href=&quot;https:\/\/github.com\/6by9\/RPiTest\/blob\/ma&quot;&gt;https:\/\/github.com\/6by9\/RPiTest\/blob\/ma&lt;\/a&gt; ... 35-v4l2.ko\n- copy it to \/lib\/modules\/3.12.20+\/kernel\/drivers\/media\/platform\/bcm2835\/ on your Pi\n- amend your modprobe line to read modprobe bcm2835-v4l2 gst_v4l2src_is_broken=1\n(no longer need steps 2 and 3 as the fix is in the main kernel)\n\nsudo modprobe bcm2835-v4l2 gst_v4l2src_is_broken=1\n\nWe have 2 worlds for the camera - one GPU centric (MMAL and bcm2835_v4l2), and one ARM centric (bcm2835_unicam).\n\nThere 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.\nMMAL 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.\n\nbcm2835_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).\nThat 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.\n\nMost people want world 1, but world 2 is there for those who want the lowest level of control.\n\nVideoCore 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.\nOne 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.\n\nbcm2835_unicam ignores the VPU, and uses the ARM to talk direct to the peripheral over the AXI bus.\n\n<\/code><\/pre>\n<h2 dir=\"auto\">Using Raspberry Pi Camera<\/h2>\n<pre><code><\/code><\/pre>\n<p dir=\"auto\">This RTSP server works with Raspberry Pi camera using :<\/p>\n<pre><code><\/code><\/pre>\n<ul dir=\"auto\">\n    <li>\n<p dir=\"auto\">the opensource V4L2 driver bcm2835-v4l2<\/p>\n<p dir=\"auto\">sudo modprobe -v bcm2835-v4l2<\/p>\n<\/li>\n    <li>\n<p dir=\"auto\">the closed source V4L2 driver for the Raspberry Pi Camera Module\u00a0<a href=\"http:\/\/www.linux-projects.org\/uv4l\/\" rel=\"nofollow\">http:\/\/www.linux-projects.org\/uv4l\/<\/a><\/p>\n<p dir=\"auto\">sudo uv4l &#8211;driver raspicam &#8211;auto-video_nr &#8211;encoding h264<\/p>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<pre><code><\/code><\/pre>\n<p>The source for the bcm2835-v4l2 kernel module is in the linux staging tree at linux\/drivers\/staging\/vc04_services\/bcm2835-camera\/<\/p>\n<pre><code><\/code><\/pre>\n<p>You can find it e.g. in the RPF Linux repository at\u00a0<a href=\"https:\/\/github.com\/raspberrypi\/linux\" rel=\"nofollow noreferrer\"><a href=\"https:\/\/github.com\/raspberrypi\/linux\">https:\/\/github.com\/raspberrypi\/linux<\/a><\/a>\u00a0For the current RPF Linux kernel (4.14.y) it&#8217;s at\u00a0<a href=\"https:\/\/github.com\/raspberrypi\/linux\/tree\/rpi-4.14.y\/drivers\/staging\/vc04_services\/bcm2835-camera\" rel=\"nofollow noreferrer\"><a href=\"https:\/\/github.com\/raspberrypi\/linux\/tree\/rpi-4.14.y\/drivers\/staging\/vc04_services\/bcm2835-camera\">https:\/\/github.com\/raspberrypi\/linux\/tree\/rpi-4.14.y\/drivers\/staging\/vc04_services\/bcm2835-camera<\/a><\/a><\/p>\n<pre><code><\/code><\/pre>\n<p>It is also available in the upstream Linux repositories.<\/p>\n<p>You need a version 1.0 or later of v4l2-ctl, available from:\ngit:\/\/git.linuxtv.org\/v4l-utils.git<\/p>\n<p>$ sudo modprobe bcm2835-v4l2<\/p>\n<p>Turn on the overlay:<\/p>\n<p>$ v4l2-ctl &#8211;overlay=1<\/p>\n<p>Turn off the overlay:<\/p>\n<p>$ v4l2-ctl &#8211;overlay=0<\/p>\n<p>Set the capture format for video:<\/p>\n<p>$ v4l2-ctl &#8211;set-fmt-video=width=1920,height=1088,pixelformat=4<\/p>\n<p>(Note: 1088 not 1080).<\/p>\n<p>Capture:<\/p>\n<p>$ v4l2-ctl &#8211;stream-mmap=3 &#8211;stream-count=100 &#8211;stream-to=somefile.h264<\/p>\n<p>Stills capture:<\/p>\n<p>$ v4l2-ctl &#8211;set-fmt-video=width=2592,height=1944,pixelformat=3\n$ v4l2-ctl &#8211;stream-mmap=3 &#8211;stream-count=1 &#8211;stream-to=somefile.jpg<\/p>\n<p>List of available formats:<\/p>\n<p>$ v4l2-ctl &#8211;list-formats<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div><span class=\"fs11lh1-5 cf2 ff1\">install rpicamsrc in 1.14.4<\/span><\/div>\n<div>\n<div><span class=\"fs12lh1-5 ff1\">$ git clone https:\/\/github.com\/thaytan\/gst-rpicamsrc.git<\/span><\/div>\n<\/div>\n<div>\n<div><span class=\"fs12lh1-5 ff1\">$ cd gst-rpicamsrc<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$ .\/autogen.sh<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$ make<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$ sudo make install<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$ sudo ldconfig<\/span><\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\n<div class=\"imTACenter\"><b><span class=\"fs14lh1-5 cf1\">ONLY Raspberry Pi 32-bit OS with rpicamsrc<\/span><\/b><\/div>\n<\/div>\n<div>\n<div><b class=\"fs12lh1-5\"><span class=\"fs12lh1-5 cf1\">UDP<\/span><\/b><\/div>\n<div><span class=\"fs11lh1-5 cf2 ff1\"># get the IP address of the<\/span>\n<b><span class=\"fs11lh1-5 cf2 ff1\">recieving<\/span><\/b>\n<span class=\"fs11lh1-5 cf2 ff1\">RPi first<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$ hostname -I<\/span><\/div>\n<div><span class=\"fs11lh1-5 cf2 ff1\"># start the sender, the one with the Raspicam<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$<\/span>\n<span class=\"fs12lh1-5 ff1\">gst-launch-1.0 -v\u00a0<\/span>\n<span class=\"fs12lh1-5 ff1\">rpicamsrc<\/span>\n<span class=\"fs12lh1-5 ff1\">\u00a0num-buffers=-1 ! video\/x-raw, width=640, height=480, framerate=30\/1<\/span>\n<span class=\"fs12lh1-5 ff1\">!\u00a0<\/span>\n<span class=\"fs12lh1-5 ff1\"><span class=\"cb1\">clockoverlay time-format=&#8221;%D %H:%M:%S&#8221;<\/span>\u00a0!<\/span>\u00a0<span class=\"fs12lh1-5 ff1\">videoconvert ! jpegenc !<\/span>\n<span class=\"fs12lh1-5 ff1\">rtpjpegpay !<\/span>\n<span class=\"fs12lh1-5 ff1\">udpsink host=192.168.178.84 port=5200<\/span><\/div>\n<div><span class=\"fs11lh1-5 cf2 ff1\"># start the reciever, the one with IP 192.168.178.84<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$<\/span>\n<span class=\"fs12lh1-5 ff1\">gst-launch-1.0 -v udpsrc port=5200 ! application\/x-rtp, media=video, clock-rate=90000, payload=96 ! rtpjpegdepay ! jpegdec ! videoconvert ! autovideosink<\/span><\/div>\n<\/div>\n<div><span class=\"fs12lh1-5 cf1\"><b>TCP<\/b><\/span><\/div>\n<div><span class=\"fs11lh1-5 cf2 ff1\"># get the IP address of the\u00a0<b>sending<\/b>\u00a0RPi first<\/span><\/div>\n<div>\n<div><span class=\"fs12lh1-5 ff1\">$ hostname -I<\/span><\/div>\n<\/div>\n<div><span class=\"fs11lh1-5 cf2 ff1\"># start the sender, the one with the Raspicam and IP 192.168.178.32<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$\u00a0<\/span>\n<span class=\"fs12lh1-5 ff1\">gst-launch-1.0 -v\u00a0<\/span>\n<span class=\"fs12lh1-5 ff1\">rpicamsrc\u00a0<\/span>\n<span class=\"cb2\"><span class=\"fs12lh1-5 cf3 ff1\">vflip=true awb-mode=tungsten\u00a0<\/span>\n<span class=\"fs12lh1-5 ff1\">preview=false<\/span><\/span>\n<span class=\"fs12lh1-5 ff1\">\u00a0num-buffers=-1 ! video\/x-raw,width=640,height=480, framerate=30\/1 !\u00a0<\/span>\n<span class=\"fs12lh1-5 ff1 cb1\">timeoverlay time-mode=&#8221;buffer-time&#8221;<\/span>\n<span class=\"fs12lh1-5\">\u00a0!\u00a0<\/span>\n<span class=\"fs12lh1-5 ff1\">videoconvert ! jpegenc ! tcpserversink \u00a0host=192.168.178.32 port=5000<\/span><\/div>\n<div>\n<div><span class=\"fs11lh1-5 cf2 ff1\"># start the reciever and connect to the server with IP 192.168.178.32<\/span><\/div>\n<div><span class=\"fs12lh1-5 ff1\">$\u00a0<\/span>\n<span class=\"fs12lh1-5 ff1\">gst-launch-1.0 tcpclientsrc host=192.168.178.32 port=5000 ! jpegdec ! videoconvert ! autovideosink<\/span><\/div>\n<\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div>\n\n\u00a0had the same problem with on a raspberrypi 4 with gstreamer and solved it by enabling the kernel side support (often referenced as &#8220;v4l2m2m&#8221;).\n\nYou can check it is activated because you get new \/dev\/video character device files in addition to \/dev\/video0. (for me it&#8217;s 3 new files \/dev\/video[10,11,12]).\n\nCheck that the kernel module is loaded or load it with:\n<pre><code>modprobe bcm2835-codec\n<\/code><\/pre>\nThen\u00a0<code>gst-inspect-1.0 video4linux2<\/code>\u00a0should show you the elements you are looking for, such as v4l2h264dec, v4l2h264enc, v4l2vp8dec, &#8230;. (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\u00a0<code>rm ~\/.cache\/gstreamer-1.0\/registry.armv8-a.bin<\/code>)\n\n<\/div>\n<p>&nbsp;<\/p>\n<p class=\"p1\"><span class=\"s1\">v4l2-ctl &#8211;get-fmt-video -d \/dev\/video2<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">modprobe v4l2loopback video_nr=5 card_label=&#8221;vcam&#8221; exclusive_caps=1<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.highvoltagecode.com\/post\/webrtc-on-raspberry-pi-live-hd-video-and-audio-streaming\">https:\/\/www.highvoltagecode.com\/post\/webrtc-on-raspberry-pi-live-hd-video-and-audio-streaming<\/a><\/p>\n<div class=\"video-container\"><blockquote class=\"wp-embedded-content\" data-secret=\"xepACaN0fh\"><a href=\"https:\/\/www.linux-projects.org\/uv4l\/installation\/\">Installation for ARM (Raspberry Pi)<\/a><\/blockquote>\n<iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"\u201cInstallation for ARM (Raspberry Pi)\u201d \u2014 (advanced) Projects\" src=\"https:\/\/www.linux-projects.org\/uv4l\/installation\/embed\/#?secret=xepACaN0fh\" data-secret=\"xepACaN0fh\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/div>\n<p>&nbsp;<\/p>\n<p>gpu_info.sh<\/p>\n<p>vcgencmd version\necho &#8220;#########################################&#8221;\necho &#8220;memory info:&#8221;\nvcgencmd get_mem arm &#038;&#038; vcgencmd get_mem gpu<\/p>\n<p>echo &#8220;#########################################&#8221;\necho &#8220;gpu temperature info:&#8221;\nvcgencmd measure_temp<\/p>\n<p>echo &#8220;#########################################&#8221;\necho &#8220;gpu clock info:&#8221;\nfor src in arm core h264 hevc isp v3d uart pwm emmc pixel vec hdmi dpi ; do\necho -e &#8220;$src:\\t$(vcgencmd measure_clock $src)&#8221; ;\ndone<\/p>\n<p>echo &#8220;#########################################&#8221;\necho &#8220;gpu volts info:&#8221;\nfor id in core sdram_c sdram_i sdram_p ; do\necho -e &#8220;$id:\\t$(vcgencmd measure_volts $id)&#8221; ;\ndone<\/p>\n<p>echo &#8220;#########################################&#8221;\necho &#8220;code info:&#8221;\nfor codec in H264 H265 HEVC MPG2 WVC1 MPG4 MJPG WMV9 ; do\necho -e &#8220;$codec:\\t$(vcgencmd codec_enabled $codec)&#8221; ;\ndone<\/p>\n<pre><code><\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>MJPEG Server (Ubuntu 16.04) gst-launch-1.0 -v filesrc location= \/home\/rein\/Videos\/big_buck_bunny_720&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2190","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=2190"}],"version-history":[{"count":24,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2190\/revisions"}],"predecessor-version":[{"id":2271,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2190\/revisions\/2271"}],"wp:attachment":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=2190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=2190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=2190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}