【问题标题】:Python Popen shell=False causes OSError: [Errno 2] No such file or directory FFREPORTPython Popen shell=False 导致 OSError: [Errno 2] No such file or directory FFREPORT
【发布时间】:2015-03-17 13:54:36
【问题描述】:

我在 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))

【问题讨论】:

    标签: python macos ffmpeg popen shlex


    【解决方案1】:

    FFREPORT 是一个环境变量。因此,在调用Popen时使用the env parameter设置:

    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})
    

    【讨论】:

    • 感谢 ubuntu,但我在使用该方法时遇到了另一个问题,我在上面的问题中添加了 UPDATE。
    • 我现在遇到了与 Windows 相同的问题:stackoverflow.com/questions/28048602/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-25
    • 2016-06-07
    • 2017-07-05
    • 2018-11-20
    • 2018-07-24
    • 1970-01-01
    • 2018-01-21
    相关资源
    最近更新 更多