powershell - 使用 2 遍编码设置 FFmpeg 进程优先级

标签 powershell ffmpeg

我正在使用 FFmpeg使用 PowerShell。

我正在尝试在使用 FFmpeg 的 2 Pass 时设置进程优先级编码。

该脚本适用于 1 Pass 和 CRF 编码。

脚本

当 Pass 1 完成时,它会再次为 Pass 2 启动 FFmpeg。

注意:Pass 1 输出到 NUL,Pass 2 输出视频文件。

(Start-Process ffmpeg -NoNewWindow -Wait -ArgumentList '-i "C:\Path\video.mpg" -c:v libx264 -b:v 2000K -pass 1 NUL' -PassThru).PriorityClass = [System.Diagnostics.ProcessPriorityClass]::AboveNormal; 

(Start-Process ffmpeg -NoNewWindow -Wait -ArgumentList '-i "C:\Path\video.mpg" -c:v libx264 -b:v 2000K -pass 2 "C:\Path\video.mp4"' -PassThru).PriorityClass = [System.Diagnostics.ProcessPriorityClass]::AboveNormal

问题

使用 -Wait导致此 PowerShell 错误:
Exception setting "PriorityClass": "Cannot process request because the process (14324) has exited."

但没有 -Wait第二遍永远不会开始,我得到这个 FFmpeg 错误:
Failed to initialize encoder: Invalid parameter
Additional information: rc_twopass_stats_in.buf not set.

最佳答案

你要找的是Wait-Process .

您将需要丢失 -wait因为该命令在运行脚本的下一部分之前等待进程退出

($Process = Start-Process ffmpeg -NoNewWindow -ArgumentList '-i "C:\Path\video.mpg" -c:v libx264 -b:v 2000K -pass 1 NUL' -PassThru).PriorityClass = [System.Diagnostics.ProcessPriorityClass]::AboveNormal; 
Wait-Process -Id $Process.id
($Process = Start-Process ffmpeg -NoNewWindow -ArgumentList '-i "C:\Path\video.mpg" -c:v libx264 -b:v 2000K -pass 2 "C:\Path\video.mp4"' -PassThru).PriorityClass = [System.Diagnostics.ProcessPriorityClass]::AboveNormal
Wait-Process -Id $Process.id

您可以使用 $Process.HasExited 验证进程是否已退出。
($Process = Start-Process ffmpeg -NoNewWindow -Wait -ArgumentList '-i "C:\Path\video.mpg" -c:v libx264 -b:v 2000K -pass 1 NUL' -PassThru).PriorityClass = [System.Diagnostics.ProcessPriorityClass]::AboveNormal; 
Wait-Process -Id $Process.id
$Process.HasExited
($Process = Start-Process ffmpeg -NoNewWindow -Wait -ArgumentList '-i "C:\Path\video.mpg" -c:v libx264 -b:v 2000K -pass 2 "C:\Path\video.mp4"' -PassThru).PriorityClass = [System.Diagnostics.ProcessPriorityClass]::AboveNormal
Wait-Process -Id $Process.id
$Process.HasExited

关于powershell - 使用 2 遍编码设置 FFmpeg 进程优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62059522/

相关文章:

powershell - 在PowerShell版本2.0中调用Web请求超时

Powershell 导入-CSV : either reorder columns with no headers or export-CSV with no header

c++ - 更改 ffmpeg 中的 mpeg ts pid 值

ffmpeg - 使用 ffmpeg 从视频中提取低/好质量的音频

python - 从python中的视频中获取特定的帧序列

powershell - 更改CSV电子邮件地址

使用 $matches 数组中的值时出现 PowerShell Set-Item 奇怪现象

powershell - Powershell获取计算机AD OU并与定义的字符串进行比较

php - 带水印的ffmpeg质量

ffmpeg - 使用 FFMPEG 从 H264 制作 HLS 剪辑