Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoMPEGRenderer Class Reference

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

#include <Inventor/MPEG/SoMPEGRenderer.h>

+ Inheritance diagram for SoMPEGRenderer:

Public Types

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

Public Member Functions

 SoMPEGRenderer ()
 Constructor.
 
virtual ~SoMPEGRenderer ()
 Destructor.
 
SbBool openFile (const char *filename, unsigned int numFrames=10000)
 Specifies the MPEG output file name.
 
void closeFile ()
 Closes the MPEG file previously opened with the openFile() method.
 
void setFilePointer (FILE *fp)
 Sets the file pointer for the MPEG output.
 
FILE * getFilePointer () const
 Gets the MPEG file pointer.
 
void setSize (const SbVec2s &size)
 Sets the frame pixel size.
 
SbVec2s getSize () const
 Gets the frame pixel size.
 
void setComponents (const Components components)
 Set the number of color components of the frames recorded.
 
SoMPEGRenderer::Components getComponents () const
 Returns the number of color components of the frames recorded.
 
virtual void setSceneGraph (SoNode *node)
 Sets the scene graph used for generating frames in the MPEG output.
 
SoNodegetSceneGraph () const
 Gets the scene graph used for generating frames in the MPEG output.
 
void setBackgroundColor (const SbColor &c)
 Sets the background color for rendering each frame.
 
SbColor getBackgroundColor () const
 Gets the background color for rendering each frame.
 
void setGLRenderAction (SoGLRenderAction *ra)
 Sets the GL Render action used to generate each frame.
 
SoGLRenderActiongetGLRenderAction () const
 Gets the GL Render action used to generate each frame.
 
void setCompressionRate (float value)
 Compression rate of the MPEG output.
 
float getCompressionRate () const
 Returns the compression rate.
 
void setBitPerSec (float mbps)
 This method allows the user to specify a fixed bit rate.
 
void setNumFramesPerSecond (float num)
 Sets the number of frames per second encoded in the MPEG output.
 
int getNumFramesPerSecond ()
 Gets the number of frames per second to be encoded in the MPEG output.
 
void addFrame (const unsigned char *frame)
 Low level method to add a new frame to the MPEG output from a buffer of unsigned characters.
 
void setShareContext (const SbGLShareContext shareCxt)
 Sets the OpenGL context to be shared by the SoMPEGRenderer.
 
const SbGLShareContext getShareContext () const
 Gets the OpenGL context shared by this object.
 
virtual void record ()
 Starts the recording.
 
virtual void pause ()
 Pauses the recording.
 
virtual void stop ()
 Stops the recording and closes the opened file.
 
SbBool isRecording () const
 Returns true if this renderer is recording.
 
void setViewerIsIdle (bool isIdle)
 Tells the recorder that the viewer is idle.
 
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() );
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Base class for g...
SoMPEGRenderer()
Constructor.
void setShareContext(const SbGLShareContext shareCxt)
Sets the OpenGL context to be shared by the SoMPEGRenderer.

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

Definition at line 125 of file SoMPEGRenderer.h.

Member Enumeration Documentation

◆ Components

Components.

Enumerator
LUMINANCE 

Luminance.

LUMINANCE_TRANSPARENCY 

Luminance transparency.

RGB 

(Default)

RGB_TRANSPARENCY 

RGB and Alpha channel.

Definition at line 140 of file SoMPEGRenderer.h.

Constructor & Destructor Documentation

◆ SoMPEGRenderer()

SoMPEGRenderer::SoMPEGRenderer ( )

Constructor.

◆ ~SoMPEGRenderer()

virtual SoMPEGRenderer::~SoMPEGRenderer ( )
virtual

Destructor.

Member Function Documentation

◆ addFrame()

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.

◆ closeFile()

void SoMPEGRenderer::closeFile ( )

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

◆ getBackgroundColor()

SbColor SoMPEGRenderer::getBackgroundColor ( ) const

Gets the background color for rendering each frame.

◆ getComponents()

SoMPEGRenderer::Components SoMPEGRenderer::getComponents ( ) const

Returns the number of color components of the frames recorded.

◆ getCompressionRate()

float SoMPEGRenderer::getCompressionRate ( ) const

Returns the compression rate.

◆ getFilePointer()

FILE * SoMPEGRenderer::getFilePointer ( ) const

Gets the MPEG file pointer.

◆ getGLRenderAction()

SoGLRenderAction * SoMPEGRenderer::getGLRenderAction ( ) const

Gets the GL Render action used to generate each frame.

◆ getNumFramesPerSecond()

int SoMPEGRenderer::getNumFramesPerSecond ( )

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

◆ getSceneGraph()

SoNode * SoMPEGRenderer::getSceneGraph ( ) const

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

◆ getShareContext()

const SbGLShareContext SoMPEGRenderer::getShareContext ( ) const

Gets the OpenGL context shared by this object.

◆ getSize()

SbVec2s SoMPEGRenderer::getSize ( ) const

Gets the frame pixel size.

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

◆ isRecording()

SbBool SoMPEGRenderer::isRecording ( ) const

Returns true if this renderer is recording.

◆ isViewerIdle()

bool SoMPEGRenderer::isViewerIdle ( ) const
inline

Definition at line 360 of file SoMPEGRenderer.h.

◆ openFile()

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.

◆ pause()

virtual void SoMPEGRenderer::pause ( )
virtual

Pauses the recording.

◆ record()

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.

◆ setBackgroundColor()

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.

◆ setBitPerSec()

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.

◆ setComponents()

void SoMPEGRenderer::setComponents ( const Components  components)

Set the number of color components of the frames recorded.

◆ setCompressionRate()

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.

◆ setFilePointer()

void SoMPEGRenderer::setFilePointer ( FILE *  fp)

Sets the file pointer for the MPEG output.

◆ setGLRenderAction()

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().

◆ setNumFramesPerSecond()

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.

◆ setSceneGraph()

virtual void SoMPEGRenderer::setSceneGraph ( SoNode node)
virtual

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

Reimplemented in SoMPEGNavRenderer.

◆ setShareContext()

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.

◆ setSize()

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.

◆ setViewerIsIdle()

void SoMPEGRenderer::setViewerIsIdle ( bool  isIdle)

Tells the recorder that the viewer is idle.

◆ stop()

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: