SoMPEGRenderer Class Reference
[MPEG]

VSG extension Base class for generating MPEG output from a scene graph. More...

#include <Inventor/MPEG/SoMPEGRenderer.h>

Inheritance diagram for SoMPEGRenderer:
SoMPEGFrameRenderer SoMPEGNavRenderer

List of all members.

Public Types

enum  Components {
  LUMINANCE = 1,
  LUMINANCE_TRANSPARENCY = 2,
  RGB = 3,
  RGB_TRANSPARENCY = 4
}

Public Member Functions

 SoMPEGRenderer ()
virtual ~SoMPEGRenderer ()
SbBool openFile (const char *filename, unsigned int numFrames=10000)
void closeFile ()
void setFilePointer (FILE *fp)
FILE * getFilePointer () const
void setSize (const SbVec2s &size)
SbVec2s getSize () const
void setComponents (const Components components)
SoMPEGRenderer::Components getComponents () const
virtual void setSceneGraph (SoNode *node)
SoNodegetSceneGraph () const
void setBackgroundColor (const SbColor &c)
SbColor getBackgroundColor () const
void setGLRenderAction (SoGLRenderAction *ra)
SoGLRenderActiongetGLRenderAction () const
void setCompressionRate (float value)
float getCompressionRate () const
void setBitPerSec (float mbps)
void setNumFramesPerSecond (float num)
int getNumFramesPerSecond ()
void addFrame (const unsigned char *frame)
void setShareContext (const SbGLShareContext shareCxt)
const SbGLShareContext getShareContext () const
virtual void record ()
virtual void pause ()
virtual void stop ()
SbBool isRecording () const
void setViewerIsIdle (bool isIdle)
bool isViewerIdle () const

Detailed Description

VSG extension Base class for generating MPEG output from a scene graph.

This class is the base class for creating MPEG video output from a scene graph. Two specialized classes SoMPEGFrameRenderer and SoMPEGNavRenderer are provided to give applications more control over video generation.

Warning : Writing in multiple streams at the same time is not possible.

This class is used by the viewer classes to record MPEG video (see for example the SoWinRenderArea method setMPEGRecorder ). The default right-mouse popup menu in the viewer classes provides an option to display a video recording dialog box. This dialog allows the user to conveniently start and stop recording the scene in the viewer window.

The setShareContext method allows you to share an existing OpenGL context with the MPEG renderer. This avoids the necessity to re-generate textures and display lists if they are already available in another OpenGL context (the viewer context, for instance). This can dramatically reduce offscreen rendering time, depending on your scene graph.

Here's how you might use these methods to share OpenGL contexts:

     SoMPEGRenderer* renderer = new SoMPEGRenderer();
     renderer->setShareContext( viewer->getShareContext() );

The MPEGRender uses two separate tasks. One to record rendered frames and one to encode the frames in MPEG format (this is a much slower task). If the recording task is stopped, the encoding one can continue. If openFile is called before the end of this task, two scenarios can occur. If the filename is the same file as the one currently in use by the encoding task, this task is stopped. The behavior is the same if record is called after stop . If the filename is different, the file is not opened and encoding continues.

It is important to note that the MPEGRenderer can only generate raw MPEG-1 video streams. In order for the generated video to be played correctly by any video player, it needs to be embedded into a container. This operation can be easily performed by the multimedia tool FFmpeg. For example, the following command allows you to embed the generated raw video stream into an MP4 container format:

   ffmpeg -i input_raw_stream.mpg -codec copy output_video.mp4

The -codec copy argument is important because it allows ffmpeg to only copy the input stream inside the container instead of doing a real re-encoding.

Different container formats can also be used, like AVI or MKV.

SEE ALSO

SoMPEGNavRenderer, SoMPEGFrameRenderer


Member Enumeration Documentation

Components.

Enumerator:
LUMINANCE 

Luminance.

LUMINANCE_TRANSPARENCY 

Luminance transparency.

RGB 

(Default)

RGB_TRANSPARENCY 

RGB and Alpha channel.


Constructor & Destructor Documentation

SoMPEGRenderer::SoMPEGRenderer (  ) 

Constructor.

virtual SoMPEGRenderer::~SoMPEGRenderer (  )  [virtual]

Destructor.


Member Function Documentation

void SoMPEGRenderer::addFrame ( const unsigned char *  frame  ) 

Low level method to add a new frame to the MPEG output from a buffer of unsigned characters.

Each pixel is stored sequentially by scanline, starting with the lower left corner. The data stored for each pixel is determined by the components set before rendering (3 by default). Pixels are stored in RGBA order and are packed without any padding between pixels or scanlines.

void SoMPEGRenderer::closeFile (  ) 

Closes the MPEG file previously opened with the openFile() method.

SbColor SoMPEGRenderer::getBackgroundColor (  )  const

Gets the background color for rendering each frame.

SoMPEGRenderer::Components SoMPEGRenderer::getComponents (  )  const

Returns the number of color components of the frames recorded.

float SoMPEGRenderer::getCompressionRate (  )  const

Returns the compression rate.

FILE* SoMPEGRenderer::getFilePointer (  )  const

Gets the MPEG file pointer.

SoGLRenderAction* SoMPEGRenderer::getGLRenderAction (  )  const

