4

I have written an openGL application and would like to produce a video of the graphics shown on the Glut window. Do you know how to do it?

From a previous question at SO, I know that one possible solution is to use glReadPixels to get the frames that were rendered by openGL and then use the FFmpeg library to produce the video. I don't really know how to use FFmpeg, so I'm not sure how I could write a program which takes the frames and outputs the video. Although the link is broken in the original question, I've found this example of video encoding, that may be useful for anyone trying to help.

Two questions:

  1. How can I use FFmpeg to write a program which takes frames and outputs a video?
  2. My application is written in OCaml, so I'm using lablgl and lablglut. Any ideas on how the FFmpeg ideas could be implemented in that case?
Community
  • 1
  • 1
Surikator
  • 1,497
  • 9
  • 26

3 Answers3

3

You can use libpng to write your frames to individual PNG files, then use the command-line ffmpeg tool to encode this into a video.

Thomas
  • 150,847
  • 41
  • 308
  • 421
  • How do I produce PNGs from within openGL? Also, that will produce tens of thousands of files. Isn't that a bit too much? – Surikator Feb 16 '11 at 17:29
  • 2
    Not from within OpenGL; you'd still have to use `glReadPixels` to grab the framebuffer contents, and then use libpng to compress the raw pixels. Tens of thousands of files is a lot, but hopefully nothing your machine can't handle. I've used similar techniques to create a video of several minutes, and it was no problem. – Thomas Feb 16 '11 at 17:56
  • With the method `png_write_png(png_ptr, info_ptr, png_transforms, NULL)`? But, if `glReadPixels` returns void, how I can use `libpng` to access the frame just read? – Surikator Feb 16 '11 at 18:25
  • http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml It writes to the buffer that you set up and hand to it via the `void *data`. How that would work in OCaml I have no idea, sorry... – Thomas Feb 16 '11 at 19:00
2

A variation on the png answser : output to bmp. Create a white image of the same size in Paint (or whatever is available on mac), open it with notepad, isolate the file header (for 800*600 it's 42 4D 36 F9 15 00 00 00 00 00 36 00 00 00 28 00-00 00 20 03 00 00 58 02 00 00 01 00 18 00 00 00-00 00 00 F9 15 00 00 00-00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 ), append results of glReadPixels, flush, close.

So yeah, lots of files, but usually not a problem since most openGL apps don't use the hard drive too much.

( I know, it's quite dirty, but it's the simplest method to implement - I did it on the train once, without any documentation )

Calvin1602
  • 9,021
  • 2
  • 38
  • 55
0

To capture video for a demo the best way is probably fraps

Martin Beckett
  • 90,457
  • 25
  • 178
  • 252