我正在编写一个python脚本来计算一个目录(和子目录,链接等)中所有视频文件的持续时间。
一切都正常,我唯一的问题是下面的代码产生了内存泄漏。我对每个媒体文件使用此函数来获取持续时间。并且所分配的内存显著增加。比如每秒50兆字节。当函数返回值时,内存不会被释放。即使在Windows中关闭所有程序或注销后,内存仍未消失。只有重新启动才会有帮助。
def probe(vid_file_path):
with subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) as proc:
cmd = ["ffprobe", "-loglevel", "quiet", "-print_format", "json", "-show_format", "-show_streams", vid_file_path]
out, err = proc.communicate()
return json.loads(out)我花了几个小时试图弄清楚问题是出在ffprobe还是子进程上。我认为它是ffprobe。
如果我这样做:
cd "<goto ffprobe directory>"
:start
ffprobe -show_streams "<a video file>"
goto start在一个批处理文件中,我可以看到内存也在增加。
EDIT1:如果你想测试我的python脚本,请看这里:https://pastebin.com/NewBgwia
发布于 2020-11-25 00:37:47
Microsoft Defenders的“受控文件夹访问”是我问题的根源。禁用它解决了我的内存泄漏问题。
https://stackoverflow.com/questions/61449192
复制相似问题