Archive for the ‘Webtechnology’ Category

1 Comment

Serve images in next-gen formats, start using webp

Friday, 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`

Thursday, 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

Sunday, 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.

1 Comment

Kdenlive video-editor and HW acceleration

Tuesday, 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:

 

3 Comments

Using A Raspberry Pi Zero as a webcam without SD card

Thursday, January 7th, 2021

The covid lock-down is sentencing a lot of people to work from home. For that we need webcams, a new pc, better monitor  and other equipment. The Raspberry Pi 400 is  a great and affordable second desktop, it’s the fastest Pi available suited for desktop use. It lacks a camera connector, so you need a Zero to connect a camera board.

So what about reusing that old gadget that was collecting dust in the drawer: a small and cheap Raspberry Pi Zero. If you also happen to own a camera board for that little computer, here is a nice project showmewebcam to turn that cheap computer into a handy webcam. It uses a small Buildroot Linux version and boots really fast.

And now that project has been forked on Github: showmewebcam-usbboot. No SD-card needed. That project will let the Raspberry Pi Zero boot over USB!

If you don’t have a camera board. You can buy a clone version of the v1 board for a few dollars in China, or get a v2 board or for the best results the really great HQ-camera board.

Interested in photography, that High Quality camera board can do some really great macro-photography.

Cheap Raspberry Pi webcam

With the Raspberry Pi Zero costing about 5 euro, and a clone camera board around 3 euro on AliExpress, you can have a very nice and decent webcam for less then 10 euro’s. And that is a bargain. Remember you don’t need an SD card. So save on the hardware where you can.

How does it work?

How does the Pi boot then? Over USB, so you do need the usbboot/rpiboot tool. That is free and opensource software made by the Raspberry Pi organization, a program that makes the Raspberry P Zero boot by pushing the operating system over USB.

Let’s try it out. I’m using an Ubuntu desktop.

Step 1: download showmewebcam-usbboot

Download the latest release .

Unzip it. You will extract a directory called showmewebcam-usbboot.

Step 2: install usbboot/rpiboot

If you have already installed a version of this tool, you can of course skip this tool and jump to step 3.

Download the usbboot/rpiboot, unzip it and build it according to the instructions.

Step 3: Connect the raspberry Pi Zero

(with installed camera board) by putting the USB plug into the middle USB connector.

Step 4: boot the webcam

You can start the webcam by executing the rpiboot tool and pointing it to the unzipped showmewebcam-usbboot directory

sudo ~/usbboot/rpiboot -d ~/showmewebcam-usbboot

After about half a minute booting the Raspberry Pi Webcam will be ready.

How to use the Webcam on the PC

For a quick start, and when no other cam is connected, you can start the webcam with (Ubuntu):

mpv /dev/video0

On a laptop with a build-in webcam the command that you have to issue will be :

mpv /dev/video2

To control your cams on the PC, you need `v4l-utils` (apt install v4l-utils)

To set the resolution

v4l2-ctl --set-fmt-video=width=1280,height=720 -d /dev/video2

To list all video devices:

v4l2-ctl --list-devices

To list the specs of your video devices:

v4l2-ctl --list-formats-ext
ffmpeg -f v4l2 -list_formats all -i /dev/video2

A serial connection will also be available, so you can connect to the Webcam to control the settings and do debugging. That works exactly the same as in showmewebcam

Control the webcam

Finer control offers the camera-ctl tool on the Zero

Connect to the Zero:

sudo screen /dev/ttyACM0 115200 Start the tool # /usr/bin/camera-ctl
Showmewebcam-usbboot - Controlling the webcam with camera-ctl

Controlling the webcam with camera-ctl

Create a stereo webcam

The tool will let you boot more then one Raspberry Pi Zero from the same directory. Just connect the two Raspberry Pi Webcams and start the tool. One will boot, just execute the tool another time and the other one will boot.

The webcams will be available as /dev/video0 (you) and /dev/video2 (your cat) on your Pi400.

Now make that video call with your boss, and ask for a raise. Switch the webcam to your cat the moment you stopped speaking.

What can showmewebcam-usbboot do what showmewebcam can’t do?

Nothing. It can do the same with less hardware, because it doesn’t need an SD card. But is does need extra software, which can limit compatibility. It also boots slower.

It hasn’t been tested that much.

Have fun, try it out,  en let me now your thoughts!

Links:

No Comments

Running Raspberry Pi OS on a RPI Zero without SD card

Saturday, January 2nd, 2021

I’ve blogged before about how to boot a Raspberry Pi Zero over USB without an SD card, just powering it with an USB cable in the middle USB connector, and connecting at the same time.

This Christmas I tried it with a new Buster version and a trusty old Raspberry Pi Zero and following the tutorial it’s still running fine with the latest Raspberry Pi OS 2020-12-02-raspios-buster-armhf-lite.img.

Time for some improvements. Updating and upgrading was always possible, but not always successful: you could easily run into disk-space problems.

Default images are shipped/downloaded as small as possible and the default action of booting a Pi with a new image is resizing the root partition to claim all available space on the SD card.

We’re mounting over NFS and of course the resizing did not happen in our case. Luckily, otherwise your guest OS would end up with no space and the Pi would have a partition size of 1GB (or so).

But for upgrades we need more space than the default.

How to increase the image size of an mounted image over NFS?

The image I have downloaded is `2020-12-02-raspios-buster-armhf-lite.zip`, and we have to follow 4 simple steps.

Step 1: unpack it:

unzip 2020-12-02-raspios-buster-armhf-lite.zip 2020-12-02-raspios-buster-armhf-lite.img

Step 2: resize raw image:

Then use qemu-img (QEMU disk image utility) to resize the raw image.

sudo qemu-img resize 2020-12-02-raspios-buster-armhf-lite.img 3G

Here we resize it to 3G, that must be enough to install some extra programs, and download and install updates.

Step 3: set it up as loop device:

sudo losetup -P /dev/loop101 2020-12-02-raspios-buster-armhf-lite.img

These day I set it up as loop101 instead of loop0 as I did in the blogpost of 2018 to avoid conflicting loop devices. Snaps are also installed as loop devices.

Step 4: resize root partition

start gparted with the loop device to resize the root partition.

sudo gparted /dev/loop101

Normally gparted never shows loop devices, but it does when you explicitly start with a loop device.

Then simply push the slider to resize the image, and apply the changes and you’ve gained 900MB of disk-space.

More than enough to do updates and upgrades for years to come.