Comments (5)
Hi, @CassianoMouraLeao
You can change devicePosition
property to .front
. Please see the example code https://github.com/nkmrh/FilterCam/blob/master/Example/Example/ViewController.swift#L25
from filtercam.
What if I watch to switch between front and back camera on button action, in that case changing the value of devicePosition is not working
from filtercam.
@khanskt786 I think I'm experiencing this as well. Although I was playing around with the framework to understand it but for now let's assume the project I downlaoded is in the same state as the OP.
Keep in mind I just began working on the camera frameworks and shaders so my knowledge may not be best practice. Although looking through Apple's Camera Project AVCam, you can tell it's similar to this awesome framework the Author has made for us, and just by looking at the changeCamera(_:) method you can made a crude adaption to the code base.
The first place we should begin is within the the Capture class. Tested on my iPhone X, you'll need to also include conditional code that applies to the target devices for your app. But this should get the camera to switch, although my video isn't mirrored properly which is something you may experience too, but we're only talking about switching cameras here.
func changeCamera(devicePosition: AVCaptureDevice.Position) {
queue.async {
guard let session = self.session else { return }
//remove existing input devices first then add the new devices
session.beginConfiguration()
//https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/avcam_building_a_camera_app
//https://stackoverflow.com/questions/30755043/avfoundation-toggle-camera-fails-at-canaddinput
for input in session.inputs {
//video
session.removeInput(input as! AVCaptureDeviceInput)
//audio
session.removeInput(input as! AVCaptureDeviceInput)
}
//create new AVCaptureDeviceInput for video
if let videoDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: devicePosition) {
self.videoDevice = videoDevice
guard let videoDeviceInput = self.videoDeviceInput else { return }
if session.canAddInput(videoDeviceInput) {
session.addInput(videoDeviceInput)
} else {
session.addInput(self.videoDeviceInput!)
}
}
//create new AVCaptureDeviceInput for audio
if let audioDevice = AVCaptureDevice.default(.builtInMicrophone, for: .audio, position: .unspecified) {
self.audioDevice = audioDevice
guard let audioDeviceInput = self.audioDeviceInput else { return }
if session.canAddInput(audioDeviceInput) {
session.addInput(audioDeviceInput)
} else {
session.addInput(self.audioDeviceInput!)
}
}
session.commitConfiguration()
}
}
I call this function in the Recorder class. So make another function in the Recorder class to be called in your appropriate ViewController and attach it to your button.
Cheers
from filtercam.
Thought I'd quickly add mirroring documentation is provided by the author. Just search for mirroring in the project itself and apply the transform as written to the videoPreviewView.
from filtercam.
@khanskt786 I think I'm experiencing this as well. Although I was playing around with the framework to understand it but for now let's assume the project I downlaoded is in the same state as the OP.
Keep in mind I just began working on the camera frameworks and shaders so my knowledge may not be best practice. Although looking through Apple's Camera Project AVCam, you can tell it's similar to this awesome framework the Author has made for us, and just by looking at the changeCamera(_:) method you can made a crude adaption to the code base.
The first place we should begin is within the the Capture class. Tested on my iPhone X, you'll need to also include conditional code that applies to the target devices for your app. But this should get the camera to switch, although my video isn't mirrored properly which is something you may experience too, but we're only talking about switching cameras here.
func changeCamera(devicePosition: AVCaptureDevice.Position) { queue.async { guard let session = self.session else { return } //remove existing input devices first then add the new devices session.beginConfiguration() //https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/avcam_building_a_camera_app //https://stackoverflow.com/questions/30755043/avfoundation-toggle-camera-fails-at-canaddinput for input in session.inputs { //video session.removeInput(input as! AVCaptureDeviceInput) //audio session.removeInput(input as! AVCaptureDeviceInput) } //create new AVCaptureDeviceInput for video if let videoDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: devicePosition) { self.videoDevice = videoDevice guard let videoDeviceInput = self.videoDeviceInput else { return } if session.canAddInput(videoDeviceInput) { session.addInput(videoDeviceInput) } else { session.addInput(self.videoDeviceInput!) } } //create new AVCaptureDeviceInput for audio if let audioDevice = AVCaptureDevice.default(.builtInMicrophone, for: .audio, position: .unspecified) { self.audioDevice = audioDevice guard let audioDeviceInput = self.audioDeviceInput else { return } if session.canAddInput(audioDeviceInput) { session.addInput(audioDeviceInput) } else { session.addInput(self.audioDeviceInput!) } } session.commitConfiguration() } }
I call this function in the Recorder class. So make another function in the Recorder class to be called in your appropriate ViewController and attach it to your button.
Cheers
thanks for your replay but please where to put this function and when call it ?
from filtercam.
Related Issues (15)
- How can we add stickers on live camera preview with capture image and record video? HOT 2
- On rotation from portrait to landscape, camera orientation got rotated by 180 degree when using front camera HOT 1
- Black overlay appearance HOT 1
- Front camera having an mirror. HOT 4
- Camera goes black and crashed when start recording if Microphone permission is denied. HOT 2
- Unable to make long videos HOT 2
- Capture some UIView
- Doesn't work with bluetooth headphones HOT 1
- Change camera front and back HOT 1
- Don't flip from front to back camera HOT 1
- can't capture image HOT 1
- apply in webrtc
- App stuck if we use more than 12 filters.
- how to start and stop session?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from filtercam.