使用2 Pass编码设置FFmpeg进程优先级 [英] Set FFmpeg Process Priority with 2 Pass Encoding

查看:131
本文介绍了使用2 Pass编码设置FFmpeg进程优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PowerShell中使用 FFmpeg .

I'm using FFmpeg with PowerShell.

我正在尝试使用FFmpeg的 2 Pass 编码.

I'm trying to set the Process Priority while using FFmpeg's 2 Pass Encoding.

该脚本可用于1 Pass和CRF编码.

The script works with 1 Pass and CRF Encoding.

脚本

第1阶段完成后,它将再次为第2阶段启动FFmpeg.

When Pass 1 finishes, it launches FFmpeg again for Pass 2.

注意:传递1输出到NUL,传递2输出视频文件.

Note: Pass 1 outputs to NUL, Pass 2 outputs the video file.

(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


问题

使用-等待会导致此PowerShell错误:

Using -Wait causes this PowerShell error:

Exception setting "PriorityClass": "Cannot process request because the process (14324) has exited."

但是如果没有 -Wait ,第二遍将永远不会开始,并且我会收到此FFmpeg错误:

But without -Wait the second pass never starts and I get this FFmpeg error:

Failed to initialize encoder: Invalid parameter
Additional information: rc_twopass_stats_in.buf not set.

推荐答案

您要查找的是 Wait-Process .

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

You will need to lose the -wait as that command waits for the process to exit before running the next part of the script

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

这篇关于使用2 Pass编码设置FFmpeg进程优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