piemonte / PBJVision

📸 iOS Media Capture – features touch-to-record video, slow motion, and photography
MIT License
1.93k stars 324 forks source link

Text in capture video #343

Closed kleruk closed 6 years ago

kleruk commented 7 years ago

We need to record the text on video. For example, the date and time. I tried to do this using the method of the delegate - (void)vision:(PBJVision *)vision didCaptureVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer

` CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

CVPixelBufferLockBaseAddress( pixelBuffer, 0 );

CIContext *ciContext = [CIContext contextWithEAGLContext:[PBJVision sharedInstance].context options:@{kCIContextWorkingColorSpace : [NSNull null]} ];

NSString *string = @"LOADING TEXT";

NSDictionary *attributes = @{NSFontAttributeName            : [UIFont systemFontOfSize:20],
                             NSForegroundColorAttributeName : [UIColor whiteColor],
                             NSBackgroundColorAttributeName : [UIColor blackColor]};

UIImage *image = [UIImage imageFromString:string
                               attributes:attributes
                                     size:CGSizeMake(320, 100)];

CIImage *filteredImage = [[CIImage alloc] initWithCGImage:image.CGImage];

[ciContext render:filteredImage toCVPixelBuffer:pixelBuffer bounds:[filteredImage extent] colorSpace:CGColorSpaceCreateDeviceRGB()];

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); `

but it does not work. Would you like to add this opportunity?

imagine commented 7 years ago

Try modifying the buffer in the earlier delegate vision:didReceiveVideoSampleBuffer: Your code will need to be super performant, so maybe cache that UIImage creation.

kleruk commented 7 years ago

@imagine, thanks for your reply. I would like to be able to do this with the help of a delegate, because it is not possible to modify it since it is used with Pods

imagine commented 7 years ago

Oh the delegate I posted may only exist in my fork! You can easily reference a GitHub branch in your Podfile, for what it’s worth.

At some point I’ll make a pull request here for my modification. The naming or commenting would need to make the performance concerns very explicit.

On Sep 27, 2017, at 5:43 AM, kleruk notifications@github.com wrote:

imagine, thanks for your reply. I would like to be able to do this with the help of a delegate, because it is not possible to modify it since it is used with Pods

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.