iOS Video Editing - Is it possible to merge (side by side not one after other) two video files into one using iOS 4 AVFoundation classes?

后端 未结 2 1329
陌清茗
陌清茗 2020-12-12 23:22

I know you could merge multiple clips and create a single video by appending one after other using AVFoundation classes- AVURLAsset, AVMutableComposition, AVMutableComposit

相关标签:
2条回答
  • 2020-12-12 23:32

    i found this link when im trying to do the same thing , But for me its not side by side , its video top of another video, You can do the same thing by this link

    Video Manipulation

    0 讨论(0)
  • Yes it is possible to merge 2 videos:
    1. Add both assets to an AVMutableComposition at start time 0.
    2. Set the preferred Transform to the tracks, in this example scale transform.

        - (void) mergeVideos{
        ///... after getting hold or your assets....firstAsset, secondAsset
    
        AVMutableComposition* mixComposition = [AVMutableComposition composition];
    
        AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo 
                                                                          preferredTracfirst:kCMPersistentTracfirst_Invalid];
        [firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration) 
                            ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 
                             atTime:kCMTimeZero error:nil];
    
        AVMutableCompositionTrack *secondTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo 
                                                                           preferredTracfirst:kCMPersistentTracfirst_Invalid];
    
        [secondTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, secondAsset.duration)
                             ofTrack:[[secondAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 
                              atTime:kCMTimeZero error:nil];    
    
        [secondTrack setPreferredTransform:CGAffineTransformMakeScale(0.25f,0.25f)]; 
    
        //... export video here...
    
    }
    
    0 讨论(0)
提交回复
热议问题