ios - what is the relation between CVBuffer and CVImageBuffer -


if check doc apple

https://developer.apple.com/library/tvos/documentation/quartzcore/reference/cvbufferref/index.html#//apple_ref/c/tdef/cvbufferref

in second line , says : "a cvbuffer object can hold video, audio, or possibly other type of data. can use cvbuffer programming interface on core video buffer." means can hold images . if yes , why have cvimagebuffer.

i have done work on generating images video using avassetimagegenerator.now want merge frames make video.so,i have started reading this.

my current status:
1.well right know need use avassetwriter.
2.then need provide input using avassetwriterinput.
3.i need use cv , cg classes.

so please me know reason using cvimagebuffer if have cvbuffer.i know cvbuffer abstract cvimagebuffer doesn't inherit cvbuffer.this bamboozles me more.

cvimagebuffer does inherit cvbuffer, in "simulated object orientation in c" way. is, if know cvbuffer's type of subclass, can safely cast type, e.g.:

if (cfgettypeid(mycvbuffer) == cvmetaltexturegettypeid()) {     cvmetaltextureref metalbuffer = mycvbuffer;     // metalbuffer } 

in fact don't need cast (not in swift!), cvbuffer types same (typealiases in swift):

typedef cvbufferref cvimagebufferref; typedef cvimagebufferref cvpixelbufferref; typedef cvimagebufferref cvmetaltextureref; // ... 

you noticed cvbuffer abstract base class, may have missed cvimagebuffer abstract too: adds few functions involving image dimensions , colour spaces , defines image attachment keys access image specific metadata.

i assume images cgimages since you're using avassetimagegenerator. @ point have 2 choices. can convert cgimage -> cvpixelbuffer , append directly avassetwriterinputpixelbufferadaptor add avassetwriterinput. or can create cmsamplebuffer cvpixelbuffer created above using cmsamplebuffercreatereadywithimagebuffer , append directly avassetwriterinput.

some people prefer pixel buffer adaptor approach, honestly, both of above approaches daunting and inefficient (e.g. don't think can create cvpixelbuffer without copying cgimage pixels), why not dump avassetimagegenerator , unwelcome cgimages , use avassetreader + avassetreaderoutput directly? vend cmsamplebuffers can append without conversion* writer input , have better chance of not hating life.

* may need change sample buffer's presentation time stamp, still pretty easy: cmsamplebuffercreatecopywithnewtiming


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -