iOS旋转videoAVAsset avfoundation

嗨,

努力旋转此video以正确的方向显示并填满整个屏幕。

我无法使用videocompisition获得avasset,但无法使其正常工作。

let videoAsset: AVAsset = AVAsset(URL: outputFileURL) as AVAsset let clipVideoTrack = videoAsset.tracksWithMediaType(AVMediaTypeVideo).first! as AVAssetTrack let newHeight = CGFloat(clipVideoTrack.naturalSize.height/3*4) let composition = AVMutableComposition() composition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID()) let videoComposition = AVMutableVideoComposition() var videoSize = CGSize() videoSize = clipVideoTrack.naturalSize videoComposition.renderSize = videoSize videoComposition.frameDuration = CMTimeMake(1, 30) let instruction = AVMutableVideoCompositionInstruction() instruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(180, 30)) // rotate to portrait let transformer:AVMutableVideoCompositionLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: clipVideoTrack) let t1 = CGAffineTransformMakeTranslation(0, 0); let t2 = CGAffineTransformRotate(t1, CGFloat(M_PI_2)); transformer.setTransform(t2, atTime: kCMTimeZero) instruction.layerInstructions = [transformer] videoComposition.instructions = [instruction] let formatter = NSDateFormatter() formatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'" let date = NSDate() let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString let outputPath = "\(documentsPath)/\(formatter.stringFromDate(date)).mp4" let outputURL = NSURL(fileURLWithPath: outputPath) let exporter = AVAssetExportSession(asset: videoAsset, presetName: AVAssetExportPresetHighestQuality)! exporter.videoComposition = videoComposition exporter.outputURL = outputURL exporter.outputFileType = AVFileTypeQuickTimeMovie exporter.exportAsynchronouslyWithCompletionHandler({ () -> Void in dispatch_async(dispatch_get_main_queue(), { self.handleExportCompletion(exporter) }) }) 

从下面的代码解决了旋转转换:

AVMutableVideoComposition旋转以纵向模式拍摄的video

现在如果有人知道下面的出口有问题:

https://stackoverflow.com/questions/35233766/avasset-failing-to-export