简体   繁体   English

使用subprocess.call()将参数传递给FFMPEG

[英]Passing arguments to FFMPEG using subprocess.call()

I was working through this answer to an FFMPEG question and the command works just fine through the Windows 10 command prompt (I've only changed the input and output filenames): 我正在解决 FFMPEG问题的答案 ,并且该命令在Windows 10命令提示符下工作正常(我仅更改了输入和输出文件名):

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

My Python 3 script gives arguments (as a list) to the subprocess.call() function and works fine for a number of basic FFMPEG operations, but not this one! 我的Python 3脚本将参数(作为列表)提供给subprocess.call()函数,并且可以很好地用于许多基本的FFMPEG操作,但不是这个! It seems to be failing at the final null - 2> test.txt part, with the following error messages depending on how I split the arguments: 在最后的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

Here's the basic list of arguments I've been trying: 这是我一直在尝试的基本参数列表:

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

Plus various permutations combining and splitting the last few elements. 加上各种排列组合和分割的最后几个元素。

Please could somebody help me with the right syntax for running FFMPEG with these arguments through Python 3? 请有人帮我正确的语法,以便通过Python 3使用这些参数运行FFMPEG吗?

Many thanks - I just can't see where I'm going wrong :( 非常感谢-我只是看不到我要去哪里错了:(

This doesn't get to the bottom of what was going wrong in my syntax but the following answer provided me with a workaround, essentially using shell=True and passing all arguments as a combined string: subprocess call ffmpeg (command line) 这并没有弄清我的语法出了什么问题,但以下答案为我提供了一种解决方法,本质上是使用shell=True并将所有参数作为组合字符串传递: 子进程调用ffmpeg(命令行)

Here's my updated call: 这是我更新的电话:

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

Thanks to the nice people at Pythonista Cafe for finding that one for me :) 感谢Pythonista Cafe的好人为我找到了一个:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM