美文网首页
录制视频相关

录制视频相关

作者: 如意神王 | 来源:发表于2019-06-11 18:19 被阅读0次

    1.设置AVSampleBufferDisplayLayer全屏

    视频输出
    [layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

    • (void)addAVSampleBufferDisplayLayer {
      AVSampleBufferDisplayLayer * layer = [[AVSampleBufferDisplayLayer alloc] init];
      layer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
      [layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
      self.sampleDisplayLayer = layer;
      [self.view.layer addSublayer:layer];
      }

    AVSampleBufferDisplayLayer 直接播放CMSampleBufferRef格式视频输出

    • (void)enqueueSampleBuffer:(CMSampleBufferRef) sampleBuffer toLayer:(AVSampleBufferDisplayLayer*) layer
      {
      if (sampleBuffer){
      CFRetain(sampleBuffer);
      [layer enqueueSampleBuffer:sampleBuffer];
      CFRelease(sampleBuffer);
      if (layer.status == AVQueuedSampleBufferRenderingStatusFailed){
      NSLog(@"ERROR: %@", layer.error);
      if (-11847 == layer.error.code){
      }
      }else{
      // NSLog(@"STATUS: %i", (int)layer.status);
      }
      }else{
      NSLog(@"ignore null samplebuffer");
      }
      }

    2.设置AVCaptureVideoPreviewLayer全屏

    视频预览
    [self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

    self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.avSession];
    [self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [self.previewLayer setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view.layer insertSublayer:self.previewLayer above:0];

    3.直接视频输出数据

    AVSampleBufferDisplayLayer 正常 全屏 横向OK 纵向OK 横纵都不变形
    AVCaptureVideoPreviewLayer 正常 全屏 横向OK 纵向OK 横纵都不变形

    相关文章

      网友评论

          本文标题:录制视频相关

          本文链接:https://www.haomeiwen.com/subject/amkcfctx.html