【问题标题】:Passing arguments to FFMPEG using subprocess.call()使用 subprocess.call() 将参数传递给 FFMPEG
【发布时间】:2018-10-18 02:44:15
【问题描述】:

我正在通过this answer 处理一个 FFMPEG 问题,并且该命令在 Windows 10 命令提示符下运行良好(我只更改了输入和输出文件名):

ffmpeg -i test.mp4  -filter:v "select='gt(scene,0.4)',showinfo" -f null  - 2> test.txt

我的 Python 3 脚本为 subprocess.call() 函数提供参数(作为列表),并且适用于许多基本的 FFMPEG 操作,但不是这个!在最后的null - 2> test.txt 部分似乎失败了,根据我拆分参数的方式显示以下错误消息:

[NULL @ 000001c7e556a3c0] [error] Unable to find a suitable output format for 'pipe:'
[error] pipe:: Invalid argument

[error] Unrecognized option '2> test.txt'.
[fatal] Error splitting the argument list: Option not found

[error] Unrecognized option '2>'.
[fatal] Error splitting the argument list: Option not found

这是我一直在尝试的基本参数列表:

args=['C:\\Program Files\\ffmpeg\\ffmpeg.exe',
      '-i',
      'test.mp4',
      '-filter:v "select=\'gt(scene,0.4)\',showinfo"',
      '-f null',
      '-',
      '2>',
      'test.txt']

加上各种排列组合和拆分最后几个元素。

请有人帮助我通过 Python 3 使用这些参数运行 FFMPEG 的正确语法?

非常感谢 - 我只是看不出哪里出错了:(

【问题讨论】:

  • 为什么不使用包装器来 ffmpeg 而不是在外部调用它(这很危险)。例如github.com/kkroening/ffmpeg-python
  • 感谢 Eypros - 想了解更多关于您认为它“危险”的原因吗?最终,包装器不必自己在外部调用 ffmpeg 吗?这是一个很好的想法,但这是我的推理:1)我正在学习这个新知识,在浏览了你提到的包装器之后,得出结论,学习包装器语法与学习 ffmpeg 标志本身一样长; 2) 减少一个依赖,通常有利于未来的验证,但我可能希望这个项目在商业上可用,并且不想仔细检查许可/版权条件等。

标签: python ffmpeg subprocess command-line-arguments


【解决方案1】:

这并没有深入了解我的语法中出了什么问题,但以下答案为我提供了一种解决方法,基本上使用 shell=True 并将所有参数作为组合字符串传递: subprocess call ffmpeg (command line)

这是我更新后的电话:

subprocess.call("ffmpeg -i test.mp4 -filter:v \"select='gt(scene,0.4)',showinfo\" -f null - 2> output.txt",shell=True)

感谢 Pythonista Cafe 的好心人为我找到了那个 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 2016-10-27
    • 2018-08-19
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多