in reply to figuring out Parallel::ForkManager slots

As an "XY answer", why are you running an encoder under Wine? Could you use a native MEncoder build and avoid these problems?

Returning to the question, the important step towards your solution is to note that $pm->start optionally accepts an indentifier, and the callback set with $pm->run_on_finish gets that identifier. An untested partial example:

my @slot_in_use = (0, 0); my @slot_names = qw/one two/; sub find_slot () { for (my $i = 0; $i < @slot_in_use; $i++) { unless ($slot_in_use[$i]) { $slot_in_use[$i] = 1; return $i } } die "slot table full"; } $pm->run_on_finish(sub { my ($c_pid, $c_exit, $c_slot) = @_; $slot_in_use[$c_slot] = 0; # release slot }); foreach my $n (@data) { my $slot = find_slot; $pm->start($slot) and next; # ... $pm->finish; }

Update: Remember how I said "untested"? Stupid variable name error fixed. Using strict does not help if you never run the code at all...

Replies are listed 'Best First'.
Re^2: figuring out Parallel::ForkManager slots
by ramicio (Novice) on Sep 07, 2019 at 00:32 UTC
    The wine part is just a frame server. Things like mencoder and ffmpeg leave much to be desired. The x265 binary is compiled on the machine for the machine. Such architectural things like AVX-512 is why I use such a binary, instead of libraries through stuff like mencoder or ffmpeg. There is really no other way to get frames to such a program other than a pipe. x264 could be built to read video files directly, but processing options were garbage. x265 I don't believe will do anything. I couldn't even get that example to run. It just dies and says slots full without doing anything.

      The example has not been tested, since I write out pipe/fork/select/waitpid longhand when I need them (usually with child processes feeding reports into the Tk event loop through pipes) and do not have Parallel::ForkManager installed. It had a silly mistake that is now fixed, although it does not actually do anything because it does not define contents for the @data array nor is there any actual code to run in the child processes.

      A frame server? Some program that buffers video piecemeal while x265 works on it? Is there a native alternative you could use? Pulling in Wine here just seems ... unnecessary.

        Are you familiar with avisynth and what it can do? I'm dealing with 10-bit HDR video here. It's not as simple as throwing it in mencoder or ffmpeg. Regardless, wine and an install of avisynth IS the easiest route to serve frames to an encoder. There are other avisynth-like things for Linux, but it's not worth my time, and I doubt they deal with higher bit depths well.
      Thank you for your time.