我在 OSX 上的 python 2.7 中已工作的 ffmpeg 命令前面添加了一个 FFREPORT 命令,这是为了重定向报告日志文件,但出现错误并且不知道如何修复它。
这是命令:
command = 'FFREPORT="level=48:file=/Users/myself/Desktop/TESTFFMPEGOUTPUT.txt" /Users/myself/Desktop/Python/ffmpeg/ffmpeg -i /Volumes/GRAID/TestInput.mov /Volumes/GRAID/TestOutput.mov'
self.process1 = Popen(shlex.split(command), shell=False)
这给了我错误:
raise child_exception
OSError: [Errno 2] No such file or directory
更新:
我现在已将其更改为包含下面的答案,但遇到了另一个问题。我需要日志文件的路径作为变量,所以我正在尝试:
ffreportCommand = 'FFREPORT=level=48:file=' + self.logFilePath
self.process1 = Popen(shlex.split(command), shell=False, env=dict(ffreportCommand))
但我收到以下错误:
self.process1 = Popen(shlex.split(command), shell=False, env=dict(ffreportCommand))
ValueError: dictionary update sequence element #0 has length 1; 2 is required
更新: 修复:
ffreportCommand = "level=48:file=" + self.logFilePath
self.process1 = Popen(shlex.split(command), shell=False, env=dict(FFREPORT='%s' % ffreportCommand))
最佳答案
FFREPORT
是一个环境变量。因此,使用 the env
parameter 设置它当调用Popen
时:
command = '/Users/myself/Desktop/Python/ffmpeg/ffmpeg -i /Volumes/GRAID/TestInput.mov /Volumes/GRAID/TestOutput.mov'
self.process1 = Popen(
shlex.split(command), shell=False,
env=dict(FFREPORT="level=48:file=/Users/myself/Desktop/TESTFFMPEGOUTPUT.txt"))
<小时/>
如果您希望基于变量构建字典,您可以使用
ffreport = "level=48:file={}".format(self.logFilePath)
self.process1 = Popen(shlex.split(command), shell=False,
env=dict(FFREPORT=ffreport))
<小时/>
顺便说一下,dict(A=val)
相当于 {'A':val}<
。所以另一种选择是
self.process1 = Popen(shlex.split(command), shell=False,
env={'FFREPORT':ffreport})
关于Python Popen shell=False 导致 OSError : [Errno 2] No such file or directory FFREPORT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28026680/