python - 使用 ffmpeg/ffprobe 的 CMD 错误输出子进程

标签 python audio cmd ffmpeg ffprobe

我在 cmd 中运行 ffmpeg 时遇到问题 我有正确的输出 "ffprobe passionfruit.mp4 -show_streams"

但是当我对子进程使用相同的方法时:

command = 'ffprobe "C:/Users/NMASLORZ/Downloads/passionfruit.mp4" -show_streams'
p = subprocess.Popen(command, universal_newlines=True, shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
text = p.stdout.read()
retcode = p.wait()
print (text)

我有这个输出: “'ffprobe' 未被识别为内部命令或外部命令、可执行程序或批处理文件。” 我尝试了每个合成器,甚至在列表中我仍然有相同的输出

最佳答案

那是因为您的 Windows 终端读取了系统的 PATH 或以其他方式定义了 ffprobe 的路径。当您使用 shell=True 运行 Popen 时,它会通过 shell 运行执行,shell 可能会或可能不会(您的情况)访问该 PATH。

可能的解决方案:

  1. 提供 ffprobe 的完整路径(最简单):
command = 'C:\whatever\ffprobe.exe "C:/Users/NMASLORZ/Downloads/passionfruit.mp4" -show_streams'
  1. 使用 shell=False。可能不起作用,取决于您的系统。
command = ('ffprobe', 'C:/Users/NMASLORZ/Downloads/passionfruit.mp4', '-show_streams')
p = subprocess.Popen(command, universal_newlines=True, shell=False,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  1. 通过env 变量添加PATH,并在该PATH 中添加ffprobe

If env is not None, it must be a mapping that defines the environment variables for the new process; these are used instead of the default behavior of inheriting the current process’ environment. It is passed directly to Popen.

检查 docs以获得进一步的指导。

关于python - 使用 ffmpeg/ffprobe 的 CMD 错误输出子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67197487/

相关文章:

jquery - 如何在同一页面上制作2个广播流的播放/停止按钮?

java - 从 .jar 文件运行服务器程序

javascript - 无法将音频转换为文本nodejs

html - 禁止自动播放同步到文本的html5音频

windows - 批处理文件,用于将超过 30 分钟的文件从一个文件夹复制到另一个文件夹

windows - 在 Windows 上对带有 jq 的文件使用通配符

python - 为什么 django 查询集不包含对我有用的内容?

python - 无法获取用于屏幕抓取的 xpath

python - 为什么 list.append 在 bool 上下文中评估为 false?

python - IMAP4 不适用于 python anywhere 服务器,但相同的代码适用于本地主机