若使用 UIKit,建议使用 VideoToolbox 框架,并对视频帧进行并发编解码处理。代码示例如下:
// 初始化VTCompressionSessionRef VTCompressionSessionRef compressionSession = NULL; CMFormatDescriptionRef formatDescriptionRef = NULL; VTCompressionSessionCreate(NULL, self.videoSize.width, self.videoSize.height, kCMVideoCodecType_H264, NULL, NULL, NULL, VideoCompressionOutputCallback, (__bridge void *)self, &compressionSession);
// 设置压缩参数 VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_MaxKeyFrameInterval, (__bridge CFTypeRef)(@(self.maxKeyFrameInterval))); VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_ExpectedFrameRate, (__bridge CFTypeRef)(@(self.expectedFps))); VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_AverageBitRate, (__bridge CFTypeRef)(@(self.averageBitRate))); VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_ProfileLevel, (__bridge CFTypeRef)(self.profileLevel)); VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_AllowFrameReordering, kCFBooleanFalse);
// 编码起始时间设置 CMSampleTimingInfo timingInfo = kCMTimingInfoInvalid; timingInfo.duration = kCMTimeInvalid; timingInfo.decodeTimeStamp = kCMTimeInvalid; timingInfo.presentationTimeStamp = CMTimeMakeWithSeconds(CACurrentMediaTime(), 1000000);
// 开始编码 VTCompressionSessionEncodeFrame(compressionSession, imageBuffer, timingInfo, &formatDescriptionRef, NULL, NULL);
上一篇:AppStore拒绝-“Policy3.1.1”外部机制,需要建议
下一篇:Appstore连接错误:在Info.plist文件中缺少目的字符串(NSBluetoothPeripheralUsageDescription)。