影片轮播问题

时间:2018-08-04 04:22:30

标签: ios iphone swift xcode

合并后合并多个视频时,我看到一些视频会自动将自己的方向(例如人像)更改为横向,所以我希望所有视频都具有自己的原始格式而不旋转。如何解决这个问题。

我的代码:

  func mergeVideos(arrayVideos:[AVAsset])
   {
    var atTimeM: CMTime = CMTimeMake(0, 0)
    var layerInstructionsArray = [AVVideoCompositionLayerInstruction]()
    var completeTrackDuration: CMTime = CMTimeMake(0, 1)
    var videoSize: CGSize = CGSize(width: 0.0, height: 0.0)
    var totalTime : CMTime = CMTimeMake(0, 0)

    let mixComposition = AVMutableComposition.init()
    for videoAsset in arrayVideos{

        let videoTrack = mixComposition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
        do {
            if videoAsset == arrayVideos.first {
                atTimeM = kCMTimeZero
            } else {
                atTimeM = totalTime // <-- Use the total time for all the videos seen so far.
            }
            try videoTrack?.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration),
                                            of: videoAsset.tracks(withMediaType: AVMediaType.video)[0],
                                            at: completeTrackDuration)
            videoSize = (videoTrack?.naturalSize)!

        } catch let error as NSError {
            print("error: \(error)")
        }
        totalTime = CMTimeAdd(totalTime, videoAsset.duration)  
    let exporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality)............
  ............
 .......countinue       

0 个答案:

没有答案