VideoToolbox不会在Swift 3.0中为mpeg4创建编码器会话

时间:2016-10-11 21:53:25

标签: ios swift swift3 video-encoding video-toolbox

我在使用Swift 3.0迁移后使用VideoToolbox为MPEG4编码器创建压缩会话时遇到了问题。在迁移之前它运行良好。

以下是我升级的代码:

    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)

每次收到状态错误-12908(kVTCouldNotFindVideoEncoderErr)。有趣的是,相同的配置,但

 let encoderType = kCMVideoCodecType_H264

工作正常。

有人知道这里发生了什么吗?

关于将编码器配置的代码更新到Swift 3.0

,这是my related question

0 个答案:

没有答案