在实时视频iOS上录制叠加层

时间:2014-08-02 13:24:16

标签: ios avfoundation core-image

我正在尝试从设备相机录制实时视频供稿的叠加层。

我只能找到合并图像或文本与录像机视频的解决方案。即录制视频后。

我打算做的是,将叠加层录制为视频的一部分。

“AVMutableComposition”还用于将多个视频和音频资产添加/混合在一起,并将它们保存为一个资产。

以下代码在视频预览中添加了子图层:

 // 1 - set up the overlay
  CALayer *overlayLayer = [CALayer layer];
  UIImage *overlayImage = nil;
  if (_frameSelectSegment.selectedSegmentIndex == 0) {
    overlayImage = [UIImage imageNamed:@"Frame-1.png"];
  } else if(_frameSelectSegment.selectedSegmentIndex == 1) {
    overlayImage = [UIImage imageNamed:@"Frame-2.png"];
  } else if(_frameSelectSegment.selectedSegmentIndex == 2) {
    overlayImage = [UIImage imageNamed:@"Frame-3.png"];
  }

  [overlayLayer setContents:(id)[overlayImage CGImage]];
  overlayLayer.frame = CGRectMake(0, 0, size.width, size.height);
  [overlayLayer setMasksToBounds:YES];

  // 2 - set up the parent layer
  CALayer *parentLayer = [CALayer layer];
  CALayer *videoLayer = [CALayer layer];
  parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
  videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
  [parentLayer addSublayer:videoLayer];
  [parentLayer addSublayer:overlayLayer];

  // 3 - apply magic
  composition.animationTool = [AVVideoCompositionCoreAnimationTool
                               videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];

0 个答案:

没有答案