如何在Powershell中运行ffmpeg命令并将变量传递给它



我想在Powershell中运行以下命令:ffmpeg -i "VIDEO.mp4" -i "AUDIO.m4a" -c copy -map 0:v:0 -map 1:a:0 "OUTPUT VIDEO.mp4"

但我想浏览一下这些文件。我试过这个:

Add-Type -AssemblyName System.Windows.Forms 
$VideoBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ 
InitialDirectory = $PSCommandPath
Filter = 'Video file (*.mp4)|*.mp4|All files (*.*)|*.*'
Title = 'Choose video file'
}
$null = $VideoBrowser.ShowDialog()
if (!($VideoBrowser.FileName))
{
return
}
$AudioBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ 
Filter = 'Video file (*.m4a)|*.m4a|All files (*.*)|*.*'
Title = 'Choose audio file'
RestoreDirectory = $true
}
$null = $AudioBrowser.ShowDialog()
if (!($AudioBrowser.FileName))
{
return
}
$NewVideoBrowser = New-Object System.Windows.Forms.SaveFileDialog -Property @{ 
Filter = 'Video file (*.mp4)|*.mp4|All files (*.*)|*.*'
Title = 'Save new video file as'
RestoreDirectory = $true
}
$null = $NewVideoBrowser.ShowDialog()
if (!($NewVideoBrowser.FileName))
{
return
}

所有这些运行命令的方法都失败了:

$ArgumentList = '"{0}" -i "{1}" -c copy -map 0:v:0 -map 1:a:0 "{2}"' -f $VideoBrowser.FileName, $AudioBrowser.FileName, $NewVideoBrowser.FileName;
Start-Process -FilePath ffmpeg.exe -ArgumentList $ArgumentList -Wait -NoNewWindow

$ArgumentList = '"' + $VideoBrowser.FileName + '" -i "' + $AudioBrowser.FileName + '" -c copy -map 0:v:0 -map 1:a:0 "' + $NewVideoBrowser.FileName + '"'
Start-Process -FilePath ffmpeg.exe -ArgumentList $ArgumentList -Wait -NoNewWindow

ffmpeg.exe $VideoBrowser.FileName -i $AudioBrowser.FileName -c copy -map 0:v:0 -map 1:a:0 $NewVideoBrowser.FileName

我应该尝试什么?

我忘记了参数开头的-I

这项工作:ffmpeg -loglevel debug -i $VideoBrowser.FileName -i $AudioBrowser.FileName -c copy -map 0:v:0 -map 1:a:0 $NewVideoBrowser.FileName

最新更新