FFMPEG for OpenGL Texture

I was here to ask how I can convert an AVFrame to an opengl texture. In fact, I created a renderer that outputs me audio (audio works) and video, but the video does not output. Here is my 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 );

Codes info: the _texture variable is GLuint that supports texture identifier

A function that receives an AVFrame and converts it to OpenGL Texture:

int VideoGL::NextVideoFrame(){
// Get a packet from the 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);
        return 0;
    }else{

        av_free_packet(videopacket);
        return -1;
    }

}else{
    return -1;
}
return 0;
}

Information about codes: there is a queue in which the thread stores AVFrames, this function is often called to receive AVFrames until it receives NULL, which ceases to be called.

This does not really work. (I tried to address some issues in the stack overflow, it still doesn't work) Any example or someone who helps me fix any error there?

: GL_RGB GL_RGBA , , GL_RGBA ( , ). Power Of 2, .

1 :

:

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);

return 0;
}

:

CreateThread(NULL, 0, VidThread, this, NULL, NULL);

, NextVideoFrame _texture.

:

datenwolf, /:

Screenshothot took

+5
1

OpenGL . OpenGL OpenGL . , OpenGL-- .

:

  • ( , )

  • OpenGL, . ( drawable, .. HDC Windows). , - . , .

+5

All Articles