【问题标题】:Mute Audio AVCaptureSession静音音频 AVCaptureSession
【发布时间】:2014-07-04 04:11:58
【问题描述】:

我正在尝试将 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");
}

有什么想法可能是什么问题以及如何解决?

【问题讨论】:

    标签: ios audio avfoundation


    【解决方案1】:

    而不是调整我没有运气的时间戳。我只是将零写入数据缓冲区。它可以工作,这样我就不需要禁用/启用任何连接。

            // 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];
            }
    

    【讨论】:

    • 你能在 AVAudioSession 上做这样的事情吗?
    猜你喜欢
    • 1970-01-01
    • 2012-05-08
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-19
    • 2014-03-19
    相关资源
    最近更新 更多