Camera and media editor improvements

This commit is contained in:
Ilya Laktyushin
2023-05-10 17:10:27 +04:00
parent c114f218b9
commit d15c48ff07
104 changed files with 9805 additions and 676 deletions

View File

@@ -64,9 +64,9 @@ final class CameraOutput: NSObject {
override init() {
super.init()
self.videoOutput.alwaysDiscardsLateVideoFrames = true;
self.videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_32BGRA] as [String : Any]
//[kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] as [String : Any]
self.videoOutput.alwaysDiscardsLateVideoFrames = false
//self.videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_32BGRA] as [String : Any]
self.videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] as [String : Any]
self.faceLandmarksOutput.outputFaceObservations = { [weak self] observations in
if let self {
@@ -108,6 +108,16 @@ final class CameraOutput: NSObject {
}
}
func configureVideoStabilization() {
if let videoDataOutputConnection = self.videoOutput.connection(with: .video), videoDataOutputConnection.isVideoStabilizationSupported {
if #available(iOS 13.0, *) {
videoDataOutputConnection.preferredVideoStabilizationMode = .cinematicExtended
} else {
videoDataOutputConnection.preferredVideoStabilizationMode = .cinematic
}
}
}
var isFlashActive: Signal<Bool, NoError> {
return Signal { [weak self] subscriber in
guard let self else {
@@ -215,26 +225,26 @@ extension CameraOutput: AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureA
}
}
let finalSampleBuffer: CMSampleBuffer = sampleBuffer
if let videoPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer), let formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer) {
var finalVideoPixelBuffer = videoPixelBuffer
if let filter = self.activeFilter {
if !filter.isPrepared {
filter.prepare(with: formatDescription, outputRetainedBufferCountHint: 3)
}
guard let filteredBuffer = filter.render(pixelBuffer: finalVideoPixelBuffer) else {
return
}
finalVideoPixelBuffer = filteredBuffer
}
self.processSampleBuffer?(finalVideoPixelBuffer, connection)
}
// let finalSampleBuffer: CMSampleBuffer = sampleBuffer
// if let videoPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer), let formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer) {
// var finalVideoPixelBuffer = videoPixelBuffer
// if let filter = self.activeFilter {
// if !filter.isPrepared {
// filter.prepare(with: formatDescription, outputRetainedBufferCountHint: 3)
// }
//
// guard let filteredBuffer = filter.render(pixelBuffer: finalVideoPixelBuffer) else {
// return
// }
// finalVideoPixelBuffer = filteredBuffer
// }
// self.processSampleBuffer?(finalVideoPixelBuffer, connection)
// }
if let videoRecorder = self.videoRecorder, videoRecorder.isRecording || videoRecorder.isStopping {
let mediaType = sampleBuffer.type
if mediaType == kCMMediaType_Video {
videoRecorder.appendVideo(sampleBuffer: finalSampleBuffer)
videoRecorder.appendVideo(sampleBuffer: sampleBuffer)
} else if mediaType == kCMMediaType_Audio {
videoRecorder.appendAudio(sampleBuffer: sampleBuffer)
}