2012-05-10 16 views
0

イメージとオーディオファイルの配列を含むムービーを作成し、作成したムービーをフォトライブラリに保存します。シミュレータで画像とオーディオファイルの配列で正しいムービーを取得していますが、while私の出力ファイル(ミックスオーディオと画像ファイルの配列)を書き込むために私が追加したもの(OutPut.mov私のコードで使用)を取得しています。ここ PhotoLibrary iPadで結果のムービーを取得できません

は、写真のlibにファイルを自分の混合音声や画像の配列を保存するために私のコードです:..あなたのようなフォトライブラリパスへのビデオファイルを記述する必要が

AVMutableComposition* mixComposition = [AVMutableComposition composition]; 
NSString* audio_inputFilePath = [[NSBundle mainBundle] pathForResource:@"Ruler" ofType:@"caf"]; 
NSURL* audio_inputFileUrl = [NSURL fileURLWithPath:audio_inputFilePath]; 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 


NSString *video_inputFilePath = [documentsDirectory stringByAppendingPathComponent:@"videoOutput1234videoOutput1234.mp4"]; 
NSLog(@"output url %@",video_inputFilePath); 


NSURL* video_inputFileUrl = [NSURL fileURLWithPath:video_inputFilePath]; 


NSString* outputFilePath = [[NSBundle mainBundle] pathForResource:@"OutPut" ofType:@"mov"]; 
NSURL* outputFileUrl = [NSURL fileURLWithPath:outputFilePath]; 

if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath]) 
    [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil]; 


if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath]) 
    [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil]; 

CMTime nextClipStartTime = kCMTimeZero; 

AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:video_inputFileUrl options:nil]; 
CMTimeRange video_timeRange = CMTimeRangeMake(kCMTimeZero,videoAsset.duration); 
AVMutableCompositionTrack *a_compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 

[a_compositionVideoTrack insertTimeRange:video_timeRange ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:nextClipStartTime error:nil]; 



AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audio_inputFileUrl options:nil]; 
CMTimeRange audio_timeRange = CMTimeRangeMake(kCMTimeZero, audioAsset.duration); 
AVMutableCompositionTrack *b_compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; 
[b_compositionAudioTrack insertTimeRange:audio_timeRange ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:nextClipStartTime error:nil]; 


AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality]; 
_assetExport.outputFileType = @"com.apple.quicktime-movie"; 
_assetExport.outputURL = outputFileUrl; 

[_assetExport exportAsynchronouslyWithCompletionHandler:^(void) {[self saveVideoToAlbum:outputFilePath]; }  ]; 

答えて

5

- (void)writeVideoToPhotoLibrary:(NSURL *)url 
{ 
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 

    [library writeVideoAtPathToSavedPhotosAlbum:url completionBlock:^(NSURL *assetURL, NSError *error){ 
     if (error) { 
      NSLog(@"Video could not be saved"); 
     } 
    }]; 
    [library release]; 
} 

- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { 
    // Let's see what happened 
    NSLog(@"finished"); 
    NSLog(@":error : %@", error); 
}