Base class for generating MPEG output from a scene graph. More...
#include <Inventor/MPEG/SoMPEGRenderer.h>
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.
SoMPEGNavRenderer, SoMPEGFrameRenderer
SoMPEGRenderer::SoMPEGRenderer | ( | ) |
Constructor.
virtual SoMPEGRenderer::~SoMPEGRenderer | ( | ) | [virtual] |
Destructor.
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.