Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone AVCaptureAudioDataOutput到ExtAudioFile_Iphone_Ios_Objective C - Fatal编程技术网

Iphone AVCaptureAudioDataOutput到ExtAudioFile

Iphone AVCaptureAudioDataOutput到ExtAudioFile,iphone,ios,objective-c,Iphone,Ios,Objective C,我想用AVCaptureSession录制一部电影,还想处理音频部分。(转换为AAC并保存)。我读书,但我没能使它为我的目的工作,我认为我不需要音频单元。这是我的密码: - (void) encodeSample:(CMSampleBufferRef) sample; { int nFrame = CMSampleBufferGetNumSamples(sample); currentSampleTime += (double) nFrame; AudioTimeStam

我想用AVCaptureSession录制一部电影,还想处理音频部分。(转换为AAC并保存)。我读书,但我没能使它为我的目的工作,我认为我不需要音频单元。这是我的密码:

- (void) encodeSample:(CMSampleBufferRef) sample;
{
    int nFrame = CMSampleBufferGetNumSamples(sample);
    currentSampleTime += (double) nFrame;
    AudioTimeStamp ts;
    memset(&ts, 0, sizeof(AudioTimeStamp));
    ts.mSampleTime = currentSampleTime;
    ts.mFlags |= kAudioTimeStampSampleTimeValid;

    AudioBufferList lBuffer;
    lBuffer.mNumberBuffers = 1;
    lBuffer.mBuffers[0].mNumberChannels = 2;
    lBuffer.mBuffers[0].mData = malloc(nFrame * sizeof(SInt16) * 2);
    lBuffer.mBuffers[0].mDataByteSize = nFrame * sizeof(SInt16) * 2;

    size_t bufferListSizeNeededOut;
    CMBlockBufferRef blockBufferOut = nil;
    OSStatus err = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sample,
                                                                  &bufferListSizeNeededOut,
                                                                  &lBuffer,
                                                                  sizeof(lBuffer),
                                                                  kCFAllocatorSystemDefault,
                                                                  kCFAllocatorSystemDefault,
                                                                  kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment,
                                                                  &blockBufferOut);

    NSLog(@"lbuff : %ld",err);
    @synchronized(self){
        if(adtsFile)
        {
            err = ExtAudioFileWriteAsync(adtsFile, nFrame, &lBuffer);
            NSLog(@"async : %ld",err);
        }
    }
}
但是,我在3次通话后获得了EXC\u BAD\u访问权限:

2013-09-04 15:01:35.669 Recoder[13683:1803] lbuff : 0
2013-09-04 15:01:35.673 Recoder[13683:1803] async : 0
2013-09-04 15:01:37.194 Recoder[13683:5b03] lbuff : 0
2013-09-04 15:01:37.197 Recoder[13683:5b03] async : 0
2013-09-04 15:01:37.201 Recoder[13683:5b03] lbuff : 0
// bad access here

我也可以分享我用来初始化ExtAudio文件的代码,但我相信它工作得很好(我在我制作的另一个应用程序中使用过)

尽管我不能回答你的问题,但我找到了一个很好的资源(将iPod音乐转换为原始PCM数据),希望它能让你更接近你的答案。