Trying out live wallpapers on Wayland
Maybe it is really time to drop X11 :(
Published: 2024-01-05

I just got into ricing again, thanks to a fellow Vietnamese who seems to share the same interest with me. He has a very impressive dotfiles repository, which made me feel like ricing again (lol).

So I did a fresh Arch Linux installation and this time decided to do everything from scratch. I wanted to use this opportunity to experiment several stuff.

I went to find some good wallpapers on Pixiv(FE), then live wallpapers just came into my mind. That's it lol, let's get some live wallpapers on Wayland.

The program

Like Hidamari: a video wallpaper program for X11, on Wayland we have mpvpaper. This program was based on mpv to do video playing itself, mpvpaper integrates this feature with wlroots.

mpvpaper is of course, extremely lightweight as it was written entirely in C. The program itself relies on mpv, so in theory, if you had a good mpv config, mpvpaper will also work seamlessly well.

No more talking, let's try out the program right now. You could build it from source, it is lightweight after all. There is also an AUR package available.

git clone --single-branch https://github.com/GhostNaN/mpvpaper
cd mpvpaper
meson build --prefix=/usr/local
ninja -C build
ninja -C build install

The README gave us some usage examples. Of course, you will have to get a video file to use the program. I found a live wallpaper of Raiden Shogun from Genshin Impact, you can find this shit anywhere, so go and look for it by yourself :)

And with that in mind, I must warn you, there are anime girls below.

Better look around.

Usage

Show the wallpaper on all displays:

mpvpaper '*' /path/to/video

Desktop with live wallpaper, but it doesn't fill the whole screen

One thing we noticed, is that the wallpaper wasn't looped, and also didn't take the whole screen as well. Luckily, mpvpaper allows us to pass arguments to mpv by using the -o flag, so we could easily fix these problems with --panscan=1 and --loop.

mpvpaper -o "--panscan=1 --loop" "*"/path/to/video

Desktop with live wallpaper, now filled the screen and looped perfectly

Looks great! , but one problem: This thing hogs too much resources (~140% with my 4-core CPU). This brings us to the next segment.

Tips and tricks

MPV optimization with hardware acceleration

You can optimize MPV and its resources usage according to your machine. Setup hardware acceleration and VAAPI.

This config file should work universally well for all machines. This basically enables hardware acceleration for MPV.

# ~/.config/mpv/mpv.conf
profile=sw-fast
dither-depth=auto
hwdec=auto
hwdec-codecs=all
cache=yes

Video encoding

You can decrease resources usage by re-encoding your videos.

This command encodes the video into H264, scale the video resolution down to 1680px width (my monitor's width) while maintaining the aspect ratio, and change the quality:

ffmpeg -i input.mp4 -c:v libx264 -vtag hvc1 -vf scale=1680:-1 -crf 20 -c:a copy output.mp4

If you encounter a scaling error (something like not divisible by 2), change the scale width to 1920px, or some values you prefer.

I personally use:

ffmpeg -i input.mp4 -preset veryslow -filter:v scale=1920:-1 output.mp4

This decreases the CPU usage from 140% to only 5% (for my video)! And I am using an Intel i5-2320, impressive?

Of course, depending on your preferences, you may or may not have to encode the video. But why not? I can't help you but to recommend you experiment with ffmpeg and see what options you prefer.

Here are some articles that could help you:

Conclusion

A video of my monitor with mpvpaper and htop on (recorded with shitty quality):

Hope this helps you.