Media Stream Recording
You can record audio and video from a stream, and control the recording process through various settings. With the stream recorder, live audio and video can be kept on your target.
The main features of the Tizen.Multimedia.StreamRecorder
class include:
-
Creating a media packet
You must create a media packet for the stream recording using raw data from the source. The media packet must be created for each buffer captured from the source and passed to the
PushBuffer()
method of theTizen.Multimedia.StreamRecorder
class. -
Recording audio and video, and controlling the recording
You can record a stream, pause, stop, and cancel the recording, and push the buffer.
-
Managing recording options
You can manage various recording details, such as the bitrate, codec, maximum recording length, and filename:
-
You can encode files in various formats:
- Video: MP4 and 3GP
- Audio: AMR, AAC, and WAV
The supported file formats are defined in the Tizen.Multimedia.RecorderFileFormat enumeration.
-
You can use various video and audio encoders.
The available video and audio codecs are defined in the Tizen.Multimedia.RecorderVideoCodec and Tizen.Multimedia.RecorderAudioCodec enumerations.
-
Valid input sources consist of external sources, such as a live buffer passed by the application. Most operations of the stream recorder work synchronously.
The following figure illustrates general stream recorder state changes. Use the stream recorder methods according to pre and post conditions, by following the state changes.
Figure: Stream recorder state changes
Prerequisites
To enable your application to use the stream recording functionality:
-
To use the Tizen.Multimedia.StreamRecorder class, the application has to request permission by adding the following privileges to the
tizen-manifest.xml
file:XMLCopy<privileges> <privilege>http://tizen.org/privilege/mediastorage</privilege> <privilege>http://tizen.org/privilege/externalstorage</privilege> </privileges>
-
To use the methods and properties of the Tizen.Multimedia.StreamRecorder class, include the Tizen.Multimedia namespace in your application:
C#Copyusing Tizen.Multimedia;
Managing Recording Options
To define recording options for video recording:
-
Create an instance of the Tizen.Multimedia.StreamRecorderOptions class with the output path and file format for the recorded media stream:
C#Copyvar options = new StreamRecorderOptions(SavePath, RecorderFileFormat.Mp4);
You can check which file formats the device supports using the
GetSupportedFileFormats()
method of theTizen.Multimedia.StreamRecorder
class. -
Define the video recording options in the
Video
property of theTizen.Multimedia.StreamRecorderOptions
class, using an instance of the Tizen.Multimedia.StreamRecorderVideoOptions class:C#Copyoptions.Video = new StreamRecorderVideoOptions(codec: RecorderVideoCodec.H263, resolution: new Size(1920, 1080), sourceFormat: StreamRecorderVideoFormat.Nv12, frameRate: 30, bitRate: 288000);
To get a list of video codecs the device supports, use the
GetSupportedVideoCodecs()
method of the Tizen.Multimedia.StreamRecorder class. The following example retrieves the first supported codec found:C#Copyvar streamRecorder = new StreamRecorder(); var videoCodec = streamRecorder.GetSupportedVideoCodecs().First();
Note
Even if a higher bitrate is set, the recording bitrate is limited by that of the stream buffer pushed.
Similarly, to record an audio stream, define the audio recording options in the Audio
property of the StreamRecorderOptions
class instance, using an instance of the Tizen.Multimedia.StreamRecorderAudioOptions class.
Creating a Media Packet
When the stream recorder is configured, create the media packet using the raw data from the source:
C#
Copy
byte[] rawbuffer; /// Data to be passed for recording
var videoFormat = new VideoMediaFormat(MediaFormatVideoMimeType.Mpeg4SP, new Size(640, 480));
var mediaPacket = MediaPacket.Create(videoFormat);
mediaPacket.Buffer.CopyFrom(rawbuffer, 0, rawbuffer.length);
The media packet must be created for each buffer captured from the source and passed to the PushBuffer()
method of the Tizen.Multimedia.StreamRecorder class when the stream recorder is prepared to record.
Recording a Stream
To record a stream:
-
Call the
Prepare()
method of the Tizen.Multimedia.StreamRecorder class with a Tizen.Multimedia.StreamRecorderOptions instance:C#CopystreamRecorder.Prepare(options);
The stream recorder state changes to
Ready
. -
Start recording by calling the
Start()
method:C#CopystreamRecorder.Start();
Once the recording starts, if you set the file path to an existing file, the file is removed automatically and replaced with a new one.
You can only call the
Start()
method in theReady
orPaused
state. After starting, the state changes toRecording
.Push the media packet to record audio or video, using the
PushBuffer()
method:C#CopystreamRecorder.PushBuffer(mediaPacket);
-
During the recording, you can pause or stop it:
-
To pause recording, use the
Pause()
method:C#CopystreamRecorder.Pause();
The stream recorder state changes from
Recording
toPaused
.To resume recording, use the
Start()
method.Alternatively, you can stop pushing the stream buffers. In this case, the stream recorder remains in the
Recording
state, and continues waiting for buffers. It creates the same effect as a pause in the recording. -
To stop recording and save the result, use the
Commit()
method. The recording result is saved to the file path defined in theTizen.Multimedia.StreamRecorderOptions
instance.C#CopystreamRecorder.Commit();
You can only call the
Start()
method in theRecording
orPaused
state. After committing, the state changes toReady
. -
To stop recording without saving the result, use the
Cancel()
method.The only difference between this method and the
Commit()
method is that the recording data is not written to the file.C#CopystreamRecorder.Cancel();
-
-
When you have finished recording, use the
Unprepare()
method to reset the stream recorder:C#CopystreamRecorder.Unprepare();
The stream recorder state changes from
Ready
toIdle
.
Related Information
- Dependencies
- Tizen 4.0 and Higher