我正在尝试将AVCaptureSession的音频静音和取消静音。一旦我开始会话,我可以启用和禁用音频连接,但一旦我播放视频,所有音频部分都被推到视频前面的后面,只留下视频的结尾没有声音。这似乎是一个时间戳问题,但我不知道怎么会这样。以防我试图调整音频样本缓冲区的PTS以匹配先前的视频缓冲区。
用于暂停
if (self.muted) {
[self.session beginConfiguration];
self.audioConnection.enabled = NO;
[self.session commitConfiguration];
} else {
[self.session beginConfiguration];
self.audioConnection.enabled = YES;
[self.session commitConfiguration];
}为了调整我上次获取的时间戳
if ( connection == self.videoConnection ) {
// Get timestamp
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp( sampleBuffer );
testPreviousTimeStamp = timestamp;然后我调整采样缓冲区上的时间戳
CMSampleBufferSetOutputPresentationTimeStamp (sampleBuffer,testPreviousTimeStamp);
if (![self.assetWriterAudioIn appendSampleBuffer:sampleBuffer]) {
[self showError:[self.assetWriter error]];
NSLog(@"Problem writing audio sample buffer");
}你知道问题可能是什么以及如何解决它吗?
发布于 2014-07-04 04:04:13
而不是调整我没有运气的时间戳。我刚在数据缓冲区里写了零。它可以工作,这样我就不需要禁用/启用任何连接。
// 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];
}https://stackoverflow.com/questions/24459178
复制相似问题