Предварительный просмотр камеры AvcaptureSession FRESTIONS на одном кадре вместо того, чтобы показывать живое видеоIOS

Программируем под IOS
Ответить
Anonymous
 Предварительный просмотр камеры AvcaptureSession FRESTIONS на одном кадре вместо того, чтобы показывать живое видео

Сообщение Anonymous »

Предварительный просмотр камеры замораживает на одной кадре (черное/частично отображаемое изображение), а прямая подача камеры никогда не запускается. Пользовательский интерфейс остается отзывчивым, но AvcaptureSession не доставляет кадры после инициализации. По сути, предварительный просмотр показывает несвежая или замороженная рама вместо живого видео. < /P>
func startReceivingUpdates() {
videoFrameService.delegate = self
cameraService.delegate = self
}

func stopReceivingUpdates() {
videoFrameService.delegate = nil
cameraService.delegate = nil
}
< /code>
Они вызываются в Onpear и Ondisappear представления соответственно < /p>
private func configureCaptureSession() {
guard status == .unconfigured else {
return
}

session.beginConfiguration()

defer {
session.commitConfiguration()
}

for input in session.inputs {
bsession.removeInput(input)
}

let device = AVCaptureDevice.default(
.builtInWideAngleCamera, for: .video, position: cameraPosition)

guard let camera = device else {
set(error: .cameraUnavailable)
status = .failed
return
}

do {
let cameraInput = try AVCaptureDeviceInput(device: camera)

if session.canAddInput(cameraInput) {
session.addInput(cameraInput)
} else {
set(error: .cannotAddInput)
status = .failed
return
}

if let audioCaptureDevice = audioCaptureDevice {
let audioInput = try AVCaptureDeviceInput(device: audioCaptureDevice)

if session.canAddInput(audioInput) {
session.addInput(audioInput)
}
}
} catch {
set(error: .createCaptureInput(error))
status = .failed
return
}

session.outputs.forEach { output in
session.removeOutput(output)
}

if session.canAddOutput(videoOutput) {
session.addOutput(videoOutput)

videoOutput.videoSettings =
[kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA]

let videoConnection = videoOutput.connection(with: .video)
videoConnection?.videoOrientation = .portrait
videoConnection?.isVideoMirrored = cameraPosition == .front
} else {
set(error: .cannotAddOutput)
status = .failed
return
}

if session.canAddOutput(audioOutput) {
session.addOutput(audioOutput)
}

if session.canAddOutput(photoOutput) {
session.addOutput(photoOutput)

let outputConnection = photoOutput.connection(with: .video)
if cameraPosition == .front {
outputConnection?.automaticallyAdjustsVideoMirroring = false
outputConnection?.isVideoMirrored = true
} else {
outputConnection?.automaticallyAdjustsVideoMirroring = false
outputConnection?.isVideoMirrored = false
}
}

status = .configured
}
< /code>
extension VideoFrameService: AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAudioDataOutputSampleBufferDelegate {
func captureOutput(
_ output: AVCaptureOutput,
didOutput sampleBuffer: CMSampleBuffer,
from connection: AVCaptureConnection
) {
DispatchQueue.main.async {
self.delegate?.update(output: output, sampleBuffer: sampleBuffer)
}
}
}
< /code>
Изображение

What couldbe the root cause for this, and how to solve this?

Подробнее здесь: https://stackoverflow.com/questions/797 ... howing-liv
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»