]> pere.pagekite.me Git - homepage.git/blob - blog/archive/2018/07/07.rss
Generated.
[homepage.git] / blog / archive / 2018 / 07 / 07.rss
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
3 <channel>
4 <title>Petter Reinholdtsen - Entries from July 2018</title>
5 <description>Entries from July 2018</description>
6 <link>http://people.skolelinux.org/pere/blog/</link>
7
8
9 <item>
10 <title>Simple streaming the Linux desktop to Kodi using GStreamer and RTP</title>
11 <link>http://people.skolelinux.org/pere/blog/Simple_streaming_the_Linux_desktop_to_Kodi_using_GStreamer_and_RTP.html</link>
12 <guid isPermaLink="true">http://people.skolelinux.org/pere/blog/Simple_streaming_the_Linux_desktop_to_Kodi_using_GStreamer_and_RTP.html</guid>
13 <pubDate>Thu, 12 Jul 2018 17:55:00 +0200</pubDate>
14 <description>&lt;p&gt;Last night, I wrote
15 &lt;a href=&quot;http://people.skolelinux.org/pere/blog/Streaming_the_Linux_desktop_to_Kodi_using_VLC_and_RTSP.html&quot;&gt;a
16 recipe to stream a Linux desktop using VLC to a instance of Kodi&lt;/a&gt;.
17 During the day I received valuable feedback, and thanks to the
18 suggestions I have been able to rewrite the recipe into a much simpler
19 approach requiring no setup at all. It is a single script that take
20 care of it all.&lt;/p&gt;
21
22 &lt;p&gt;This new script uses GStreamer instead of VLC to capture the
23 desktop and stream it to Kodi. This fixed the video quality issue I
24 saw initially. It further removes the need to add a m3u file on the
25 Kodi machine, as it instead connects to
26 &lt;a href=&quot;https://kodi.wiki/view/JSON-RPC_API/v8&quot;&gt;the JSON-RPC API in
27 Kodi&lt;/a&gt; and simply ask Kodi to play from the stream created using
28 GStreamer. Streaming the desktop to Kodi now become trivial. Copy
29 the script below, run it with the DNS name or IP address of the kodi
30 server to stream to as the only argument, and watch your screen show
31 up on the Kodi screen. Note, it depend on multicast on the local
32 network, so if you need to stream outside the local network, the
33 script must be modified. Note, I have no idea if audio work, as I
34 only care about the picture part.&lt;/p&gt;
35
36 &lt;blockquote&gt;&lt;pre&gt;
37 #!/bin/sh
38 #
39 # Stream the Linux desktop view to Kodi. See
40 # http://people.skolelinux.org/pere/blog/Streaming_the_Linux_desktop_to_Kodi_using_VLC_and_RTSP.html
41 # for backgorund information.
42
43 # Make sure the stream is stopped in Kodi and the gstreamer process is
44 # killed if something go wrong (for example if curl is unable to find the
45 # kodi server). Do the same when interrupting this script.
46 kodicmd() {
47 host=&quot;$1&quot;
48 cmd=&quot;$2&quot;
49 params=&quot;$3&quot;
50 curl --silent --header &#39;Content-Type: application/json&#39; \
51 --data-binary &quot;{ \&quot;id\&quot;: 1, \&quot;jsonrpc\&quot;: \&quot;2.0\&quot;, \&quot;method\&quot;: \&quot;$cmd\&quot;, \&quot;params\&quot;: $params }&quot; \
52 &quot;http://$host/jsonrpc&quot;
53 }
54 cleanup() {
55 if [ -n &quot;$kodihost&quot; ] ; then
56 # Stop the playing when we end
57 playerid=$(kodicmd &quot;$kodihost&quot; Player.GetActivePlayers &quot;{}&quot; |
58 jq .result[].playerid)
59 kodicmd &quot;$kodihost&quot; Player.Stop &quot;{ \&quot;playerid\&quot; : $playerid }&quot; &gt; /dev/null
60 fi
61 if [ &quot;$gstpid&quot; ] &amp;&amp; kill -0 &quot;$gstpid&quot; &gt;/dev/null 2&gt;&amp;1; then
62 kill &quot;$gstpid&quot;
63 fi
64 }
65 trap cleanup EXIT INT
66
67 if [ -n &quot;$1&quot; ]; then
68 kodihost=$1
69 shift
70 else
71 kodihost=kodi.local
72 fi
73
74 mcast=239.255.0.1
75 mcastport=1234
76 mcastttl=1
77
78 pasrc=$(pactl list | grep -A2 &#39;Source #&#39; | grep &#39;Name: .*\.monitor$&#39; | \
79 cut -d&quot; &quot; -f2|head -1)
80 gst-launch-1.0 ximagesrc use-damage=0 ! video/x-raw,framerate=30/1 ! \
81 videoconvert ! queue2 ! \
82 x264enc bitrate=8000 speed-preset=superfast tune=zerolatency qp-min=30 \
83 key-int-max=15 bframes=2 ! video/x-h264,profile=high ! queue2 ! \
84 mpegtsmux alignment=7 name=mux ! rndbuffersize max=1316 min=1316 ! \
85 udpsink host=$mcast port=$mcastport ttl-mc=$mcastttl auto-multicast=1 sync=0 \
86 pulsesrc device=$pasrc ! audioconvert ! queue2 ! avenc_aac ! queue2 ! mux. \
87 &gt; /dev/null 2&gt;&amp;1 &amp;
88 gstpid=$!
89
90 # Give stream a second to get going
91 sleep 1
92
93 # Ask kodi to start streaming using its JSON-RPC API
94 kodicmd &quot;$kodihost&quot; Player.Open \
95 &quot;{\&quot;item\&quot;: { \&quot;file\&quot;: \&quot;udp://@$mcast:$mcastport\&quot; } }&quot; &gt; /dev/null
96
97 # wait for gst to end
98 wait &quot;$gstpid&quot;
99 &lt;/pre&gt;&lt;/blockquote&gt;
100
101 &lt;p&gt;I hope you find the approach useful. I know I do.&lt;/p&gt;
102
103 &lt;p&gt;As usual, if you use Bitcoin and want to show your support of my
104 activities, please send Bitcoin donations to my address
105 &lt;b&gt;&lt;a href=&quot;bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&quot;&gt;15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;
106 </description>
107 </item>
108
109 <item>
110 <title>Streaming the Linux desktop to Kodi using VLC and RTSP</title>
111 <link>http://people.skolelinux.org/pere/blog/Streaming_the_Linux_desktop_to_Kodi_using_VLC_and_RTSP.html</link>
112 <guid isPermaLink="true">http://people.skolelinux.org/pere/blog/Streaming_the_Linux_desktop_to_Kodi_using_VLC_and_RTSP.html</guid>
113 <pubDate>Thu, 12 Jul 2018 02:00:00 +0200</pubDate>
114 <description>&lt;p&gt;A while back, I was asked by a friend how to stream the desktop to
115 my projector connected to Kodi. I sadly had to admit that I had no
116 idea, as it was a task I never had tried. Since then, I have been
117 looking for a way to do so, preferable without much extra software to
118 install on either side. Today I found a way that seem to kind of
119 work. Not great, but it is a start.&lt;/p&gt;
120
121 &lt;p&gt;I had a look at several approaches, for example
122 &lt;a href=&quot;https://github.com/mfoetsch/dlna_live_streaming&quot;&gt;using uPnP
123 DLNA as described in 2011&lt;/a&gt;, but it required a uPnP server, fuse and
124 local storage enough to store the stream locally. This is not going
125 to work well for me, lacking enough free space, and it would
126 impossible for my friend to get working.&lt;/p&gt;
127
128 &lt;p&gt;Next, it occurred to me that perhaps I could use VLC to create a
129 video stream that Kodi could play. Preferably using
130 broadcast/multicast, to avoid having to change any setup on the Kodi
131 side when starting such stream. Unfortunately, the only recipe I
132 could find using multicast used the rtp protocol, and this protocol
133 seem to not be supported by Kodi.&lt;/p&gt;
134
135 &lt;p&gt;On the other hand, the rtsp protocol is working! Unfortunately I
136 have to specify the IP address of the streaming machine in both the
137 sending command and the file on the Kodi server. But it is showing my
138 desktop, and thus allow us to have a shared look on the big screen at
139 the programs I work on.&lt;/p&gt;
140
141 &lt;p&gt;I did not spend much time investigating codeces. I combined the
142 rtp and rtsp recipes from
143 &lt;a href=&quot;https://wiki.videolan.org/Documentation:Streaming_HowTo/Command_Line_Examples/&quot;&gt;the
144 VLC Streaming HowTo/Command Line Examples&lt;/a&gt;, and was able to get
145 this working on the desktop/streaming end.&lt;/p&gt;
146
147 &lt;blockquote&gt;&lt;pre&gt;
148 vlc screen:// --sout \
149 &#39;#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128}:rtp{dst=projector.local,port=1234,sdp=rtsp://192.168.11.4:8080/test.sdp}&#39;
150 &lt;/pre&gt;&lt;/blockquote&gt;
151
152 &lt;p&gt;I ssh-ed into my Kodi box and created a file like this with the
153 same IP address:&lt;/p&gt;
154
155 &lt;blockquote&gt;&lt;pre&gt;
156 echo rtsp://192.168.11.4:8080/test.sdp \
157 &gt; /storage/videos/screenstream.m3u
158 &lt;/pre&gt;&lt;/blockquote&gt;
159
160 &lt;p&gt;Note the 192.168.11.4 IP address is my desktops IP address. As far
161 as I can tell the IP must be hardcoded for this to work. In other
162 words, if someone elses machine is going to do the steaming, you have
163 to update screenstream.m3u on the Kodi machine and adjust the vlc
164 recipe. To get started, locate the file in Kodi and select the m3u
165 file while the VLC stream is running. The desktop then show up in my
166 big screen. :)&lt;/p&gt;
167
168 &lt;p&gt;When using the same technique to stream a video file with audio,
169 the audio quality is really bad. No idea if the problem is package
170 loss or bad parameters for the transcode. I do not know VLC nor Kodi
171 enough to tell.&lt;/p&gt;
172
173 &lt;p&gt;&lt;strong&gt;Update 2018-07-12&lt;/strong&gt;: Johannes Schauer send me a few
174 succestions and reminded me about an important step. The &quot;screen:&quot;
175 input source is only available once the vlc-plugin-access-extra
176 package is installed on Debian. Without it, you will see this error
177 message: &quot;VLC is unable to open the MRL &#39;screen://&#39;. Check the log
178 for details.&quot; He further found that it is possible to drop some parts
179 of the VLC command line to reduce the amount of hardcoded information.
180 It is also useful to consider using cvlc to avoid having the VLC
181 window in the desktop view. In sum, this give us this command line on
182 the source end
183
184 &lt;blockquote&gt;&lt;pre&gt;
185 cvlc screen:// --sout \
186 &#39;#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128}:rtp{sdp=rtsp://:8080/}&#39;
187 &lt;/pre&gt;&lt;/blockquote&gt;
188
189 &lt;p&gt;and this on the Kodi end&lt;p&gt;
190
191 &lt;blockquote&gt;&lt;pre&gt;
192 echo rtsp://192.168.11.4:8080/ \
193 &gt; /storage/videos/screenstream.m3u
194 &lt;/pre&gt;&lt;/blockquote&gt;
195
196 &lt;p&gt;Still bad image quality, though. But I did discover that streaming
197 a DVD using dvdsimple:///dev/dvd as the source had excellent video and
198 audio quality, so I guess the issue is in the input or transcoding
199 parts, not the rtsp part. I&#39;ve tried to change the vb and ab
200 parameters to use more bandwidth, but it did not make a
201 difference.&lt;/p&gt;
202
203 &lt;p&gt;I further received a suggestion from Einar Haraldseid to try using
204 gstreamer instead of VLC, and this proved to work great! He also
205 provided me with the trick to get Kodi to use a multicast stream as
206 its source. By using this monstrous oneliner, I can stream my desktop
207 with good video quality in reasonable framerate to the 239.255.0.1
208 multicast address on port 1234:
209
210 &lt;blockquote&gt;&lt;pre&gt;
211 gst-launch-1.0 ximagesrc use-damage=0 ! video/x-raw,framerate=30/1 ! \
212 videoconvert ! queue2 ! \
213 x264enc bitrate=8000 speed-preset=superfast tune=zerolatency qp-min=30 \
214 key-int-max=15 bframes=2 ! video/x-h264,profile=high ! queue2 ! \
215 mpegtsmux alignment=7 name=mux ! rndbuffersize max=1316 min=1316 ! \
216 udpsink host=239.255.0.1 port=1234 ttl-mc=1 auto-multicast=1 sync=0 \
217 pulsesrc device=$(pactl list | grep -A2 &#39;Source #&#39; | \
218 grep &#39;Name: .*\.monitor$&#39; | cut -d&quot; &quot; -f2|head -1) ! \
219 audioconvert ! queue2 ! avenc_aac ! queue2 ! mux.
220 &lt;/pre&gt;&lt;/blockquote&gt;
221
222 &lt;p&gt;and this on the Kodi end&lt;p&gt;
223
224 &lt;blockquote&gt;&lt;pre&gt;
225 echo udp://@239.255.0.1:1234 \
226 &gt; /storage/videos/screenstream.m3u
227 &lt;/pre&gt;&lt;/blockquote&gt;
228
229 &lt;p&gt;Note the trick to pick a valid pulseaudio source. It might not
230 pick the one you need. This approach will of course lead to trouble
231 if more than one source uses the same multicast port and address.
232 Note the ttl-mc=1 setting, which limit the multicast packages to the
233 local network. If the value is increased, your screen will be
234 broadcasted further, one network &quot;hop&quot; for each increase (read up on
235 multicast to learn more. :)!&lt;/p&gt;
236
237 &lt;p&gt;Having cracked how to get Kodi to receive multicast streams, I
238 could use this VLC command to stream to the same multicast address.
239 The image quality is way better than the rtsp approach, but gstreamer
240 seem to be doing a better job.&lt;/p&gt;
241
242 &lt;blockquote&gt;&lt;pre&gt;
243 cvlc screen:// --sout &#39;#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128}:rtp{mux=ts,dst=239.255.0.1,port=1234,sdp=sap}&#39;
244 &lt;/pre&gt;&lt;/blockquote&gt;
245
246 &lt;p&gt;As usual, if you use Bitcoin and want to show your support of my
247 activities, please send Bitcoin donations to my address
248 &lt;b&gt;&lt;a href=&quot;bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&quot;&gt;15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;
249 </description>
250 </item>
251
252 <item>
253 <title>What is the most supported MIME type in Debian in 2018?</title>
254 <link>http://people.skolelinux.org/pere/blog/What_is_the_most_supported_MIME_type_in_Debian_in_2018_.html</link>
255 <guid isPermaLink="true">http://people.skolelinux.org/pere/blog/What_is_the_most_supported_MIME_type_in_Debian_in_2018_.html</guid>
256 <pubDate>Mon, 9 Jul 2018 08:05:00 +0200</pubDate>
257 <description>&lt;p&gt;Five years ago,
258 &lt;a href=&quot;http://people.skolelinux.org/pere/blog/What_is_the_most_supported_MIME_type_in_Debian_.html&quot;&gt;I
259 measured what the most supported MIME type in Debian was&lt;/a&gt;, by
260 analysing the desktop files in all packages in the archive. Since
261 then, the DEP-11 AppStream system has been put into production, making
262 the task a lot easier. This made me want to repeat the measurement,
263 to see how much things changed. Here are the new numbers, for
264 unstable only this time:
265
266 &lt;p&gt;&lt;strong&gt;Debian Unstable:&lt;/strong&gt;&lt;/p&gt;
267
268 &lt;pre&gt;
269 count MIME type
270 ----- -----------------------
271 56 image/jpeg
272 55 image/png
273 49 image/tiff
274 48 image/gif
275 39 image/bmp
276 38 text/plain
277 37 audio/mpeg
278 34 application/ogg
279 33 audio/x-flac
280 32 audio/x-mp3
281 30 audio/x-wav
282 30 audio/x-vorbis+ogg
283 29 image/x-portable-pixmap
284 27 inode/directory
285 27 image/x-portable-bitmap
286 27 audio/x-mpeg
287 26 application/x-ogg
288 25 audio/x-mpegurl
289 25 audio/ogg
290 24 text/html
291 &lt;/pre&gt;
292
293 &lt;p&gt;The list was created like this using a sid chroot: &quot;cat
294 /var/lib/apt/lists/*sid*_dep11_Components-amd64.yml.gz| zcat | awk &#39;/^
295 - \S+\/\S+$/ {print $2 }&#39; | sort | uniq -c | sort -nr | head -20&quot;&lt;/p&gt;
296
297 &lt;p&gt;It is interesting to see how image formats have passed text/plain
298 as the most announced supported MIME type. These days, thanks to the
299 AppStream system, if you run into a file format you do not know, and
300 want to figure out which packages support the format, you can find the
301 MIME type of the file using &quot;file --mime &amp;lt;filename&amp;gt;&quot;, and then
302 look up all packages announcing support for this format in their
303 AppStream metadata (XML or .desktop file) using &quot;appstreamcli
304 what-provides mimetype &amp;lt;mime-type&amp;gt;. For example if you, like
305 me, want to know which packages support inode/directory, you can get a
306 list like this:&lt;/p&gt;
307
308 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;
309 % appstreamcli what-provides mimetype inode/directory | grep Package: | sort
310 Package: anjuta
311 Package: audacious
312 Package: baobab
313 Package: cervisia
314 Package: chirp
315 Package: dolphin
316 Package: doublecmd-common
317 Package: easytag
318 Package: enlightenment
319 Package: ephoto
320 Package: filelight
321 Package: gwenview
322 Package: k4dirstat
323 Package: kaffeine
324 Package: kdesvn
325 Package: kid3
326 Package: kid3-qt
327 Package: nautilus
328 Package: nemo
329 Package: pcmanfm
330 Package: pcmanfm-qt
331 Package: qweborf
332 Package: ranger
333 Package: sirikali
334 Package: spacefm
335 Package: spacefm
336 Package: vifm
337 %
338 &lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
339
340 &lt;p&gt;Using the same method, I can quickly discover that the Sketchup file
341 format is not yet supported by any package in Debian:&lt;/p&gt;
342
343 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;
344 % appstreamcli what-provides mimetype application/vnd.sketchup.skp
345 Could not find component providing &#39;mimetype::application/vnd.sketchup.skp&#39;.
346 %
347 &lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
348
349 &lt;p&gt;Yesterday I used it to figure out which packages support the STL 3D
350 format:&lt;/p&gt;
351
352 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;
353 % appstreamcli what-provides mimetype application/sla|grep Package
354 Package: cura
355 Package: meshlab
356 Package: printrun
357 %
358 &lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
359
360 &lt;p&gt;PS: A new version of Cura was uploaded to Debian yesterday.&lt;/p&gt;
361
362 &lt;p&gt;As usual, if you use Bitcoin and want to show your support of my
363 activities, please send Bitcoin donations to my address
364 &lt;b&gt;&lt;a href=&quot;bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&quot;&gt;15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;
365 </description>
366 </item>
367
368 <item>
369 <title>Debian APT upgrade without enough free space on the disk...</title>
370 <link>http://people.skolelinux.org/pere/blog/Debian_APT_upgrade_without_enough_free_space_on_the_disk___.html</link>
371 <guid isPermaLink="true">http://people.skolelinux.org/pere/blog/Debian_APT_upgrade_without_enough_free_space_on_the_disk___.html</guid>
372 <pubDate>Sun, 8 Jul 2018 12:10:00 +0200</pubDate>
373 <description>&lt;p&gt;Quite regularly, I let my Debian Sid/Unstable chroot stay untouch
374 for a while, and when I need to update it there is not enough free
375 space on the disk for apt to do a normal &#39;apt upgrade&#39;. I normally
376 would resolve the issue by doing &#39;apt install &amp;lt;somepackages&amp;gt;&#39; to
377 upgrade only some of the packages in one batch, until the amount of
378 packages to download fall below the amount of free space available.
379 Today, I had about 500 packages to upgrade, and after a while I got
380 tired of trying to install chunks of packages manually. I concluded
381 that I did not have the spare hours required to complete the task, and
382 decided to see if I could automate it. I came up with this small
383 script which I call &#39;apt-in-chunks&#39;:&lt;/p&gt;
384
385 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;
386 #!/bin/sh
387 #
388 # Upgrade packages when the disk is too full to upgrade every
389 # upgradable package in one lump. Fetching packages to upgrade using
390 # apt, and then installing using dpkg, to avoid changing the package
391 # flag for manual/automatic.
392
393 set -e
394
395 ignore() {
396 if [ &quot;$1&quot; ]; then
397 grep -v &quot;$1&quot;
398 else
399 cat
400 fi
401 }
402
403 for p in $(apt list --upgradable | ignore &quot;$@&quot; |cut -d/ -f1 | grep -v &#39;^Listing...&#39;); do
404 echo &quot;Upgrading $p&quot;
405 apt clean
406 apt install --download-only -y $p
407 for f in /var/cache/apt/archives/*.deb; do
408 if [ -e &quot;$f&quot; ]; then
409 dpkg -i /var/cache/apt/archives/*.deb
410 break
411 fi
412 done
413 done
414 &lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
415
416 &lt;p&gt;The script will extract the list of packages to upgrade, try to
417 download the packages needed to upgrade one package, install the
418 downloaded packages using dpkg. The idea is to upgrade packages
419 without changing the APT mark for the package (ie the one recording of
420 the package was manually requested or pulled in as a dependency). To
421 use it, simply run it as root from the command line. If it fail, try
422 &#39;apt install -f&#39; to clean up the mess and run the script again. This
423 might happen if the new packages conflict with one of the old
424 packages. dpkg is unable to remove, while apt can do this.&lt;/p&gt;
425
426 &lt;p&gt;It take one option, a package to ignore in the list of packages to
427 upgrade. The option to ignore a package is there to be able to skip
428 the packages that are simply too large to unpack. Today this was
429 &#39;ghc&#39;, but I have run into other large packages causing similar
430 problems earlier (like TeX).&lt;/p&gt;
431
432 &lt;p&gt;Update 2018-07-08: Thanks to Paul Wise, I am aware of two
433 alternative ways to handle this. The &quot;unattended-upgrades
434 --minimal-upgrade-steps&quot; option will try to calculate upgrade sets for
435 each package to upgrade, and then upgrade them in order, smallest set
436 first. It might be a better option than my above mentioned script.
437 Also, &quot;aptutude upgrade&quot; can upgrade single packages, thus avoiding
438 the need for using &quot;dpkg -i&quot; in the script above.&lt;/p&gt;
439
440 &lt;p&gt;As usual, if you use Bitcoin and want to show your support of my
441 activities, please send Bitcoin donations to my address
442 &lt;b&gt;&lt;a href=&quot;bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&quot;&gt;15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;
443 </description>
444 </item>
445
446 </channel>
447 </rss>