Audio Encoding Using RealProducer G2 SDK
Introduction
This paper will focus on the processes surrounding the conversion of an audio file into the RealMedia format. It explains the usability of the RealProducer G2 SDK through code snippets to make the understanding of the COM like implementation of the SDK easier.
Real Producer
RealProducer is a technology from RealNetworks that provides for an easy conversion of non-RealMedia format files to RealMedia files. The purpose of the RealProducer SDK is to allow you to create an application that converts audio, video, events, and image map data into the RealMedia file format. The output file can then be streamed over the Internet or Intranet using a RealServer and viewed with a RealPlayer. An application created with the RealProducer SDK can also broadcast a stream that is sent directly to a RealServer.
Why RealProducer?
The advantages are the following
- The size of a realmedia file is dramatically lesser than a normal wav file. The RealProducer is able to achieve this through its encoding algorithms. The working of the encoding engine is explained a little later.
- The realmedia files can be streamed over the net. This is a highly desirable feature that makes broadcasting of audio and video a lot simpler.
- The realmedia files can be edited using SDK. The list below are the editable properties
- Edit title, author, copyright, and comment fields
- Modify Allow Recording and Allow Download settings
- Trim the start and end times of a .rm file. This is referred to as a cut operation.
- Paste two or more .rm files together. This is referred to as a paste operation.
- Dump the contents of a .rm file to a text file. This is known as a dump operation.
- Add meta information to the file that is specific to your application
- Obtain information on the types of streams contained in the .rm file
- Obtain the size of the video image
- Determine whether a .rm file is single rate or SureStream
SureStream advantage
SureStream is a technology by which RealMedia files achieve the following
- Creates one file for all connection rate environments
- Switches to different streams based on link speed
Encoding
The Entire SDK centers on the concept of Encoding. Lets see how it works.
The general encoding process consists of converting an input data source of one format into an output of a different format. An application that supports encoding will consist of three main components: input sources, an encoding session manager and an encoding engine. The role of the RealProducer SDK is to provide the encoding engine that takes various media input and produces output in the RealMedia format.
The working of the encoding session can be put into blocks as below.

The application using the RealProducer SDK is responsible for interpreting an input source into streams of different data types. For example, a QuickTime source file is interpreted as a stream of audio data and video data. The application then passes logical units of the input data stream into the encoding engine so that the stream can be converted into a RealMedia formatted stream and sent to the RealServer or written to a file.
The SDK is a component like library i.e. the SDK is a collection of interfaces, which the applications should use to accomplish RealMedia file format.
In the RealProducer SDK, "The RealMedia Build Engine" and distinct "Input Pins" for each type of input data represent the encoding engine. The input data that passes through the system is packaged as "Media Samples" objects. The application using the RealProducer SDK should use the RealMedia Build Engine and Input Pins to pass the data through the codecs and create the RealMedia output.
RealMedia Build Engine
This is the primary object of any application using the RealProducer SDK. It is used to set up an encoding session that converts audio to the RealMedia format. It is also responsible for coordinating the entire encoding process. The encoding process creates an output file that can be streamed from RealServers or HTTP Servers, as well as streamed real-time to a RealServer for live broadcasting.
The interface that represents the RealMedia Engine is IRMABuildEngine.
Input Pins
The Input Pins are the actual objects that take the raw audio, video, events, or image maps and convert them by encoding and packetization to a format for streaming. The RealMedia Build Engine exposes an Input Pin for each media type that it supports.
Each input pin supports a specific properties object, which the application will use to define the input source format. Each pin also takes a specific format of input data, which must be passed through the RealMedia Build Engine. The application initializes the Input Pin properties with the properties of the source. After the engine is prepared to encode, the application starts encoding by passing in raw data from each input pin.
The interface that represents the Input Pins is IRMAInputPin.
Media Samples
Media Samples are used as a generic way to pass time stamped data units from a media source to an Input Pin for encoding. For example, a Media Sample can be used to pass a chunk of wav data to the RealAudio Input Pin.
The interface that represents the media samples is IRMAMediaSamples.
Steps for an Encoding Session
Step 1: Set the target audience
Target Audience is the link type on which the resulting file will be streamed. For example, if the file generated will be used only in the local machine, we can set maximum speed
The various target audiences present are
- DUAL_ISDN
- LAN_HIGH
- LAN_LOW
- SINGLE_ISDN
- 56_MODEM
- 512_DSL_CABLE
- 28_MODEM
- 256_DSL_CABLE
Step2: Create the Engine
Once the Engine is created enumerate and get all the input pins available and their output mime types.
Now set the other properties for the engine.
- Output mime type For example, if we need the output mime type to be of RealAudio format we would do the following setting.
- Multirate encoding or single rate encoding
- When this property is set to be TRUE, the realmedia file can store data for more than one type of link. This enables the file to be streamed according to the speed of the connection.
- We can decide the generated file to go to a server or to a local hard disk. This can be achieved by setting the clip properties of the engine. The clip properties are obtained through the engine.
- Now that we have the clip interface of the engine, we can set the destination for the resulting realmedia file.
This call ensures that the resulting realmedia file will become a file in the local and not on a real server.
Step 3: Encoding
Since the initialization is complete for the engine, the engine can be started to perform the actual encoding.
There are a total of 21 codecs n the G2 SDK to choose from for encoding.
- 5 kbps Voice
- 6.5 kbps Voice
- 8.5 kbps Voice
- 16 kbps Voice
- 32 kbps Voice
- 64 kbps Voice
- 6 kbps Music
- 8 kbps Music
- 11 kbps Music
- 16 kbps Music
- 20 kbps Music
- 20 kbps Music - High Response
- 32 kbps Music
- 32 kbps Music - High Response
- 44 kbps Music
- 64 kbps Music
- 20 kbps Stereo Music
- 32 kbps Stereo Music
- 44 kbps Stereo Music
- 64 kbps Stereo Music
- 96 kbps Stereo Music
The appropriate codec is set to the engine. Now the engine is set for the final launch. The encode() function called with chunks of data taken from the input file. This process will continue until the entire input file is converted to a realmedia file.
The encoding steps would be like this
Get the pin using which the Engine will start the encoding. This is a two step process. Firstly the available pins in the Engine should be obtained through the pin enumerator.
Once the enumerator is obtained, the Audio pin is obtained by passing through the list of pins provided by the engine.
Having got the required pin, get the data to be sent to the input pin.GetFirstAudioSample (pAudSample, suggestedAudioInputSize);
Conclusion
The RealProducer G2 SDK is thus a library that provides a COM like implementation of an engine that can be used to convert an audio file to realmedia format.
References
- The G2 SDK can be downloaded from the link below http://www.real.com/index.html
- Follow the link below to get documentation on other technologies surrounding RealProducer http://service.real.com/realone/goldpass.html

