CMSampleBufferSetDataBufferFromAudioBufferList返回错误12731 [英] CMSampleBufferSetDataBufferFromAudioBufferList returning error 12731

查看:1069
本文介绍了CMSampleBufferSetDataBufferFromAudioBufferList返回错误12731的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试捕获app声音并将其作为输入传递给AVAssetWriter。

我正在为音频单元设置回调来获取AudioBufferList。

问题始于将AudioBufferList转换为CMSampleBufferRef。

总是返回错误-12731,表示缺少必需参数



谢谢
Karol

I am trying to capture app sound and pass it to AVAssetWriter as input.
I am setting callback for audio unit to get AudioBufferList.
The problem starts with converting AudioBufferList to CMSampleBufferRef.
It always return error -12731 which indicates that required parameter is missing

Thanks
Karol

-(OSStatus) recordingCallbackWithRef:(void*)inRefCon
                            flags:(AudioUnitRenderActionFlags*)flags
                        timeStamp:(const AudioTimeStamp*)timeStamp
                        busNumber:(UInt32)busNumber
                     framesNumber:(UInt32)numberOfFrames
                             data:(AudioBufferList*)data
{

AudioBufferList bufferList;
bufferList.mNumberBuffers = 1;
bufferList.mBuffers[0].mData = NULL;

OSStatus status;

status = AudioUnitRender(audioUnit,
                         flags,
                         timeStamp,
                         busNumber,
                         numberOfFrames,
                         &bufferList);
[self checkOSStatus:status];

AudioStreamBasicDescription audioFormat;
// Describe format
audioFormat.mSampleRate         = 44100.00;
audioFormat.mFormatID           = kAudioFormatLinearPCM;
audioFormat.mFormatFlags        = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
audioFormat.mFramesPerPacket    = 1;
audioFormat.mChannelsPerFrame   = 1;
audioFormat.mBitsPerChannel     = 16;
audioFormat.mBytesPerPacket     = 2;
audioFormat.mBytesPerFrame      = 2;

CMSampleBufferRef buff = NULL;
CMFormatDescriptionRef format = NULL;
CMSampleTimingInfo timing = { CMTimeMake(1, 44100), kCMTimeZero, kCMTimeInvalid };

status = CMAudioFormatDescriptionCreate(kCFAllocatorDefault, &audioFormat, 0, NULL, 0, NULL, NULL, &format);
[self checkOSStatus:status];

status = CMSampleBufferCreate(kCFAllocatorDefault,NULL,false,NULL,NULL,format,1, 1, &timing, 0, NULL, &buff);
[self checkOSStatus:status];

status = CMSampleBufferSetDataBufferFromAudioBufferList(buff, 
                                                        kCFAllocatorDefault, 
                                                        kCFAllocatorDefault, 
                                                        0, 
                                                        &bufferList);

[self checkOSStatus:status]; //Status here is 12731

//Do something with the buffer

return noErr;
}



编辑:

我检查了bufferList.mBuffers [0] .mData,它不是null,所以可能不是问题。



I checked bufferList.mBuffers[0].mData and it is not null so probably that's not a problem.

推荐答案

因为有一个类似的问题没有在互联网上回答。

我设法解决了它并且录音完全有效。

我的问题是错误的参数传递给 CMSampleBufferCreate

numSamples而不是1应该等于numberOfFrames。



所以最后的调用是:

Since there is a similar question without answer all over the internet.
I managed to solve it and the recording fully works.
My problem was wrong parameter passed to CMSampleBufferCreate.
numSamples instead of 1 should be equal to numberOfFrames.

So the final call is:

CMSampleBufferCreate(kCFAllocatorDefault,NULL,false,NULL,NULL,format,
                    (CMItemCount)numberOfFrames, 1, &timing, 0, NULL, &buff);

这篇关于CMSampleBufferSetDataBufferFromAudioBufferList返回错误12731的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