I`ve catch a problem to create a compression session for the MPEG4 encoder with VideoToolbox after migration on Swift 3.0. Before the migration it worked fine.
Here is my upgraded code:
let imageAttributes:[NSString: AnyObject] = [
kCVPixelBufferPixelFormatTypeKey: Int(colorScheme) as AnyObject,
kCVPixelBufferIOSurfacePropertiesKey: [:] as AnyObject,
kCVPixelBufferOpenGLESCompatibilityKey: true as AnyObject,
kCVPixelBufferWidthKey: outputWidth as AnyObject,
kCVPixelBufferHeightKey: outputHeight as AnyObject,
]
let imgeAttributesDictionary: CFDictionary = imageAttributes as CFDictionary
let encoderType = kCMVideoCodecType_MPEG4Video
var status = VTCompressionSessionCreate(kCFAllocatorDefault, Int32(outputWidth), Int32(outputHeight), encoderType, nil, imgeAttributesDictionary, nil, { (outputCallbackRefCon: UnsafeMutableRawPointer?, sourceFrameRefCon: UnsafeMutableRawPointer?, status: OSStatus, infoFlags: VTEncodeInfoFlags, sampleBuffer: CMSampleBuffer?) -> Void in
VideoEncoder.compressionCallback(outputCallbackRefCon: outputCallbackRefCon, sourceFrameRefCon: sourceFrameRefCon, status: status, infoFlags: infoFlags, sampleBuffer: sampleBuffer)
}, nil, &session)
And every time I receive status error -12908 (kVTCouldNotFindVideoEncoderErr). The interesting point is that the same configuration but with
let encoderType = kCMVideoCodecType_H264
is working perfect.
Does anybody know what happening here?
This is my related question about updating code for the encoder configuration upto Swift 3.0
来源:https://stackoverflow.com/questions/39987373/videotoolbox-does-not-create-an-encoder-session-for-mpeg4-in-swift-3-0