'getting Missing opening '(' after keyword error in ffmpeg loop command
How can I run this command that runs in Linux in Windows 10 powershell for ffmpeg?
for file in D:\input\*.mkv; do ffmpeg -i "$file" -map 0:v:0 -map 0:a:0 -map 0:a:1 -map 0:s:0 -map 0:s:1 -c:v copy -c:a flac -c:s copy D:\output; done
I tried
for file in D:\input\*.mkv; do ./ffmpeg -i "$file" -map 0:v:0 -map 0:a:0 -map 0:a:1 -map 0:s:0 -map 0:s:1 -c:v copy -c:a flac -c:s copy D:\output; done
But I get this error:
At line:1 char:4
+ for file in D:\input\*.mkv; do ./ffmpeg -i "$fil ...
+ ~
Missing opening '(' after keyword 'for'.
At line:1 char:52
+ for file in D:\input\*.mkv; do ./ffmpeg -i "$fil ...
+ ~
Missing statement body in do loop.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
So how can I change this command to run properly in Windows 10 powershell?
Solution 1:[1]
As the error indicates, PowerShell does not recognize bash
's for
loop syntax.
In PowerShell, you'd do something like this instead:
Get-ChildItem -Path D:\input -Filter *.mkv |ForEach-Object {
./ffmpeg -i $_.FullName -map 0:v:0 -map 0:a:0 -map 0:a:1 -map 0:s:0 -map 0:s:1 -c:v copy -c:a flac -c:s copy D:\output
}
Solution 2:[2]
use rather 'Developer Command Prompt for vs 2022' than powershell(in windows Terminal).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mathias R. Jessen |
Solution 2 | user10822495 |