我正在制作像Instagram这样的应用程序。我正在使用GPUImage框架,在此我必须拍摄照片和视频并分享。我能够使用这个框架捕捉照片,现在我必须捕捉视频,但我正在努力如何将相机模式照片更改为视频。任何帮助和教程然后它对我很好。我用这个代码相机拍照模式。
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
self.overlayView.frame = self.imagepicker.cameraOverlayView.frame;
self.imagepicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
CGSize result = [[UIScreen mainScreen] bounds].size;
self.imagepicker.showsCameraControls = NO;
self.imagepicker.allowsEditing = NO;
self.imagepicker.wantsFullScreenLayout = NO;
// self.imagepicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
}
else{
self.imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
答案 0 :(得分:0)
在我的情况下,我使用GPUImage同时执行这两项操作(图片和视频)。因此,我创建了两个对象:一个是GPUImageStillCamera(图片)类型,另一个是GPUImageVideoCamera(视频)类型。
因此,无论何时需要在摄像机之间切换,您基本上都会停止GPUImageStillCamera捕获并初始化摄像机(请注意,您必须将此片段调整到您的项目中):
func initializeVideoCamera() {
// Stop the capture of GPUImageStillCamera
stillCamera.stopCameraCapture()
videoCamera = GPUImageVideoCamera.init(sessionPreset: AVCaptureSessionPreset1920x1080, cameraPosition: .Back)
videoCamera?.outputImageOrientation = .Portrait
videoCamera?.addTarget(filter)
// If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
unlink(pathToMovieFile)
initializeWriteWithPath(pathToMovieFile)
videoCamera?.startCameraCapture()
}