我已经完全设置了使用AVFoundation
框架进行视频录制的能力,这一切都很好,但是现在我想在录制过程中添加一个叠加层(也可见于AVCaptureVideoPreviewLayer
层)
我可以将此覆盖层的UIView
对象添加到VideoPreviewLayer,但我不知道如何使相同的视图出现在录制的视频上。 这个UIView
可以包含任何东西,从UILabel
到UIImageView
。
我已经完全设置了使用AVFoundation
框架进行视频录制的能力,这一切都很好,但是现在我想在录制过程中添加一个叠加层(也可见于AVCaptureVideoPreviewLayer
层)
我可以将此覆盖层的UIView
对象添加到VideoPreviewLayer,但我不知道如何使相同的视图出现在录制的视频上。 这个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: %f s", -[startTime timeIntervalSinceNow]];
[weakUIElementInput update];
}];
}
UIView
,但如果您不介意使用CALayer
,则可以在导出后使用AVAssetExportSession
的AVVideoComposition
属性添加覆盖层。它有一个属性AVVideoCompositionCoreAnimationTool *animationTool
,可让您将动画CALayer
添加到输出中,尽管我认为如果您的覆盖层外观无法由CABasicAnimation
描述,则会失去运气。您提供的显示标题的示例可能是可能的,但我想像当前时间计数器这样简单的东西可能不行。如果您可以接受此限制,则WWDC 2010代码示例“AVEditDemo”是一个很好的起点。UIView
渲染到捕获帧上,使用[view.layer renderInContext:contextToThenRenderToFrame]
,然后使用AVAssetWriter
将这些帧写入文件(一旦您将帧捕获到内存中,您将无法再使用AVCaptureMovieFileOutput
)。AVVideoComposition
为您处理。
UIView
添加为水印呢?这里有一个相关的问题https://dev59.com/wWUo5IYBdhLWcg3wkQNq - Gabriele Petronella