I am currently trying to shoot a video, but when I execute the following code, I get the error "because more than one output of the same type is unsupported."
var myDevice: AVCaptureDevice?
let devices = AVCaptureDevice.devices()
for device in devices {
if(device.position==AVCaptureDevicePosition.Front){
myDevice=device as ?AVCaptureDevice
}
}
do{
let videoInput=try AVCaptureDeviceInput (device:myDevice) as AVCaptureDeviceInput
self.captureSession.addInput (videoInput)
let audioInput=try AVCaptureDeviceInput (device:self.audioDevice) as AVCaptureDeviceInput
self.captureSession.addInput(audioInput);
} catch{
}
let movieFileOutput=AVCaptureMovieFileOutput()
self.captureSession.addOutput(movieFileOutput)
var videoConnection: AVCaptureConnection?=nil
for connection: AVCaptureConnection in movieFileOutput.connections as![AVCaptureConnection]{
print(connection)
for inputport in connection.inputPorts {
iflet port = inputport as ?AVCaptureInputPort{
print(port)
if port.mediaType==AVMediaTypeVideo{
videoConnection=connection
}
}
}
}
if((videoConnection?.supportVideoOrientation)!=nil){
videoConnection?.videoOrientation=AVCaptureVideoOrientation.LandscapeLeft
}
self.captureSession.commitConfiguration()
self.captureSession.addOutput(self.fileOutput)
self.captureSession.startRunning()
From the line let movieFileOutput=AVCaptureMovieFileOutput()
if((videoConnection?.supportVideoOrientation)!=nil){
The above error occurred when I added the line up to .(The added cord is used to fix the direction of the video sideways.)
What should I do to be able to shoot a video?
Please let me know if anyone knows.Thank you for your cooperation.
I think the error is caused by addOutput()
both self.fileOutput
and movieFileOutput
for captureSession
.
Do you want to fix the orientation of the video when outputting to self.fileOutput
?The current code looks like the connection leading to the newly created movieFileOutput
is fixing the orientation of the video.
Shouldn't we look for a connection that leads to self.fileOutput
instead of movieFileOutput
and set the orientation of the video?
Note A very short sample showing the camera in Objective-C-AVFoundation - Qiita
© 2024 OneMinuteCode. All rights reserved.