Ludicrous processor usage on my script. How to optimize it?

53 views Asked by At

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!

1

There are 1 answers

0
Silly Freak On

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.