one more rtsp link
[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 ## WebRTC signaling
14
15 * https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Signaling_and_video_calling
16 * https://www.tutorialspoint.com/webrtc/webrtc_signaling.htm
17 * https://www.html5rocks.com/en/tutorials/webrtc/infrastructure/
18 * https://github.com/topics/webrtc-signaling
19
20 # gstreamer
21 * Supports RTP
22 * Supports webcam capture via v4l (video for linux)
23 * Supports screen capture via xmanager/ximagesrc
24 * Interesting URLs:
25   * WebRTC in one direction only: https://stackoverflow.com/questions/57430215/how-to-use-webrtcbin-create-offer-only-receive-video
26   * gstreamer to VLC via RTP: https://stackoverflow.com/questions/13154983/gstreamer-rtp-stream-to-vlc
27   * https://github.com/intel/gstreamer-media-SDK/issues/138
28   * https://developer.ridgerun.com/wiki/index.php?title=GstWebRTC_Pipelines
29   * https://developer.ridgerun.com/wiki/index.php?title=GstWebRTC_-_H264-Opus_Examples#Receive_Pipeline
30
31 ## WebRTC
32 gstreamer has a WebRTC implementation.
33 The examples at https://github.com/centricular/gstwebrtc-demos.git work once
34
35     export OPENSSL_CONF=''
36
37 has been set (see https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/811)
38
39 There's a new recvonly example:
40
41 * https://github.com/centricular/gstwebrtc-demos/commit/000cfb6cd817ca0f07d761795b352a8b8b9074f8
42 * `sendonly/webrtc-recvonly-h264.c`
43
44 ## gstreamer examples
45     gst-launch-1.0 -v playbin uri=file:///home/philipp/tmp/GerisGame.mp4
46     
47     # send
48     gst-launch-1.0 ximagesrc ! videoconvert ! videoscale ! video/x-raw,width=800,height=600 ! vp8enc ! rtpvp8pay ! udpsink host=239.255.12.42 port=5004
49     # receive
50     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
51     
52     # send
53     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
54     # receive
55     gst-launch-1.0 udpsrc address=239.255.12.42 port=5004 ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink
56
57
58 * https://stackoverflow.com/questions/33747500/using-gstreamer-to-capture-screen-and-show-it-in-a-window/33822024#33822024
59 * http://www.einarsundgren.se/gstreamer-basic-real-time-streaming-tutorial/
60 * https://gist.github.com/tetkuz/0c038321d05586841897
61 * https://gist.github.com/esrever10/7d39fe2d4163c5b2d7006495c3c911bb
62 * https://gist.github.com/nebgnahz/26a60cd28f671a8b7f522e80e75a9aa5
63 * https://salsa.debian.org/debconf-video-team/ansible/-/blob/master/roles/voctomix/templates/videoteam-stream.j2
64 * https://github.com/xfxf/video-scripts/blob/master/michael/youtube-live.sh
65   (and others in the same repo)
66
67 ## gstreamer webrtc, another example
68
69 * blog post: https://aweirdimagination.net/2020/07/05/gstreamer-webrtc/
70 * code: https://git.aweirdimagination.net/perelman/minimal-webrtc-gstreamer
71     
72 ## websockets
73
74 connecting to websockets (plus gstreamer and v4l2sink)
75
76 https://michael.stapelberg.ch/posts/2020-06-06-iphone-camera-linux-v4l2loopback/
77
78         # send
79         laplace / chromium
80
81         # receive
82         websocat --insecure "wss://localhost:8080/ws_connect?id=cranky_kind_chipmunk"
83
84 ## more v4l2loopback/v4l2sink
85
86         # send
87         gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video42
88
89         # receive
90         cvlc v4l2:///dev/video42
91
92 ## SRT and gstreamer
93
94 * https://github.com/Haivision/srt/blob/master/docs/gstreamer.md
95 * https://srtlab.github.io/srt-cookbook/
96
97 ## gstreamer and rtsp
98
99 working minimal example: https://github.com/Enne2/PyGObject-GstRtspServer/blob/master/rtsp-server.py
100
101 other maybe helpful links (for getting an existing pipeline streamed):
102
103 * https://stackoverflow.com/questions/52562499/is-it-possible-to-stream-an-existing-gstreamer-pipeline-through-gstrtspserver
104 * http://gstreamer-devel.966125.n4.nabble.com/Continuously-streaming-a-video-file-code-review-td4671364.html
105 * https://stackoverflow.com/questions/59858898/how-to-convert-a-video-on-disk-to-a-rtsp-stream
106 * http://gstreamer-devel.966125.n4.nabble.com/RTSP-Server-from-a-manually-created-and-linked-pipeline-td4680305.html
107 * http://gstreamer-devel.966125.n4.nabble.com/Using-C-API-based-pipelines-in-RTSP-server-without-quot-launch-quot-arg-td4680144.html
108
109 a "relay" between cameras and rtsp, in rust:
110
111 * https://github.com/thirtythreeforty/neolink
112
113 ## gstreamer: from udp to rtsp
114
115 * http://trac.gateworks.com/wiki/Yocto/gstreamer/streaming
116
117 ## HLS
118
119 or gstreamer's `hlssink(2)`, if we want to serve files via HTTP and kodi can
120 read/play .m3u8 playlist
121
122 # VLC
123 Note that you have to close VLC and open it again for new streaming as VLC leaves the connections
124 open (I spent hours figuring out why http based streaming doesn't work - `netstat -4 --ip` is nice
125 for debugging in that respect).
126
127 ## RTP
128 ### Source
129 The address has to be the address where the video should be streamed **to**. In the following
130 examples, a multicast address is used. It is either the IP address of the device receiving the video (unicast address) or a multicast address 
131 like 239.255.12.42 (multicast addresses are between 224.0.0.0 and 239.255.255.255, some of
132 them being reserved, 239.0.0.0 to 239.255.255.255 are Organization-Local Scope so they are
133 good candidates, see
134 https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml).
135
136     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
137     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
138     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
139     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
140
141 ### Player
142     cvlc rtp://239.255.12.42
143
144
145 ## RTSP
146 For VLC, RTSP means RTSP combined with RTP.
147
148 ### Source
149 We assume that the video source computer has the external IP 192.168.1.54.
150 Instead of rtsp://192.168.1.54:8554/ we could also use rtsp://192.168.1.54:8554/mystream.sdp
151
152     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
153     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
154
155
156 ### Player
157 The address needs to be the address of the source. Note the backslash at the end.
158
159     vlc rtsp://192.168.1.54:8554/
160
161
162 ## VLC Remarks
163 * Latency: The following options are said to reduce latency:
164
165       --network-caching=150 --clock-jitter=0 --clock-synchro=0
166
167 * Duplicating a stream is nice for debugging:
168
169       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
170       cvlc rtp://239.255.12.42
171
172
173 ## HTTP
174 The address at the source side has to be the external one of the local computer.
175
176 ### Source (server)
177     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
178
179 ### Player (client)
180
181     vlc http://192.168.1.54:8080
182
183
184 # Kodi
185 The player built into code knows at least the following streaming protocols: http, rtsp.
186
187 https://kodi.wiki/index.php?title=Internet_video_and_audio_streams