PowerShell command for ffmpeg to process items in a folder recursively
Here's an example of a powershell command for converting all files in a directory to mp4 and resizing to 1280x720:
dir *.* | foreach-object { $newname = $_.Name.Remove($_.Name.Length - $_.Extension.Length) + ".mp4"; .\ffmpeg.exe -i "$_" -s 1280x720 $newname }
Related videos on Youtube
user260467
Updated on September 18, 2022Comments
-
user260467 almost 2 years
I'm trying to figure out what PowerShell command [or script if necessary] might allow
ffmpeg
to recursively traverse a directory, pull stills via the-vf
flag, and put all the stills into a folder without any filename conflicts that would cause overwriting.So I know that this works fine for an individual file:
ffmpeg -i input.mov -vf fps=10/60 still%04d.jpg
The files generated start from
still0001.jpg
and count up tostill0002.jpg
,still0003.jpg
, etc.I have a directory that looks like this, with video files at different levels:
-
topFolder1
-
midFolder1
video1.mov
video2.mov
-
midFolder2
video3.mov
video4.mov
-
I'm trying to use a PowerShell command that can pull stills from all the videos
video1.mov
,video2.mov
,video3.mov
, andvideo4.mov
and drop them into one folder.I found a PowerShell command that purports to have ffmpeg traverse a directory recursively, but when I try to adapt it, it's not working.
I run:
PS T:\Exports\1 - Dailies\stills test> for /F "tokens=*" "%G" IN ('dir "T:\Exports\1 - Dailies" *.mov') do ffmpeg -i "%G" -vf fps=10/60 still%05d.jpg
But I get this error:
At line:1 char:4 + for /F "tokens=*" "%G" IN ('dir "T:\Exports\1 - Dailies" *.mov') do f... + ~ Missing opening '(' after keyword 'for'. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
Where am I going wrong?
-
sean christe about 6 yearsThe command that you are running is intended for cmd.exe or batch file execution. Not powershell. To convert this to powershell research these commands:
Get-ChildItem
,foreach
, andInvoke-Expression
among others. -
user260467 about 6 years@EBGreen OK. Running it in
cmd.exe
returns:"%G" was unexpected at this time.
. Any ideas? -
sean christe about 6 yearsThe link that you provided literally says that you need to double the % symbols. The command in that link is also quoted differently than the command that you are running.
-
Vomit IT - Chunky Mess Style about 6 years@user260467 Try to convert your iteration routine logic to run via PS commands, edit your question with what you are trying code wise, to potentially help draw more attention for some assistance as you need. Simply, take a few minutes, and tag me back afterwards. Otherwise run your looped command from
cmd.exe
and notpowershell.exe
and see what happens because at least errorAt line:1 char:4
should not occur. -
user260467 almost 6 years@EBGreen Yes, this is not a batch
.bat
file. Also, I am trying a different command.
-
-
MagTun almost 5 yearsif needed, set your working directory like that
Set-Location -Path "C:\Users\user"
. Also I had to add a line break instead of the; .`
in".mp4"; .\ffmpeg.exe
and remove the.exe