NVIDIA / VideoProcessingFramework

Set of Python bindings to C++ libraries which provides full HW acceleration for video decoding, encoding and GPU-accelerated color space and pixel format conversions
Apache License 2.0
1.32k stars 233 forks source link

Why the rendering effect of samples/SampleOpenGL.py is flipped vertically. #550

Open TurtleZhong opened 1 year ago

TurtleZhong commented 1 year ago

Describe the bug In samples/SampleOpenGL.py, the rendering effect of OpenGL is flipped vertically. here is the origin video in tests/test.mp4 image

and below is the render results of OpenGL image

python3 SampleOpenGL.py -g 0 -e /PATH/VideoProcessingFramework/tests/test.mp4

To Reproduce Steps to reproduce the behavior:

  1. Before I use this command line, I need fix some bugs in SampleOpenGL.py, Line 346 and Line 347 need to be exchanged.
  2. Go to the samples folder and run
    python3 SampleOpenGL.py -g 0 -e /PATH/VideoProcessingFramework/tests/test.mp4
  3. Then we can get the above result.
  4. See error->the rendering result is flipped vertically.

Screenshots

https://github.com/NVIDIA/VideoProcessingFramework/assets/19700579/eb4e773c-8d73-4f2d-a257-ce4efe32305c

Desktop (please complete the following information):

wld22145 commented 11 months ago

Hi, I faced the same problem and here is my solution:

Add one line of code in the vertex shader of the compile_shader() function to vertically flip the uv coordinates:

vertex_shader_source = """
        #version 450 core
        out vec2 uv;
        void main( void)
        {
            // Declare a hard-coded array of positions
            const vec2 vertices[4] = vec2[4](vec2(-0.5,  0.5),
                                                 vec2( 0.5,  0.5),
                                                 vec2( 0.5, -0.5),
                                                 vec2(-0.5, -0.5));
            // Index into our array using gl_VertexID
            uv=vertices[gl_VertexID]+vec2(0.5,0.5);
            uv.y = 1.0 - uv.y; // Flip the texture vertically
            gl_Position = vec4(2*vertices[gl_VertexID],1.0,1.0);
            }
        """

Hopefully, this will also work for you.