如何用Python启动Windows播放器电影和电视以及Potplayer播放视频文件,并统计播放过程中的平均CPU的Memory占用以及CPU使用率,统计播放过程中平均的GPU的Memory占用率,以及GPU的使用率。以及统计GPU中具体Decoder engine的平均使用率
时间: 2024-03-20 22:41:25 浏览: 168
可以使用Python的subprocess模块来启动Windows Media Player和Potplayer,使用psutil模块来获取CPU和内存占用率,使用nvidia-smi命令来获取GPU占用率和Decoder engine的使用率。具体实现代码如下:
```python
import subprocess
import psutil
# 启动Windows Media Player播放视频文件
subprocess.Popen('wmplayer.exe path_to_video_file')
# 启动Potplayer播放视频文件
subprocess.Popen('path_to_potplayer.exe path_to_video_file')
# 统计播放过程中的CPU和内存占用率
process = psutil.Process(subprocess.pid)
cpu_percent_list = []
memory_percent_list = []
for i in range(60):
cpu_percent = process.cpu_percent()
memory_percent = process.memory_percent()
cpu_percent_list.append(cpu_percent)
memory_percent_list.append(memory_percent)
average_cpu_percent = sum(cpu_percent_list) / len(cpu_percent_list)
average_memory_percent = sum(memory_percent_list) / len(memory_percent_list)
# 统计播放过程中的GPU占用率和Decoder engine的使用率
gpu_info = subprocess.check_output('nvidia-smi', shell=True).decode()
gpu_memory_list = []
gpu_utilization_list = []
decoder_utilization_list = []
for line in gpu_info.split('\n'):
if 'MiB / ' in line:
gpu_memory = int(line.split('MiB / ')[0].split('|')[-1].strip())
gpu_utilization = int(line.split(' ')[-1].split()[0])
gpu_memory_list.append(gpu_memory)
gpu_utilization_list.append(gpu_utilization)
elif 'Decoder' in line:
decoder_utilization = int(line.split()[2])
decoder_utilization_list.append(decoder_utilization)
average_gpu_memory = sum(gpu_memory_list) / len(gpu_memory_list)
average_gpu_utilization = sum(gpu_utilization_list) / len(gpu_utilization_list)
average_decoder_utilization = sum(decoder_utilization_list) / len(decoder_utilization_list)
```
需要注意的是,如果你的电脑没有安装nvidia-smi命令或者没有NVIDIA GPU,则无法获取GPU的占用率和Decoder engine的使用率。
阅读全文