piemonte / PBJVision

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

Switching camera modes causes UI flicker/glitch #231

Closed oligriffiths closed 3 years ago

oligriffiths commented 9 years ago

Hey

First off, great library.

I've found a glitch when switching camera modes. When switching from photo mode to video mode, the preview appears to shrink to around half the size, then flick back to full size again in a split second. Is there any way to mitigate this? It's most noticeable on older hardware (4s) but still visible on iphone 6.

You can test this with the following code:

@interface ViewController () <PBJVisionDelegate>
@property (nonatomic) PBJVision *camera;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.camera = [PBJVision sharedInstance];
    self.camera.cameraMode = PBJCameraModePhoto;
    self.camera.cameraOrientation = PBJCameraOrientationPortrait;
    self.camera.focusMode = PBJFocusModeContinuousAutoFocus;
    self.camera.captureSessionPreset = AVCaptureSessionPresetMedium;
    self.camera.previewLayer.frame = self.view.bounds;
    [self.view.layer addSublayer:self.camera.previewLayer];

    [self.camera startPreview];

    [self performSelector:@selector(swapModes) withObject:nil afterDelay:3.f];
}

-(void)swapModes{
    self.camera.cameraMode = PBJCameraModeVideo;
}

@end
markst commented 9 years ago

[self.view layoutIfNeeded] before start preview? You should probably be calling startPreview on viewWillAppear:

oligriffiths commented 9 years ago

This is just sample code, but yes you are correct, however even with that, the flicker still occurs. In my app im switching the mode whilst the preview is already running, as above (after 3s delay)

piemonte commented 9 years ago

thanks @oligriffiths @markst will check it out

alak commented 9 years ago

Any news about this?

rromanchuk commented 9 years ago

Hey guys, this probably not exactly related to your mode switch issues, but i just want to let you know that you may never solve this problem with modern day hardware and SDK when it comes to mode switching. This plagues all video libraries including GPUImage If you look on the market, no one is able to achieve this. Even Apple. If you look at most photo capture apps that also do video, they almost always will require the user to do a "mode switch". There is workaround however, if you don't care about the quality of your photos (you're ok with not using AVCaptureSessionPresetPhoto), for example snapshat, where you can simply take a frame from the live preview buffer #183 without ever having to call a preset change.

There are other "clever" tricks you can do to distract the user, for example, a long "warm up" animation, but from my 5 years trying to accomplish smooth preset changes...it has been futile. The example i'm talking about here is long press to record while single press to capture high resolution photo. It can be done, but not without a very visible hiccup from the hardware.

oligriffiths commented 9 years ago

Up, that's exactly what I did, used #183 to achieve what I'm looking for. Thanks