CoreMedia/Video Toolbox API使用了很多指針,這些指針在Swift中令我困惑!CMVideoFormatDescriptionCreateFromH264ParameterSets in 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)
你有沒有想過這個? @ZENUAV –
嘿@ZENUAV,我試圖將H.264流形式的DJI轉換爲MP4文件。我注意到你也遇到類似的問題(在DJI論壇上看到)。你能轉換它嗎?你能分享一個有效的代碼嗎? –