Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
829 views
in Technique[技术] by (71.8m points)

command line - What's the equivalent of cmd for powershell with ffmpeg

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 Filesffmpeginffmpeg" -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 Filesffmpeginffmpeg" -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:ProgramFilesffmpeginffmpeg -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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...