ios - EXC_BAD_ACCESS 发生在 H264 编码 CMSampleBuffer 上
问题描述
试图将 a 转换CMSampleBuffer
为H264
编码数据
aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
- (void) encode:(CMSampleBufferRef )sampleBuffer
{
dispatch_sync(aQueue, ^{
self->frameCount++;
CVImageBufferRef imageBuffer = (CVImageBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
CMTime presentationTimeStamp = CMTimeMake(self->frameCount, 1);
VTEncodeInfoFlags flags;
OSStatus statusCode = VTCompressionSessionEncodeFrame(self->EncodingSession,
imageBuffer,
presentationTimeStamp,
kCMTimeInvalid,
NULL, NULL, &flags);
if (statusCode != noErr) {
self->error = @"H264: VTCompressionSessionEncodeFrame failed ";
VTCompressionSessionInvalidate(self->EncodingSession);
self->EncodingSession = NULL;
self->error = NULL;
return;
}
});
}
上述方法被连续调用。好像扔了EXC_BAD_ACCESS
。
我尝试使用NSZombie
对象,但仍然无法弄清楚是什么原因造成的。
我尝试创建一个副本CMSampleBufferRef
并传递它以确保它不会被释放。还是EXC_BAD_ACCESS
被扔了。
谁能帮我弄清楚发生了什么?
PS -CMSampleBuffer
创建自CVPixelBuffer
var sampleBfr:CMSampleBuffer?
let scale = CMTimeScale(USEC_PER_SEC)
let pts = CMTime(value: CMTimeValue(NSDate().timeIntervalSince1970 * Double(scale)), timescale: scale)
var timingInfo = CMSampleTimingInfo(duration: CMTime.invalid,
presentationTimeStamp: pts,
decodeTimeStamp: CMTime.invalid)
var videoDesc:CMVideoFormatDescription? = nil
let _:OSStatus = CMVideoFormatDescriptionCreateForImageBuffer(allocator: kCFAllocatorDefault, imageBuffer: pxBuffer!, formatDescriptionOut: &videoDesc)
let _:OSStatus = CMSampleBufferCreateReadyWithImageBuffer(allocator: kCFAllocatorDefault, imageBuffer: pxBuffer!, formatDescription: videoDesc!, sampleTiming: &timingInfo, sampleBufferOut: &sampleBfr)
解决方案
推荐阅读
- ios - 线程 1:EXC_BAD_ACCESS (code=2, address=..) 使用 Macaw Pod iOS Swift?
- sql-server - Sql Server 奇怪的 CASE 语句
- javascript - ApolloError.js:43 Uncaught (in promise) 错误:网络错误:无法读取未定义的属性“突变”
- sql-server - 谁在 SQL Server 2016 上部署了 SSIS 包?
- directory - OCaml 的“mkdir -p”是什么?
- javascript - 如何在 javascript 中更新 firebase-messaging-sw.js
- python - 在 GPU 上运行 Keras(Tensorflow 后端)时出现 OOM 错误。相同的脚本在 CPU 上运行完成
- python - 有没有办法将 .obj 文件加载到 Pandas 或 Numpy 中?
- php - Laravel Passport 通过网络问题使用自己的 API
- reactjs - 有条件地渲染 DataSearch 组件