2011-10-30 2 views
0

"Talking tom"과 비슷한 앱의 동영상을 녹화해야합니다. HereHere에서 도움을 얻으면 화면을 캡처하고 해당 이미지를 사용하여 동영상을 만들었지 만 소리가 들리지 않습니다."Talking tom"iphone (오디오 추가시 문제)과 같은 동영상 녹화

내가 따로 둘 사운드와 비디오 파일을 기록했지만 그들

사람이 비디오 사운드로 기록하는 방법 또는 에 사운드를 추가하는 방법을 나 을 알 수 있습니다 추가하는 방법을 모르겠어요.

아무도 도와 줄 수 있습니까?

+0

가능한 [Tomcat 응용 프로그램이 iPhone에서 말하는 것처럼 화면 비디오를 기록하는 방법?] (http://stackoverflow.com/questions/6980370/how-to-record-screen-video-as-like-talking) - - 아이폰) – duskwuff

+1

그래, 비슷한 (하지만 중복되지 않음) 또한 내 링크에 언급했다 .... downvoting하기 전에 전체 질문을 읽어보십시오 ...... 문제입니다 소리를 추가하는 것. – sajwan

+0

u는 이것의 해결을 얻었다..? – Rajneesh071

답변

0

iOS 앱은 자신이 만든 사운드를 (공개 API를 사용하여) 실제로 녹음 할 수 없습니다. 앱에서 수행 할 수있는 작업은 동일한 오디오를 두 번 재생하는 것입니다. 하나는 재생 용이고 다른 하나는 파일로 스트리밍하는 것입니다. PCM 파형을 버퍼로 복사하는 등 두 가지 방법을 수행하는 방법을 알고있는 소리 만 사용해야합니다.

중복 된 오디오 샘플 버퍼가 있으면 보낸 방법에 대한 예제 코드가 있어야합니다 AVAssetWriter에 연결합니다. ProcessVideo method.Then 그냥 다른 곳에서 audioInfoArray에 사운드 파일을 (당신이 당신의 비디오를 병합 할) 추가 이상

+0

네, 내가 묻고있는 것과 똑같은 ... 나는 비디오와 사운드를 2 개의 분리 된 파일로 만들었지 만, 나는 그들과 어울리는 법을 모른다. – sajwan

1
-(void) processVideo: (NSURL*) videoUrl{ 
AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL: videoUrl options:nil]; 

AVMutableComposition* mixComposition = [AVMutableComposition composition]; 

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

NSError * error = nil; 

for (NSMutableDictionary * audioInfo in appDelegate.audioInfoArray) 
{ 
    NSString *pathString = [[NSHomeDirectory() stringByAppendingString:@”/Documents/”] stringByAppendingString: [audioInfo objectForKey: @”fileName”]]; 

    AVURLAsset * urlAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:pathString] options:nil]; 

    AVAssetTrack * audioAssetTrack = [[urlAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]; 
    AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio 
                        preferredTrackID: kCMPersistentTrackID_Invalid]; 

    NSLog(@”%lf”, [[audioInfo objectForKey: @”startTime”] doubleValue]); 

    CMTime audioStartTime = CMTimeMake(([[audioInfo objectForKey: @”startTime”] doubleValue]*TIME_SCALE), TIME_SCALE); 

    [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,urlAsset.duration) ofTrack:audioAssetTrack atTime:audioStartTime error:&error];  
} 


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 = [[self pathToDocumentsDirectory] 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) { 
    switch (_assetExport.status) 
    { 
     case AVAssetExportSessionStatusCompleted: 
      //export complete 
      NSLog(@”Export Complete”); 
      //[self uploadToYouTube]; 

      break; 
     case AVAssetExportSessionStatusFailed: 
      NSLog(@”Export Failed”); 
      NSLog(@”ExportSessionError: %@”, [_assetExport.error localizedDescription]); 
      //export error (see exportSession.error) 
      break; 
     case AVAssetExportSessionStatusCancelled: 
      NSLog(@”Export Failed”); 
      NSLog(@”ExportSessionError: %@”, [_assetExport.error localizedDescription]); 
      //export cancelled 
      break; 
    } 
}]; } 

그냥 NSURL에 (오디오 ie.without) 동영상 파일을 할당하고에 전달 programVideo 메서드를 호출하기 전에 프로그램을 실행합니다. 그러면 오디오가 비디오 파일과 병합됩니다.

audioinfoArray에서 "startTime"키 아래에 할당 된 값에 따라 사운드가 비디오에서 재생되기 시작하는 위치를 결정할 수도 있습니다. 스위치 케이스를 사용하여 원하는대로 동영상을 재생하고 페이스 북에 업로드 할 수 있습니다.