gpt4 book ai didi

ios - 将 NSData 转换为 CMSampleBufferRef

转载 作者:行者123 更新时间:2023-12-03 21:40:22 25 4
gpt4 key购买 nike

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

提前致谢...

最佳答案

-(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;
}

关于ios - 将 NSData 转换为 CMSampleBufferRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19592820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com