enebin / Aespa

From camera to album, in just 2 lines
https://enebin.github.io/Aespa/documentation/aespa/
MIT License
75 stars 16 forks source link

Mirror front camera output #47

Open missphyrgames opened 2 weeks ago

missphyrgames commented 2 weeks ago

Hey again @enebin! I'd like to be able to mirror the front camera output but not the back camera (for the photo capture not the actual preview). With AVFoundation, I think you can do it using the AV connection. How can I do it using this library?

missphyrgames commented 2 weeks ago

Managed to get it working with this piece of code. I think it would be good if you could expose photoOutput

extension VideoContentViewModel {
    struct MirrorTuner: AespaSessionTuning {
        func tune<T>(_ session: T) throws where T : AespaCoreSessionRepresentable {
            let output = session.avCaptureSession.outputs.first {
                $0 as? AVCapturePhotoOutput != nil
            }

            if let photoOutput = output as? AVCapturePhotoOutput {
                if let photoOutputConnection = photoOutput.connection(with: .video) {
                    photoOutputConnection.automaticallyAdjustsVideoMirroring = false
                    photoOutputConnection.isVideoMirrored = true
                }
            }
        }
    }
}
missphyrgames commented 2 weeks ago

Hmm this doesn't quite work when I switch from the front camera to the back camera and then back to the front camera. It stops the mirroring on the photo output image