Hello. Some day ago, I wanted to use an animated wallpaper for plasma (replacing the previous one). However, this was an animated GIF image that is at a lower resolution than the one of my screen (and with very visible compression artifact) (if anyone is interest… #2606077 - safe, artist:smowu, oc, oc:lacy, oc:seeker, bat pony, dog, dog pony, pegasus, pony, animated, autumn, bridge, car, cinemagraph, crepuscular rays, detailed background, looped, mouth hold, radiation sign, rope, scenery, scenery porn, tail wag, technically advanced, tree, truck, tug of war, tugging, wings - Derpibooru ). I anyway added it to my my wallpaper folder with home-manager and fetchurl.
I then looked at tool that could help enhance the quality of the image. I started using Anime4K (not managed via Nix) a few month ago, and have been really happy for upscaling video at resolution lower or equal to 720p (my screen is at 1080p). After taking a look, I found waifu2x to be the best for this kind of stuff (and the only upscaling software packaged in Nix).
As I like to play with Nix, I started making a nix derivation that would upscale the input video, and make it loop. I based part of my work on my previous experience using Nix for computing another animated wallpaper I hacked with python and inkscape ( https://github.com/marius851000/MLP-loyalty-animated/blob/a1f5d10f1d0ebbe9e7d1315b0a840dd2498c7fd7/default.nix ).
Waifu2x only apply on each frame idividually (don’t directly work on video) so I followed those step (derivation)
- get video metadata (number of frame and framerate) (depend on input video)
- extract each frame as a PNG image (single derivation) (depend on input video)
- for each frame (depend on the metadata), upscale it with waifu2x (depend on extracted frame). There is one derivation per frame (making use of… not sure the name, but dynamic resolution or something like that).
- combine all the frame in a final video at the correct frame rate (depend on every frames and the metadata)
This take some input parameter. Noteworthy is additional_waifu_args = "-m noise-scale --noise-level 3";
, usefull for badly compressed GIF (still cause some artifact). and loop
, that loop the video, and default to true
.
The code is avalaible here lib/upscale_video.nix · master · marius david / mariusnur · GitLab and is avalaible in my nur ( marius david / mariusnur · GitLab ) with the path lib.upscale_video
. Additionally, I have a nix flake that can be used to use animated image wallpaper with plasma ( GitHub - marius851000/ricenur: a Nix User Repository containing various stuff for Nixos ricing ).
Nice aspect of Nix (in addition to theorical reproducibility) is that “automatic” parallelism (well, still needed to package it) and possibility of sharing the work between multiple computer.
I have some question concerning Nix for this kind of work, thought :
- Is it possible to make platform-indendant derivation ? This result should in theory be independant of the hardware used to compute it, but I see many problem that can arise with nix if trying to use multiple CPU family interchangeably. This can be usefull for distributing load with other computer CPU (I have my rasberry pi at home, thought it’s likely not powerfull enought to make an important difference. But with a cluster with Apple, FreeBDS and Linux computer, this could lead to some gain).
(badly wored, see this comment Video upscaling with a Nix derivation - #3 by marius851000 ) - Does Nix cache evaluation at a lower level than flake level and derivation level ?
- Also, do you have any general tips for derivation that output data/images ?