b3394d442561e0fbce4fe036d2cdcf46822abe22
[toast/stream2beamer.git] / stream2beamer.md
1 # Stream Desktop/Video/Webcam to Kodi/Beamer/other PCs
2 Gregor and I had a closer look at the following projects:
3
4 # Laplace
5 Simple WebRTC implementation in GO: https://github.com/adamyordan/laplace.git
6 Simple to compile and just works.
7 WebRTC actually uses SRTP (Secure Real-time Transport Protocol). 
8
9 IPv6+IPv4, and no TLS:
10
11     ./laplace -addr "[::]:8080" -tls=false
12
13 # gstreamer
14 * Supports RTP
15 * Supports webcam capture via v4l (video for linux)
16 * Supports screen capture via xmanager/ximagesrc
17 * Interesting URLs:
18   * WebRTC in one direction only: https://stackoverflow.com/questions/57430215/how-to-use-webrtcbin-create-offer-only-receive-video
19   * gstreamer to VLC via RTP: https://stackoverflow.com/questions/13154983/gstreamer-rtp-stream-to-vlc
20   * https://github.com/intel/gstreamer-media-SDK/issues/138
21   * https://developer.ridgerun.com/wiki/index.php?title=GstWebRTC_Pipelines
22   * https://developer.ridgerun.com/wiki/index.php?title=GstWebRTC_-_H264-Opus_Examples#Receive_Pipeline
23
24 ## WebRTC
25 gstreamer has a WebRTC implementation.
26 The examples at https://github.com/centricular/gstwebrtc-demos.git work once
27
28     export OPENSSL_CONF=''
29
30 has been set (see https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/811)
31
32 ## gstreamer examples
33     gst-launch-1.0 -v playbin uri=file:///home/philipp/tmp/GerisGame.mp4
34     
35     # send
36     gst-launch-1.0 ximagesrc ! videoconvert ! videoscale ! video/x-raw,width=800,height=600 ! vp8enc ! rtpvp8pay ! udpsink host=239.255.12.42 port=5004
37     # receive
38     gst-launch-1.0 udpsrc address=239.255.12.42 port=5004 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)VP8-DRAFT-IETF-01, payload=(int)96, ssrc=(uint)2990747501, clock-base=(uint)275641083, seqnum-base=(uint)34810" ! rtpvp8depay ! vp8dec ! autovideosink
39     
40     # send
41     gst-launch-1.0 -v ximagesrc ! videoconvert ! videoscale ! video/x-raw,format=I420,width=800,height=600,framerate=25/1 ! jpegenc ! rtpjpegpay ! udpsink host=239.255.12.42 port=5004
42     # receive
43     gst-launch-1.0 udpsrc address=239.255.12.42 port=5004 ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink
44
45
46 * https://stackoverflow.com/questions/33747500/using-gstreamer-to-capture-screen-and-show-it-in-a-window/33822024#33822024
47 * http://www.einarsundgren.se/gstreamer-basic-real-time-streaming-tutorial/
48 * https://gist.github.com/tetkuz/0c038321d05586841897
49 * https://gist.github.com/esrever10/7d39fe2d4163c5b2d7006495c3c911bb
50 * https://gist.github.com/nebgnahz/26a60cd28f671a8b7f522e80e75a9aa5
51 * https://salsa.debian.org/debconf-video-team/ansible/-/blob/master/roles/voctomix/templates/videoteam-stream.j2
52 * https://github.com/xfxf/video-scripts/blob/master/michael/youtube-live.sh
53   (and others in the same repo)
54     
55 # VLC
56 Note that you have to close VLC and open it again for new streaming as VLC leaves the connections
57 open (I spent hours figuring out why http based streaming doesn't work - `netstat -4 --ip` is nice
58 for debugging in that respect).
59
60 ## RTP
61 ### Source
62 The address has to be the address where the video should be streamed **to**. In the following
63 examples, a multicast address is used. It is either the IP address of the device receiving the video (unicast address) or a multicast address 
64 like 239.255.12.42 (multicast addresses are between 224.0.0.0 and 239.255.255.255, some of
65 them being reserved, 239.0.0.0 to 239.255.255.255 are Organization-Local Scope so they are
66 good candidates, see
67 https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml).
68
69     cvlc -vv --sout '#transcode{vcodec=h264,acodec=mpga,channels=2,vb=800,ab=128}:rtp{mux=ts,dst=239.255.12.42,sdp=sap,name="Geris Game"}' GerisGame.mp4
70     cvlc -vv --sout '#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:rtp{dst=239.255.12.42,port=5004,mux=ts,sap,name=Geris Game}' :no-sout-all :sout-keep GerisGame.mp4
71     cvlc -vv --sout '#transcode{vcodec=h264,acodec=mpga,channels=2}:rtp{mux=ts,dst=239.255.12.42,sdp=sap,name="Videokamera"}' v4l2:///dev/video0 # long latency
72     cvlc -vv --sout '#transcode{vcodec=h264,acodec=mpga,channels=2}:rtp{mux=ts,dst=239.255.12.42,sdp=sap,name="Desktop"}' screen:// # not convincing
73
74 ### Player
75     cvlc rtp://239.255.12.42
76
77
78 ## RTSP
79 For VLC, RTSP means RTSP combined with RTP.
80
81 ### Source
82 We assume that the video source computer has the external IP 192.168.1.54.
83 Instead of rtsp://192.168.1.54:8554/ we could also use rtsp://192.168.1.54:8554/mystream.sdp
84
85     cvlc -vv --sout '#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:rtp{sdp=rtsp://:8554/}' :no-sout-all :sout-keep GerisGame.mp4
86     cvlc -vv --sout '#rtp{dst=239.255.12.42,port=1234,sdp=rtsp://192.168.1.54:8554/}' :no-sout-all :sout-keep GerisGame.mp4
87
88
89 ### Player
90 The address needs to be the address of the source. Note the backslash at the end.
91
92     vlc rtsp://192.168.1.54:8554/
93
94
95 ## VLC Remarks
96 * Latency: The following options are said to reduce latency:
97
98       --network-caching=150 --clock-jitter=0 --clock-synchro=0
99
100 * Duplicating a stream is nice for debugging:
101
102       cvlc -vv --sout '#duplicate{dst=display,dst="transcode{vcodec=h264,acodec=mpga,channels=2,vb=800,ab=128}:rtp{mux=ts,dst=239.255.12.42,sdp=sap,name=Geris Game}"}' GerisGame.mp4
103       cvlc rtp://239.255.12.42
104
105
106 ## HTTP
107 The address at the source side has to be the external one of the local computer.
108
109 ### Source (server)
110     cvlc -vv --sout '#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128}:standard{access=http,mux=ogg,dst=0.0.0.0:8080}' GerisGame.mp4
111
112 ### Player (client)
113
114     vlc http://192.168.1.54:8080
115
116
117 # Kodi
118 The player built into code knows at least the following streaming protocols: http, rtsp.
119
120 https://kodi.wiki/index.php?title=Internet_video_and_audio_streams