Icalittlesillouhetto
Posts: 8
Joined: Wed Oct 31, 2018 4:57 pm

Raspberry Pi receiving UDP

Wed Oct 31, 2018 4:59 pm

Does anybody know if the Raspberry Pi can receive a UDP stream? I know I can send one from the pi, but can another pi receive that video instead of my laptop.

Andyroo
Posts: 3756
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Raspberry Pi receiving UDP

Wed Oct 31, 2018 6:54 pm

UDP is just a data packet on the network rather than a video so it’s the application that takes the stream and turns it into a video.

Have a look at https://wiki.python.org/moin/UdpCommunication for a Python example of sending and receiving data.

I’m sure someone will chip in with the OSI layers for the fun of it :lol:
Need Pi spray - these things are breeding in my house...

User avatar
DougieLawson
Posts: 35517
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi receiving UDP

Wed Oct 31, 2018 8:01 pm

UDP/IP is just a layer three transport. As long as you've got a layer 2 connection on the layer 1 (eth0 or wlan0) it's going to work.

The clever stuff happens at the application layer (layer 4) using the TCP/IP or UDP/IP at layer 3.

Tl;Dr yes it will work.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Icalittlesillouhetto
Posts: 8
Joined: Wed Oct 31, 2018 4:57 pm

Re: Raspberry Pi receiving UDP

Wed Oct 31, 2018 8:35 pm

i'm using gstreamer

is gstreamer a good choice to send and receive udp video between two raspberry pis? I know sending a UDP Video stream from a raspberry pi shows good performance (1080p 30fps) with gstreamer.

I use this pipeline as an example on the pi cam enabled rpi (transmitting rpi):

Code: Select all

raspivid -t 0 -w 1280 -h 720 -fps 30 -b 1700000 -rot 180 -o - | gst-launch-1.0 -v fdsrc ! h264parse config-interval=1 ! rtph264pay ! udpsink host = XXX.XXX.X.X port= 9000
But for the Receiving Rpi (A Pi2 with Screen) What would be an ideal pipeline?

I tried:

Code: Select all

gst-launch-1.0 udpsrc port=9000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink
But it barely runs at 1fps

Is the pipeline needing to use Broadcom BCM2835 Hardware decoding somehow?

I read that gstreamer can maybe use gst-omx for hardware decoding: https://imgur.com/a/e00iUzE

https://wiki.matthiasbock.net/index.php ... spberry_Pi

User avatar
DougieLawson
Posts: 35517
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi receiving UDP

Wed Oct 31, 2018 9:15 pm

Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Icalittlesillouhetto
Posts: 8
Joined: Wed Oct 31, 2018 4:57 pm

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 12:00 am

Anyone using gst-omx with gstreamer to receive UDP

I search for gst-omx plugin on rpi using:

Code: Select all

gst-inspect-1.0 | grep omx
and it shows up ok, I just am not sure how to implement it into pipeline using omxh264dec


or

Anyone using OMXplayer to receive UDP video stream? using command:

Code: Select all

omxplayer udp://xxx.xxx.x.xxx:9000
Gives message "Have a nice Day ;)"

jahboater
Posts: 4590
Joined: Wed Feb 04, 2015 6:38 pm

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 8:30 am

Why the interest in streaming stuff over UDP ?

Of course it is possible, and has the advantage that there is no upper limit on the number of concurrent streams (TCP is quite limited)
However, you have to implement all the flow control, re-sending of lost or out of sequence packets etc - which is what TCP does, only much much better. The TCP code in the IP stack is extremely well tuned and tested.

gkreidl
Posts: 5992
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 9:19 am

Icalittlesillouhetto wrote:
Thu Nov 01, 2018 12:00 am
Anyone using gst-omx with gstreamer to receive UDP

I search for gst-omx plugin on rpi using:

Code: Select all

gst-inspect-1.0 | grep omx
and it shows up ok, I just am not sure how to implement it into pipeline using omxh264dec


or

Anyone using OMXplayer to receive UDP video stream? using command:

Code: Select all

omxplayer udp://xxx.xxx.x.xxx:9000
Gives message "Have a nice Day ;)"
1) Forget gstreamer for displaying any video.

2) omxplayer DOES play streams on UDP. But the udp stream must carry a container and a codec format which is recognized by omxplayer and suitable for streaming, e.g. MPEG-TS with H264 codec.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

Icalittlesillouhetto
Posts: 8
Joined: Wed Oct 31, 2018 4:57 pm

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 10:22 am

