我添加了带有AVCaptureSession
. 我需要通过 delegateMethod 的音频。每次我得到它时,这种方法都会在服务器上写入音频。但是 AUDIO FORMAT 是不对的。PCM 中需要服务器。那么如何获取 PCM 格式的音频数据呢?这是在服务器上写入数据的方法:
(void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
AudioBufferList audioBufferList;
NSMutableData *data=[[NSMutableData alloc] init];
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
for( int y=0; y<audioBufferList.mNumberBuffers; y++ )
{
AudioBuffer audioBuffer = audioBufferList.mBuffers[y];
Byte *frame = (Byte*)audioBuffer.mData;
[data appendBytes:frame length:audioBuffer.mDataByteSize];
}
CFRelease(blockBuffer);
blockBuffer=NULL;
[outputStream write:[data bytes]maxLength:[data length]];
}
是否有任何理由在此阶段代码中添加音频设置,以便我可以根据我的要求获取数据。