在Powershell中使用FFMPEG

在Powershell中使用FFMPEG,powershell,ffmpeg,Powershell,Ffmpeg,我使用的是Windows Server Edition 2012,对使用Powershell非常陌生。基本上,我正在尝试将目录中的一组视频文件转换为.flv。我使用的代码如下: $inProcessPath = "E:\Random Videos\In Process\$env:username\" $oldVideos = Get-ChildItem -Include @("*.mp4", "*.avi", "*.divx

我使用的是Windows Server Edition 2012,对使用Powershell非常陌生。基本上,我正在尝试将目录中的一组视频文件转换为.flv。我使用的代码如下:

$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也不会运行。我肯定我忽略了一些东西,但不知道那会是什么。我搜索了网站并将代码与其他代码进行了比较,但仍然不知道。

这很可能与您的命令行参数有关。因为文件系统路径中有空格,所以需要确保文件系统路径被引用

尝试一下这段代码:

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

用于运行powershell脚本。示例:脚本run.ps1将使用运行。\run.ps1从ffmpeg的脚本中取出。有点惊讶您没有收到错误,但本质上应该说ffmpeg.exe不是一个可识别的cmdlet

实际上,``与脚本无关,更不用说cmdlet了;相反,它是用于覆盖PowerShell安全检查的语法,通常阻止从当前目录执行任何命令(ps1、bat、exe、cmd等等)。代码中的小错误而不是$newVideo=[io.path]::ChangeExtension($oldSong.FullName,'.flv'),更改为:$newVideo=[io.path]::ChangeExtension($oldVideo.FullName,.flv'))