android - Converting FFmpeg frame to OpenGL ES texture -
i'm trying convert video using ffmpeg opengl es texture in jni, black texture. have output opengl glgeterror(), there no error.
here code:
void* pixels; int err; int i; int framefinished = 0; avpacket packet; static struct swscontext *img_convert_ctx; static struct swscontext *scale_context = null; int64_t seek_target; int target_width = 320; int target_height = 240; glenum error = gl_no_error; sws_freecontext(img_convert_ctx); = 0; while((i==0) && (av_read_frame(pformatctx, &packet)>=0)) { if(packet.stream_index==videostream) { avcodec_decode_video2(pcodecctx, pframe, &framefinished, &packet); if(framefinished) { logi("packet pts %llu", packet.pts); img_convert_ctx = sws_getcontext(pcodecctx->width, pcodecctx->height, pcodecctx->pix_fmt, target_width, target_height, pix_fmt_rgb24, sws_bicubic, null, null, null); if(img_convert_ctx == null) { loge("could not initialize conversion context\n"); return; } sws_scale(img_convert_ctx, (const uint8_t* const*)pframe->data, pframe->linesize, 0, pcodecctx->height, pframergb->data, pframergb->linesize); logi("sws_scale"); videotextures = new texture*[1]; videotextures[0]->mwidth = 256; //(unsigned)pcodecctx->width; videotextures[0]->mheight = 256; //(unsigned)pcodecctx->height; videotextures[0]->mdata = pframergb->data[0]; glpixelstorei(gl_unpack_alignment, 1); glgentextures(1, &(videotextures[0]->mtextureid)); glbindtexture(gl_texture_2d, videotextures[0]->mtextureid); gltexparameterf(gl_texture_2d, gl_texture_min_filter, gl_linear); gltexparameterf(gl_texture_2d, gl_texture_mag_filter, gl_linear); if(0 == got_texture) { glteximage2d(gl_texture_2d, 0, gl_rgba, videotextures[0]->mwidth, videotextures[0]->mheight, 0, gl_rgba, gl_unsigned_byte, (glvoid *)videotextures[0]->mdata); gltexsubimage2d(gl_texture_2d, 0, 0,0, videotextures[0]->mwidth, videotextures[0]->mheight, gl_rgba, gl_unsigned_byte, (glvoid *)videotextures[0]->mdata); }else { gltexsubimage2d(gl_texture_2d, 0, 0,0, videotextures[0]->mwidth, videotextures[0]->mheight, gl_rgba, gl_unsigned_byte, (glvoid *)videotextures[0]->mdata); } = 1; error = glgeterror(); if( error != gl_no_error ) { loge("couldn't create texture!!"); switch (error) { case gl_invalid_enum: loge("gl error: enum argument out of range"); break; case gl_invalid_value: loge("gl error: numeric value out of range"); break; case gl_invalid_operation: loge("gl error: operation illegal in current state"); break; case gl_out_of_memory: loge("gl error: not enough memory execute command"); break; default: break; } } } } av_free_packet(&packet); } i have succeeded in changing pframergb java bitmap, want change texture in c code.
edit1 have output texture id, 0; texture id zero? changed code zero.
edit2 texture display, mess.
not used gles, gl. in there 320, 240 not valied 512,256 power of 2. else need use texture_rectangle extension texcoords not 0-1 0-w/h. uploading texture data, glteximage(...) needed used first time (even data 0), gltexsubimage enough, think sizing etc initialized first, second sends meat.
regarding ffmpeg usage, perhaps version issue img_context more near renamed sws_getcontext, , initialized once, if cpu usage issue use sws_linear instead of sws_cubic, assume pframergb has been correctly avcodec_alloc_frame()'ed, if going use gl_rgba should use pix_fmt_rgba, pix_fmt_rgb24 gl_rgb texture piping, lack packet stack can go reading in advance keep display in sync , not late.
i've read comments unpack alignment, didn't need (and seeing success in area doubt of it) implement ffmpeg opengl/openal media library (http://code.google.com/p/openmedialibrary), nicely audio bits have been extracted ffmpeg openal loader (http://code.google.com/p/openalextensions). haves nice features , i'm trying work texture compression see if can perform still better. consider tutorials or ready use gpl code.
hope give enlightenment on obscure (by lack) art of ffmpeg opengl/al integration.
Comments
Post a Comment