参考号:http://www.youtube.com/watch?v=BJ3_xMGzauk(从0到10秒钟)
从我的分析,我发现AVFoundation框架可以是有帮助的.
参考:
http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html
从上述链接复制并粘贴:
“
编辑
AV基金会使用组合从现有的媒体(通常是一个或多个视频和音轨)创建新的资产.您使用可变组合来添加和删除曲目,并调整其时间顺序.您还可以设置音轨的相对音量和斜坡;并设置视频轨道的不透明度和不透明度斜坡.一个组合是在记忆体中保存的一组媒体.使用导出会话导出作品时,它会折叠到一个文件.
在iOS 4.1及更高版本上,您还可以使用资产编写器从介质(如样本缓冲区或静态图像)创建资源.
“
问题:
可以使用AVFoundation框架做“慢动作”视频/音频文件吗?还是有其他包装可用吗?如果我想单独处理音视频,请指导我怎么办?
AV导出会话更新::代码:
NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES); Nsstring *outputURL = paths[0]; NSfileManager *manager = [NSfileManager defaultManager]; [manager createDirectoryAtPath:outputURL withIntermediateDirectorIEs:YES attributes:nil error:nil]; outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"]; // Remove Existing file [manager removeItemAtPath:outputURL error:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:self.inputAsset presetname:AVAssetExportPresetLowQuality]; exportSession.outputURL = [NSURL fileURLWithPath:outputURL]; // output path; exportSession.outputfileType = AVfileTypeQuickTimeMovIE; [exportSession exportAsynchronouslyWithCompletionHandler:^(voID) { if (exportSession.status == AVAssetExportSessionStatusCompleted) { [self writeVIDeotophotolibrary:[NSURL fileURLWithPath:outputURL]]; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library writeVIDeoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:outputURL] completionBlock:^(NSURL *assetURL,NSError *error){ if (error) { NSLog(@"VIDeo Could not be saved"); } }]; } else { NSLog(@"error: %@",[exportSession error]); } }];解决方法 您可以使用AVFoundation和CoreMedia框架来缩放视频.
看看AVMutableCompositionTrack方法:
- (voID)scaleTimeRange:(CMTimeRange)timeRange toDuration:(CMTime)duration;
样品:
AVURLAsset* vIDeoAsset = nil; //self.inputAsset;//create mutable compositionAVMutableComposition *mixComposition = [AVMutableComposition composition];AVMutableCompositionTrack *compositionVIDeoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVIDeo preferredTrackID:kCMPersistentTrackID_InvalID];NSError *vIDeoInsertError = nil;BOol vIDeoInsertResult = [compositionVIDeoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,vIDeoAsset.duration) ofTrack:[[vIDeoAsset tracksWithMediaType:AVMediaTypeVIDeo] objectAtIndex:0] atTime:kCMTimeZero error:&vIDeoInsertError];if (!vIDeoInsertResult || nil != vIDeoInsertError) { //handle error return;}//slow down whole vIDeo by 2.0double vIDeoScaleFactor = 2.0;CMTime vIDeoDuration = vIDeoAsset.duration;[compositionVIDeoTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero,vIDeoDuration) toDuration:CMTimeMake(vIDeoDuration.value*vIDeoScaleFactor,vIDeoDuration.timescale)];//exportAVAssetExportSession* assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetname:AVAssetExportPresetLowQuality];
(也许也可以将来自vIDeoAsset的音轨添加到mixComposition中)
总结以上是内存溢出为你收集整理的如何在IOS中做慢动作视频全部内容,希望文章能够帮你解决如何在IOS中做慢动作视频所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)