Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
  2.  
  3. - (void) encode:(CMSampleBufferRef )sampleBuffer
  4. {
  5. dispatch_sync(aQueue, ^{
  6. self->frameCount++;
  7. CVImageBufferRef imageBuffer = (CVImageBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
  8.  
  9. CMTime presentationTimeStamp = CMTimeMake(self->frameCount, 1);
  10. VTEncodeInfoFlags flags;
  11.  
  12. OSStatus statusCode = VTCompressionSessionEncodeFrame(self->EncodingSession,
  13. imageBuffer,
  14. presentationTimeStamp,
  15. kCMTimeInvalid,
  16. NULL, NULL, &flags);
  17. if (statusCode != noErr) {
  18. self->error = @"H264: VTCompressionSessionEncodeFrame failed ";
  19. VTCompressionSessionInvalidate(self->EncodingSession);
  20. self->EncodingSession = NULL;
  21. self->error = NULL;
  22. return;
  23. }
  24. });
  25. }
  26.  
  27. var sampleBfr:CMSampleBuffer?
  28. let scale = CMTimeScale(USEC_PER_SEC)
  29. let pts = CMTime(value: CMTimeValue(NSDate().timeIntervalSince1970 * Double(scale)), timescale: scale)
  30. var timingInfo = CMSampleTimingInfo(duration: CMTime.invalid,
  31. presentationTimeStamp: pts,
  32. decodeTimeStamp: CMTime.invalid)
  33. var videoDesc:CMVideoFormatDescription? = nil
  34. let _:OSStatus = CMVideoFormatDescriptionCreateForImageBuffer(allocator: kCFAllocatorDefault, imageBuffer: pxBuffer!, formatDescriptionOut: &videoDesc)
  35. let _:OSStatus = CMSampleBufferCreateReadyWithImageBuffer(allocator: kCFAllocatorDefault, imageBuffer: pxBuffer!, formatDescription: videoDesc!, sampleTiming: &timingInfo, sampleBufferOut: &sampleBfr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement