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 横纵都不变形
网友评论