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

问题描述

这是我的裁剪视频代码,它在iPhone上效果很好,但在iPad上效果不好,这意味着我在iPad上保存了一个黑色视频,在此应用程序中使用了该应用程序的人像,在iPad中此应用程序在横向模式下使用了,但是我找不到任何错误,只是在iOS 13或iPadOS中发生了变化!我认为这是iPad上iOS 13中的问题星标

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]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)