Reputation: 167
I am trying to mute and unmute the audio for AVCaptureSession. Once I start the sessions I can enable and disable the audio connection, but once I play back the video all of the audio portions are pushed back to back at the front of the video leaving only the end of the video with no sound. This seems to be a time stamp issue but I don't know how it could be. Just in case I have tried to adjust the PTS of the audio sample buffer to match the previous video buffer.
For pausing
if (self.muted) {
[self.session beginConfiguration];
self.audioConnection.enabled = NO;
[self.session commitConfiguration];
} else {
[self.session beginConfiguration];
self.audioConnection.enabled = YES;
[self.session commitConfiguration];
}
For adjusting the time stamp I grab last timestamp
if ( connection == self.videoConnection ) {
// Get timestamp
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp( sampleBuffer );
testPreviousTimeStamp = timestamp;
Then I adjust the timestamp on the sample buffer
CMSampleBufferSetOutputPresentationTimeStamp (sampleBuffer,testPreviousTimeStamp);
if (![self.assetWriterAudioIn appendSampleBuffer:sampleBuffer]) {
[self showError:[self.assetWriter error]];
NSLog(@"Problem writing audio sample buffer");
}
Any ideas what the problem could be and how to fix it?
Upvotes: 2
Views: 1509
Reputation: 167
Rather than adjusting the time stamp which I had no luck with. I just wrote zero to the data buffer. It works and this way I don't need to disable/enable any connections.
// Write audio data to file
if (readyToRecordAudio && readyToRecordVideo) {
if (self.muted) {
CMBlockBufferRef buffRef = CMSampleBufferGetDataBuffer(sampleBuffer);
char fillByte = 0;
CMBlockBufferFillDataBytes(fillByte,buffRef,0,CMBlockBufferGetDataLength(buffRef));
}
[self writeSampleBuffer:sampleBuffer ofType:AVMediaTypeAudio];
}
Upvotes: 3