ios - Render dynamic text onto CVPixelBufferRef while recording video -


i'm recording video , audio using avcapturevideodataoutput , avcaptureaudiodataoutput , in captureoutput:didoutputsamplebuffer:fromconnection: delegate method, want draw text onto each individual sample buffer i'm receiving video connection. text changes every frame (it's stopwatch label) , want recorded on top of video data that's captured.

here's i've been able come far:

//1. cvpixelbufferref pixelbuffer = cmsamplebuffergetimagebuffer(samplebuffer);  //2.    uiimage *textimage = [self createtextimage]; ciimage *maskimage = [ciimage imagewithcgimage:textimage.cgimage];  //3. cvpixelbufferlockbaseaddress(pixelbuffer, 0);  cgcolorspaceref colorspace = cgcolorspacecreatedevicergb(); nsdictionary *options = [nsdictionary dictionarywithobject:(__bridge id)colorspace forkey:kciimagecolorspace]; ciimage *inputimage = [ciimage imagewithcvpixelbuffer:pixelbuffer options:options];  //4. cifilter *filter = [cifilter filterwithname:@"ciblendwithmask"]; [filter setvalue:inputimage forkey:@"inputimage"]; [filter setvalue:maskimage forkey:@"inputmaskimage"]; ciimage *outputimage = [filter outputimage]; cvpixelbufferunlockbaseaddress(pixelbuffer, 0);  //5.    [self.rendercontext render:outputimage tocvpixelbuffer:pixelbuffer bounds:[outputimage extent] colorspace:cgcolorspacecreatedevicergb()];  //6. [self.pixelbufferadaptor appendpixelbuffer:pixelbuffer withpresentationtime:timestamp]; 
  1. here grab pixel buffer, easy pie.
  2. i use core graphics write text blank uiimage (that's createtextimage does. able verify step works; saved image text drawn photos.
  3. i create cgimage pixel buffer.
  4. i make cifilter ciblendwithmask, setting input image 1 created original pixel buffer , input mask ciimage made image text drawn on it.
  5. finally, render filter output image pixelbuffer. cicontext created beforehand [cicontext contextwithoptions:nil];.
  6. after that, append pixel buffer pixelbufferadaptor appropriate timestamp.

the video that's saved @ end of recording has no visible changes i.e. no mask image has been drawn onto pixel buffers.

anyone have idea i'm going wrong here? i've been stuck on days, appreciated.

edit:

- (uiimage *)createtextimage {     uigraphicsbeginimagecontextwithoptions(cgsizemake(self.view.bounds.size.width, self.view.bounds.size.height), no, 1.0);     nsmutableattributedstring *timestamp = [[nsmutableattributedstring alloc]initwithstring:self.timelabel.text attributes:@{nsforegroundcolorattributename:self.timelabel.textcolor, nsfontattributename: self.timelabel.font}];     nsmutableattributedstring *countdownstring = [[nsmutableattributedstring alloc]initwithstring:self.cdownlabel.text attributes:@{nsforegroundcolorattributename:self.cdownlabel.textcolor, nsfontattributename:self.cdownlabel.font}];     [timestamp drawatpoint:self.timelabel.center];     [countdownstring drawatpoint:self.view.center];     uiimage *blank = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     return blank; } 

do want below? enter image description here

instead of using ciblendwithmask, should use cisourceovercompositing, try this:

//4. cifilter *filter = [cifilter filterwithname:@"cisourceovercompositing"]; [filter setvalue:maskimage forkey:kciinputimagekey]; [filter setvalue:inputimage forkey:kciinputbackgroundimagekey]; ciimage *outputimage = [filter outputimage]; 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -