How to fix video orientation issue in iOS

后端 未结 2 626
死守一世寂寞
死守一世寂寞 2020-12-14 04:15

I am working with an app in which user picks video from Photos and uploads it to server. As my server is .Net server , the video gets rotated. I know the reason of problem i

相关标签:
2条回答
  • 2020-12-14 04:45

    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];
    
    0 讨论(0)
  • 2020-12-14 04:46
    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];
        }
    
    0 讨论(0)
提交回复
热议问题