11

I am using Windows Server Edition 2012 and am very new to using Powershell. Basically, I am trying to convert a bunch of video files that are in a directory to .flv. The code I am using is this:

$inProcessPath = "E:\Random Videos\In Process\$env:username\"

$oldVideos = Get-ChildItem -Include @("*.mp4", "*.avi", "*.divx", "*.mov", "*.mpg", "*.wmv", "*.mkv") -Path $inProcessPath -Recurse #gets all of the videos

cd "E:\FFMPEG\bin\"

foreach ($oldVideo in $oldVideos) {
    $newVideo = [io.path]::ChangeExtension($oldSong.FullName, '.flv')
    .\ffmpeg.exe -i $oldVideo -y -async 1 -b 2000k -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -preset superfast $newVideo 
}

Whenever I run this I don't get any error messages but ffmpeg doesn't run either. I'm sure I'm overlooking something but have no idea what that could be. I've searched the website and compared code to others and still have no idea.

2 Answers 2

16

It most likely has to do with your command line arguments. Since your filesystem path has spaces in it, you'll need to make sure that your filesystem paths are quoted.

Give this code a shot:

$inProcessPath = "E:\Random Videos\In Process\$env:username\"

$oldVideos = Get-ChildItem -Include @("*.mp4", "*.avi", "*.divx", "*.mov", "*.mpg", "*.wmv", "*.mkv") -Path $inProcessPath -Recurse;

Set-Location -Path 'E:\FFMPEG\bin\';

foreach ($oldVideo in $oldVideos) {
    $newVideo = [io.path]::ChangeExtension($oldSong.FullName, '.flv')

    # Declare the command line arguments for ffmpeg.exe
    $ArgumentList = '-i "{0}" -y -async 1 -b 2000k -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -preset superfast "{1}"' -f $oldVideo, $newVideo;

    # Display the command line arguments, for validation
    Write-Host -ForegroundColor Green -Object $ArgumentList;
    # Pause the script until user hits enter
    $null = Read-Host -Prompt 'Press enter to continue, after verifying command line arguments.';

    # Kick off ffmpeg
    Start-Process -FilePath c:\path\to\ffmpeg.exe -ArgumentList $ArgumentList -Wait -NoNewWindow;
}
Sign up to request clarification or add additional context in comments.

1 Comment

small bug in code instead of $newVideo = [io.path]::ChangeExtension($oldSong.FullName, '.flv'), change to : $newVideo = [io.path]::ChangeExtension($oldVideo.FullName, '.flv')
-3

.\ is used to run powershell scripts. example: script run.ps1 would be ran using .\run.ps1 take it out of your script for ffmpeg. Bit surprised your not getting an error but essentially it should say ffmpeg.exe is not a recognized cmdlet

1 Comment

Actually, `.` has nothing to do with scripts specifically, never mind cmdlets; rather, it's the syntax used to override PowerShell's security check that normally prevents executing any command (ps1, bat, exe, cmd, whatever) from the current directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.