我使用下面的代碼,試圖合併存儲在文件夾2個M4V文件:合併兩個M4V電影文件使用AVMutableComposition - 影片不會合並
CMTime insertionPoint = kCMTimeZero;
NSError * error = nil;
AVMutableComposition *composition = [AVMutableComposition composition];
AVURLAsset* asset = [AVURLAsset URLAssetWithURL: [assetURLArray objectForKey:kIntroVideo] options:nil];
if (![composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration)
ofAsset:asset
atTime:insertionPoint
error:&error])
{
NSLog(@"error: %@",error);
}
insertionPoint = CMTimeAdd(insertionPoint, asset.duration);
AVURLAsset* asset2 = [AVURLAsset URLAssetWithURL: [assetURLArray objectForKey:kMainVideo] options:nil];
if (![composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset2.duration)
ofAsset:asset2
atTime:insertionPoint
error:&error])
{
NSLog(@"error: %@",error);
}
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality];
NSString *exportVideoPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/FinishedVideo.m4v"];
NSURL *exportURL = [NSURL fileURLWithPath:exportVideoPath];
exportSession.outputURL = exportURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusFailed:{
NSLog (@"FAIL");
break;
}
case AVAssetExportSessionStatusCompleted: {
NSLog (@"SUCCESS");
}
};
}];
}
的問題是,兩個視頻不會合並正確。整個合併的電影持續時間是正確的,但是視頻永遠不會轉換到第二部電影,並在其持續時間內繼續顯示第一部電影的最後一幀。奇怪的是,我可以聽到背景中播放的第二個視頻的音頻。
有沒有人有任何想法是什麼錯?
編輯 - 奇怪的是,如果我合併兩個完全相同長度的剪輯,它的作品。
編輯 - 試圖改變文件擴展名爲.mov與同樣的問題。
任何想法都將不勝感激。 – GuybrushThreepwood 2012-04-24 09:12:19
您是否嘗試過使用不同的視頻文件?另外,當你說它與兩個相同長度的剪輯一起工作時,那些實際上是兩個不同的剪輯,還是它們是同一剪輯的兩個實例? – Sean 2012-04-24 15:13:20
肖恩 - 感謝您的幫助 - 同一片段的兩個實例。 – GuybrushThreepwood 2012-04-24 15:42:02