如您的问题中所示,该命令在 PowerShell 中可以正常工作。
# OK - executable name isn't quoted.
ffmpeg -i jellyfish-3-mbps-hd-h264.mkv
但是,如果您引用可执行路径,问题就会浮出水面。
# FAILS, due to SYNTAX ERROR, because the path is (double)-quoted.
PS> "C:\Program Files\ffmpeg\bin\ffmpeg" -i jellyfish-3-mbps-hd-h264.mkv
Unexpected token '-i' in expression or statement.
出于语法原因,PowerShell 需要&、call operator 来调用路径被引用和/或包含变量的可执行文件引用或子表达式。
# OK - use of &, the call operator, required because of the quoted path.
& "C:\Program Files\ffmpeg\bin\ffmpeg" -i jellyfish-3-mbps-hd-h264.mkv
或者,通过环境变量:
# OK - use of &, the call operator, required because of the variable reference.
# (Double-quoting is optional in this case.)
& $env:ProgramFiles\ffmpeg\bin\ffmpeg -i jellyfish-3-mbps-hd-h264.mkv
如果您不想考虑 & 何时真正需要,您可以简单地始终使用它。
& 的语法需求源于具有两种基本解析模式的 PowerShell,在 this answer 中有详细说明。