1

I'm running FFmpeg in Command Prompt with low priority.

start /low /b ffmpeg -i "C:\video.mpg" -c:v libx264 -crf 25 "C:\video.mp4"

How can I set FFmpeg's priority in PowerShell for low, below normal, normal, above normal, high?

Using the CMD command above in PowerShell, I get the errors:

Parameter cannot be processed because the parameter name 'i' is ambiguous.
Start-Process : A positional parameter cannot be found that accepts argument 'ffmpeg'.

Testing Solutions

I'm trying to use the first example in ArcSet's answer.

Start-Process ffmpeg -NoNewWindow -Wait -ArgumentList '-i "C:\video.mpg" -c:v libx264 -crf 25 "C:\video.mp4"' -PassThru Set-ProcessPriority -ProcessId $Process.id -Priority AboveNormal

I'm getting the error:

A positional parameter cannot be found that accepts argument 'Set-ProcessPriority'
Matt McManis
  • 4,475
  • 5
  • 38
  • 93
  • In `cmd.exe`, `start` is a built-in command. In PowerShell, it's an alias for `Start-Process`, which will interpret those parameters differently. If you want to run a `cmd.exe`-specific command line, you'll have to do that in `cmd.exe`. – Lance U. Matthews May 27 '20 at 21:52

1 Answers1

5

Using ether Set-ProcessPriority

$Process = Start-Process "C:\ffmpeg\bin\ffmpeg.exe" -ArgumentList "-i `"C:\ffmpeg\Test\Test.mpg`" -c:v libx264 -crf 25 `"C:\ffmpeg\Test\Test.mp4`"" -PassThru
Set-ProcessPriority -ProcessId $Process.id -Priority BelowNormal

Or setting it in the properties of a process

($Process = Start-Process "C:\ffmpeg\bin\ffmpeg.exe" -ArgumentList "-i `"C:\ffmpeg\Test\Test.mpg`" -c:v libx264 -crf 25 `"C:\ffmpeg\Test\Test.mp4`"" -NoNewWindow -PassThru).PriorityClass = [System.Diagnostics.ProcessPriorityClass]::BelowNormal

If you need to verify its set to the Priority you requested you can call the variable you stored the process in and check

$Process.PriorityClass

As a side note you will see the char ` used. This is a escape char and is used so you can use quotes inside quotes

"Hey `"There`" People"

that would return

Hey "There" People
ArcSet
  • 6,518
  • 1
  • 20
  • 34
  • For the given command, I don't think `cmd.exe` is needed at all. `Start-Process ffmpeg -NoNewWindow ... ` combined with either of your approaches to change the priority should suffice. – Lance U. Matthews May 27 '20 at 21:54
  • I want to use the first method, without CMD PassThru. `Start-Process ffmpeg.exe`. How do I then set the Priority and run the ffmpeg arguments after that? – Matt McManis May 27 '20 at 22:03
  • Does this script look correct? https://pastebin.com/raw/sP6gnKAP – Matt McManis May 27 '20 at 22:12
  • @BACON I was showing a example not what he should do. – ArcSet May 28 '20 at 01:00
  • I'm not understanding. All three snippets in your answer show how to launch `cmd.exe` at a particular priority, but you're saying that is _not_ the course of action you're recommending? Why not just make an example based on what you _do_ recommend? There's only two executables to choose from and, in its current state, this answer certainly seems to suggest launching the one that serves no purpose. – Lance U. Matthews May 28 '20 at 02:27
  • I found a way that works using `Start-Process`, `-NoNewWindow -Wait` and `-ArgumentList`, but how can I tell if it is actually setting the priority? https://pastebin.com/raw/mkAaC9ak – Matt McManis May 28 '20 at 02:33
  • Ill look as soon as i can :) @MattMcManis – ArcSet May 28 '20 at 03:23
  • @BACON I am showing him examples of how to set priority. The examples used only show how to set the priority. Him manipulating the example to work for him is where he can learn. – ArcSet May 28 '20 at 03:25
  • @MattMcManis I have added a better example for you in my answer now – ArcSet May 28 '20 at 03:38
  • @ArcSet I'm trying to use the first one, I'm getting the error `A positional parameter cannot be found that accepts argument 'Set-ProcessPriority'`. – Matt McManis May 28 '20 at 04:05
  • Paste your command in your post @MattMcManis. It sounds like you didnt place the ` correctly before " – ArcSet May 28 '20 at 04:06
  • @MattMcManis you posted the command on one line. Those are 2 lines of code not 1. Also get rid of the `-wait`. Since you are doing one line of code i would suggest the second option in my post. If you wanted the first one to be one line you could do this `$Process = Start-Process ffmpeg -NoNewWindow -ArgumentList '-i "C:\video.mpg" -c:v libx264 -crf 25 "C:\video.mp4"' -PassThru ; Set-ProcessPriority -ProcessId $Process.id -Priority AboveNormal` – ArcSet May 28 '20 at 04:13
  • @ArcSet I see, it worked on 2 lines. Though I won't be able to use it with my project, I need it on 1 line. I will have to use solution #2, but with that I get an error at the end `Exception setting "PriorityClass": "Cannot process request because the process (14324) has exited."`. – Matt McManis May 28 '20 at 04:19
  • @MattMcManis That error means the process has already completed before you could set the priority. You need to get rid of the `-wait` – ArcSet May 28 '20 at 04:20
  • @ArcSet Removing `-wait` got it to work, but it causes a problem with 2 Pass encoding, `-wait` made that work. I will open up another question for that and let you know, if you want to take a look at it. – Matt McManis May 28 '20 at 04:35
  • @ArcSet Though I don't really understand how the process is ending before the Priority can be set, because FFmpeg runs for a long time and then PowerShell throws the error at the end. Is the Process not being set while FFmpeg is running? Its setting it after FFmpeg has already finished? – Matt McManis May 28 '20 at 04:49
  • 1
    @MattMcManis `-wait` says stay on this command till its done running. Thats why if you set `-wait` you cant set the priority. The next command takes the process and then sets the priority up. You can then use the `Wait-Process` command to wait after you set the priority. But i feel like that would be a second question – ArcSet May 28 '20 at 05:00
  • @ArcSet Here's my new 2 Pass question https://stackoverflow.com/q/62059522/6806643 – Matt McManis May 28 '20 at 07:46