how to control orientation of video assembled with AVMutableComposition

前端 未结 3 2067
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 12:36

I am assembling a bunch of video clips filmed on the iPhone in portrait mode. To assemble them I am taking straightforward approach as follows:

AVURLAsset to get hold

3条回答
  •  我在风中等你
    2021-01-31 13:32

    If all you want is preserve you video orientation you may want to assign AVMutableCompositionTrack prefferedTransition value from AVAssetTrack like this:

    AVAssetTrack *videoAssetTrack= [[videoAsset tracksWithMediaType:AVMediaTypeVideo] lastObject];
    
    AVMutableCompositionTrack *videoCompositionTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
    [videoCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:videoAssetTrack atTime:kCMTimeZero error:&error];
    
    videoCompositionTrack.preferredTransform = videoAssetTrack.preferredTransform;
    

提交回复
热议问题