Python Popen shell=False 导致 OSError : [Errno 2] No such file or directory FFREPORT

标签 python macos ffmpeg popen shlex

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

相关文章:

python - 如何使用 Pandas 将字符串与数据框中的字符串进行比较?

python - 在 python 中包装交互式 CLI

python - pip 卸载包和唯一的依赖项

php - 如何在 linux 中更改 windows 或 mac 文件的文件结尾?

python - 如何根据日期对日期进行分组?

macos - Sierra 上的 kprintf(内核 printf)日志在哪里?

php - 使用帐户获取/解析数据库数据

android - 打开输出流编码器时出错 #0 :0 for Creating Video from image, Gif,music

javascript - Firebase 的云功能 : completing long processes without touching maximum timeout

laravel - FFmpeg 是我唯一可以用来压缩视频文件的东西吗?