Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 裁剪视频保存在iPad iOS 13中的黑色视频中_Swift_Ipad_Crop_Ios13_Avasset - Fatal编程技术网

Swift 裁剪视频保存在iPad iOS 13中的黑色视频中

Swift 裁剪视频保存在iPad iOS 13中的黑色视频中,swift,ipad,crop,ios13,avasset,Swift,Ipad,Crop,Ios13,Avasset,这是我的裁剪视频代码,它在iPhone中工作得很好,但在iPad中不工作,这意味着我在iPhone中的iPad中保存了一个黑色视频此应用程序工作肖像,在iPad中此应用程序在横向模式下工作,但我找不到任何错误,可能只是iOS 13或iPadOS中出现了一些错误!!我认为iPad上ios13的问题之星这里是我的代码 func cropVideoAsset() { let videoAsset: AVAsset = AVAsset(url: Op_

这是我的裁剪视频代码,它在iPhone中工作得很好,但在iPad中不工作,这意味着我在iPhone中的iPad中保存了一个黑色视频此应用程序工作肖像,在iPad中此应用程序在横向模式下工作,但我找不到任何错误,可能只是iOS 13或iPadOS中出现了一些错误!!我认为iPad上ios13的问题之星这里是我的代码

func cropVideoAsset() {
        
        
        let videoAsset: AVAsset = AVAsset(url: Op_URL!) as AVAsset

        
        let track = videoAsset.tracks(withMediaType: AVMediaType.video)[0]
        let length = min(track.naturalSize.width, track.naturalSize.height)
        
        var transform = track.preferredTransform
        
        let size = track.naturalSize
        
        //let size = UIScreen.main.bounds
        
        let scale: CGFloat = (transform.a == -1 && transform.b == 0 && transform.c == 0 && transform.d == -1) ? -1 : 1 // check for inversion
        
        transform = transform.translatedBy(x: scale * -(size.width - length) / 2, y: scale * -(size.height - length) / 2)
        
        let transformer = AVMutableVideoCompositionLayerInstruction(assetTrack: track)
        transformer.setTransform(transform, at: CMTime.zero)
        
        let instruction = AVMutableVideoCompositionInstruction()
        instruction.timeRange = CMTimeRange(start: CMTime.zero, duration: CMTime.positiveInfinity)
        instruction.layerInstructions = [transformer]
        
        var composition = AVMutableVideoComposition()
        composition.frameDuration = CMTime(value: 1, timescale: 30)
        composition.renderSize = CGSize(width: length, height: length)
        composition.instructions = [instruction]

        
        ////
        
        
        
      
        
        
        
        
        let videoComposition = AVMutableVideoComposition()
        let croppedSize = CGSize(width: ((cropVwWidth.constant + 10) * cropRatio), height: ((cropVwHeight.constant + 10) * cropRatio))
        
        let cropNewSz = CGSize(width: croppedSize.height, height: croppedSize.width)
        
        videoComposition.renderSize = CGSize(width: cropNewSz.width-2, height: cropNewSz.height-2) //CGSize(width: 800, height: 600) //CGSize(width: ((cropVwWidth.constant - 8) * cropRatio), height: ((cropVwHeight.constant - 8) * cropRatio)) // clipVideoTrack.naturalSize  //CGSize(width: 1920, height: 1080)
        videoComposition.frameDuration = CMTimeMake(value: 1, timescale: 30)
        
        let instruction0 = AVMutableVideoCompositionInstruction()
        instruction0.timeRange = CMTimeRangeMake(start: CMTime.zero, duration: CMTimeMakeWithSeconds(60, preferredTimescale: 30))
        
        // rotate to portrait
        let transformer0:AVMutableVideoCompositionLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: track)
        
        
        if isLandscapeVdo {
            let t1 = CGAffineTransform(translationX: -(cropVwX.constant * cropRatio), y: -(cropVwY.constant));
            transformer0.setTransform(t1, at: CMTime.zero)
        }
        else {
            
           
            
        }
        
        instruction0.layerInstructions = [transformer]
            videoComposition.instructions = [instruction]
}