2014-06-19 35 views
2

我正在製作像Instagram一樣的應用程序。我使用GPUImage框架,在此我必須拍攝照片和視頻並共享。我能夠使用這個框架捕捉照片,現在我必須捕捉視頻,但我正在努力如何將相機模式照片更改爲視頻。任何幫助和教程,那麼它對我來說非常好。我用這個代碼相機的照片模式。如何在ios中使用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() 
} 
相關問題