3

CoreMedia/Video Toolbox API は、Swift で私を混乱させる多くのポインターを使用します!

SPS、PPS データは h264 ストリームから取得されたもので、そのための VFD を作成しようとしています。

以下を試してみましたが、うまくいくと思っていましたが、-12710 エラー (kCMFormatDescriptionError_InvalidParameter = -12710) が発生しました。

これが私の遊び場です..私は何を間違っていますか??

// uses CoreMedia Framework
import CoreMedia

// sps and pps variables
var spsData: [UInt8] = []
var ppsData: [UInt8] = []

// CMVideoFormatDescriptionCreateFromH264ParameterSets parameters
let parameterSetCount: Int = 2
var parameterSetPointers: UnsafePointer<UnsafePointer<UInt8>> = nil
var parameterSetSizes: UnsafePointer<Int> = nil
let NALUnitHeaderLength: Int32 = 4
var formatDescriptionOut: UnsafeMutablePointer<Unmanaged<CMFormatDescription>?> = nil

// set raw sps and pps data
let rawSPS: [UInt8] = [0x00,0x00,0x00,0x01,0x67,0x64,0x00,0x32,0xAC,0xB4,0x02,0x80,0x2D,0xD2,0xA4,0x00,0x00,0x0F,0xA4,0x00,0x03,0xA9,0x85,0x81,0x00,0x00,0x63,0x2E,0x80,0x01,0x65,0x0E,0xF7,0xBE,0x17,0x84,0x42,0x35]
let rawPPS: [UInt8] = [0x00,0x00,0x00,0x01,0x68,0xEE,0x3C,0xB0]

// extract sps data
spsData = Array(rawSPS[Int(NALUnitHeaderLength)..<rawSPS.count])

// extract pps data
ppsData = Array(rawPPS[Int(NALUnitHeaderLength)..<rawPPS.count])

let dataParamArray = [UnsafePointer<UInt8>(spsData), UnsafePointer<UInt8>(ppsData)]
parameterSetPointers = UnsafePointer(dataParamArray)

let sizeParamArray = [UnsafePointer<Int>(bitPattern: spsData.count), UnsafePointer<Int>(bitPattern: ppsData.count)]
parameterSetSizes = UnsafePointer(sizeParamArray)

// create video format description
let result: OSStatus = CMVideoFormatDescriptionCreateFromH264ParameterSets(kCFAllocatorDefault, parameterSetCount, parameterSetPointers, parameterSetSizes, NALUnitHeaderLength, formatDescriptionOut)
4

2 に答える 2

0

確かにそうでした。これがコードです。

                        // get pointer to sps and pops data
                        let pointerSPS = UnsafePointer<UInt8>(spsData)
                        let pointerPPS = UnsafePointer<UInt8>(ppsData)

                        // make pointers array
                        let dataParamArray = [pointerSPS, pointerPPS]

                        // set parameter set pointers
                        _parameterSetPointers = UnsafePointer<UnsafePointer<UInt8>>(dataParamArray)

                        // make parameter sizes array
                        let sizeParamArray = [spsData.count, ppsData.count]

                        // set parameter set sizes
                        _parameterSetSizes = UnsafePointer<Int>(sizeParamArray)

                        // create video format description
                        let result: OSStatus = CMVideoFormatDescriptionCreateFromH264ParameterSets(
                            kCFAllocatorDefault,
                            _parameterSetCount,
                            _parameterSetPointers,
                            _parameterSetSizes,
                            _NALUnitHeaderLength,
                            &_formatDescriptionOut)
于 2015-10-07T08:26:47.073 に答える