2

I am calling FFMpeg inside a C# Windows Forms application. Since it uses so much CPU(almost 100%), none of my threads can continue working. Is there a way to limit this CPU usage?

Below is my working code,

Process ffmpeg = new Process();
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.FileName = '..\ffmpeg.exe'
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.Start();

I've tried to set Process.PriorityClass to PriorityClass.BelowNormal but this totally blocked the ffmpeg process.

Is there any other way out?

3
  • possible duplicate of How can I limit FFMpeg CPU usage? Jul 6, 2012 at 7:37
  • You got it right but how can I use -threads parameter? I could not find a proper tutorial to implement -threads.
    – user735647
    Jul 6, 2012 at 7:39
  • 1
    You pass in -threads to FFMPeg as a parameter. I'll post an example shortly.
    – Eric J.
    Jul 6, 2012 at 7:40

1 Answer 1

3

The solution as outlined here

How can I limit FFMpeg CPU usage?

is to limit the number of threads that FFMpeg uses to less than the number of available cores on the computer.

Following up on your comment, you can supply an Argument via StartInfo

Process ffmpeg = new Process();
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.FileName = "..\ffmpeg.exe";
ffmpeg.StartInfo.Arguments = "-threads 2";  // <=== Add this line
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.Start();
3
  • Thanks a lot :) Let me try it out
    – user735647
    Jul 6, 2012 at 7:44
  • 1
    I set -threads=1, but still it does not make any difference to the cpu usage.
    – user735647
    Jul 6, 2012 at 7:54
  • 1
    The syntax for the argument is "-threads 1" not "-threads=1". Did you literally have an equal sign in your code? If so, remove it.
    – Eric J.
    Jul 6, 2012 at 18:32

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.