title: layer rotation: CGAffineTranslate, CGAffineRotate and AVMutableVideoCompositionLayerInstruction
body: <p>for days now I am trying to solve this, apparently I just can't get affine transforms.</p>
  
  <p>Basically, I would like to rotate a movie <strong>multiple times</strong> by 90 degrees. There is a good example here:</p>
  
  <p><a href="https://stackoverflow.com/questions/5187789/rotating-video-w-avmutablevideocompositionlayerinstruction">Rotating Video w/ AVMutableVideoCompositionLayerInstruction</a></p>
  
  <p>but this works only for the first rotation, while I would like to rotate it from portrait to landscape, back to portrait, back to landscape.</p>
  
  <p>Whatever I tried, I get absolutely weird results. Unfortunately, even after much reading, my understanding of affine transforms obviously did not improve either.</p>
  
  <p>So I am basically asking for a layout of an algorithm which will</p>
  
  <ol>
  <li>rotate the layer of an AVMutableVideoComposition by 90 degrees,
  regardless of its current orientation.</li>
  <li>Apply a translation to move the layer into the center.</li>
  </ol>
  
  <p>This should be called each time I click on a button.</p>
  
  <p>But whatever I try, the layer is rotating correctly, but the translation is moving the layer out of the center. What is the right way to do this?</p>