My setup is fairly straight forward. I have a composition with a video and audio track. Videos are captured in either left or right landscape orientations. Video frame buffers are captured with an AVCaptureVideoDataOutput object and written with AVAssetWriter/AVAssetWriterInput objects. These videos are then displayed in an AVPlayerLayer.
I am setting the writer input's transform based on the device orientation.
if UIDevice.currentDevice.orientation == UIDeviceOrientation.LandscapeRight {
videoWriterVideoInput.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}
Reviewing the output video in Quicktime looks like this:
Next, this video is displayed in an AVPlayerLayer:
Exporting the AVMutableComposition with AVAssetExportSession also results in the video flipped 180 degrees.
I can't set the preferredTransform on the composition's video track because videos will be recorded in either landscape left or right orientation.