python - 我的脚本中处理器的使用情况可笑。如何优化呢?

标签 python python-3.x ctypes wallpaper desktop-wallpaper

我看到一些应用程序可以将视频设置为壁纸,但它们不是免费的。我没有很多钱,所以我决定用 Python 创建自己的!

创建比我想象的要容易得多! 不幸的是,我对这个脚本的处理器使用百分比完全疯狂!

事实上,背景的改变,因为我确实为explorer.exe请求了大量资源

我的意思是,等等,看看: enter image description here 噢...这是 25 FPS 的版本!

因此,我请求您的帮助和您的知识,希望能够在不需要处理器太多的情况下实现 30 FPS。

这是我的脚本,很短:

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 !

谢谢!

最佳答案

通过定期设置图像,您将无法获得该性能。脚本中的瓶颈不是 Python 代码,而是壁纸更改时加载 Windows 时必须执行的操作。

要获得您想要的内容,您需要播放实际的视频;视频在空间和时间上进行压缩,编解码器通常有硬件支持,因此处理器更容易获取下一帧。我没有尝试,但显然 VLC should be able to do it .

关于python - 我的脚本中处理器的使用情况可笑。如何优化呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59156238/

相关文章:

python - 如何获取通常在 Django 中递增的字段的默认值?

python - 如何使用 Prometheus 监控 Celery 任务完成情况

python - 为什么不能同时将 args 和仅关键字参数与 *args 和 **kwargs 混合

python - 在 Python 中仅从 CSV 文件中获取一列

python - 操作系统错误 : [WinError 193] %1 is not a valid Win32 application while reading custom DLL in python with CTypes

python - Pandas 数据框将唯一值转换为列名

python - Django "ValueError: embedded null byte"

Python ctypes 指针和分配的内存

python - 如何使用 Python 解析 JPEG 文件中的复杂结构?

python - 一次随机将 Pandas 数据框分成几组以进行 x 折交叉验证