1

I saw some apps to set a video as wallpaper but they are not free. I don't have a lot of money, so I've decided to create my own with Python!

It was way easier to create than I thought! Unfortunately, I have completely insane percent of processor use with this script!

In fact, the change of background as I does ask lot of resources for explorer.exe

I mean, wait, just look: enter image description here Oof... And this is for the version of 25 FPS!

So, I ask your help and your knowledge to, I hope, achieve the 30 FPS without so much from the processor.

This is my script, it's pretty short:

from time import sleep
import ctypes, os

imagePath = [os.path.normpath("C:/Users/Administrateur/Pictures/bg/output ({}).jpg".format(i)) for i in range(250)]
while True :
    for i in range(250):
        ctypes.windll.user32.SystemParametersInfoW(20, 0, imagePath[i], 0)
        sleep(0.04) # only 25 fps !

Thanks!

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • 1: You have ***Undefined Behavior*** (https://stackoverflow.com/questions/58610333/c-function-called-from-python-via-ctypes-returns-incorrect-value/58611011#58611011). On *64bit* it's likely to crash. 2: You don't have *25 fps* (unless *SystemParametersInfoW* takes no time to execute, which is not true as it has to access the disk, decode the *.jpg*, display it and repaint all the windows on top of desktop). Id suggest to get the time at the beginning, at the end, leave the program to run for a while, then compare the number of *while* iterations to the difference between the 2 timestamps. – CristiFati Dec 03 '19 at 12:35
  • 3: Looking at the *SPI\_GETDESKWALLPAPER*, doc, it mentions smth about a bitmap. Not sure whether it would make any difference, but I'd try convert all *jpg*s to *.bmp*s and try with those. – CristiFati Dec 03 '19 at 12:39
  • Ok I check this ! –  Dec 03 '19 at 12:49
  • @ChrisFati 2. will likely not be as bad as you make out; I don't think that all the IO etc happens synchronously with that API call. But in principle you're correct – Silly Freak Dec 03 '19 at 19:09

1 Answers1

2

With periodically setting images, you won't get that performance. The bottleneck in your script is not the Python code, it's in the loading Windows has to do when the wallpaper changes.

To get what you want, you'll need to play an actual video; videos are compressed across space and time, and codecs often have hardware support, so getting the next frame is easier on the processor. I didn't try, but apparently VLC should be able to do it.

Silly Freak
  • 4,061
  • 1
  • 36
  • 58