VideoToolbox does not create an encoder session for mpeg4 in Swift 3.0

喜夏-厌秋 提交于 2019-12-08 03:22:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!