fix: Synchronize Audio Frames with Video Frames using masterClock
(#161)
* Synchronize Audio Frames with Video Frames using `masterClock` * Update CameraView+RecordVideo.swift
This commit is contained in:
parent
aaad8fc94a
commit
ca0c0e92e0
@ -152,9 +152,12 @@ extension CameraView: AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAud
|
|||||||
}
|
}
|
||||||
switch captureOutput {
|
switch captureOutput {
|
||||||
case is AVCaptureVideoDataOutput:
|
case is AVCaptureVideoDataOutput:
|
||||||
recordingSession.appendBuffer(sampleBuffer, type: .video)
|
recordingSession.appendBuffer(sampleBuffer, type: .video, timestamp: CMSampleBufferGetPresentationTimeStamp(sampleBuffer))
|
||||||
case is AVCaptureAudioDataOutput:
|
case is AVCaptureAudioDataOutput:
|
||||||
recordingSession.appendBuffer(sampleBuffer, type: .audio)
|
let timestamp = CMSyncConvertTime(CMSampleBufferGetPresentationTimeStamp(sampleBuffer),
|
||||||
|
from: audioCaptureSession.masterClock!,
|
||||||
|
to: captureSession.masterClock!)
|
||||||
|
recordingSession.appendBuffer(sampleBuffer, type: .audio, timestamp: timestamp)
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ class RecordingSession {
|
|||||||
ReactLogger.log(level: .info, message: "Started RecordingSession at \(initialTimestamp!.seconds) seconds.")
|
ReactLogger.log(level: .info, message: "Started RecordingSession at \(initialTimestamp!.seconds) seconds.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendBuffer(_ buffer: CMSampleBuffer, type bufferType: BufferType) {
|
func appendBuffer(_ buffer: CMSampleBuffer, type bufferType: BufferType, timestamp: CMTime) {
|
||||||
if !CMSampleBufferDataIsReady(buffer) {
|
if !CMSampleBufferDataIsReady(buffer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -117,7 +117,6 @@ class RecordingSession {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let timestamp = CMSampleBufferGetPresentationTimeStamp(buffer)
|
|
||||||
latestTimestamp = timestamp
|
latestTimestamp = timestamp
|
||||||
|
|
||||||
switch bufferType {
|
switch bufferType {
|
||||||
|
Loading…
Reference in New Issue
Block a user