What are some of the preferred methods or libraries for creating video from an OpenGL graphics simulation?

For example, I want to create a visualization(video) of an N-Body gravity simulation by rendering non-real-time OpenGL frames.

The simulation is already coded, I just don't know how to convert it to video.

EDIT: I am also interested in providing the described functionality: The user can adjust parameters including the time step between captured frames and then initiate the simulation. The user waits for the simulation to complete, and then can watch the results. The user is able to increase or decrease the playback speed of the simulation whereas in slow motion, more frames are used i.e., you see higher resolution time steps, and when the speed is increased, you see lower resolution time steps at a higher rate, but the frames per second flashing on the screen is constant.

  • 1
    \$\begingroup\$ Have you tried outputting the raw OpenGL framebuffers as pngs using glReadPixels and libpng? If you do that you can use something like ffmpeg to generate a video for you. \$\endgroup\$ – Mokosha Nov 2 '13 at 0:01
  • 1
    \$\begingroup\$ FRAPS can make movies from DX or OGL applications \$\endgroup\$ – Plato Nov 2 '13 at 0:25

The easy way: Use glReadPixels on the framebuffer every time you are about to swap, then feed these frames into libavcodec / libavformat (ffmpeg).

If you would like a video larger than the screen, there is the hard way:

Use an FBO to render your frames into a texture, then retrieve your data through glGetTexImage and feed it to your video encoder.

(If performance is absolutely critical for some reason, instead of glGetTexImage, you would ask the graphics driver to do async DMA uploads using a PBO, and use multiple buffers to allow one image to copy & encode while the next renders)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.