Last active
August 3, 2017 06:48
-
-
Save exce11ent/6696235 to your computer and use it in GitHub Desktop.
Merge two videos using AVFoundation ios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init]; | |
NSString *path1 = _exportPaths[0]; | |
NSString *path2 = _exportPaths[1]; | |
//load assets | |
AVURLAsset *asset1 = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:path1] options:nil]; | |
AVURLAsset *asset2 = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:path2] options:nil]; | |
//create mutable composition track and add all assets to this track | |
AVMutableCompositionTrack *track = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; | |
NSArray *tracks = [asset1 tracksWithMediaType:AVMediaTypeVideo]; | |
if (tracks.count > 0) { | |
AVAssetTrack *assetTrack = tracks[0]; | |
[track insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset1.duration) | |
ofTrack:assetTrack | |
atTime:kCMTimeZero error:nil]; | |
} | |
NSArray *tracks2 = [asset2 tracksWithMediaType:AVMediaTypeVideo]; | |
if (tracks2.count > 0) { | |
AVAssetTrack *assetTrack = tracks2[0]; | |
[track insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset2.duration) | |
ofTrack:assetTrack | |
atTime:asset1.duration | |
error:nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment