How to fix video orientation issue in iOS

試著忘記壹切 提交于 2019-11-28 19:41:49
Or Arbel

Add this after the //VIDEO TRACK part

        //AUDIO TRACK
        AVMutableCompositionTrack *firstAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
        [firstAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration) ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:@"your video url here..." options:nil];

Add After AVMutableCompositionTrack.

set setPreferredTransform: set here your source video that you want to export with same orientation.

 // Grab the source track from AVURLAsset for example.
AVAssetTrack *assetVideoTrack = [videoAsset tracksWithMediaType:AVMediaTypeVideo].lastObject;

// Grab the composition video track from AVMutableComposition you already made.
AVMutableCompositionTrack *compositionVideoTrack = [mixComposition tracksWithMediaType:AVMediaTypeVideo].lastObject;

// Apply the original transform.
if (assetVideoTrack && compositionVideoTrack) {
        [compositionVideoTrack setPreferredTransform:assetVideoTrack.preferredTransform];
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!