Why the interest in streaming stuff over UDP ?
UDP is lowest latency, TCP higher latency.
UDP needed or very low latency.
1) Forget gstreamer for displaying any video.
WHy?
2) omxplayer DOES play streams on UDP. But the udp stream must carry a container and a codec format which is recognized by omxplayer and suitable for streaming, e.g. MPEG-TS with H264 codec.
What format does omxplayer recognise? Does it recognise omxh264

Example command line for displaying UDP stream anyone has?
Such as:

Code: Select all

omxplayer udp://<IP HERE>:<PORT HERE>
What is the way?

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 10:35 am

Two years ago I did the streaming from a Pi camera to a laptop like this:

Sending command: raspivid --inline -t 0 --output - | avconv -re -f h264 -i - -vcodec copy -tune zerolatency -an -f mpegts udp://224.0.0.2:61234

Receiving command: ffplay -i udp://224.0.0.2:61234


The 224.0.0.2 address is a multicast address. You could change it, or just use it like above.

The avconv command on the Pi side is from libav. There was no ffmpeg in the repository. Don't know today.

Icalittlesillouhetto
Posts: 8
Joined: Wed Oct 31, 2018 4:57 pm

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 10:45 am

Two years ago I did the streaming from a Pi camera to a laptop like this:
I too have good results with sending to a laptop.

What I am looking for is to send to another Raspberry Pi that has a screen.

User avatar
DougieLawson
Posts: 35517
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 10:50 am

It should just work the same way. There's nothing special about a Raspberry Pi, it's a general purpose Linux computer as far as this is concerned.

The only hard part is getting the right viewer program (omxplayer, gstreamer, vlc) installed.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 11:08 am

Icalittlesillouhetto wrote:
Thu Nov 01, 2018 10:45 am
Two years ago I did the streaming from a Pi camera to a laptop like this:
I too have good results with sending to a laptop.

What I am looking for is to send to another Raspberry Pi that has a screen.
Could you give a try for change the receiving command to omxplayer udp://224.0.0.2:61234 ?

The avconv would pack up the stream as MPEG-TS, so maybe omxplayer could read it.

I don't have a screen for Pi, so can't test myself.

Icalittlesillouhetto
Posts: 8
Joined: Wed Oct 31, 2018 4:57 pm

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 2:02 pm

Interesting

Using the following:

Code: Select all

raspivid --inline -t 0 --output - | avconv -re -f h264 -i - -vcodec copy -tune zerolatency -an -f mpegts udp://<IP HERE>:<PORT HERE>
also seems to starts sending pi cam video

Code: Select all