Gets the GL Render action used to generate each frame.

int SoMPEGRenderer::getNumFramesPerSecond (  ) 

Gets the number of frames per second to be encoded in the MPEG output.

SoNode* SoMPEGRenderer::getSceneGraph (  )  const

Gets the scene graph used for generating frames in the MPEG output.

const SbGLShareContext SoMPEGRenderer::getShareContext (  )  const

Gets the OpenGL context shared by this object.

SbVec2s SoMPEGRenderer::getSize (  )  const

Gets the frame pixel size.

These values may be different from those given by the setSize() method.

SbBool SoMPEGRenderer::isRecording (  )  const

Returns true if this renderer is recording.

bool SoMPEGRenderer::isViewerIdle (  )  const [inline]
SbBool SoMPEGRenderer::openFile ( const char *  filename,
unsigned int  numFrames = 10000 
)

Specifies the MPEG output file name.

numFrames gives an estimate of the number of frames that the MPEG output will contain.

If filename is the same as the one currently in use by the encoding task (if there is one), the encoding task is stopped. If the filename is different, the file is not opened and the current encoding task continues.

Returns FALSE if the file cannot be opened, TRUE otherwise.

virtual void SoMPEGRenderer::pause (  )  [virtual]

Pauses the recording.

virtual void SoMPEGRenderer::record (  )  [virtual]

Starts the recording.

If called directly after stop method, the current encoding task (if one) is stopped.

Note: A file must have been opened or a file pointer set.

Reimplemented in SoMPEGNavRenderer.

void SoMPEGRenderer::setBackgroundColor ( const SbColor c  ) 

Sets the background color for rendering each frame.

The default background color is 0 0 0 (black).

The default value can be set using the environment variable OIV_BACKGROUND_COLOR. Specify three floats (R, G, B) in the range 0. to 1., separated by spaces.

void SoMPEGRenderer::setBitPerSec ( float  mbps  ) 

This method allows the user to specify a fixed bit rate.

This is useful when the MPEG output is to be put on a video CD, for example. If you do not know what this rate means, you can use the default value (-1) which indicates that the bit rate is variable. The standards bit rates for VCD are 1205862 bps and 2726300 bps. (It is the speed the MPEG stream is read by VCD players)

The default value is 1205862. The maximum value is 104857600. NOTE: This method must be called before openFile or setFilePointer in order to have an effect. Calling it after calling openFile or setFilePointer may cause undesirable results.

void SoMPEGRenderer::setComponents ( const Components  components  ) 

Set the number of color components of the frames recorded.

void SoMPEGRenderer::setCompressionRate ( float  value  ) 

Compression rate of the MPEG output.

Values are between 0 and 1. 0=no compression, 1=maximum compression.

The default value is 0.3.

NOTE: This method must be called before openFile or setFilePointer in order to have an effect. Calling it after calling openFile or setFilePointer may cause undesirable results.

void SoMPEGRenderer::setFilePointer ( FILE *  fp  ) 

Sets the file pointer for the MPEG output.

void SoMPEGRenderer::setGLRenderAction ( SoGLRenderAction ra  ) 

Sets the GL Render action used to generate each frame.

If no render action is specified, an internal instance of an SoGLRenderAction will be maintained with a viewport region set to the size given with the method setSize().

void SoMPEGRenderer::setNumFramesPerSecond ( float  num  ) 

Sets the number of frames per second encoded in the MPEG output.

It has nothing to do with the speed of playback. The default value is 30.

NOTE: This method must be called before openFile or setFilePointer in order to have an effect. Calling it after calling openFile or setFilePointer may cause undesirable results.

virtual void SoMPEGRenderer::setSceneGraph ( SoNode node  )  [virtual]

Sets the scene graph used for generating frames in the MPEG output.

Reimplemented in SoMPEGNavRenderer.

void SoMPEGRenderer::setShareContext ( const SbGLShareContext  shareCxt  ) 

Sets the OpenGL context to be shared by the SoMPEGRenderer.

Its use is strongly recommended, because it can improve performance when switching between on-screen and off-screen rendering. This is because it allows the display lists and texture objects to be shared between the on-screen and off-screen render context. The shared context info is normally obtained by calling the viewer's getShareContext method.

NOTE: It has no effect when the hardware (or driver) does not allow sharing with the off-screen context, for example if Pbuffers are not supported.

void SoMPEGRenderer::setSize ( const SbVec2s size  ) 

Sets the frame pixel size.

The width and height of the frame must be a multiple of 16. If they are not, they are reduced to the next lower multiple of 16.

By default, width and height values are 96.

NOTE: This method must be called before openFile or setFilePointer in order to have an effect. Calling it after calling openFile or setFilePointer may cause undesirable results.

void SoMPEGRenderer::setViewerIsIdle ( bool  isIdle  ) 

Tells the recorder that the viewer is idle.

virtual void SoMPEGRenderer::stop (  )  [virtual]

Stops the recording and closes the opened file.

Reimplemented in SoMPEGNavRenderer.


The documentation for this class was generated from the following file:

Open Inventor Toolkit reference manual, generated on 4 Sep 2023
Copyright © Thermo Fisher Scientific All rights reserved.
https://www.openinventor.com/