Monday, 15 February 2010

c++ - FFMPEG to OpenGL Texture -



c++ - FFMPEG to OpenGL Texture -

i here ask, how can convert avframe opengl texture. actually, created renderer outputs me sound (audio working) , video, video not outputing. here code:

texture creation:

glgentextures(1,&_texture); glbindtexture(gl_texture_2d,_texture); glpixelstorei(gl_unpack_alignment, 1); gltexparameteri( gl_texture_2d, gl_texture_min_filter, gl_linear ); gltexparameteri( gl_texture_2d, gl_texture_mag_filter, gl_linear );

code info: _texture variable gluint keeps texture id

function gets avframe , convert opengl texture:

int videogl::nextvideoframe(){ // packet queue avpacket *videopacket = this->dequeue(video); int framefinished; if(videopacket!=0){ avcodec_decode_video2(_codec_context_video, _std_frame,&framefinished,videopacket); if(framefinished){ sws_scale(sws_ctx, _std_frame->data, _std_frame->linesize, 0, _codec_context_video->height, _rgb_frame->data, _rgb_frame->linesize); if(_firstrendering){ glbindtexture(gl_texture_2d,_texture); glteximage2d(gl_texture_2d, 0, gl_rgb, _codec_context_video->width,_codec_context_video->height,0,gl_rgb,gl_unsigned_byte,_rgb_frame->data[0]); _firstrendering = false; }else{ glactivetexture(_texture); glbindtexture(gl_texture_2d,_texture); gltexsubimage2d(gl_texture_2d,0,0,0,_codec_context_video->width,_codec_context_video->height,gl_rgb,gl_unsigned_byte,_rgb_frame->data[0]); } av_free_packet(videopacket); homecoming 0; }else{ av_free_packet(videopacket); homecoming -1; } }else{ homecoming -1; } homecoming 0; }

code information: there queue thread store avframes, function called avframes, until gets null stops beingness called.

that's not working. (i tried @ questions in stack overflow, it's still not working) example, or helps me right error there?

additional data: tried alter gl_rgb gl_rgba , started play formats, anyway crashes when seek gl_rgba (because width , height big, anyway tried resize them). have tried alter sizes powerfulness of 2, stills not working.

1 edit:

thread function:

dword winapi videogl::vidthread(lpvoid myparam){ videogl * instance = (videogl*) myparam; instance->wave_audio->start(); int quantity=0; avpacket packet; while(av_read_frame(instance->_format_context,&packet) >= 0){ if(packet.stream_index==instance->videostream){ instance->enqueue(video,&packet); } if(packet.stream_index==instance->audiostream){ instance->enqueue(audio,&packet); } } instance->enqueue(audio,null); instance->enqueue(video,null); homecoming 0; }

thread creation function:

createthread(null, 0, vidthread, this, null, null);

where refers class contains nextvideoframe, , _texture members.

solved:

i followed of datenwolf tips, , video displaying correctly audio/video:

opengl multithreading bit tricky. there's 1 or no active opengl context per thread and given opengl context can active in 1 thread @ time. migrating context between threads possible, shouldn't play hot opengl-context-potato between threads.

there 2 possible ways:

use memory mapped pixel buffer objects (map in 1 thread, update in other)

use secondary opengl context, sharing textures other. bind 1 context each thread (you can utilize same drawable, i.e. hdc on windows). can update texture in 1 thread while other draws it. texture updates introduce synchronization points between threads, can't accidently write texture while it's beingness accessed drawing.

c++ opengl ffmpeg libavformat

No comments:

Post a Comment