ffmpeg version 3.2.10-1~deb9u1+rpt2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1+deb9u1) 20170516
  configuration: --prefix=/usr --extra-version='1~deb9u1+rpt2' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx-rpi --enable-mmal --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --arch=armhf --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[h264 @ 0x20361e0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, h264, from 'pipe:':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Output #0, mpegts, to 'udp://ip:port':
  Metadata:
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, q=2-31, 25 fps, 25 tbr, 90k tbn, 1200k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
[mpegts @ 0x20ac740] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
frame=   14 fps=0.0 q=-1.0 size=     704kB time=00:00:00.52 bitrate=11097.5kbitsframe=   25 fps= 24 q=-1.0 size=    1625kB time=00:00:00.96 bitrate=13869.5kbitsframe=   35 fps= 22 q=-1.0 size=    2659kB time=00:00:01.36 bitrate=16017.5kbitsframe=   51 fps= 24 q=-1.0 size=    3817kB time=00:00:02.00 bitrate=15636.3kbitsframe=   63 fps= 24 q=-1.0 size=    4849kB time=00:00:02.48 bitrate=16016.3kbitsframe=   79 fps= 25 q=-1.0 size=    5898kB time=00:00:03.12 bitrate=15485.8kbitsframe=   92 fps= 26 q=-1.0 size=    6882kB time=00:00:03.64 bitrate=15488.7kbitsframe=  105 fps= 26 q=-1.0 size=    7852kB time=00:00:04.16 bitrate=15463.3kbitsframe=  118 fps= 25 q=-1.0 size=    8830kB time=00:00:04.68 bitrate=15456.1kbitsframe=  131 fps= 25 q=-1.0 size=    9806kB time=00:00:05.20 bitrate=15448.4kbitsframe=  143 fps= 25 q=-1.0 size=   10688kB time=00:00:05.68 bitrate=15414.4kbitsframe=  156 fps= 25 q=-1.0 size=   11626kB time=00:00:06.20 bitrate=15361.9kbitsframe=  169 fps= 25 q=-1.0 size=   12632kB time=00:00:06.72 bitrate=15398.7kbitsframe=  182 fps= 25 q=-1.0 size=   13829kB time=00:00:07.24 bitrate=15647.2kbitsframe=  195 fps= 25 q=-1.0 size=   14654kB time=00:00:07.76 bitrate=15469.3kbitsframe=  208 fps= 25 q=-1.0 size=   15593kB time=00:00:08.28 bitrate=15427.6kbitsframe=  221 fps= 25 q=-1.0 size=   16554kB time=00:00:08.80 bitrate=15410.0kbitsframe=  234 fps= 25 q=-1.0 size=   17490kB time=00:00:09.32 bitrate=15372.7kbitsframe=  247 fps= 25 q=-1.0 size=   18505kB time=00:00:09.84 bitrate=15405.4kbitsframe=  260 fps= 25 q=-1.0 size=   19441kB time=00:00:10.36 bitrate=15372.6kbitsframe=  272 fps= 25 q=-1.0 size=   20327kB time=00:00:10.84 bitrate=15361.5kbitsframe=  285 fps= 25 q=-1.0 size=   21304kB time=00:00:11.36 bitrate=15363.0kbitsframe=  298 fps= 25 q=-1.0 size=   22265kB time=00:00:11.88 bitrate=15353.2kbitsframe=  311 fps= 25 q=-1.0 size=   23272kB time=00:00:12.40 bitrate=15374.4kbitsframe=  324 fps= 25 q=-1.0 size=   24232kB time=00:00:12.92 bitrate=15364.2kbitsframe=  337 fps= 25 q=-1.0 size=   25193kB time=00:00:13.44 bitrate=15355.7kbitsframe=  350 fps= 25 q=-1.0 size=   26153kB time=00:00:13.96 bitrate=15347.0kbitsframe=  362 fps= 25 q=-1.0 size=   27221kB time=00:00:14.44 bitrate=15442.5kbitsframe=  376 fps= 25 q=-1.0 size=   28113kB time=00:00:15.00 bitrate=15353.5kbitsframe=  388 fps= 25 q=-1.0 size=   29019kB time=00:00:15.48 bitrate=15356.9kbitsframe=  401 fps= 25 q=-1.0 size=   29977kB time=00:00:16.00 bitrate=15348.3kbitsframe=  414 fps= 25 q=-1.0 size=   30936kB time=00:00:16.52 bitrate=15340.6kbitsframe=  427 fps= 25 q=-1.0 size=   31966kB time=00:00:17.04 bitrate=15367.5kbitsframe=  440 fps= 25 q=-1.0 size=   32817kB time=00:00:17.56 bitrate=15309.6kbitsframe=  453 fps= 25 q=-1.0 size=   33830kB time=00:00:18.08 bitrate=15328.4kbitsframe=  466 fps= 25 q=-1.0 size=   34828kB time=00:00:18.60 bitrate=15339.3kbitsframe=  479 fps= 25 q=-1.0 size=   35776kB time=00:00:19.12 bitrate=15328.4kbitsframe=  492 fps= 25 q=-1.0 size=   36789kB time=00:00:19.64 bitrate=15345.1kbitsframe=  505 fps= 25 q=-1.0 size=   37733kB time=00:00:20.16 bitrate=15333.0kbitsframe=  518 fps= 25 q=-1.0 size=   38707kB time=00:00:20.68 bitrate=15333.2kbitsframe=  530 fps= 25 q=-1.0 size=   39604kB time=00:00:21.16 bitrate=15332.5kbitsframe=  543 fps= 25 q=-1.0 size=   40756kB time=00:00:21.68 bitrate=15400.1kbits^Cmmal: Aborting program

frame=  547 fps= 25 q=-1.0 Lsize=   40955kB time=00:00:21.84 bitrate=15361.7kbits/s speed=   1x    
video:37930kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 7.972964%
Exiting normally, received signal 2.
(I abort using ctrl + c)

Using the following on the receiving rpi:

Code: Select all

omxplayer -i udp://<ip here>:<port here>
It also seems to run correctly, giving the following:

Code: Select all

[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] decode_slice_header error
[h264 @ 0x1ce3e0] no frame!
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] decode_slice_header error
[h264 @ 0x1ce3e0] no frame!
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] decode_slice_header error
[h264 @ 0x1ce3e0] no frame!
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] decode_slice_header error
[h264 @ 0x1ce3e0] no frame!
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] non-existing PPS 0 referenced
[h264 @ 0x1ce3e0] decode_slice_header error
[h264 @ 0x1ce3e0] no frame!
Input #0, mpegts, from 'udp://ip:port':
  Duration: N/A, start: 11.800000, bitrate: N/A
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn, 180k tbc
have a nice day ;)
(Again I abort using ctrl + c)

