VTCompressionSessionCreate适用于iOS 9,但不适用于iOS 8

VTCompressionSessionCreate适用于iOS 9,但不适用于iOS 8

问题描述:

这些简单的代码行(在应用程序中没有任何其他内容)可以在iOS 9(iPhone 6和iPhone 4S)上正常工作,但不适用于iOS 8(iPhone 5和iPod Touch 5G):VTCompressionSessionCreate适用于iOS 9,但不适用于iOS 8

VTCompressionSessionRef videoEncoder; 
OSStatus err = VTCompressionSessionCreate(NULL, 1920, 1080, 
              kCMVideoCodecType_H264, 
              NULL, 
              NULL, 
              NULL, 
              NULL, 
              (__bridge void*)self, &videoEncoder); 
if (err != noErr) { 
    NSLog(@"Error when creating compression session : %d", (int)err); 
} else { 
    NSLog(@"All systems go!"); 
} 

我也曾尝试以较低的分辨率,尝试提供部分或全部可选参数,在它适用于iOS 9和与错误-12902(kVTParameterErr)无法在iOS 8的所有情况。很高兴知道某些参数是错误的,但哪一个为什么在iOS 9上不被认为是错误的?

请注意,VTCopyVideoEncoderList给我一个列表,其中avc1(H264)编码器也存在于所有情况下。

任何想法是怎么回事?

答案有点晚,但我想它可能对其他人有用。对于iOS 8,您应在创建压缩会话时指定VTCompressionOutputCallback outputCallback。从文档:

@param outputCallback 
    The callback to be called with compressed frames. 
    This function may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeFrame. 
    Pass NULL if and only if you will be calling VTCompressionSessionEncodeFrameWithOutputHandler for encoding frames. 

反过来,VTCompressionSessionEncodeFrameWithOutputHandler只有availabel从iOS 9开始:

__OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0)

+0

好点,感谢提到这一点。我最终在苹果公司打开了一个支持请求,他回答说,我的一小部分代码在iOS 8上确实不起作用,并且没有解决方法。他们没有提到使用VTCompressionOutputCallback。 –

+0

这很奇怪,因为有明显的记录解决方法。我在'iOS 8'上使用'VTCompressionSessionCreate'和一个基于C的'VTCompressionOutputCallback'回调函数,效果很好。 –