the*_*ude 17 iphone avfoundation ios
我现在已经完全设置了使用AVFoundation框架录制视频的功能,这一切都很好,但现在我希望在录制期间添加叠加层(也可以在AVCaptureVideoPreviewLayer层上看到)
我可以将此叠加UIView对象添加到VideoPreviewLayer,但我正在努力如何在录制的视频上获得相同的视图.这UIView可能包含从UILabels到UIImageViews的任何内容.
sin*_*sin 10
我不确定这是否是您正在寻找的东西,但我想您可以使用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: %f s", -[startTime timeIntervalSinceNow]];
[weakUIElementInput update];
}];
}
Run Code Online (Sandbox Code Playgroud)
你想要叠加UIView,但如果你不介意使用CALayers,你可以在使用AVAssetExportSession's AVVideoComposition属性导出后添加叠加.它有一个属性,AVVideoCompositionCoreAnimationTool *animationTool可以让你CALayer为你的输出添加动画,虽然我觉得如果你的叠加的外观不能被描述你运气不好CABasicAnimation.您可以使用显示标题的示例,尽管我想象的事情就像当前时间计数器那样简单.如果您能忍受此限制,WWDC 2010代码示例'AVEditDemo'是一个很好的起点.
如果您需要更多控制,可以手动将覆盖渲染UIView到捕获帧上,[view.layer renderInContext:contextToThenRenderToFrame]然后使用然后将这些帧写入文件AVAssetWriter(一旦将帧捕获到内存中就不能再使用了AVCaptureMovieFileOutput).
警告:您捕获的帧可能无法达到统一的速率,并且取决于环境照明甚至系统负载.如果叠加层的更改速率高于捕获视频,则需要在第二个解决方案中重复帧.这是AVVideoComposition在第一个解决方案中为您处理的.
PS解决方案二是繁琐的,但没有详细说明,iOS7似乎使这更容易.
| 归档时间: |
|
| 查看次数: |
3682 次 |
| 最近记录: |