[英]Mute Audio AVCaptureSession
我正在嘗試使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");
}
任何想法可能是什么問題以及如何解決?
而不是調整我沒有運氣的時間戳。 我只是將零寫入數據緩沖區。 它可以工作,這樣我就不需要禁用/啟用任何連接。
// 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];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.