python-ffmpeg icon indicating copy to clipboard operation
python-ffmpeg copied to clipboard

Add started event directly after process is started.

Open dmcken opened this issue 1 year ago • 0 comments

I have a similar issue to https://github.com/jonghwanhyeon/python-ffmpeg/pull/61 where I want to change the priority of the FFMpeg process.

The problem I see is there are too many options available and in my humble opinion I don't think its something this library should get involved with. The steps are different:

  • Windows you drop the current process's priority and then raise back to normal after.
  • Linux doesn't allow you to raise yourself back to normal if you do drop your priority so the windows pattern doesn't work.
  • I can't speak to Mac, Solaris or other platforms at this point.

From a chunk of my code that handles Windows and Linux:

if psutil.WINDOWS:
    psutil.Process().nice(PRIORITY_LOWER)
    prog_h = subprocess.Popen(
        call_params,
        stdin=subprocess.PIPE,
        stdout=f_stdout,
        stderr=subprocess.STDOUT,
    )
    psutil.Process().nice(PRIORITY_NORMAL)
elif psutil.LINUX:
    # PermissionError is thrown when attempting to return to the normal
    # priority that is being done above on windows.
    # We are since python 3.3 able to just set the priority of the ffmpeg
    # process directly so this will likely become the default going
    # forward.
    prog_h = subprocess.Popen(
        call_params,
        stdin=subprocess.PIPE,
        stdout=f_stdout,
        stderr=subprocess.STDOUT,
    )
    os.setpriority(os.PRIO_PROCESS, prog_h.pid, PRIORITY_LOWER)

So I recommend a started event that occurs directly after process start, which together with the existing start event can allow the user to use whatever library they want in at least these two scenarios (I expect since the user can put whatever code they want directly before and after the process creation it should cover other scenarios as well).

dmcken avatar Oct 07 '24 16:10 dmcken