0

We are able to use the mpv library to draw onto the bottom-left corner of an OpenGL window. While mpv seems able to draw an arbitrary width and height, the only way we found to draw to another location is to write to another frame buffer, but then we have to blit the second frame buffer onto the first.

Is there a way to tell mpv to draw into OpenGL onto (x,y,w,h)?

Also, when we copy it crashes multiple times, then suddenly starts wortking which is very odd. Even when it works, it shows two pictures which we completely don't understand.

enter image description here

To create the frame buffer:

 glGenFramebuffers(1, &fbo);
 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 glGenTextures(1, &texture);
 glBindTexture(GL_TEXTURE_2D, texture);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, drawWidth, drawHeight, 0, GL_RGB,
               GL_UNSIGNED_BYTE, nullptr);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
                         texture, 0);
 glBindTexture(GL_TEXTURE_2D, 0);
  glBindFramebuffer(GL_FRAMEBUFFER, 0);

To copy the movie framebuffer into the regular one:

glBindFramebuffer(GL_FRAMEBUFFER, fbo);
  if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
    std::cout << "ERROR::FRAMEBUFFER:: Framebuffer is not complete!"
              << std::endl;
  glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT);
  checkError(mpv_render_context_render(mpv_gl, redrawParams));
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  glBindFramebuffer(GL_READ_BUFFER, fbo);
  glBlitFramebuffer(0, 0, drawWidth, drawHeight, x, y, x + drawWidth,
                    y + drawHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
genpfault
  • 51,148
  • 11
  • 85
  • 139
Dov
  • 8,000
  • 8
  • 46
  • 75
  • it appears that we are reading both from the regular framebuffer and the extra one, which accounts for the 2 copies. The original question still stands: all we want is to have mpv draw to an arbitrary rectangle. Is there a reasonable way of doing that? – Dov Jul 06 '21 at 18:56

1 Answers1

0

From a skim of the mpv C API header files, yes. render.h says that you can use render properties to change where video is drawn, how scaled, and even crop if you want.

Hugh Fisher
  • 2,321
  • 13
  • 8