【问题标题】:What's the equivalent of cmd for powershell with ffmpeg带有ffmpeg的powershell的cmd相当于什么
【发布时间】:2020-10-18 12:43:32
【问题描述】:

来自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 command-line syntax


    【解决方案1】:

    如您的问题中所示,该命令在 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 中有详细说明。

    【讨论】:

    • 很奇怪,直到现在我阅读的 Powershell 文章中都没有提到这一点,谢谢。
    • @user310291,是的,这并不明显,虽然& 的需求也适用于通过引用字符串或变量提供的 PowerShell 命令,但它最有可能在调用外部程序时发生。有一个未决提案要引入一个帮助主题,该主题涵盖了调用外部程序时适用的所有特殊注意事项:github.com/MicrosoftDocs/PowerShell-Docs/issues/5152
    猜你喜欢
    • 2018-05-27
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多