How to change the orientation of an AVPlayer video?

I want to rotate video playback using AVPlayer. Is there any way to rotate it 90 degrees clockwise?
Here is the code:

self.player = AVPlayer(URL: NSURL(fileURLWithPath: dataPath)) playerLayer = AVPlayerLayer.init(player: self.player) playerLayer.frame = view.bounds playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill view.layer.addSublayer(playerLayer) player.play() 

UPDATE

It works:

 self.player = AVPlayer(URL: NSURL(fileURLWithPath: dataPath)) playerLayer = AVPlayerLayer.init(player: self.player) playerLayer.setAffineTransform(CGAffineTransformMakeRotation(CGFloat(M_PI)) playerLayer.frame = view.bounds playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill view.layer.addSublayer(playerLayer) player.play() 
+7
ios rotation swift avfoundation orientation
source share
2 answers

Hooni answer in Swift 3:

 let affineTransform = CGAffineTransform(rotationAngle: degreeToRadian(90)) avPlayerLayer.setAffineTransform(affineTransform) func degreeToRadian(_ x: CGFloat) -> CGFloat { return .pi * x / 180.0 } 
+3
source share

If you are using Objective-C, the code below will help.

Code example:

 #define degreeToRadian(x) (M_PI * x / 180.0) #define radianToDegree(x) (180.0 * x / M_PI) - (void)rotateVideoPlayerWithDegree:(CGFloat)degree { [_playerLayer setAffineTransform:CGAffineTransformMakeRotation(degreeToRadian(degree))]; } 
+2
source share

All Articles