我必须录制与“Talking tom”完全相似的应用视频。 从Here和Here接受帮助,我已经捕获屏幕并使用这些图像制作了视频,但没有任何声音。录制视频像“Talking tom”iphone(添加音频时发出的问题)
我已分别记录声音和视频文件,但不知道如何将它们添加
谁能告诉我怎么将声音添加到该视频或如何与声音记录下来。
任何人都可以帮忙吗?
我必须录制与“Talking tom”完全相似的应用视频。 从Here和Here接受帮助,我已经捕获屏幕并使用这些图像制作了视频,但没有任何声音。录制视频像“Talking tom”iphone(添加音频时发出的问题)
我已分别记录声音和视频文件,但不知道如何将它们添加
谁能告诉我怎么将声音添加到该视频或如何与声音记录下来。
任何人都可以帮忙吗?
iOS应用程序无法真正记录(使用任何公共API)其自身产生的声音。一个应用可以做的是生成两次相同的音频,一个用于播放,一个用于流式传输到文件。你必须坚持只有你知道如何做到这两种方式的声音,如将PCM波形复制到缓冲区等。
一旦你有你的音频样本的重复缓冲区,应该有如何发送它的示例代码到AVAssetWriter。
是的,我在问什么...我已经创建了2个独立的文件中的视频和声音,但我不知道如何加入他们 – sajwan
-(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;
}
}]; }
你的电影文件(ie.without音频)刚分配到NSURL并将它传递给上述ProcessVideo method.Then只是在audioInfoArray添加您的声音文件(您想与您的视频进行合并)在别的地方该程序在调用processVideo方法之前。然后它会将您的音频与您的视频文件合并。
您还可以根据audioinfoArray中按键“startTime”下分配的值决定视频在视频中播放的位置。使用Switch Case,您可以根据自己的愿望播放视频,上传到Facebook等。
可能重复[如何记录屏幕视频就像Talking Tomcat应用程序在iPhone中所做的一样?](http://stackoverflow.com/questions/6980370/how-to-record-screen-video-as-like-talking -tomcat-application-does-in-iphone) – duskwuff
是的,是类似的(但不重复),也有提到,在我的链接....请阅读完整的问题之前downvoting ...... 问题是加入声音.... – sajwan
你有没有得到这个..的解决方案? – Rajneesh071