1

for days now I am trying to solve this, apparently I just can't get affine transforms.

Basically, I would like to rotate a movie multiple times by 90 degrees. There is a good example here:

Rotating Video w/ AVMutableVideoCompositionLayerInstruction

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.

Whatever I tried, I get absolutely weird results. Unfortunately, even after much reading, my understanding of affine transforms obviously did not improve either.

So I am basically asking for a layout of an algorithm which will

  1. rotate the layer of an AVMutableVideoComposition by 90 degrees, regardless of its current orientation.
  2. Apply a translation to move the layer into the center.

This should be called each time I click on a button.

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?

Community
  • 1
  • 1
user1840267
  • 408
  • 1
  • 5
  • 18

1 Answers1

0

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?

The right way to do this is with 2 transforms: one to rotate, and one to translate. At the beginning of the processing, make sure that your current position is set - by assigning the current transform at the start of processing. Then, create two independent transforms - one for rotate, and the other for translation. You can 'concat' these two transforms to create a new one which does both operations - but if you expect the translation to function 'in place', be sure to re-set the original transform before you apply the new one.

ibisum
  • 521
  • 4
  • 6