Capturing video out of an OpenGL window in Windows

前端 未结 4 1637
感动是毒
感动是毒 2020-12-15 09:48

I am supposed to provide my users a really simple way of capturing video clips out of my OpenGL application\'s main window. I am thinking of adding buttons and/or keyboard s

相关标签:
4条回答
  • 2020-12-15 10:25

    There are two different questions here - how to grab frames from an OpenGL application, and how to turn them into a movie file.

    The first question is easy enough; you just grab each frame with glReadPixels() (via a PBO if you need the performance).

    The second question is a little harder since the cross-platform solutions (ffmpeg) tend to be GPL'd or LGPL'd. Is LGPL acceptable for your project? The Windows way of doing this (DirectShow) is a bit of a headache to use.

    Edit: Since LGPL is ok and you can use ffmpeg, see here for an example of how to encode video.

    0 讨论(0)
  • 2020-12-15 10:46

    This does look pretty relevant for merging into an AVI (as suggested by Andrew), however I was really hoping to avoid the LPBITMAPINFOHEADERs etc.

    Thanks for the answers, I will report on the success if there is going to be any :)

    In the meantime, additional tips for encoding the raw frames from glReadPixels into video clips would be appreciated.

    Edit: So far, ffmpeg suggested by Mike F seems to be the way to go. However, I didn't get into the actual implementation yet, but hopefully that will change in the near future!

    0 讨论(0)
  • 2020-12-15 10:47

    I had to create a demo project of recording an OpenGL rendering into a video. I used glReadPixels to get the pixel data and created the video with OpenCV's cvWriteFrame. OpenCV lets you write in divx or even x264/vp8(with ffmpeg compiled in).

    I have a more detailed writeup on my blog post along with a sample project. http://tommy.chheng.com/2013/09/09/encode-opengl-to-video-with-opencv/

    0 讨论(0)
  • 2020-12-15 10:49

    The easiest option is going to be saving each rendered frame from within your app and then merging them into an AVI. When you have the AVI there are many libraries available that can convert it into a more optimal format, or possibly skip the AVI step altogether.

    In terms of getting each frame, you could accomplish this either by rendering into an offscreen texture as you suggest or using the backbuffer directly as a source if your hardware supports this. Doing either of these (and saving each frame) is going to be difficult without a heavy penalty on framerate.

    Providing your application is deterministic you could "record" the users actions as a series of inputs and then have an export mode that sequentially renders these to an offscreen surface to generate the AVI.

    0 讨论(0)
提交回复
热议问题