Surikator
Surikator

Reputation: 1463

capturing openGL graphics in a video

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?

Upvotes: 4

Views: 1619

Answers (3)

Calvin1602
Calvin1602

Reputation: 9547

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 )

Upvotes: 2

Martin Beckett
Martin Beckett

Reputation: 96197

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

Upvotes: 0

Thomas
Thomas

Reputation: 182093

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.

Upvotes: 3

Related Questions