- <title>Using VLC to stream bittorrent sources</title>
- <link>http://people.skolelinux.org/pere/blog/Using_VLC_to_stream_bittorrent_sources.html</link>
- <guid isPermaLink="true">http://people.skolelinux.org/pere/blog/Using_VLC_to_stream_bittorrent_sources.html</guid>
- <pubDate>Wed, 14 Feb 2018 08:00:00 +0100</pubDate>
- <description><p>A few days ago, a new major version of
-<a href="https://www.videolan.org/">VLC</a> was announced, and I
-decided to check out if it now supported streaming over
-<a href="http://bittorrent.org/">bittorrent</a> and
-<a href="https://webtorrent.io">webtorrent</a>. Bittorrent is one of
-the most efficient ways to distribute large files on the Internet, and
-Webtorrent is a variant of Bittorrent using
-<a href="https://webrtc.org">WebRTC</a> as its transport channel,
-allowing web pages to stream and share files using the same technique.
-The network protocols are similar but not identical, so a client
-supporting one of them can not talk to a client supporting the other.
-I was a bit surprised with what I discovered when I started to look.
-Looking at
-<a href="https://www.videolan.org/vlc/releases/3.0.0.html">the release
-notes</a> did not help answering this question, so I started searching
-the web. I found several news articles from 2013, most of them
-tracing the news from Torrentfreak
-("<a href=https://torrentfreak.com/open-source-giant-vlc-mulls-bittorrent-support-130211/">Open
-Source Giant VLC Mulls BitTorrent Streaming Support</a>"), about a
-initiative to pay someone to create a VLC patch for bittorrent
-support. To figure out what happend with this initiative, I headed
-over to the #videolan IRC channel and asked if there were some bug or
-feature request tickets tracking such feature. I got an answer from
-lead developer Jean-Babtiste Kempf, telling me that there was a patch
-but neither he nor anyone else knew where it was. So I searched a bit
-more, and came across an independent
-<a href="https://github.com/johang/vlc-bittorrent">VLC plugin to add
-bittorrent support</a>, created by Johan Gunnarsson in 2016/2017.
-Again according to Jean-Babtiste, this is not the patch he was talking
-about.</p>
-
-<p>Anyway, to test the plugin, I made a working Debian package from
-the git repository, with some modifications. After installing this
-package, I could stream videos from
-<a href="https://www.archive.org/">The Internet Archive</a> using VLC
-commands like this:</p>
-
-<p><blockquote><pre>
-vlc https://archive.org/download/LoveNest/LoveNest_archive.torrent
-</pre></blockquote></p>
-
-<p>The plugin is supposed to handle magnet links too, but since The
-Internet Archive do not have magnet links and I did not want to spend
-time tracking down another source, I have not tested it. It can take
-quite a while before the video start playing without any indication of
-what is going on from VLC. It took 10-20 seconds when I measured it.
-Some times the plugin seem unable to find the correct video file to
-play, and show the metadata XML file name in the VLC status line. I
-have no idea why.</p>
-
-<p>I have created a <a href="https://bugs.debian.org/890360">request for
-a new package in Debian (RFP)</a> and
-<a href="https://github.com/johang/vlc-bittorrent/issues/1">asked if
-the upstream author is willing to help make this happen</a>. Now we
-wait to see what come out of this. I do not want to maintain a
-package that is not maintained upstream, nor do I really have time to
-maintain more packages myself, so I might leave it at this. But I
-really hope someone step up to do the packaging, and hope upstream is
-still maintaining the source. If you want to help, please update the
-RFP request or the upstream issue.</p>
-
-<p>I have not found any traces of webtorrent support for VLC.</p>
+ <title>Streaming the Linux desktop to Kodi using VLC and RTSP</title>
+ <link>http://people.skolelinux.org/pere/blog/Streaming_the_Linux_desktop_to_Kodi_using_VLC_and_RTSP.html</link>
+ <guid isPermaLink="true">http://people.skolelinux.org/pere/blog/Streaming_the_Linux_desktop_to_Kodi_using_VLC_and_RTSP.html</guid>
+ <pubDate>Thu, 12 Jul 2018 02:00:00 +0200</pubDate>
+ <description><p>PS: See
+<ahref="http://people.skolelinux.org/pere/blog/Simple_streaming_the_Linux_desktop_to_Kodi_using_GStreamer_and_RTP.html">the
+followup post</a> for a even better approach.</p>
+
+<p>A while back, I was asked by a friend how to stream the desktop to
+my projector connected to Kodi. I sadly had to admit that I had no
+idea, as it was a task I never had tried. Since then, I have been
+looking for a way to do so, preferable without much extra software to
+install on either side. Today I found a way that seem to kind of
+work. Not great, but it is a start.</p>
+
+<p>I had a look at several approaches, for example
+<a href="https://github.com/mfoetsch/dlna_live_streaming">using uPnP
+DLNA as described in 2011</a>, but it required a uPnP server, fuse and
+local storage enough to store the stream locally. This is not going
+to work well for me, lacking enough free space, and it would
+impossible for my friend to get working.</p>
+
+<p>Next, it occurred to me that perhaps I could use VLC to create a
+video stream that Kodi could play. Preferably using
+broadcast/multicast, to avoid having to change any setup on the Kodi
+side when starting such stream. Unfortunately, the only recipe I
+could find using multicast used the rtp protocol, and this protocol
+seem to not be supported by Kodi.</p>
+
+<p>On the other hand, the rtsp protocol is working! Unfortunately I
+have to specify the IP address of the streaming machine in both the
+sending command and the file on the Kodi server. But it is showing my
+desktop, and thus allow us to have a shared look on the big screen at
+the programs I work on.</p>
+
+<p>I did not spend much time investigating codeces. I combined the
+rtp and rtsp recipes from
+<a href="https://wiki.videolan.org/Documentation:Streaming_HowTo/Command_Line_Examples/">the
+VLC Streaming HowTo/Command Line Examples</a>, and was able to get
+this working on the desktop/streaming end.</p>
+
+<blockquote><pre>
+vlc screen:// --sout \
+ '#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128}:rtp{dst=projector.local,port=1234,sdp=rtsp://192.168.11.4:8080/test.sdp}'
+</pre></blockquote>
+
+<p>I ssh-ed into my Kodi box and created a file like this with the
+same IP address:</p>
+
+<blockquote><pre>
+echo rtsp://192.168.11.4:8080/test.sdp \
+ > /storage/videos/screenstream.m3u
+</pre></blockquote>
+
+<p>Note the 192.168.11.4 IP address is my desktops IP address. As far
+as I can tell the IP must be hardcoded for this to work. In other
+words, if someone elses machine is going to do the steaming, you have
+to update screenstream.m3u on the Kodi machine and adjust the vlc
+recipe. To get started, locate the file in Kodi and select the m3u
+file while the VLC stream is running. The desktop then show up in my
+big screen. :)</p>
+
+<p>When using the same technique to stream a video file with audio,
+the audio quality is really bad. No idea if the problem is package
+loss or bad parameters for the transcode. I do not know VLC nor Kodi
+enough to tell.</p>
+
+<p><strong>Update 2018-07-12</strong>: Johannes Schauer send me a few
+succestions and reminded me about an important step. The "screen:"
+input source is only available once the vlc-plugin-access-extra
+package is installed on Debian. Without it, you will see this error
+message: "VLC is unable to open the MRL 'screen://'. Check the log
+for details." He further found that it is possible to drop some parts
+of the VLC command line to reduce the amount of hardcoded information.
+It is also useful to consider using cvlc to avoid having the VLC
+window in the desktop view. In sum, this give us this command line on
+the source end
+
+<blockquote><pre>
+cvlc screen:// --sout \
+ '#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128}:rtp{sdp=rtsp://:8080/}'
+</pre></blockquote>
+
+<p>and this on the Kodi end<p>
+
+<blockquote><pre>
+echo rtsp://192.168.11.4:8080/ \
+ > /storage/videos/screenstream.m3u
+</pre></blockquote>
+
+<p>Still bad image quality, though. But I did discover that streaming
+a DVD using dvdsimple:///dev/dvd as the source had excellent video and
+audio quality, so I guess the issue is in the input or transcoding
+parts, not the rtsp part. I've tried to change the vb and ab
+parameters to use more bandwidth, but it did not make a
+difference.</p>
+
+<p>I further received a suggestion from Einar Haraldseid to try using
+gstreamer instead of VLC, and this proved to work great! He also
+provided me with the trick to get Kodi to use a multicast stream as
+its source. By using this monstrous oneliner, I can stream my desktop
+with good video quality in reasonable framerate to the 239.255.0.1
+multicast address on port 1234:
+
+<blockquote><pre>
+gst-launch-1.0 ximagesrc use-damage=0 ! video/x-raw,framerate=30/1 ! \
+ videoconvert ! queue2 ! \
+ x264enc bitrate=8000 speed-preset=superfast tune=zerolatency qp-min=30 \
+ key-int-max=15 bframes=2 ! video/x-h264,profile=high ! queue2 ! \
+ mpegtsmux alignment=7 name=mux ! rndbuffersize max=1316 min=1316 ! \
+ udpsink host=239.255.0.1 port=1234 ttl-mc=1 auto-multicast=1 sync=0 \
+ pulsesrc device=$(pactl list | grep -A2 'Source #' | \
+ grep 'Name: .*\.monitor$' | cut -d" " -f2|head -1) ! \
+ audioconvert ! queue2 ! avenc_aac ! queue2 ! mux.
+</pre></blockquote>
+
+<p>and this on the Kodi end<p>
+
+<blockquote><pre>
+echo udp://@239.255.0.1:1234 \
+ > /storage/videos/screenstream.m3u
+</pre></blockquote>
+
+<p>Note the trick to pick a valid pulseaudio source. It might not
+pick the one you need. This approach will of course lead to trouble
+if more than one source uses the same multicast port and address.
+Note the ttl-mc=1 setting, which limit the multicast packages to the
+local network. If the value is increased, your screen will be
+broadcasted further, one network "hop" for each increase (read up on
+multicast to learn more. :)!</p>
+
+<p>Having cracked how to get Kodi to receive multicast streams, I
+could use this VLC command to stream to the same multicast address.
+The image quality is way better than the rtsp approach, but gstreamer
+seem to be doing a better job.</p>
+
+<blockquote><pre>
+cvlc screen:// --sout '#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128}:rtp{mux=ts,dst=239.255.0.1,port=1234,sdp=sap}'
+</pre></blockquote>