No Comments

Playing 4K smoothly on the Pi4, compiling Kodi 19 on Raspberry Pi OS

June 24th, 2021

Kodi is the best software to watch video on a Raspberry Pi. The Raspberry Pi 4 supports 4K, but the only software that can play it well is Kodi. That’s a bit disappointing, knowing the the Pi4 is already available since early 2019.

On the other hand, Kodi is nice open source software, with a thriving community.

Playing video in a browser is energy-wise, (privacy-wise IMHO) and performance-wise a bad thing. Try playing YouTube movies in a browser and in Kodi (unofficial YouTube plugin), and see the differences. Stuttering play, and high CPU usage in the browser, smooth play and lower CPU usage in Kodi.

The best performance for Kodi is offered by LibreELEC, a lightweight ‘Just enough OS’ Linux distribution. if you wanna run the latest Kodi on Raspberry Pi OS, you’ll need to compile it yourself at the moment.

Compile instructions Kodi 19

There isn’t yet an updated version Kodi 19 in Raspberry Pi OS, so you’ll need to compile Kodi 19 yourself. Big underlying changes in the way video and hardware-accceleration is done in the new kernel 5.10 broke Kodi 18.7 and

On the Kodi forum there are several attempts to compile a working version, but apparently that is not so simple. Still I used those instructions as a base, but added the kernel-header packages ` as a dependency and use a patched version of Kodi.

# sudo apt update && sudo apt full-upgrade -y


sudo apt install                                                     \
autoconf automake autopoint autotools-dev cmake cpp curl default-jre \
g++ gawk gcc gdc gettext git gperf libasound2-dev libass-dev             \
libavahi-client-dev libavahi-common-dev libbluetooth-dev             \
libbluray-dev libbz2-dev libcdio-dev libcec4 libcec-dev              \
libcrossguid-dev libcurl4-openssl-dev libcwiid-dev libdbus-1-dev     \
libdrm-dev libegl1-mesa-dev libenca-dev libflac-dev libfmt3-dev      \
libfontconfig-dev libfreetype6-dev libfribidi-dev libfstrcmp-dev     \
libgbm-dev libgcrypt-dev libgif-dev libgles2-mesa-dev libglew-dev    \
libglu1-mesa-dev libgnutls28-dev libgpg-error-dev libgtest-dev       \
libinput-dev libiso9660-dev libjpeg-dev liblcms2-dev liblirc-dev     \
libltdl-dev liblzo2-dev libmariadb-dev libmicrohttpd-dev libnfs-dev  \
libogg-dev libomxil-bellagio-dev libpcre3-dev libplist-dev           \
libpng-dev libpulse-dev libshairplay-dev libsmbclient-dev            \
libsqlite3-dev libssl-dev libtag1-dev libtiff5-dev libtinyxml-dev    \
libtool libudev-dev libunistring-dev libva-dev libvdpau-dev          \
libvorbis-dev libxkbcommon-dev libxmu-dev libxrandr-dev libxslt1-dev \
libxt-dev lsb-release meson nasm ninja-build python3-dev python3-pil \
python-support rapidjson-dev raspberrypi-kernel-headers swig unzip \
uuid-dev wayland-protocols yasm zip zlib1g-dev

Then you need a special GBM version of Kodi, but instead of this version.

wget https://github.com/popcornmix/xbmc/archive/gbm_matrix.zip

I used a patched version:

wget https://github.com/graysky2/xbmc/archive/refs/heads/gs-gbm_matrix.zip

Then this workaround is needed, Raspberry Pi OS uses a different path for some files. This just creates a symbolic link to the right path.


# drm_fourcc error workaround
sudo mkdir /usr/include/drm/ 
sudo ln -s /usr/include/libdrm/drm_fourcc.h /usr/include/drm/drm_fourcc.h

Extract the downloaded zip:

unzip gs-gbm_matrix.zip

Enter the map

cd xbmc-gs-gbm_matrix

Create build directory:

mkdir kodi-build

Enter build directory

cd kodi-build

Then make:

cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DCORE_PLATFORM_NAME=gbm -DAPP_RENDER_SYSTEM=gles -DX11_RENDER_SYSTEM=gles -DENABLE_INTERNAL_FMT=ON -DENABLE_INTERNAL_FLATBUFFERS=ON -DENABLE_INTERNAL_SPDLOG=ON -DENABLE_VAAPI=OFF -DENABLE_VDPAU=OFF

Then compile

cmake --build . -- VERBOSE=1 -j$(getconf _NPROCESSORS_ONLN)

If done properly, ti should take about 2 hours. Afterwards you can start Kodi with `kodi-build/kodi-gbm`

That’s all. And don’t forget to backup your existing Kodi profile.

Occasionally the script exits with an error. Seems it’s running out of memory. Just restart the building process, executing the cmake –build command, to finish compiling.

No Comments

Serve images in next-gen formats, start using webp

June 11th, 2021

Since Apple added webp support in Safari on both desktop and mobile devices, it’s worth serving images in webp to significantly reduce the size of your images while preserving their quality.  As a guess, you can save 50-66% bandwidth on your images!

Yes, mother earth will like that!

Webp is nowadays supported by 95% of all devices

You can check webp support here, in general you will will be covered for about 95% of all users. A small 5% is using older (out-of-date) software, that probably shouldn’t be used anymore. Now they have a reason to stop using it.

https://caniuse.com/webp

Creating next-gen webp images

Converting jpg to webp isn’t difficult on a modern Linux computer:

convert -quality 50 image.jpg  image.webp

I guess no explanation is needed here.

For a directory of images you could do something like :

mogrify -quality 50 -format webp *.jpg

Creating next-gen webp images the smart way on multi-core machines

On a multi-core machine, start using those cores by running tasks parallel:

parallel "convert -quality 50 -auto-orient {} {.}.webp" ::: *.jpg

This will use all cores and threads and speed up generating next-gen images considerably, 800%  on a modern quad-core machine.

Advantages of webp images

  • webp supports transparency
  • webp supports animation
  • webp supports 24bit RGB color-support
  • smaller size

For PNG images you can save 90% bandwidth, when the main reason to use PNG is transparency.

What about image quality?

Image quality is a subjective matter. I find it acceptable to use a 50% quality by default. Compared to jpg: 60% size reduction, and less artifacts but a bit smoother. That’s OK for me.

No Comments

Raspberry Pi Foundation fixes `Microsoft privacy leak`

March 11th, 2021

The Raspberry Pi Foundation pushed an update to fix the forced addition of the not-so-opensource Visual Studio Code editor from Microsoft to the Raspberry OS repositories.

That means that no longer pings are automatically send to the servers from Microsoft every time a user is checking on his Pi for updates. That is great.

What is exactly done:

Unpacking raspberrypi-sys-mods (20210310) over (20210208) ...
Setting up raspberrypi-sys-mods (20210310) ...
Blocking vscode repo...
Removing obsolete conffile /etc/apt/preferences.d/3rd_parties.pref ...

So this file has been  /etc/apt/sources.list.d/vscode.list has been emptied:

### Disabled by raspberrypi-sys-mods ###

In an earlier post we already advised to edit that file to disable the automatic checking.

We’re glad the Raspberry Pi Foundation followed our advise 😉 .

Furthermore this file has been removed: /etc/apt/preferences.d/3rd_parties.pref

cat /etc/apt/preferences.d/3rd_parties.pref
Package: code code-exploration code-insiders
Pin: release o=code stable
Pin-Priority: 400

Package: *
Pin: release o=code stable
Pin-Priority: -1

Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 400
~

Still the big question, Microsoft is touting about open source and coding for everybody. Why their open source code editor is not released with an open source license is still unanswered. Proprietary telemetry is too important apparently. Disappointing.

Let’s end by citing Jim Bennet, a Microsoft evangelist.

As a young child it was mind-blowing when my Dad brought home a work PC so he could write reports and I could use it to write up my school work – I was using what Dad used at work, making me feel important. I see this with my seven-year-old daughter, seeing her excitement that I use Microsoft Teams for work, the same as she uses for her virtual schooling (she’s even offered to teach me how to use it if I get stuck). To be able to bring that unadulterated joy of using ‘grown-up tools’ to our young learners is priceless.

Arghh, what more to say, a free sample, a marketing trick, priceless for Microsoft. Another reason why schools and kids should use only open source software.

Share knowledge, don’t exploit it.

No Comments

Debugging Audio problems on a Raspberry Pi

February 21st, 2021

A Raspberry Pi is a great small computer that can run 24 hours with no problem, and just consumes a few watts, so it’s a fine candidate for a modern flexible media player.

The default high quality sound output of a Raspberry Pi is HDMI, which is great for video, but not so great for classic stereo systems. The standard analogue out is near CD quality. Fine for system sounds and video calling, but not enough for HiFi. Remember the Pi is designed as a cheap computer for educational purposes.

HiFi audiophiles probably want to add a dedicated USB-DAC (you lose an USB port) or dedicated HAT like HiFiBerry or IQAudio.

ALSA and PulseAudio soundserver

Then we have the software thing. Raspbian always used Advanced Linux Sound Architecture (ALSA) as the driver and skipped the layer of PulseAudio, which is the default sound server that lays on top of ALSA in modern Debian and Ubuntu desktops.

Since the Pi400 was introduced, and marketed as a serious affordable desktop, the now renamed Raspberry Pi OS, started to offer PulseAudio as well in December 2020. The big win of PulseAudio, better support for Bluetooth and more programs can output sound at the same time. With ALSA output would be locked  by one program: you can’t mix.

Well with a caveat. Raspberry Pi OS with desktop is shipped with PulseAudio, but Raspberry Pi OS Lite is not shipped with PulseAudio, because shipping it with PulseAudio would make it a Raspberry Pi OS Medium. ;(

So Raspberry Pi OS Lite uses just ALSA, Raspberry Pi OS with desktop uses also ALSA, but on top of that the PulseAudio layer.

Debug audio on a Raspberry Pi

Check the hardware, it doesn’t matter in this step if you use PulseAudio or not.

Start with listing all audio outputs:

aplay -l

This should output something like:

**** List of PLAYBACK Hardware Devices ****
card 0: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1 [bcm2835 HDMI 1]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 1: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 2: IQaudIODAC [IQaudIODAC], device 0: IQaudIO DAC HiFi pcm512x-hifi-0 [IQaudIO DAC HiFi pcm512x-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 3: DAC [USB AUDIO DAC], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

Here you see the four outputs: HDMI output (0), analogue out (1),  IQAudio HAT  (2), and an USB-DAC (3)

To test your hardware, upload a test.wav file to your Pi (aplay can’t play mp3 files), and try the different outputs.

aplay -D plughw:0 test.wav # HDMI
aplay -D plughw:1 test.wav #headphones/audio out
aplay -D plughw:2 test.wav # iqaudio
aplay -D plughw:3 test.wav # USB DAC

Of course you need to have the outputs properly connected to an amplifier, monitor or headphone. Now you know your hardware is working OK.

Check for a faulty power supply

If you have hisses, or distortion, also always check your Raspberry Pi for throttling and a possible power or heating problem:

vcgencmd get_throttled
throttled=0x0

If you see a different output, that suggests you have a faulty power supply. Phone chargers typically are not stable PSU’s. Better use the official Raspberry Pi power supply. Also the quality of the cable really does matter.

If that is also OK, it’s just about configuring the right output in your software.

Configuring the Music Player Daemon

To set the IQAudio HAT as the default ALSA output in /etc/mpd.conf

audio_output {
type "alsa"
name "IQAudio"
device "hw:2" # set hw:3 for DAC out
}

To set PulseAudio as the default output:

audio_output { type "pulse" 
name "pulse audio" 
}

Do not edit boot/config.txt by default

In general there is no need to edit /boot/config.txt. Official HATS will configure automatically and the same goes for USB-DACS. Plug and play. You see older tutorials or manuals instructing you to edit /boot/config.txt for configuration. IMHO that is only needed in special cases. If you don’t know what you’re doing, don’t edit boot/config.txt.

No Comments

Stop your Raspberry Pi from leaking telemetry to Microsoft

{}
February 19th, 2021

Visual Studio Code is a highly rewarded and much used code-editor from Microsoft.

Microsoft tells you it’s open source, but when you actually install it on your Raspberry Pi 4 or Raspberry Pi 400 as promoted, it suddenly isn’t open source anymore. The installation binaries come packed with some proprietary stuff, like telemetry and tracking.

There is no real reason for that, Microsoft could absolutely disable telemetry by default and offer it 100% open source, but Microsoft doesn’t do that. The company wants to ride on the popular waves of open source without actually practicing it.

Luckily there is a real open source version of VSCode and that is called VSCodium:
https://github.com/VSCodium/vscodium

Somehow Microsoft has managed to get the Raspberry Pi Foundation to add a Microsoft repository with the non-open source version of VSCode.

So when you even do not want to use a Microsoft product, Microsoft is still getting some info about your usage of your Raspberry Pi. In every update your Pi will check with the servers if there is a update.

If you want to stop the spying and tracking, execute this command on your Raspberry Pi:

sudo sed -i 's/^deb/#deb/g' /etc/apt/sources.list.d/vscode.list

Or when you wanna do that remotely:

ssh yourpi "sudo sed -i 's/^deb/#deb/g' /etc/apt/sources.list.d/vscode.list"

This will comment-out the Microsoft repository, and stop checking / leaking usage data to Microsoft.

To install the real VSCode open source version on your Raspberry Pi 4(00):

Install from repository for Debian/Ubuntu/Linux Mint

Recommended way of install. It will update automatically, and now the Gitlab servers will be pinged and not Microsoft’s. 😉

That’s not much of a gain, but you get a version without telemetry and tracking and without proprietary code, and that is of course a real win.

See:

https://github.com/VSCodium/vscodium#install-with-package-manager

Install as Flatpak

Not the best choice, but you can install it aside a repository version; to check and test the speed and functionality of Flatpak builds.

Chances are high, you get a slightly older build this way.

flatpak install flathub com.vscodium.codium

flatpak run com.vscodium.codium
The 100% open source VSCodium running on a Pi 400

The 100% open source VSCodium running on a Pi 400

 

The main ten million dollar question remains, why doesn’t Microsoft offer a 100% open source version of VSCode in the first place?

It’s like wrapping a nice sustainable vegetable up in non-degradable plastic. We won’t save the planet with that attitude.

1 Comment

Kdenlive video-editor and HW acceleration

{}
February 16th, 2021

Trying out the latest and the greatest Kdenlive 20.12.2 on my Ubuntu laptop I was delighted that HW-acceleration was working out of the box on my AMD Ryzen 4000 laptop.

Rendering is nearly twice as fast with HW-acceleration on a AMD Ryzen 4800u, no additional graphics card installed.

Using Kdenlive on flatpak, installing and updating is a breeze.

Installing kdenlive

flatpak install kdenlive
 
Looking for matches…
Found similar ref(s) for ‘kdenlive’ in remote ‘flathub’ (system).
Use this remote? [Y/n]: y
Found ref ‘app/org.kde.kdenlive/x86_64/stable’ in remote ‘flathub’ (system).
Use this ref? [Y/n]: y
Skipping: org.kde.kdenlive/x86_64/stable is already installed

Updating flatpak apps

flatpak update
 
Looking for updates…
Nothing to do.

How to encode with HW-acceleration on your AMD Ryzen laptop for Kdenlive?

Try out these settings for rendering: