Windows下python 命令行启动播放Movie TV以及Potplayer播放目录下面的视频文件,以及统计播放过程中平均的GPU的Memory占用率,以及GPU的使用率,注意是非Nvidia的GPU。以及统计GPU中具体Decoder engine的平均使用率
时间: 2024-04-04 15:34:00 浏览: 11
好的,您可以使用Python的os模块来执行Windows命令行命令。以下是一个示例代码,可以实现播放指定目录下的视频文件,并使用psutil和GPUtil模块来监测GPU的使用情况:
``` python
import os
import psutil
import GPUtil
# 播放器路径
player_path = r"C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe"
# 视频文件目录
video_dir = r"D:\Videos"
# 遍历目录下的视频文件,并播放
for file in os.listdir(video_dir):
if file.endswith(".mp4") or file.endswith(".avi"):
file_path = os.path.join(video_dir, file)
os.system(f'"{player_path}" "{file_path}"')
# 监测GPU使用情况
gpus = GPUtil.getGPUs()
if len(gpus) > 0:
gpu = gpus[0] # 选择第一块GPU
print("GPU memory usage: {:.2f}GB / {:.2f}GB".format(gpu.memoryUsed / 1024 ** 3, gpu.memoryTotal / 1024 ** 3))
print("GPU utilization: {:.2f}%".format(gpu.load * 100))
for i, engine in enumerate(gpu.decoderUsage):
print("Decoder engine {} utilization: {:.2f}%".format(i, engine * 100))
else:
print("No GPU found.")
```
请注意,您需要安装psutil和GPUtil模块,可以使用以下命令进行安装:
``` bash
pip install psutil GPUtil
```
另外请注意,以上代码仅在Windows系统下测试过,如果在其他系统下运行可能会出现错误。