piemonte / PBJVision

📸 iOS Media Capture – features touch-to-record video, slow motion, and photography
MIT License
1.94k stars 324 forks source link

Flipping camera causes delay when flipping from Front to Back #309

Closed ramonsgds closed 8 years ago

ramonsgds commented 8 years ago

Hello @piemonte! First of all, congratulations on such an awesome library. I am having a issue of delay when flipping the camera from Front to Back. I am using the following properties:

vision.cameraMode = PBJCameraModeVideo; //vision.cameraMode = PBJCameraModePhoto; // PHOTO: uncomment to test photo capture vision.cameraOrientation = PBJCameraOrientationPortrait; vision.focusMode = PBJFocusModeContinuousAutoFocus; vision.outputFormat = PBJOutputFormatPreset; vision.videoRenderingEnabled = YES; vision.additionalCompressionProperties = @{AVVideoProfileLevelKey : AVVideoProfileLevelH264HighAutoLevel}; // AVVideoProfileLevelKey requires specific captureSessionPreset vision.captureSessionPreset = AVCaptureSessionPresetHigh;

//specify a maximum duration with the following property vision.maximumCaptureDuration = CMTimeMakeWithSeconds(15, 600); // ~ 15 seconds

on PBJVision.m, in -(id) init I have

_videoBitRate = PBJVideoBitRate640x480; _audioBitRate = 64000;

When using captureSessionPresetMedium there's no delay so far, only in AVCaptureSessionPresetHigh. The delay takes about 2-3 seconds to turn the camera from front to back, and there is no delay from back to front (Even after going multiple times front-back and back-front the only delay is always on front-back). I believe this is because the setupSession being called. So, it is kind of annoying to record a video with freezings every time I switch the camera from front to back. Is there any solution or workaround here? Since there's a lot of queue's already being used, I don't think sending setupSession to background will solve the issue. Any ideas?

piemonte commented 8 years ago

hey @ramonsgds ! :v: thanks for your interest in the project.

currently, i'm unable to contribute fixes because of some on-going project work but my friends and i have a library which is almost available and will hopefully address some of these performance issues. not explicitly sure what the problem would be without looking into it in detail.

when i get a chance, i'll let you know.

https://github.com/nextlevel/nextlevel

redroostertech commented 8 years ago

I use the following code

@IBAction func switchCamButtonAct(sender: AnyObject) {

    vision.maximumCaptureDuration = CMTimeMakeWithSeconds(5, 30)
    vision.cameraMode = PBJCameraMode.Video
    vision.cameraOrientation = PBJCameraOrientation.Portrait

    if vision.cameraDevice == PBJCameraDevice.Front {

        vision.cameraDevice = PBJCameraDevice.Back
    } else {
        vision.cameraDevice = PBJCameraDevice.Front
    }

    vision.focusMode = PBJFocusMode.ContinuousAutoFocus
    vision.outputFormat = PBJOutputFormat.Square

    vision.startPreview()

    UIView.transitionWithView(self.view, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromLeft, animations: {}, completion: nil)
}
redroostertech commented 8 years ago

@ramonsgds did it work for you?