1 <?xml version=
"1.0" encoding=
"ISO-8859-1"?>
2 <rss version='
2.0' xmlns:lj='http://www.livejournal.org/rss/lj/
1.0/'
>
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>
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><p
>Last night, I wrote
15 <a href=
"http://people.skolelinux.org/pere/blog/Streaming_the_Linux_desktop_to_Kodi_using_VLC_and_RTSP.html
">a
16 recipe to stream a Linux desktop using VLC to a instance of Kodi
</a
>.
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.
</p
>
22 <p
>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 <a href=
"https://kodi.wiki/view/JSON-RPC_API/v8
">the JSON-RPC API in
27 Kodi
</a
> 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. Also note, I have no idea if audio work, as
34 I only care about the picture part.
</p
>
36 <blockquote
><pre
>
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.
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.
50 curl --silent --header
'Content-Type: application/json
' \
51 --data-binary
"{ \
"id\
":
1, \
"jsonrpc\
": \
"2.0\
", \
"method\
": \
"$cmd\
", \
"params\
": $params }
" \
52 "http://$host/jsonrpc
"
55 if [ -n
"$kodihost
" ] ; then
56 # Stop the playing when we end
57 playerid=$(kodicmd
"$kodihost
" Player.GetActivePlayers
"{}
" |
58 jq .result[].playerid)
59 kodicmd
"$kodihost
" Player.Stop
"{ \
"playerid\
" : $playerid }
" > /dev/null
61 if [
"$gstpid
" ]
&& kill -
0 "$gstpid
" >/dev/null
2>&1; then
62 kill
"$gstpid
"
67 if [ -n
"$
1" ]; then
78 pasrc=$(pactl list | grep -A2
'Source #
' | grep
'Name: .*\.monitor$
' | \
79 cut -d
" " -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 > /dev/null
2>&1 &
90 # Give stream a second to get going
93 # Ask kodi to start streaming using its JSON-RPC API
94 kodicmd
"$kodihost
" Player.Open \
95 "{\
"item\
": { \
"file\
": \
"udp://@$mcast:$mcastport\
" } }
" > /dev/null
98 wait
"$gstpid
"
99 </pre
></blockquote
>
101 <p
>I hope you find the approach useful. I know I do.
</p
>
103 <p
>As usual, if you use Bitcoin and want to show your support of my
104 activities, please send Bitcoin donations to my address
105 <b
><a href=
"bitcoin:
15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
</a
></b
>.
</p
>
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><p
>PS: See
115 <ahref=
"http://people.skolelinux.org/pere/blog/Simple_streaming_the_Linux_desktop_to_Kodi_using_GStreamer_and_RTP.html
">the
116 followup post
</a
> for a even better approach.
</p
>
118 <p
>A while back, I was asked by a friend how to stream the desktop to
119 my projector connected to Kodi. I sadly had to admit that I had no
120 idea, as it was a task I never had tried. Since then, I have been
121 looking for a way to do so, preferable without much extra software to
122 install on either side. Today I found a way that seem to kind of
123 work. Not great, but it is a start.
</p
>
125 <p
>I had a look at several approaches, for example
126 <a href=
"https://github.com/mfoetsch/dlna_live_streaming
">using uPnP
127 DLNA as described in
2011</a
>, but it required a uPnP server, fuse and
128 local storage enough to store the stream locally. This is not going
129 to work well for me, lacking enough free space, and it would
130 impossible for my friend to get working.
</p
>
132 <p
>Next, it occurred to me that perhaps I could use VLC to create a
133 video stream that Kodi could play. Preferably using
134 broadcast/multicast, to avoid having to change any setup on the Kodi
135 side when starting such stream. Unfortunately, the only recipe I
136 could find using multicast used the rtp protocol, and this protocol
137 seem to not be supported by Kodi.
</p
>
139 <p
>On the other hand, the rtsp protocol is working! Unfortunately I
140 have to specify the IP address of the streaming machine in both the
141 sending command and the file on the Kodi server. But it is showing my
142 desktop, and thus allow us to have a shared look on the big screen at
143 the programs I work on.
</p
>
145 <p
>I did not spend much time investigating codeces. I combined the
146 rtp and rtsp recipes from
147 <a href=
"https://wiki.videolan.org/Documentation:Streaming_HowTo/Command_Line_Examples/
">the
148 VLC Streaming HowTo/Command Line Examples
</a
>, and was able to get
149 this working on the desktop/streaming end.
</p
>
151 <blockquote
><pre
>
152 vlc screen:// --sout \
153 '#transcode{vcodec=mp4v,acodec=mpga,vb=
800,ab=
128}:rtp{dst=projector.local,port=
1234,sdp=rtsp://
192.168.11.4:
8080/test.sdp}
'
154 </pre
></blockquote
>
156 <p
>I ssh-ed into my Kodi box and created a file like this with the
157 same IP address:
</p
>
159 <blockquote
><pre
>
160 echo rtsp://
192.168.11.4:
8080/test.sdp \
161 > /storage/videos/screenstream.m3u
162 </pre
></blockquote
>
164 <p
>Note the
192.168.11.4 IP address is my desktops IP address. As far
165 as I can tell the IP must be hardcoded for this to work. In other
166 words, if someone elses machine is going to do the steaming, you have
167 to update screenstream.m3u on the Kodi machine and adjust the vlc
168 recipe. To get started, locate the file in Kodi and select the m3u
169 file while the VLC stream is running. The desktop then show up in my
170 big screen. :)
</p
>
172 <p
>When using the same technique to stream a video file with audio,
173 the audio quality is really bad. No idea if the problem is package
174 loss or bad parameters for the transcode. I do not know VLC nor Kodi
175 enough to tell.
</p
>
177 <p
><strong
>Update
2018-
07-
12</strong
>: Johannes Schauer send me a few
178 succestions and reminded me about an important step. The
"screen:
"
179 input source is only available once the vlc-plugin-access-extra
180 package is installed on Debian. Without it, you will see this error
181 message:
"VLC is unable to open the MRL
'screen://
'. Check the log
182 for details.
" He further found that it is possible to drop some parts
183 of the VLC command line to reduce the amount of hardcoded information.
184 It is also useful to consider using cvlc to avoid having the VLC
185 window in the desktop view. In sum, this give us this command line on
188 <blockquote
><pre
>
189 cvlc screen:// --sout \
190 '#transcode{vcodec=mp4v,acodec=mpga,vb=
800,ab=
128}:rtp{sdp=rtsp://:
8080/}
'
191 </pre
></blockquote
>
193 <p
>and this on the Kodi end
<p
>
195 <blockquote
><pre
>
196 echo rtsp://
192.168.11.4:
8080/ \
197 > /storage/videos/screenstream.m3u
198 </pre
></blockquote
>
200 <p
>Still bad image quality, though. But I did discover that streaming
201 a DVD using dvdsimple:///dev/dvd as the source had excellent video and
202 audio quality, so I guess the issue is in the input or transcoding
203 parts, not the rtsp part. I
've tried to change the vb and ab
204 parameters to use more bandwidth, but it did not make a
205 difference.
</p
>
207 <p
>I further received a suggestion from Einar Haraldseid to try using
208 gstreamer instead of VLC, and this proved to work great! He also
209 provided me with the trick to get Kodi to use a multicast stream as
210 its source. By using this monstrous oneliner, I can stream my desktop
211 with good video quality in reasonable framerate to the
239.255.0.1
212 multicast address on port
1234:
214 <blockquote
><pre
>
215 gst-launch-
1.0 ximagesrc use-damage=
0 ! video/x-raw,framerate=
30/
1 ! \
216 videoconvert ! queue2 ! \
217 x264enc bitrate=
8000 speed-preset=superfast tune=zerolatency qp-min=
30 \
218 key-int-max=
15 bframes=
2 ! video/x-h264,profile=high ! queue2 ! \
219 mpegtsmux alignment=
7 name=mux ! rndbuffersize max=
1316 min=
1316 ! \
220 udpsink host=
239.255.0.1 port=
1234 ttl-mc=
1 auto-multicast=
1 sync=
0 \
221 pulsesrc device=$(pactl list | grep -A2
'Source #
' | \
222 grep
'Name: .*\.monitor$
' | cut -d
" " -f2|head -
1) ! \
223 audioconvert ! queue2 ! avenc_aac ! queue2 ! mux.
224 </pre
></blockquote
>
226 <p
>and this on the Kodi end
<p
>
228 <blockquote
><pre
>
229 echo udp://@
239.255.0.1:
1234 \
230 > /storage/videos/screenstream.m3u
231 </pre
></blockquote
>
233 <p
>Note the trick to pick a valid pulseaudio source. It might not
234 pick the one you need. This approach will of course lead to trouble
235 if more than one source uses the same multicast port and address.
236 Note the ttl-mc=
1 setting, which limit the multicast packages to the
237 local network. If the value is increased, your screen will be
238 broadcasted further, one network
"hop
" for each increase (read up on
239 multicast to learn more. :)!
</p
>
241 <p
>Having cracked how to get Kodi to receive multicast streams, I
242 could use this VLC command to stream to the same multicast address.
243 The image quality is way better than the rtsp approach, but gstreamer
244 seem to be doing a better job.
</p
>
246 <blockquote
><pre
>
247 cvlc screen:// --sout
'#transcode{vcodec=mp4v,acodec=mpga,vb=
800,ab=
128}:rtp{mux=ts,dst=
239.255.0.1,port=
1234,sdp=sap}
'
248 </pre
></blockquote
>
250 <p
>As usual, if you use Bitcoin and want to show your support of my
251 activities, please send Bitcoin donations to my address
252 <b
><a href=
"bitcoin:
15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
</a
></b
>.
</p
>
257 <title>What is the most supported MIME type in Debian in
2018?
</title>
258 <link>http://people.skolelinux.org/pere/blog/What_is_the_most_supported_MIME_type_in_Debian_in_2018_.html
</link>
259 <guid isPermaLink=
"true">http://people.skolelinux.org/pere/blog/What_is_the_most_supported_MIME_type_in_Debian_in_2018_.html
</guid>
260 <pubDate>Mon,
9 Jul
2018 08:
05:
00 +
0200</pubDate>
261 <description><p
>Five years ago,
262 <a href=
"http://people.skolelinux.org/pere/blog/What_is_the_most_supported_MIME_type_in_Debian_.html
">I
263 measured what the most supported MIME type in Debian was
</a
>, by
264 analysing the desktop files in all packages in the archive. Since
265 then, the DEP-
11 AppStream system has been put into production, making
266 the task a lot easier. This made me want to repeat the measurement,
267 to see how much things changed. Here are the new numbers, for
268 unstable only this time:
270 <p
><strong
>Debian Unstable:
</strong
></p
>
274 ----- -----------------------
286 30 audio/x-vorbis+ogg
287 29 image/x-portable-pixmap
289 27 image/x-portable-bitmap
297 <p
>The list was created like this using a sid chroot:
"cat
298 /var/lib/apt/lists/*sid*_dep11_Components-amd64.yml.gz| zcat | awk
'/^
299 - \S+\/\S+$/ {print $
2 }
' | sort | uniq -c | sort -nr | head -
20"</p
>
301 <p
>It is interesting to see how image formats have passed text/plain
302 as the most announced supported MIME type. These days, thanks to the
303 AppStream system, if you run into a file format you do not know, and
304 want to figure out which packages support the format, you can find the
305 MIME type of the file using
"file --mime
&lt;filename
&gt;
", and then
306 look up all packages announcing support for this format in their
307 AppStream metadata (XML or .desktop file) using
"appstreamcli
308 what-provides mimetype
&lt;mime-type
&gt;. For example if you, like
309 me, want to know which packages support inode/directory, you can get a
310 list like this:
</p
>
312 <p
><blockquote
><pre
>
313 % appstreamcli what-provides mimetype inode/directory | grep Package: | sort
320 Package: doublecmd-common
322 Package: enlightenment
342 </pre
></blockquote
></p
>
344 <p
>Using the same method, I can quickly discover that the Sketchup file
345 format is not yet supported by any package in Debian:
</p
>
347 <p
><blockquote
><pre
>
348 % appstreamcli what-provides mimetype application/vnd.sketchup.skp
349 Could not find component providing
'mimetype::application/vnd.sketchup.skp
'.
351 </pre
></blockquote
></p
>
353 <p
>Yesterday I used it to figure out which packages support the STL
3D
356 <p
><blockquote
><pre
>
357 % appstreamcli what-provides mimetype application/sla|grep Package
362 </pre
></blockquote
></p
>
364 <p
>PS: A new version of Cura was uploaded to Debian yesterday.
</p
>
366 <p
>As usual, if you use Bitcoin and want to show your support of my
367 activities, please send Bitcoin donations to my address
368 <b
><a href=
"bitcoin:
15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
</a
></b
>.
</p
>
373 <title>Debian APT upgrade without enough free space on the disk...
</title>
374 <link>http://people.skolelinux.org/pere/blog/Debian_APT_upgrade_without_enough_free_space_on_the_disk___.html
</link>
375 <guid isPermaLink=
"true">http://people.skolelinux.org/pere/blog/Debian_APT_upgrade_without_enough_free_space_on_the_disk___.html
</guid>
376 <pubDate>Sun,
8 Jul
2018 12:
10:
00 +
0200</pubDate>
377 <description><p
>Quite regularly, I let my Debian Sid/Unstable chroot stay untouch
378 for a while, and when I need to update it there is not enough free
379 space on the disk for apt to do a normal
'apt upgrade
'. I normally
380 would resolve the issue by doing
'apt install
&lt;somepackages
&gt;
' to
381 upgrade only some of the packages in one batch, until the amount of
382 packages to download fall below the amount of free space available.
383 Today, I had about
500 packages to upgrade, and after a while I got
384 tired of trying to install chunks of packages manually. I concluded
385 that I did not have the spare hours required to complete the task, and
386 decided to see if I could automate it. I came up with this small
387 script which I call
'apt-in-chunks
':
</p
>
389 <p
><blockquote
><pre
>
392 # Upgrade packages when the disk is too full to upgrade every
393 # upgradable package in one lump. Fetching packages to upgrade using
394 # apt, and then installing using dpkg, to avoid changing the package
395 # flag for manual/automatic.
400 if [
"$
1" ]; then
401 grep -v
"$
1"
407 for p in $(apt list --upgradable | ignore
"$@
" |cut -d/ -f1 | grep -v
'^Listing...
'); do
408 echo
"Upgrading $p
"
410 apt install --download-only -y $p
411 for f in /var/cache/apt/archives/*.deb; do
412 if [ -e
"$f
" ]; then
413 dpkg -i /var/cache/apt/archives/*.deb
418 </pre
></blockquote
></p
>
420 <p
>The script will extract the list of packages to upgrade, try to
421 download the packages needed to upgrade one package, install the
422 downloaded packages using dpkg. The idea is to upgrade packages
423 without changing the APT mark for the package (ie the one recording of
424 the package was manually requested or pulled in as a dependency). To
425 use it, simply run it as root from the command line. If it fail, try
426 'apt install -f
' to clean up the mess and run the script again. This
427 might happen if the new packages conflict with one of the old
428 packages. dpkg is unable to remove, while apt can do this.
</p
>
430 <p
>It take one option, a package to ignore in the list of packages to
431 upgrade. The option to ignore a package is there to be able to skip
432 the packages that are simply too large to unpack. Today this was
433 'ghc
', but I have run into other large packages causing similar
434 problems earlier (like TeX).
</p
>
436 <p
>Update
2018-
07-
08: Thanks to Paul Wise, I am aware of two
437 alternative ways to handle this. The
"unattended-upgrades
438 --minimal-upgrade-steps
" option will try to calculate upgrade sets for
439 each package to upgrade, and then upgrade them in order, smallest set
440 first. It might be a better option than my above mentioned script.
441 Also,
"aptutude upgrade
" can upgrade single packages, thus avoiding
442 the need for using
"dpkg -i
" in the script above.
</p
>
444 <p
>As usual, if you use Bitcoin and want to show your support of my
445 activities, please send Bitcoin donations to my address
446 <b
><a href=
"bitcoin:
15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
</a
></b
>.
</p
>