什么是 cmd for powershell 与 ffmpeg 的等价物

What's the equivalent of cmd for powershell with ffmpeg

来自 https://www.poftut.com/ffmpeg-command-tutorial-examples-video-audio/

ffmpeg -i jellyfish-3-mbps-hd-h264.mkv

在 cmd 中有效,但在 Powershell 中同样有效

Unexpected token '-i' in expression or statement.

那么正确的语法是什么?

如您目前的问题所示,该命令在 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 来调用路径为 的可执行文件quoted and/or 包含 变量引用或子表达式.

# 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

如果您不想考虑什么时候 & 实际上是 必需的,您可以简单地 always 使用它。

& 的语法需求源于具有两种基本解析模式的 PowerShell,并在 .

中进行了详细解释