2014-01-20 159 views
2

我使用的是Windows Server Edition 2012,對於使用Powershell是非常新的。基本上,我試圖將一組目錄中的視頻文件轉換爲.flv。我使用的代碼是這樣的:在Powershell中使用FFMPEG

$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 
} 

每當我運行此我沒有得到任何錯誤消息,但ffmpeg的不要麼運行。我確定我忽略了一些東西,但不知道這可能是什麼。我搜索了網站,並將代碼與其他人進行了比較,但仍然不知道。

任何幫助將非常感激。

回答

5

它很可能與您的命令行參數有關。由於您的文件系統路徑中有空格,因此您需要確保文件系統路徑被引用。

給這個代碼一個鏡頭:

$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; 
} 
+0

代碼中的小錯誤,而不是 $ newVideo = [io.path] :: ChangeExtension($ oldSong.FullName,'.flv '),更改爲:$ newVideo = [io.path] :: ChangeExtension($ oldVideo.FullName,'.flv') – visual

-2

\用於運行PowerShell腳本。例如:腳本run.ps1將使用。\ run.ps1從ffmpeg腳本中取出。有點驚訝你沒有得到一個錯誤,但本質上它應該說ffmpeg.exe不是一個公認的cmdlet

+0

實際上,'。\'與腳本沒有任何關係,不用介意cmdlet;相反,它是用於覆蓋PowerShell安全檢查的語法,通常可以防止從當前目錄執行任何命令(ps1,bat,exe,cmd,無論)。 –