0
I have been using just a standard foreach
loop, which executes as it should. However, I have an 8 core processor and 16GB of RAM and thought I would utilize such with a Parallel.foreach
loop. Well, this syntax works as it should
$filelist = Get-ChildItem G:\GoodFilesForServer\ -filter *.mkv
$num = $filelist | measure
$filecount = $num.count
$i = 0;
ForEach ($file in $filelist)
{
$Workflow:i++;
$oldfile = $file.DirectoryName + "\" + $file.BaseName + $file.Extension;
$newfile = $file.DirectoryName + "\" + $file.BaseName + ".mp4";
$progress = ($Workflow:i / $filecount) * 100
$progress = [Math]::Round($progress,2)
Clear-Host
Write-Host -------------------------------------------------------------------------------
Write-Host Handbrake Batch Encoding
Write-Host "Processing - $oldfile"
Write-Host "File $Workflow:i of $filecount - $progress%"
Write-Host -------------------------------------------------------------------------------
Start-Process "C:\Program Files\HandBrake\HandBrakeCLI.exe" -ArgumentList "-i `"$oldfile`" -t 1 --angle 1 -c 1 -o `"$newfile`" -f mp4 -O --decomb --modulus 16 -e x264 -q 32 --vfr -a 1 -E lame -6 dpl2 -R Auto -B 48 -D 0 --gain 0 --audio-fallback ffac3 --x264-preset=veryslow --x264-profile=high --x264-tune=`"animation`" --h264-level=`"4.1`" --verbose=0" -Wait -NoNewWindow
del $oldfile
}
Simple enough, but it is not Parallel
this syntax does not work, and no error is shown to help me determine why it does not work.
Workflow ParallelTest
{
$filelist = Get-ChildItem G:\GoodFilesForServer\ -filter *.mkv
$num = $filelist | measure
$filecount = $num.count
$i = 0;
ForEach -Parallel -ThrottleLimit 20 ($file in $filelist)
{
$Workflow:i++;
$oldfile = $file.DirectoryName + "\" + $file.BaseName + $file.Extension;
$newfile = $file.DirectoryName + "\" + $file.BaseName + ".mp4";
$progress = ($Workflow:i / $filecount) * 100
$progress = [Math]::Round($progress,2)
Clear-Host
Write-Host -------------------------------------------------------------------------------
Write-Host Handbrake Batch Encoding
Write-Host "Processing - $oldfile"
Write-Host "File $Workflow:i of $filecount - $progress%"
Write-Host -------------------------------------------------------------------------------
Start-Process "C:\Program Files\HandBrake\HandBrakeCLI.exe" -ArgumentList "-i `"$oldfile`" -t 1 --angle 1 -c 1 -o `"$newfile`" -f mp4 -O --decomb --modulus 16 -e x264 -q 32 --vfr -a 1 -E lame -6 dpl2 -R Auto -B 48 -D 0 --gain 0 --audio-fallback ffac3 --x264-preset=veryslow --x264-profile=high --x264-tune=`"animation`" --h264-level=`"4.1`" --verbose=0" -Wait -NoNewWindow
del $oldfile
}
}
What should I alter in my Workflow
syntax in order to be able to run the conversion in Parallel
(btw, if a ThrottleLimit
of 20 is insane to try, we can decrease that)
you surely can't
write-host
inside a workflow without an InlineScript. what happens if you delete allx-host
from your workflow? – SimonS – 2016-07-06T09:59:26.437@SimonS - if I delete all the write-host lines, still nothing appears to takes place. For example, in my powershell window when code was executing it would hang on the PS C:\Users\Me line, but when I execute this, there is no delay it immediately writes the syntax to the window and a new C:\Users\Me line is shown (which is what happens when the code has completed execution) – user2676140 – 2016-07-06T11:38:27.980
hmm... are you loading the workflow into the cache first and then call it by executing
ParallelTest
? a workflow behaves like a function so it needs to be loaded into the cache first and then called. – SimonS – 2016-07-06T15:24:29.887@SimonS - I am not sure what you mean by "Loading the workflow into the cache" but I am calling it by using ParallelTest – user2676140 – 2016-07-06T15:28:39.307
you are executing your whole
workflow parallelTest { #stuff }
(this is the loading into cache) and then you're executingParallelTest
(call the workflow). that's what I mean. Just to be sure. – SimonS – 2016-07-06T15:31:33.603Ah, yes that is exactly how I am executing. – user2676140 – 2016-07-06T15:32:24.013
Let us continue this discussion in chat.
– SimonS – 2016-07-06T15:38:40.963