gbarcena
7/7/2017 - 7:21 PM

Correcting the transform on a video for AVExportSession

Correcting the transform on a video for AVExportSession

let preferredTransform = originalVideoTrack.preferredTransform
let finalTransform: CGAffineTransform
// These if statements were added to handle time lapse videos which use abcd for transforms
// and not tx, ty
if preferredTransform.a == -1 && preferredTransform.d == -1 {
    transform = transform.scaledBy(x: -1, y: -1)
    finalTransform = transform.translatedBy(x: -outputVideoSize.width, y: -outputVideoSize.height)
} else if preferredTransform.b == 1 && preferredTransform.c == -1 {
    transform = transform.rotated(by: CGFloat.pi/2)
    finalTransform = transform.translatedBy(x: 0, y: -outputVideoSize.width)
} else if preferredTransform.b == -1 && preferredTransform.c == 1 {
    transform = transform.rotated(by: -CGFloat.pi/2)
    finalTransform = transform.translatedBy(x: -outputVideoSize.height, y: 0)
} else {
    finalTransform = preferredTransform.concatenating(transform)
}