However no video picture shows up on the receiving rpi.

It appears to run quite fast too, I suspect that omxplayer is hardware decoding as expected.

So how come no picture on the hdmi screen, just numbers scrolling in terminal? Do I need to specify hdmi in the omxplayer command?

For example

Code: Select all

omxplayer -i hdmi udp://<ip here>:<port here>
Can I specify (reduce from 1080p to 480p) the frame size and bitrate using avconv with mpegts?

It is more progress than previous attempts I think omxplayer hardware decoding might be the way for UDP video on the Rpi ;)
Last edited by Icalittlesillouhetto on Thu Nov 01, 2018 2:46 pm, edited 1 time in total.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 2:45 pm

allfox wrote:
Thu Nov 01, 2018 10:35 am
The 224.0.0.2 address is a multicast address. You could change it, or just use it like above.
224.0.0.2 is a special multicast address (as are many of the others in 224.0.0.0/24).

For your own stuff you might be better choosing something in 239.255.0.0/16 (although if your on a corporate/education network talk to the network guys first as there might be policies in place about address usage).

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 4:44 pm

mfa298 wrote:
Thu Nov 01, 2018 2:45 pm
224.0.0.2 is a special multicast address (as are many of the others in 224.0.0.0/24).

For your own stuff you might be better choosing something in 239.255.0.0/16 (although if your on a corporate/education network talk to the network guys first as there might be policies in place about address usage).
I didn't know that, thanks!

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Raspberry Pi receiving UDP

Thu Nov 01, 2018 5:14 pm

Icalittlesillouhetto wrote:
Thu Nov 01, 2018 2:02 pm
However no video picture shows up on the receiving rpi.
I used ffmpeg -i, because -i in ffmpeg means "input".
According to https://www.raspberrypi.org/documentati ... xplayer.md
In omxplayer, -i means "info".
So maybe you could just try "omxplayer udp://address:port". No -i

Icalittlesillouhetto wrote:
Thu Nov 01, 2018 2:02 pm
Can I specify (reduce from 1080p to 480p) the frame size and bitrate using avconv with mpegts?
You shouldn't do the scaling in avconv. Because it would use CPU to do the job, which would be slow. The raspivid is HW accelerated.
Accroding to https://www.raspberrypi.org/documentati ... aspivid.md
You might try something like "raspivid -w 640 -h 480 -fps 25"


Again, I don't have a screen to test. Good luck.

Icalittlesillouhetto
Posts: 8
Joined: Wed Oct 31, 2018 4:57 pm

Re: Raspberry Pi receiving UDP

Fri Nov 02, 2018 1:54 pm

So that is an improvement over my experience using gsteamer receiver.

Raspberry pi with Pi Camera:

Code: Select all

raspivid --inline -t 0 --output - | avconv -re -f h264 -i - -vcodec copy -tune zerolatency -an -f mpegts udp://address:port
Raspberry pi with HDMI Screen:

Code: Select all

omxplayer udp://<ip here>:<port here>
Works somewhat.

High Latency happens (maybe 6 second delay between send and receive), but it is running 25fps (24fps better than software decoding)
omxplayer seems to be performing better at UDP receiving than Standard Gstreamer, so perhaps it is using hardware decoding.

I think I will try to reduce latency more
in avconv adjust settings:
-r (Framerate)
-qscale:v (video quality)
-b:v (bitrate)

Maybe a different codec will be better?
Last edited by Icalittlesillouhetto on Fri Nov 02, 2018 2:51 pm, edited 1 time in total.

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Raspberry Pi receiving UDP

Fri Nov 02, 2018 2:47 pm

About the latency, my GUESS is that the Linux pipe buffer is a problem.

The "|" between raspivid and avconv contains a buffer. I don't know its size nor how to change its size.

Well, I'm happy it's working anyway.

Icalittlesillouhetto
Posts: 8
Joined: Wed Oct 31, 2018 4:57 pm

Re: Raspberry Pi receiving UDP

Fri Nov 02, 2018 7:27 pm

ffmpeg is basically the same as avconv but with different name correct?

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Raspberry Pi receiving UDP

Fri Nov 02, 2018 9:48 pm

Icalittlesillouhetto wrote:
Fri Nov 02, 2018 7:27 pm
ffmpeg is basically the same as avconv but with different name correct?
Yes they are.

Return to “General discussion”