ARVideoKit
ARVideoKit copied to clipboard
[AVAssetWriterInput appendSampleBuffer:] Cannot append sample buffer: Must start a session (using -[AVAssetWriter startSessionAtSourceTime:) first
Xcode 11.2.1
Swift 5
ARVideoKit (~> 1.5.51)
iPhone 7+
ARSCNView
I have the vc setup the same exact way that you have it in your sample project except I grab the url once it's time to save:
recorder?.stop({ [weak self](url) in
DispatchQueue.main.async { [weak self] in
self?.alertToSaveOrDelete(videoUrl: url)
}
})
Also in viewDidLoad I have this because I display a SKVideoNode
and I need it for sound:
do {
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .videoRecording, options: [.defaultToSpeaker])
//try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) // I tried this too
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}
When I first start recording the recorder works fine. The problem occurs when I go the background and come back then start recording again. Once I press the stop/save button I get a crash:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetWriterInput appendSampleBuffer:] Cannot append sample buffer: Must start a session (using -[AVAssetWriter startSessionAtSourceTime:) first' *** First throw call stack:
In viewWillAppear
I run recorder?.prepare(configuration)
In viewWillDisappear
if running I stop it and regardless I call recorder?.rest()
.
I tried grabbing the url in the delegate method:
recorder?.stop()
func recorder(didEndRecording path: URL, with noError: Bool) {
if noError {
// with and without the mainqueue it crashes here
DispatchQueue.main.async { [weak self] in
self?.alertToSaveOrDelete(videoUrl: path)
}
}
}
But the same problem occurs even when I first try to record before going to the background.
The crash always occurs when I go to the background and back then record and save but it also occasionally happens when I successfully record/save the first time but the second or third time is the same exact crash.
UPDATE:
Looking at the StackTrace the problem seems to stem from thread 83 __pthread_kill
:
let audioBufferQueue = DispatchQueue(label: "com.ahmedbekhit.AudioBufferQueue")
UPDATE:
I posted the question on Stack Overflow. Somebody tried to help me but their answer didn't work. There is something else causing the issue:
https://stackoverflow.com/q/60146678/4833705
UPDATE
Without having to go to the background it crashes randomly and more often then not when saving using:
recorder?.stop({ [weak self](url) in ...
Same crash result when using:
func recorder(didEndRecording path: URL, with noError: Bool) {
helpοΌsame problem
iPhone 7 plus 13.3οΌ 13.3.1 Will appear
@DPRuin it appears that the AudioSession queue is beginning before the start session method is executed. Looking into it.
audioSettings = audioDataOutput.recommendedAudioSettingsForAssetWriter(writingTo: .m4a) as? [String : Any]----fix audio .m4v to .m4a, success fix iphone 7 plus 13.3.1 13.3 problem
update : But iphone 7 plus 13.2.3 some time crash
@DPRuin it appears that the AudioSession queue is beginning before the start session method is executed. Looking into it.
What should I do
Was a resolution for this ever found @AFathi ?
same problem
Any solutions for this? Getting the same problem.
Same problem
What if we check assetWriter status while we append to buffer in captureOutput ? @AFathi
I think it's fixed here. https://github.com/AFathi/ARVideoKit/pull/122
Let me know if it helps someone.