OpenGL Programming/Video Capture

From Wikibooks, open books for an open world
Jump to: navigation, search

apitrace is a nice debugging tool.

It has a save/replay feature that captures everything you told the graphic card, and can reproduce it later on, and even save the result as a stream of pictures.

We'll use this to create a video suitable for upload at Wikicommons!

Contents

Compilation (instructions for GNU/Linux) [edit]

Get the source code:

cd /usr/src/
git clone https://github.com/apitrace/apitrace.git
cd apitrace/

Install cmake:

apt-get install cmake

Compile!

cmake -H. -Bbuild
cd build
make

Capture [edit]

Let's test with the simple wave post-processing effect:

cd wikibooks-opengl-modern-tutorials/obj/
LD_PRELOAD=/usr/src/apitrace/build/wrappers/glxtrace.so make test

Run the program for a few seconds, rotate the object, zoom, etc., and then quit the program.

This will create a suzanne.trace binary file. If the file already exists, it will create suzanne.2.trace, and so on.

Replay [edit]

You use the glretrace command, passing it the trace file as parameter:

/usr/src/apitrace/build/glretrace suzanne.trace

Of course, this is not interactive anymore, this is just a replay.

Convert to video [edit]

Let's install ffmpeg:

apt-get install ffmpeg

Note: we tried to use ffmpeg's scaling filter to reduce the screen size (-vf scale=200:150), but sadly it caused a segfault however we tried[1]. So instead we just recompiled the application and specified a smaller screen size directly.

ffmpeg's options are organized the following way:

ffmpeg <input options> -i source <output options> destination
  • We'll use a .ogg output since that's the only format accepted by Wikicommons (if you know who could get support for the free and better .webm format, please contact him/her!).
  • The screen used during the tutorial has a refresh rate of 75Hz, but videos usually are 25 images/s, so we'll reduce the rate (double input and ouput -r parameters)
  • We'll use a fixed, good quality (-qscale)
  • We overwrite the destination file (-y)

We get:

/usr/src/apitrace/build/glretrace -s - suzanne.trace \
  | ffmpeg -r 75 -f image2pipe -vcodec ppm -i pipe: -r 25 -qscale 31 -y output.ogg

We've got our video - and no additional code was needed.

Here's the result!


References [edit]

  1. This bug might be related to https://ffmpeg.org/trac/ffmpeg/ticket/397

< OpenGL Programming

Browse & download complete code