我们在使用setPreferredVideoStabilizationMode:AVCaptureVideoStabilizationModeAuto
时在iOS上捕捉视频,但视频有时会在开始和结束时出现模糊(尽管中间很好),这是非常有问题的,因为我们抓住了第一帧作为静止图像(为了在不切换相机模式的情况下启用视频和照片功能)。
将设备平放在桌面上会消除所有模糊现象,因此整个视频都很清晰。这表明它与视频稳定有关,但还有其他属性可以设置吗?
锁定焦点模式是否重要?
其他任何疑难解答提示?
以下是PBJVision的视频捕捉功能,我们使用:
- (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];
}];
}];
}
此代码配置PBJVision并开始视频捕获:
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)
}
答案 0 :(得分:2)
视频本质上是模糊的。每秒24或30帧的视频在镜头中总会有一些模糊,因为这是我们的眼睛被欺骗的方式,相信图片实际上正在移动。较长的快门速度可让相机给人以动感的印象。
照片使用更短的快门速度(1/60秒或更短)来拍摄清晰的静态照片。
这里有一些关于如何在录制视频时拍照的信息:
答案 1 :(得分:2)
我不知道PBJVision框架,但您可以在提取所需图片之前检查AVCaptureDevice的adjustingFocus。
显然,您可以使用PBJVision isAdjustingFocus
方法检查设备的聚焦状态。