1

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

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

works in cmd but same on Powershell gives

Unexpected token '-i' in expression or statement.

what's then the right syntax ?

mklement0
  • 382,024
  • 64
  • 607
  • 775
user310291
  • 36,946
  • 82
  • 271
  • 487

1 Answers1

2

As currently shown in your question, the command would work just fine in PowerShell.

# OK - executable name isn't quoted.
ffmpeg -i jellyfish-3-mbps-hd-h264.mkv

However, if you quote the executable path, the problem surfaces.

# 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.

For syntactic reasons, PowerShell requires &, the call operator, to invoke executables whose paths are quoted and/or contain variable references or subexpressions.

# 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

Or, via an environment variable:

# 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

If you don't want to have to think about when & is actually required, you can simply always use it.

The syntactic need for & stems from PowerShell having two fundamental parsing modes and is explained in detail in this answer.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    weird I have not seen that mentioned until now in Powershell articles I read, thanks. – user310291 Oct 18 '20 at 14:59
  • 1
    @user310291, yes, it isn't obvious, and while the need for `&` also applies to PowerShell commands supplied via quoted strings or variables, it is most likely to occur when calling external programs. There is a pending proposal to introduce a help topic that covers all special considerations that apply when calling external programs: https://github.com/MicrosoftDocs/PowerShell-Docs/issues/5152 – mklement0 Oct 18 '20 at 15:33