同时录制覆盖AVFoundation iOS
我现在已经完全设置了使用AVFoundation
框架录制video的AVFoundation
,这一切都很好,但现在我希望在录制期间添加叠加层(也可以在AVCaptureVideoPreviewLayer
层上看到)
我可以将这个叠加的UIView
对象添加到VideoPreviewLayer,但是我正在努力如何在录制的video上获得相同的视图。这个UIView
可以包含从UILabel
到UIImageView
的任何内容。
我不确定这是否是您正在寻找的东西,但我想您可以使用Brad Larson的GPU库,有一个名为GPUImageElement的类,它允许您添加叠加层和视图。请查看示例,尤其是名为Filter showcase的示例并滚动到名为UIElement的东西。
以下是一些示例代码:
else if (filterType == GPUIMAGE_UIELEMENT) { GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; blendFilter.mix = 1.0; NSDate *startTime = [NSDate date]; UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 240.0f, 320.0f)]; timeLabel.font = [UIFont systemFontOfSize:17.0f]; timeLabel.text = @"Time: 0.0 s"; timeLabel.textAlignment = UITextAlignmentCenter; timeLabel.backgroundColor = [UIColor clearColor]; timeLabel.textColor = [UIColor whiteColor]; uiElementInput = [[GPUImageUIElement alloc] initWithView:timeLabel]; [filter addTarget:blendFilter]; [uiElementInput addTarget:blendFilter]; [blendFilter addTarget:filterView]; __unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput; [filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){ timeLabel.text = [NSString stringWithFormat:@"Time: %fs", -[startTime timeIntervalSinceNow]]; [weakUIElementInput update]; }]; }
你想要叠加UIView
,但是如果你不介意使用CALayer
你可以在导出后使用AVAssetExportSession
的AVVideoComposition
属性添加叠加。 它有一个属性, AVVideoCompositionCoreAnimationTool *animationTool
,它允许你将动画CALayer
添加到你的输出,虽然我认为如果你的叠加的外观不能由CABasicAnimation
描述你运气不好。 你的显示标题的例子是可能的,虽然我想象一些像当前时间计数器那样简单的东西。 如果您可以接受此限制,WWDC 2010代码示例’AVEditDemo’是一个很好的起点。
如果需要更多控制,可以使用[view.layer renderInContext:contextToThenRenderToFrame]
手动将叠加UIView
渲染到捕获帧上,然后使用AVAssetWriter
将这些帧写入文件(一旦将帧捕获到内存,就不能再使用AVCaptureMovieFileOutput
) 。
警告 :您捕获的帧可能无法达到统一的速率,并且取决于环境照明甚至系统负载。 如果叠加层的更改速率高于捕获video,则需要在第二个解决方案中重复帧。 这是由AVVideoComposition
在第一个解决方案中为您处理的。
PS解决方案二是繁琐的,但没有详细说明,iOS7似乎使这更容易。
您可以在编辑部分的AVFoundation Programming Guide中找到它
有一个部分处理图像的叠加。 我将尝试提供示例代码/项目。
为了解决您的问题,有关raywenderlich教程网站的两个非常详细的解释。 这是一个两部分的教程。
第一个是在这里: http : //www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios
第二个是在这里: http : //www.raywenderlich.com/30200/avfoundation-tutorial-adding-overlays-and-animations-to-videos
祝你好运,希望这能帮到你!!
- 整合评论与Facebook iOS SDK(iPhone)
- prepareForSegue没有被调用,当我点击一个button,而不使用performSegueWithIdentifier
- 设置UINavigationBar的背景颜色没有效果?
- 苹果是否修改了提交给App Store的应用程序上的iOS应用程序可执行文件?
- 为什么我们只使用aurioTouch项目中的第一个缓冲区
- 我如何在IBAction(button)中放置一个void(shake手势)?
- 如何在swift中将视图控制器popup到以前的视图控制器之一?
- 我有很多图像arrays,我想淡入淡出imageview重复
- 当进入背景时,MPMoviePlayerViewController变黑