Since the image from the front camera is mirrored, you will also need to reflect the conversion. The function for this is simply to scale one of the parameters with -1. Try playing with this:
transform = CGAffineTransformConcat(CGAffineTransformMakeRotation(angle), CGAffineTransformMakeScale(1.0, -1.0));
Note. Possible permutations (next to the angle) X scale factor -1 and or substitution order concat
EDIT: clarification
AVCaptureSession will return you image data that does not rotate, like your device, naturally, I believe that it will be a landscape on the left or right. If you need your video to be correctly oriented depending on how you hold the device, you need to apply some kind of transformation to it, in most cases it is enough to just apply some rotation. However, the front camera is a specific case because it mimics a mirror while you still get non-mirror frames. As a result of this, your video appears up-down or left-right or all other combinations depending on which rotation you apply, so as you said, โI tried a lot of angles, but I just can't get it right ... " Again, to simulate the effect of a mirror, you must scale one of the axes by -1.
EDIT: swap orientation (from comments)
This is just an idea, and I think it is a good one. Do not use asset transformation at all, do your thing. Create a view with the size you want your video to be, and then create a subtitle to view the images with all the transformations, cropping and content modes you need. From samples, you create images, set them as images and get a snapshot of the layer from the view. Then send the snapshot to the resource recorder.
I know what you think here is "overhead." Well, I donโt think so. Since the representations and representations of the images make the conversion on the processor the same as the owner of the resource, so all you have done is cancel its internal conversion and use your own system. If you try this, I really want to hear your results.
To get a layer image:
- (UIImage *)imageFromLayer:(CALayer *)layer { UIGraphicsBeginImageContext([layer frame].size); [layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return outputImage; }