I haven't put together a video from an OSG app yep, but its inevitable
one day I'll need to so I thought I'd pen down what I think might be a
nice way to tackle it.  This might also be a good example to have
added to the OSG, so users are welcome to add one :-)

My thought was to have a slave Camera that tracks the master camera,
but with an FBO or Pbuffer set to PAL dimensions (or whatever target
res you want for the video), this will record the frames at the
correct size, and without any toolboxes etc interfering.

Second up would be to attach a post draw callback to the slave Camera,
and in this callback you'd do the osg::Image::readPixels to do this
for you.  In theory one could set up a PixelBufferObject to help speed
to read up.  Next up you have to save this image to disk, or just
cache it.   Now writing to disk will be slow, so you don't want to do
this in the rendering thread, rather spawn an OperationThread to do
the writing to disk, with a custom ImageWriteOperation added to the
OperationThread.  Due to the asynchronous nature of write one will
need to use a circular buffer of osg::Image, one at the head being
written to by the rendering thread, and the rest being used by
ImageWriteOperations, when the image is written to disk one simply
then put the Image back into the buffer ready to be reused.

Then once you've stopped your recording of images, you wait till the
last frame is written to disk (the OperationThread's queue is empty)
then you span a tool to glue all these frames together as a video.
Potentially you could use video library like ffmpeg to do this in a
background thread.

Other little changes one could make would be to cut the framerate of
the app down to 25fps to match the needs of the video, or perhaps even
let the app run at a multiple, say 50 or 75fps and then blend frames
together, and only write out at 25fps.

Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to