Creating an application for image and video processing, where app requirement is set device Orientation according to selected video content orientation from the gallery. So I have used some line of code to get selected media current orientation kindly check Below code for orientation get from selected content.
var video_orientation: UIInterfaceOrientation {
guard let transform = tracks(withMediaType: AVMediaType.video).first?.preferredTransform else {
return .portrait
}
switch (transform.tx, transform.ty) {
case (0, 0):
return .landscapeLeft
case (videoFirstFrameSize.width, videoFirstFrameSize.height):
return .landscapeRight
case (0, videoFirstFrameSize.width):
return .portraitUpsideDown
default:
return .portrait
}
}
Now, the problem is when user select video (slow-Mo, Normal) from Gallery its working fine.
But when user select Time-Lapse video from gallery orientation going to changed, I have done too many research related to get orientation also have create many experiment and then finally I got some solution, and the solution is if we selected Time-lapse we need to pass AVMediaType.timecode
in video type but now the problem is, how should I set it on selected assets.
Any help is really appreciable and will save my life :P but its going little frustrating.
NOTE:- var video_orientation
Is the Extension property of AVAssets