我正在尝试将 AVCaptureSession 的音频静音和取消静音。一旦我开始 session ,我可以启用和禁用音频连接,但是一旦我播放视频,所有音频部分都被推回到视频的前面,只剩下视频的末尾没有声音。这似乎是一个时间戳问题,但我不知道这是怎么回事。以防万一我尝试调整音频样本缓冲区的 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");
}
您知道问题可能是什么以及如何解决吗?
最佳答案
而不是调整我没有运气的时间戳。我刚刚向数据缓冲区写入了零。它有效,这样我不需要禁用/启用任何连接。
// 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];
}
关于ios - 静音音频 AVCaptureSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24459178/