繁体   English   中英

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

[英]How to run a ffmpeg command in Powershell and pass variables to it?

我想在 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM