Posts

Post not yet marked as solved
0 Replies
449 Views
Below is the code that i have In broadcast upload extensionoverride func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) { // 1. create compression session let status = VTCompressionSessionCreate(allocator: nil, width: 1280, height: 720, codecType: kCMVideoCodecType_H264, encoderSpecification: nil, imageBufferAttributes: nil, compressedDataAllocator: nil, outputCallback: compressionOutputCallback as? VTCompressionOutputCallback, refcon: nil, compressionSessionOut: &compression_session) if let session = compression_session{ VTSessionSetProperty(session, key: kVTCompressionPropertyKey_RealTime, value: kCFBooleanTrue) let retStatus = VTCompressionSessionPrepareToEncodeFrames(session) print("SBC: VTCompressionSessionCreate -", status == noErr, "PrepareToEncodeFrames -", retStatus == noErr) } }override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) { //print("SBC: processSampleBuffer", sampleBuffer.numSamples, sampleBufferType.rawValue) switch sampleBufferType { case RPSampleBufferType.video: // Handle video sample buffer let pts = CMSampleBufferGetPresentationTimeStamp(sampleBuffer) let imageBuffer:CVImageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)! if let session = compression_session { // 2. encode frame let ret = VTCompressionSessionEncodeFrame(session, imageBuffer: imageBuffer, presentationTimeStamp: pts, duration: CMTime.invalid, frameProperties: nil, sourceFrameRefcon: nil, infoFlagsOut: nil) if ret == noErr{ print("SBC: VTCompressionSessionEncodeFrame ret", ret) } } break case RPSampleBufferType.audioApp: // Handle audio sample buffer for app audio break case RPSampleBufferType.audioMic: // Handle audio sample buffer for mic audio break @unknown default: // Handle other sample buffer types fatalError("Unknown type of sample buffer") }func compressionOutputCallback(outputCallbackRefCon:UnsafeMutableRawPointer?, sourceFrameRefCon:UnsafeMutableRawPointer?, status:OSStatus, infoFlags:VTEncodeInfoFlags, sampleBuffer:CMSampleBuffer) { // Do whatever you want with the sampleBuffer if status != noErr{ NSLog("SBC: Error encoding video", status) print("SBC: Error encoding video", status) return } print("SBC: compressionOutputCallback dataBuffer", status)}What am i missing? ANY HELP WOULD BE APPRECIATED
Posted Last updated
.