4

有什么方法可以从 NSData 创建 CMSampleBufferRef 吗?NSData 对象以前也是从 CMSampleBufferRef 构造的。我需要这种转换,因为我想保存使用 AVFoundation 从实时摄像机拍摄的 CMSampleBufferRef 帧(作为 NSData),然后能够使用 CMSampleBufferRef 帧(通过将 NSData 对象转换为 CMSampleBufferRef)来构建视频。

提前致谢...

4

1 回答 1

0

-(AudioBufferList *) getBufferListFromData: (NSData *) data
{
       if (data.length > 0)
       {
            NSUInteger len = [data length];
            //I guess you can use Byte*, void* or Float32*. I am not sure if that makes any difference.
            Byte * byteData = (Byte*) malloc (len);
            memcpy (byteData, [data bytes], len);
            if (byteData)
            {
                 AudioBufferList * theDataBuffer =(AudioBufferList*)malloc(sizeof(AudioBufferList) * 1);
                 theDataBuffer->mNumberBuffers = 1;
                 theDataBuffer->mBuffers[0].mDataByteSize = len;
                 theDataBuffer->mBuffers[0].mNumberChannels = 1;
                 theDataBuffer->mBuffers[0].mData = byteData;
                 // Read the data into an AudioBufferList
                 return theDataBuffer;
             }
        }
        return nil;
}

于 2021-06-11T08:52:48.727 回答