有没有办法从NSData创建CMSampleBufferRef?NSData对象以前也是从CMSampleBufferRef构建的。我需要转换,因为我想保存CMSampleBufferRef帧(作为NSData),这些帧是使用AVFoundation从现场摄像机拍摄的,然后能够使用CMSampleBufferRef帧(通过将NSData对象转换为CMSampleBufferRef)来构建视频。
先谢谢你...
发布于 2021-06-11 16:52:49
-(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;
}
https://stackoverflow.com/questions/19592820
复制相似问题