ios - 将 NSData 转换为 CMSampleBufferRef

标签 ios avfoundation nsdata cmsamplebufferref

有没有办法从 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/

相关文章:

ios - 线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x48)avaudiofoundation

iphone - AVCaptureMovieFileOutput开始录制到输出文件URL : recordingDelegate: is not calling delegate

swift - 将图像的 NSData 转换为字符串

ios - 当手指触摸/拖动时更改 UIButton 大小

我无法弄清楚的iOS7状态栏问题

ios - TableView索引从rootcontroller到detailcontroller(UINavigationController)

ios - 在 NSOperation 中取消 NSData initWithContentsOfURL

ios - 如何使用其标签字段使 UITextField 成为第一响应者

ios - setFlashMode 导致 Apple 审阅者崩溃

iphone - NSDictionary 上是否有一个开源类别可以快速将其从 NSData 转换为/转换为 NSData?