我沒有問題,添加一個視頻資產和一個音頻資產的AVMutableComposition
和使用AVAssetExportSession
後得到一個可玩的MOV文件。但是,當我嘗試在第一個問題結束後立即添加另一個視頻軌道時。無論是 1),第一視頻爲發揮其最後一幀被凍結的MOV文件的持續時間(第二視頻沒玩過)。 2)是顯示直到第二視頻中充分發揮了黑幀。 3)會議將不出口的。添加多個視頻資產AVMutableComposition
我通過調整對視頻資產的時間範圍在各自insertTimeRange:ofTrack:
..方法獲得這些不同的結果。
AVURLAsset *firstAsset = [AVURLAsset URLAssetWithURL:vidPathURL options:nil];
AVURLAsset *secondAsset = [AVURLAsset URLAssetWithURL:audPathURL options:nil];
AVURLAsset *thirdAsset = [AVURLAsset URLAssetWithURL:vidPathURL2 options:nil];
AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration) ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];
CMTime nextClipStartTime = CMTimeAdd(kCMTimeZero, firstAsset.duration);
CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, thirdAsset.duration);
AVAssetTrack *secondVideoTrack = [[thirdAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
[firstTrack insertTimeRange:timeRange ofTrack:secondVideoTrack atTime:nextClipStartTime error:nil];
AVMutableCompositionTrack *secondTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
[secondTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, secondAsset.duration) ofTrack:[[secondAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(M_PI_2);
firstTrack.preferredTransform = rotationTransform;
// export session
有沒有人有什麼想法,應該調整什麼?
謝謝。