Login  Register

Red-colored videos using libav

Posted by Aksenov239 on Nov 20, 2016; 11:38pm
URL: https://forum.jogamp.org/Red-colored-videos-using-libav-tp4037437.html

Hello, I'm trying to have a simple example on playing a video.
As a library for FFMPEGMediaPlayer I've taken libav-11.3-win64.

GLMediaPlayer player;

public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glClearDepth(1f);
    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthFunc(GL.GL_LEQUAL);
    player = GLMediaPlayerFactory.create(GLMediaPlayer.class.getClassLoader(),
                 "jogamp.opengl.util.av.impl.FFMPEGMediaPlayer");
    try {
        player.initStream(Uri.cast("BigBuckBunny_320x180.mp4"),
                GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO,
                GLMediaPlayer.TEXTURE_COUNT_DEFAULT);
    } catch (java.net.URISyntaxException e) {
        e.printStackTrace();
        return;
    }
    while (player.getState() != GLMediaPlayer.State.Initialized) {}
    try {
        player.initGL(gl);
    } catch (GLMediaPlayer.StreamException e) {
        e.printStackTrace();
    }
    while (player.getState() != GLMediaPlayer.State.Paused) {
    }
    player.play();
    while (player.getState() != GLMediaPlayer.State.Playing) {
    }
}

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();
    if (height == 0) height = 1;
    this.width = width;
    this.height = height;
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0, Widget.BASE_WIDTH, 0, Widget.BASE_HEIGHT, 0, 1);
 
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
}

public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glClearColor(1, 1, 1, 1);

    Texture texture = player.getNextTexture(gl).getTexture();
    texture.enable(gl);
    texture.bind(gl);
    TextureCoords coords = texture.getImageTexCoords();
    gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
    gl.glBegin(GL2.GL_QUADS);
    gl.glTexCoord2f(coords.left(), coords.bottom());
    gl.glVertex2i(0, 0);
    gl.glTexCoord2f(coords.left(), coords.top());
    gl.glVertex2i(0, 180);
    gl.glTexCoord2f(coords.right(), coords.top());
    gl.glVertex2i(320, 180);
    gl.glTexCoord2f(coords.right(), coords.bottom());
    gl.glVertex2i(320, 0);
    gl.glEnd();
    texture.disable(gl);
}

Unfortunately, the code above doesn't work as expected. It somehow loses blue and green channels, because avplay.exe plays video properly. Do you know where the problem could be?

It seems, the code to show a texture should work, because I used it draw pictures.

Thanks in advance,
Vitaly Aksenov