AVFoundation: add text to the CMSampleBufferRef video frame

后端 未结 1 877
囚心锁ツ
囚心锁ツ 2021-02-03 14:43

I\'m building an app using AVFoundation.

Just before I call [assetWriterInput appendSampleBuffer:sampleBuffer] in - (void)captureOutput:(AVCaptureOutp

1条回答
  •  鱼传尺愫
    2021-02-03 15:04

    You should refer the CIFunHouse sample from apple, and you may use this api to draw directly to the buffer

    -(void)render:(CIImage *)image toCVPixelBuffer:(CVPixelBufferRef)buffer bounds:(CGRect)r colorSpace:(CGColorSpaceRef)cs

    You can download it here WWDC2013

    Create the context

    _eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
    _ciContext = [CIContext contextWithEAGLContext:_eaglContext options:@{kCIContextWorkingColorSpace : [NSNull null]} ];
    

    Now render the image

    CVPixelBufferRef renderedOutputPixelBuffer = NULL;
    OSStatus err = CVPixelBufferPoolCreatePixelBuffer(nil, self.pixelBufferAdaptor.pixelBufferPool, &renderedOutputPixelBuffer);
    [_ciContext render:filteredImage toCVPixelBuffer:renderedOutputPixelBuffer bounds:[filteredImage extent]
    

    0 讨论(0)
提交回复
热议问题