无人机实时流怎么开_无人机H264视频流解码

- (CVPixelBufferRef) decode:(uint8_t *)frameBuf frameLen:(int)frameLen {

//NSLog(@"frameLen:%d",frameLen);

CVPixelBufferRef outputPixelBuffer =  NULL;

CMBlockBufferRef blockBuffer = NULL;

//创建CMBlockBuffer

OSStatus status  = CMBlockBufferCreateWithMemoryBlock(kCFAllocatorDefault,(void*)frameBuf,frameLen,kCFAllocatorNull,NULL,0,frameLen,0,&blockBuffer);

if(status == kCMBlockBufferNoErr) {

CMSampleBufferRef sampleBuffer = NULL;

const size_t sampleSizeArray[] = {frameLen};

//创建CMSampleBuffer

status = CMSampleBufferCreateReady(kCFAllocatorDefault,blockBuffer,_decoderFormatDescription ,1, 0, NULL, 1, sampleSizeArray,&sampleBuffer);

if (status == kCMBlockBufferNoErr && sampleBuffer) {

VTDecodeFrameFlags flags = 0;

VTDecodeInfoFlags flagOut = 0;

if (_deocderSession == NULL || sampleBuffer == NULL) {

//printf("null pointer %p %p", _deocderSession, sampleBuffer);

return NULL;

}

//开始解码,解码后存放在outputPixelBuffer

OSStatus decodeStatus = VTDecompressionSessionDecodeFrame(_deocderSession,sampleBuffer,flags,&outputPixelBuffer,&flagOut);

if(decodeStatus == kVTInvalidSessionErr) {

[self initH264DecoderAndisValid:NO];

//NSLog(@"IOS8VT: Invalid session, reset decoder session");

} else if(decodeStatus == kVTVideoDecoderBadDataErr) {

//NSLog(@"IOS8VT: decode failed status=%d(Bad data)", (int)decodeStatus);

} else if(decodeStatus != noErr) {

[self clearH264Deocder];

[self initH264DecoderAndisValid:NO];

//NSLog(@"IOS8VT: decode failed status=%d", (int)decodeStatus);

return nil;

}

CFRelease(sampleBuffer);

sampleBuffer = NULL;

}

CFRelease(blockBuffer);

blockBuffer = NULL;

}

return outputPixelBuffer;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值