1

在 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 的相关问题

4

0 回答 0