title: How to pipe ppm data into ffmpeg from blender frameserver with while loop in PowerShell
body: <p>Blender 2.6 manual features this little <code>sh</code> script for encoding a video from the Blender frameserver via <code>ffmpeg</code>. It works great on Windows with Cygwin, but only without <code>-hwaccel</code> hardware acceleration flag.</p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/sh
  BLENDER=http://localhost:8080
  OUTPUT=/tmp/output.ogv
  eval `wget ${BLENDER}/info.txt -O - 2&gt;/dev/null |
      while read key val ; do
          echo R_$key=$val  
      done`
  i=$R_start
  {
      while [ $i -le $R_end ] ; do
         wget ${BLENDER}/images/ppm/$i.ppm -O - 2&gt;/dev/null
         i=$(($i+1))
      done
  } | ffmpeg -vcodec ppm -f image2pipe -r $R_rate -i pipe:0 -b 6000k -vcodec libtheora $OUTPUT
  wget ${BLENDER}/close.txt -O - 2&gt;/dev/null &gt;/dev/null
  </code></pre>
  
  <p>I'd like to encode my videos from Blender's in Windows with <code>-hwaccel dxva2</code> which works with PowerShell. I've begun converting the script to PowerShell but I have run into one last problem. I am having difficulty replicating this part of the script in PowerShell.</p>
  
  <pre class="lang-sh prettyprint-override"><code>i=$R_start
  {
      while [ $i -le $R_end ] ; do
         wget ${BLENDER}/images/ppm/$i.ppm -O - 2&gt;/dev/null
         i=$(($i+1))
      done
  } | ffmpeg -vcodec ppm -f image2pipe -r $R_rate -i pipe:0 -b 6000k -vcodec libtheora $OUTPUT
  </code></pre>
  
  <p>Below is my conversion to PowerShell.</p>
  
  <pre class="lang-bsh prettyprint-override"><code>echo "gathering data";
  $blender = "http://localhost:8080";
  $output = "C:\Users\joel\Desktop\output.mp4";
  $webobj = wget $blender"/info.txt";
  $lines = $webobj.Content -split('[\r\n]') | ? {$_};
  $info = @{};
  foreach ($line in $lines) {
      $lineinfo = $line -split('[\s]') | ? {$_};
      $info[$lineinfo[0]] = $lineinfo[1];
  }
  echo $info;
  [int]$end = [convert]::ToInt32($info['end'],10);
  [int]$i = [convert]::ToInt32($info['start'],10);
  $video="";
  ( while ($i -le $end) {
      $frame = wget $blender"/images/ppm/"$i".ppm" &gt; $null;
      echo $frame.Content &gt; $null;
      $i++;
  } ) | ffmpeg -hwaccel dxva2 -vcodec ppm -f image2pipe -r $info['rate'] -i pipe:0 -b 6000k -vcodec libx264 $output;
  </code></pre>
  
  <p>This is the piece I'm having trouble with. I'm not quite sure what the proper syntax is to pipe the data into the <code>ffmpeg</code> command in the same way as the bash script above.</p>
  
  <pre class="lang-bsh prettyprint-override"><code>( while( $i -le $end ) {
      $frame = wget $blender"/images/ppm/"$i".ppm" &gt; $null;
      echo $frame.Content &gt; $null;
      $i++;
  } ) | ffmpeg -hwaccel dxva2 -vcodec ppm -f image2pipe -r $info['rate'] -i pipe:0 -b 6000k -vcodec libx264 $output;
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre>PS C:\Users\joel\Desktop> .\encode.ps1
  gathering data
  
  Name                           Value
  ----                           -----
  rate                           30
  height                         720
  ratescale                      1
  end                            57000
  width                          1280
  start                          1
  while : The term 'while' is not recognized as the name of a cmdlet, function,
  script file, or operable program. Check the spelling of the name, or if a path
  was included, verify that the path is correct and try again.
  At C:\Users\joel\Desktop\encode.ps1:15 char:3
  + ( while ($i -le $end) {
  +   ~~~~~
      + CategoryInfo          : ObjectNotFound: (while:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException</pre>