小编CTR*_*x64的帖子

在iOS中将视频裁剪为正方形[Swift 3]

我无法裁剪视频以使其与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)

video crop ios swift

5
推荐指数
1
解决办法
2901
查看次数

标签 统计

crop ×1

ios ×1

swift ×1

video ×1