3
AVAssetExportSessionStatusCompletedステータスを取得してもビデオを取得できませんでした。しかし、私はXCodeのシミュレータで使用するとビデオを取得することができました。AVAssetExportSessionStatusCompletedステータス、目的cを取得してもビデオを合成できない
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *videoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *audioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
CMTime insertTime = kCMTimeZero;
for(i=0;i<videoForMerging.count;i++) {
AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",videoForMerging[i]]]];
CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);
[videoTrack insertTimeRange:timeRange
ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
atTime:insertTime
error:nil];
[audioTrack insertTimeRange:timeRange
ofTrack:[[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
atTime:insertTime
error:nil];
insertTime = CMTimeAdd(insertTime,asset.duration);
}
NSString* documentsDirectory= [self applicationDocumentsDirectory];
NSString *myDocumentPath= [documentsDirectory stringByAppendingPathComponent:@"merge_video.mp4"];
NSURL *urlVideoMain = [[NSURL alloc] initFileURLWithPath: myDocumentPath];
if([[NSFileManager defaultManager] fileExistsAtPath:myDocumentPath])
{
[[NSFileManager defaultManager] removeItemAtPath:myDocumentPath error:nil];
}
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL = urlVideoMain;
exporter.outputFileType = @"com.apple.quicktime-movie";
exporter.shouldOptimizeForNetworkUse = YES;
[exporter exportAsynchronouslyWithCompletionHandler:^{
switch ([exporter status])
{
case AVAssetExportSessionStatusFailed:
break;
case AVAssetExportSessionStatusCancelled:
break;
case AVAssetExportSessionStatusCompleted:
[Util okAlert:@"Video save successfull" viewController:self];
break;
default:
break;
}
}];
}
ドキュメントディレクトリた:
-(NSString*) applicationDocumentsDirectory { NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; return basePath; }