我无法裁剪视频以使其与Swift 3和iOS 10.x相适应。执行剪裁例程后,我将视频保存到我的照片库中,看起来与原始视频相同。
我使用以下帖子作为参考:使用AVFoundation裁剪AVAsset视频无法正常运行iOS 8
func suqareCropVideo(inputURL: NSURL, completion: @escaping (_ outputURL : NSURL?) -> ())
{
let videoAsset: AVAsset = AVAsset( url: inputURL as URL )
let clipVideoTrack = videoAsset.tracks( withMediaType: AVMediaTypeVideo ).first! as AVAssetTrack
let composition = AVMutableComposition()
composition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID())
let videoComposition = AVMutableVideoComposition()
videoComposition.renderSize = CGSize( width: clipVideoTrack.naturalSize.height, height: clipVideoTrack.naturalSize.height )
videoComposition.frameDuration = CMTimeMake(1, 30)
let transformer = AVMutableVideoCompositionLayerInstruction(assetTrack: clipVideoTrack)
let instruction = AVMutableVideoCompositionInstruction()
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(60, 30))
let transform1: CGAffineTransform = CGAffineTransform(translationX: …Run Code Online (Sandbox Code Playgroud)