避免video开始和结束时的模糊(甚至在使用setPreferredVideoStabilizationMode:AVCaptureVideoStabilizationModeAuto之后)?
我们在使用setPreferredVideoStabilizationMode:AVCaptureVideoStabilizationModeAuto
同时在iOS上捕捉video,但是video在开始和结束时有时会变得模糊(尽pipe在中间很好),这是非常有问题的,因为我们把第一帧作为静止图像以便在不切换相机模式的情况下启用video和照片function)。
将设备平放在桌面上可以消除所有模糊现象,因此整个video都非常清晰。 这表明它与video稳定有关,但是还有其他属性可以设置吗?
locking焦点模式的问题吗?
其他疑难解答提示?
以下是PBJVision的video捕获function,我们使用这个function:
- (void)startVideoCapture { if (![self _canSessionCaptureWithOutput:_currentOutput] || _cameraMode != PBJCameraModeVideo) { [self _failVideoCaptureWithErrorCode:PBJVisionErrorSessionFailed]; DLog(@"session is not setup properly for capture"); return; } DLog(@"starting video capture"); [self _enqueueBlockOnCaptureVideoQueue:^{ if (_flags.recording || _flags.paused) return; NSString *guid = [[NSUUID new] UUIDString]; NSString *outputFile = [NSString stringWithFormat:@"video_%@.mp4", guid]; if ([_delegate respondsToSelector:@selector(vision:willStartVideoCaptureToFile:)]) { outputFile = [_delegate vision:self willStartVideoCaptureToFile:outputFile]; if (!outputFile) { [self _failVideoCaptureWithErrorCode:PBJVisionErrorBadOutputFile]; return; } } NSString *outputDirectory = (_captureDirectory == nil ? NSTemporaryDirectory() : _captureDirectory); NSString *outputPath = [outputDirectory stringByAppendingPathComponent:outputFile]; NSURL *outputURL = [NSURL fileURLWithPath:outputPath]; if ([[NSFileManager defaultManager] fileExistsAtPath:outputPath]) { NSError *error = nil; if (![[NSFileManager defaultManager] removeItemAtPath:outputPath error:&error]) { [self _failVideoCaptureWithErrorCode:PBJVisionErrorOutputFileExists]; DLog(@"could not setup an output file (file exists)"); return; } } if (!outputPath || [outputPath length] == 0) { [self _failVideoCaptureWithErrorCode:PBJVisionErrorBadOutputFile]; DLog(@"could not setup an output file"); return; } if (_mediaWriter) { _mediaWriter.delegate = nil; _mediaWriter = nil; } _mediaWriter = [[PBJMediaWriter alloc] initWithOutputURL:outputURL]; _mediaWriter.delegate = self; AVCaptureConnection *videoConnection = [_captureOutputVideo connectionWithMediaType:AVMediaTypeVideo]; [self _setOrientationForConnection:videoConnection]; _startTimestamp = CMClockGetTime(CMClockGetHostTimeClock()); _timeOffset = kCMTimeInvalid; _flags.recording = YES; _flags.paused = NO; _flags.interrupted = NO; _flags.videoWritten = NO; _captureThumbnailTimes = [NSMutableSet set]; _captureThumbnailFrames = [NSMutableSet set]; if (_flags.thumbnailEnabled && _flags.defaultVideoThumbnails) { [self captureVideoThumbnailAtFrame:0]; } [self _enqueueBlockOnMainQueue:^{ if ([_delegate respondsToSelector:@selector(visionDidStartVideoCapture:)]) [_delegate visionDidStartVideoCapture:self]; }]; }]; }
此代码configurationPBJVision并启动video捕获:
private func initPBJVision() { // Configure PBJVision pbj.delegate = self pbj.cameraMode = .Video pbj.cameraOrientation = .Portrait pbj.focusMode = .AutoFocus pbj.outputFormat = .Preset pbj.cameraDevice = .Back pbj.thumbnailEnabled = false // Log status print("Configured PBJVision") pbj.startVideoCapture() }
一旦PBJ准备好预览,我们使相机对焦在屏幕的中点。
// Called when PBJVision preview begins func visionSessionDidStartPreview(vision: PBJVision) { // Focus screen at midpoint let focus_x = CGFloat(0.5) let focus_y = CGFloat(0.5) }
video的性质是模糊的。 每秒24或30帧的video在镜头中总会有一些模糊,因为这是我们的眼睛被欺骗,相信照片实际上在移动的方式。 较长的快门速度可以让相机给人以运动的印象。
照片使用更短的快门速度(1/60秒或更less)来拍摄清晰静止的照片。
这里有一些关于录制video时如何拍照的信息:
如何在录制video时以编程方式拍照
我不知道PBJVision框架,但你可以在提取你需要的图片之前检查AVCaptureDevice的调整焦点。
显然,您可以使用PBJVision isAdjustingFocus
方法检查设备的对焦状态。