BradLarson / GPUImage2

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
BSD 3-Clause "New" or "Revised" License
4.85k stars 605 forks source link

How to integrate Flash/Torch? #231

Open aaasifrz9 opened 6 years ago

aaasifrz9 commented 6 years ago

Hi @BradLarson,

I tried to identify AVCaptureTorchMode for integration of Flash/Torch but not able to get anything. 1- How can I integrate it? 2- How can I change mode ON/OFF?

Please help. Thanks in advance.

aaasifrz9 commented 6 years ago

Actually, we are not able to access inputCamera:AVCaptureDevice of class Camera because this variable is not public. Please do the needful. Either make it public or provide any method to enable torch. Thanks in advance.

joshbernfeld commented 6 years ago
extension AVCaptureDevice {
    func setTorchMode(mode: AVCaptureTorchMode) {
        do {
            try self.lockForConfiguration()

            if(self.hasTorch && self.isTorchModeSupported(mode)) {
                self.torchMode = mode
            }

            self.unlockForConfiguration()
        } catch {
            print("Could not set flash mode: \(error)")
        }
    }
}

Then make sure the inputCamera var is public on the Camera class and you can do the following:

self.camera!.inputCamera.setTorchMode(mode: .auto)

aaasifrz9 commented 6 years ago

Thanks @joshbernfeld