1

I have a function that takes a CVImageBufferRef and passes it to my VTCompressionSession for processing.

The VTCompressionSession is started and my call to VTCompressionSessionCreate is successful.

I am retrieving a video URL from the photo library and processing it using the following:

- (void)processImageBuffersFromURL:(NSURL *)url withBlock:(void (^)(CVImageBufferRef bufferRef))block {
    AVAsset *asset = [AVAsset assetWithURL:url];
    AVAssetTrack *track = [[asset
                            tracksWithMediaType:AVMediaTypeVideo]
                           objectAtIndex:0];

    AVAssetReaderTrackOutput
    *readerTrack = [AVAssetReaderTrackOutput
                    assetReaderTrackOutputWithTrack:track
                    outputSettings:@{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange)}];
    AVAssetReader *reader = [AVAssetReader assetReaderWithAsset:asset
                                                          error:nil];
    [reader addOutput:readerTrack];
    [reader startReading];

    CMSampleBufferRef sample = NULL;

    while ((sample = [readerTrack copyNextSampleBuffer])) {
        CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sample);
        block(imageBuffer);
    }
}

The block basically just calls

    SInt32 status = VTCompressionSessionEncodeFrame(_compressionSession, imageBuffer, CMTimeMake(self.currentFrameNumber++, 30), kCMTimeInvalid, NULL, (__bridge void *)self, NULL);

and the status is -12902. I looked on this site for information about the status, and I can't find any other relevant information. The site says that the error is kVTParameterErr.

My VTCompressionOutputCallback is not being called.

Can anyone explain this error code to me?

JasonMArcher
  • 12,386
  • 20
  • 54
  • 51
JuJoDi
  • 13,081
  • 22
  • 75
  • 121

1 Answers1

0

It turns out my _compressionSession was NULL, hence the kVTParameterErr.

Breaking on VTCompressionSessionEncodeFrame will help to figure out which parameter is incorrect, and the docs tell you what parameters can be NULL (pretty much everything but the session and image buffer).

For my particular case, I was accidentally using VTCompressionSessionCreate in a class method instead of an instance method, so the instance I was sending the imageBuffer did not have its own compression session.

JuJoDi
  • 13,081
  • 22
  • 75
  • 121