背景:在iOS11以及以上的系统中通过VTDecompressionSessionDecodeFrame进行硬解H264视频的时候会很大概率的卡住,导致无法解码。
解决:经过调试发现,在创建VTDecompressionSession的时候设置destinationImageBufferAttributes时,不能将颜色格式设置为kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,而是应该设置为kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange。
NSDictionary *destinationImageBufferAttributes =[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO],(id)kCVPixelBufferMetalCompatibilityKey,[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange],(id)kCVPixelBufferPixelFormatTypeKey,nil];