ios - OpenGL format texture -
i trying display video on screen using opengl es 2
on ios.
i sum bit doing playback , display video on screen :
first have .mov file recorded using gpuimagemoviewriter
object. when recording completed going playback video using avplayer
. therefore set avplayeritemvideooutput
able retrieve frame video :
nsdictionary *test = [nsdictionary dictionarywithobject: [nsnumber numberwithint:kcvpixelformattype_32bgra] forkey: (id)kcvpixelbufferpixelformattypekey]; self.videooutput = [[avplayeritemvideooutput alloc] initwithpixelbufferattributes:test];
i use copypixelbufferforitemtime
function avplayeritemvideooutput
, receive cvimagebufferref
corresponding frame of initial video @ specific time.
finally, here function created create opengl
texture buffer :
- (void)setuptexturefrombuffer:(cvimagebufferref)imagebuffer { cvpixelbufferlockbaseaddress(imagebuffer, 0); int bufferheight = cvpixelbuffergetheight(imagebuffer); int bufferwidth = cvpixelbuffergetwidth(imagebuffer); cvpixelbuffergetpixelformattype(imagebuffer); glbindtexture(gl_texture_2d, m_videotexture); glteximage2d(gl_texture_2d, 0, gl_rgba, bufferwidth, bufferheight, 0, gl_rgba, gl_unsigned_byte, cvpixelbuffergetbaseaddress(imagebuffer)); cvpixelbufferunlockbaseaddress(imagebuffer, 0); }
by doing (and using non related algorithms augmented reality things) got strange result if video has been put in slices(i can't show because don't have enough reputation so).
it looks data not interpreted opengl
(wrong format ? type ?)
i checked whether corrupted buffer error using function :
- (void)saveimage:(cvpixelbufferref)pixbuffer { ciimage *ciimage = [ciimage imagewithcvpixelbuffer:pixbuffer]; cicontext *temporarycontext = [cicontext contextwithoptions:nil]; cgimageref videoimage = [temporarycontext createcgimage:ciimage fromrect:cgrectmake(0, 0, cvpixelbuffergetwidth(pixbuffer), cvpixelbuffergetheight(pixbuffer))]; uiimage *uiimage = [uiimage imagewithcgimage:videoimage]; uiimagewritetosavedphotosalbum(uiimage, self, @selector(image:didfinishsavingwitherror:contextinfo:), nil); }
-> saved image appeared in photo album.
it may come .mov
file can check if there's wrong file ?
thanks lot help, i'm stuck on problem hours/days !
you need use kcvpixelformattype_420ypcbcr8biplanarvideorange.
then transfer them separate chroma , luma opengles textures. example @ https://developer.apple.com/library/ios/samplecode/avbasicvideooutput/listings/avbasicvideooutput_apleaglview_m.html
i tried using several rgb based options not make work.
Comments
Post a Comment