我正在创建相机应用,该相机使用 SCRecorder 捕获视频。我正在尝试对视频应用多个过滤器。我正在按以下方式更改Recorder的视频配置
func swipeableFilterView(_ swipeableFilterView: SCSwipeableFilterView, didScrollTo filter: SCFilter?) {
selectedFilter = filter!
recorder.videoConfiguration.filter = filter!
}
当我将摄像头改回前部时,我正在使用应用滤镜捕获视频,然后在右侧出现黑屏,成为波纹图像:
带有后置摄像头,它将完美工作
这是appendVideoSampleBuffer的代码
- (void)appendVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer toRecordSession:(SCRecordSession *)recordSession duration:(CMTime)duration connection:(AVCaptureConnection *)connection completion:(void(^)(BOOL success))completion {
@autoreleasepool {
CVPixelBufferRef sampleBufferImage = CMSampleBufferGetImageBuffer(sampleBuffer);
size_t bufferWidth = (CGFloat)CVPixelBufferGetWidth(sampleBufferImage);
size_t bufferHeight = (CGFloat)CVPixelBufferGetHeight(sampleBufferImage);
CMTime time = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
SCFilter *filterGroup = _videoConfiguration.filter;
SCFilter *transformFilter = [self _transformFilterUsingBufferWidth:bufferWidth bufferHeight:bufferHeight mirrored:
_device == AVCaptureDevicePositionFront
];
if (filterGroup == nil && transformFilter == nil) {
[recordSession appendVideoPixelBuffer:sampleBufferImage atTime:time duration:duration completion:completion];
return;
}
CVPixelBufferRef pixelBuffer = [recordSession createPixelBuffer];
if (pixelBuffer == nil) {
completion(NO);
return;
}
CIImage *image = [CIImage imageWithCVPixelBuffer:sampleBufferImage];
CFTimeInterval seconds = CMTimeGetSeconds(time);
if (transformFilter != nil) {
image = [transformFilter imageByProcessingImage:image atTime:seconds];
}
if (filterGroup != nil) {
image = [filterGroup imageByProcessingImage:image atTime:seconds];
}
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
[_context render:image toCVPixelBuffer:pixelBuffer];
[recordSession appendVideoPixelBuffer:pixelBuffer atTime:time duration:duration completion:^(BOOL success) {
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CVPixelBufferRelease(pixelBuffer);
completion(success);
}];
}
}
我调试了代码,我认为问题出在
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
任何人请帮助我!