ios xcode GPUimage视频录制和静态图像捕获
我正在使用的应用程序允许用户录制具有选定效果的视频。它基于GPUIamge FilterShowcase示例 我刚刚添加了一个选项,用于捕获所选当前视频效果的静态图像 捕获静止图像可以工作,但速度非常慢。从调用捕获静态图像方法到实际保存图像的时间有很长的延迟(1到2秒) 有没有更优化的方法来实现这一点 多谢各位 代码如下:ios xcode GPUimage视频录制和静态图像捕获,ios,video-capture,gpuimage,image-capture,Ios,Video Capture,Gpuimage,Image Capture,我正在使用的应用程序允许用户录制具有选定效果的视频。它基于GPUIamge FilterShowcase示例 我刚刚添加了一个选项,用于捕获所选当前视频效果的静态图像 捕获静止图像可以工作,但速度非常慢。从调用捕获静态图像方法到实际保存图像的时间有很长的延迟(1到2秒) 有没有更优化的方法来实现这一点 多谢各位 代码如下: -(IBAction)savePhotoWithEffects:(id)sender { // disable buttons - prevent user
-(IBAction)savePhotoWithEffects:(id)sender
{
// disable buttons - prevent user
btnPhoto.enabled=NO;
btnRecord.enabled=NO;
// stop videoCamera capture
[videoCamera stopCameraCapture];
[stillCamera capturePhotoAsImageProcessedUpToFilter:filter withCompletionHandler:^(UIImage *captureImage, NSError *error){
if (error) {
NSLog(@"ERROR: Could not capture!");
}
else {
// save file
NSLog(@"PHOTO SAVED - ??");
// save photo to album
UIImageWriteToSavedPhotosAlbum(captureImage, nil, nil, nil);
}
runOnMainQueueWithoutDeadlocking(^{
// Start video camera capture again
[videoCamera startCameraCapture];
// enable the take photo and start recording buttons again
btnPhoto.enabled=YES;
btnRecord.enabled=YES;
});
}];
}
如果非要我猜的话,我会说延迟是因为试图同时运行GPUImageStillCamera和GPUIMageSvideoCamera造成的。您可以尝试这样做:
[videoCamera pauseCameraCapture];
UIImage *capturedImage = [filter imageFromCurrentlyProcessedOutput];
UIImageWriteToSavedPhotosAlbum(capturedImage, nil, nil, nil);
[videoCamera resumeCameraCapture];
这样你就根本不需要GPUImageStillCamera了。希望这有帮助 你的案子没问题。只是在拍摄前不要停止拍摄视频 //禁用按钮-防止用户 btnPhoto.enabled=否; btnRecord.enabled=否
[stillCamera capturePhotoAsImageProcessedUpToFilter:filter withCompletionHandler:^(UIImage *captureImage, NSError *error){
if (error) {
NSLog(@"ERROR: Could not capture!");
}
else {
// save file
NSLog(@"PHOTO SAVED - ??");
// save photo to album
UIImageWriteToSavedPhotosAlbum(captureImage, nil, nil, nil);
}
runOnMainQueueWithoutDeadlocking(^{
// enable the take photo and start recording buttons again
btnPhoto.enabled=YES;
btnRecord.enabled=YES;
});
}];
}