Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
- - (void) encode:(CMSampleBufferRef )sampleBuffer
- {
- dispatch_sync(aQueue, ^{
- self->frameCount++;
- CVImageBufferRef imageBuffer = (CVImageBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
- CMTime presentationTimeStamp = CMTimeMake(self->frameCount, 1);
- VTEncodeInfoFlags flags;
- OSStatus statusCode = VTCompressionSessionEncodeFrame(self->EncodingSession,
- imageBuffer,
- presentationTimeStamp,
- kCMTimeInvalid,
- NULL, NULL, &flags);
- if (statusCode != noErr) {
- self->error = @"H264: VTCompressionSessionEncodeFrame failed ";
- VTCompressionSessionInvalidate(self->EncodingSession);
- self->EncodingSession = NULL;
- self->error = NULL;
- return;
- }
- });
- }
- var sampleBfr:CMSampleBuffer?
- let scale = CMTimeScale(USEC_PER_SEC)
- let pts = CMTime(value: CMTimeValue(NSDate().timeIntervalSince1970 * Double(scale)), timescale: scale)
- var timingInfo = CMSampleTimingInfo(duration: CMTime.invalid,
- presentationTimeStamp: pts,
- decodeTimeStamp: CMTime.invalid)
- var videoDesc:CMVideoFormatDescription? = nil
- let _:OSStatus = CMVideoFormatDescriptionCreateForImageBuffer(allocator: kCFAllocatorDefault, imageBuffer: pxBuffer!, formatDescriptionOut: &videoDesc)
- let _:OSStatus = CMSampleBufferCreateReadyWithImageBuffer(allocator: kCFAllocatorDefault, imageBuffer: pxBuffer!, formatDescription: videoDesc!, sampleTiming: &timingInfo, sampleBufferOut: &sampleBfr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement