1

These simple lines of code (nothing else whatsoever in the app) work fine on iOS 9 (iPhone 6 and iPhone 4S), but not on iOS 8 (iPhone 5 and iPod Touch 5G):

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!");
}

I have also tried with lower resolutions, tried providing some or all of the optional parameters, in all cases it works on iOS 9 and fails on iOS 8 with the error -12902 (kVTParameterErr). Nice to know that some parameter is wrong, but which one and why isn't it considered wrong on iOS 9?

Note that VTCopyVideoEncoderList does give me a list where the avc1 (H264) encoder is present in all cases also.

Any idea what's going on?

Guy Moreillon
  • 993
  • 10
  • 28

1 Answers1

1

The answer is a bit late but I guess it could be useful for others. For iOS 8 you should specify VTCompressionOutputCallback outputCallback while creating a compression session. From the documentation:

@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.

In turn, VTCompressionSessionEncodeFrameWithOutputHandler is only availabel starting from iOS 9:

__OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0)

Dmytro Hutsuliak
  • 1,741
  • 4
  • 21
  • 37
  • Good point, thanks for mentioning it. I ended up opening a support request at Apple, who answered that my bit of code indeed does not work on iOS 8 and there is no work-around. They did not mention the use of the VTCompressionOutputCallback. – Guy Moreillon Mar 20 '17 at 09:15
  • It's strange because there is the obvious documented workaround. I use `VTCompressionSessionCreate` with a C-based `VTCompressionOutputCallback` callback on `iOS 8` and it works great. – Dmytro Hutsuliak Mar 20 '17 at 09:51