2011-05-06 1 views
1

Audion CAF 파일과 비디오/이미지 UIImage을 병합하여 .mov 형식의 동영상 파일을 만듭니다.오디오 파일과 비디오/이미지를 병합하여 동영상 파일을 만듭니다.

내 오디오 길이가 30 초이고 UIImage입니다.이 오디오가 재생되는 전체 시간 동안 표시되도록 .mov 파일을 만들고 싶습니다.

나는이 참조를 발견 How to add audio to video file on iphone SDK

내 오디오와 영상의 길이는/비디오 다르기 때문에

사람이,이, 내 경우에는 도움이 말씀해 주시겠습니까?

미리 감사드립니다.

답변

0

Quicktime Pro에서이를 수행 할 수 있습니다. 내 자신의 앱에 해당 작업을 완료했습니다. 이미지에서 동영상을 만듭니다. Quicktime은 일련의 이미지를 읽고이를 사용하여 동영상을 만듭니다. 그는 또한 수입 중 FPS를 요청합니다.

오디오 트랙을 병합하거나, 어딘가에 붙여 넣거나, 영화의 선택된 범위로 확장 할 수 있습니다.

+0

어떤 클래스/프레임 워크는 사용됩니다? 필요한 경우 자습서 또는 참조 링크를 제공하십시오. 감사. –

+0

Quicktime은 모든 Mac에 설치됩니다. Quicktime Pro는 Quicktime의 상용 업그레이드입니다. 당신은 사과 온라인 상점에서 열쇠를 얻을 수 있습니다. Quicktime 프레임 워크를 사용하여 수동으로 염두에두고있는 모든 편집 작업을 수행 할 수 있다고 생각합니다. 그러나 그에 대한 예제는 없습니다. Quicktime은 Apples 기술의 일부이므로, 개발자 사이트에서 예제를 볼 수 있습니다. –

1

예, AVMutableComposition을 사용해야합니다. UIImage에서 비디오 트랙을 만들려면 AVAssetWriter를 사용하십시오. 내가 그물에이 곳을 발견이, 내가 기억하지 못하는

+1

이 샘플 데모 응용 프로그램을 제공 할 수 있습니까? 자습서로도 충분합니다 .. 제발 .. 도와주세요. –

0

사용 ...

 
NSString *fileNamePath = @"audio.caf"; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *oldappSettingsPath = [documentsDirectory stringByAppendingPathComponent:fileNamePath]; 
    NSURL *audioUrl = [NSURL fileURLWithPath:oldappSettingsPath]; 
    NSString *fileNamePath1 = @"output.mp4"; 
    NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
    NSString *documentsDirectory1 = [paths1 objectAtIndex:0]; 
    NSString *oldappSettingsPath1 = [documentsDirectory1 stringByAppendingPathComponent:fileNamePath1]; 
    NSLog(@"oldpath=%@",oldappSettingsPath); 
    NSURL *videoUrl = [NSURL fileURLWithPath:oldappSettingsPath1]; 
    if (avPlayer.duration >0.00000) 
    { 
     NSLog(@"SOMEDATA  IS THERE "); 
     AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioUrl options:nil]; 
     AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:videoUrl options:nil]; 

     AVMutableComposition* mixComposition = [AVMutableComposition composition]; 

     NSLog(@"audio =%@",audioAsset); 
     AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; 
     [compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration) ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil]; 

     AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 
     [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil]; 


     AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetPassthrough]; 

     NSString* videoName = @"export.mov"; 

     NSString *exportPath = [NSTemporaryDirectory() stringByAppendingPathComponent:videoName]; 
     NSURL *exportUrl = [NSURL fileURLWithPath:exportPath]; 

     if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) 
     { 
      [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil]; 
     } 

     _assetExport.outputFileType = @"com.apple.quicktime-movie"; 
     NSLog(@"file type %@",_assetExport.outputFileType); 
     _assetExport.outputURL = exportUrl; 
     _assetExport.shouldOptimizeForNetworkUse = YES; 



     [_assetExport exportAsynchronouslyWithCompletionHandler: 
     ^(void) 
     {  

      NSString *fileNamePath = @"sound_record.mov"; 
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
      NSString *documentsDirectory = [paths objectAtIndex:0]; 
      NSString *oldappSettingsPath = [documentsDirectory stringByAppendingPathComponent:fileNamePath]; 


      //    if ([[NSFileManager defaultManager] fileExistsAtPath:oldappSettingsPath]) { 
//     
//     NSFileManager *fileManager = [NSFileManager defaultManager]; 
//     [fileManager removeItemAtPath: oldappSettingsPath error:NULL]; 
//     
//    } 
      NSURL *documentDirectoryURL = [NSURL fileURLWithPath:oldappSettingsPath]; 
      [[NSFileManager defaultManager] copyItemAtURL:exportUrl toURL:documentDirectoryURL error:nil]; 
      [audioAsset release]; 
      [videoAsset release]; 
      [_assetExport release]; 
     }  
     ];