From: coderhyme Date: Fri, 22 Sep 2017 05:19:51 +0000 (+0900) Subject: [TCSACR-53][StreamRecorder] Add a guide for the stream recorder. X-Git-Tag: GitHub/PR#69/guides-native-web~12^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=655879ffc3958760c7d65918dc243d750b379757;p=sdk%2Fonline-doc.git [TCSACR-53][StreamRecorder] Add a guide for the stream recorder. PS2: Reviewed Change-Id: I07514a8badf28104b2276fe0eea2ebd6c63ea4c5 Signed-off-by: coderhyme --- diff --git a/org.tizen.guides/html/dotnet/media/stream_recorder.htm b/org.tizen.guides/html/dotnet/media/stream_recorder.htm new file mode 100644 index 0000000..635aa11 --- /dev/null +++ b/org.tizen.guides/html/dotnet/media/stream_recorder.htm @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + Media Stream Recording + + + + + +
+ +
+

Dependencies

+
    +
  • Tizen 4.0 and Higher
  • +
+ +

Content

+ + +

Related Info

+ +
+
+ +
+

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:

+ + +

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

+

Stream recorder state changes

+ +

Prerequisites

+ +

To use the methods and properties of the Tizen.Multimedia.StreamRecorder class, include the Tizen.Multimedia namespace in your application:

+
+using Tizen.Multimedia;
+
+ +

Managing Recording Options

+To define recording options for video recording: +
    +
  1. Create an instance of the Tizen.Multimedia.StreamRecorderOptions class with the output path and file format for the recorded media stream:

    +
    +var options = new StreamRecorderOptions(SavePath, RecorderFileFormat.Mp4);
    +
    +

    You can check which file formats the device supports using the GetSupportedFileFormats() method of the Tizen.Multimedia.StreamRecorder.Capabilities class.

  2. +
  3. Define the video recording options in the Video property of the Tizen.Multimedia.StreamRecorderOptions class, using an instance of the Tizen.Multimedia.StreamRecorderVideoOptions class: +
    +options.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 GetSupportedVideoEncodings() method of the Tizen.Multimedia.StreamRecorder.Capabilities class. The following example retrieves the first supported codec found:

    +
    +var streamRecorder = new StreamRecorder();
    +
    +var videoCodec = streamRecorder.Capabilities.GetSupportedVideoEncodings().First();
    +
    +
    +Note +Even if a higher bitrate is set, the recording bitrate is limited by that of the stream buffer pushed. +
    +
  4. +
+ +

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:

+
+byte[] rawbuffer; /// Data to be passed for recording
+
+var videoFormat = new VideoMediaFormat(MediaFormatVideoMimeType.Mpeg4SP, new Size(640, 480));
+var mediaPacket = MediaPacket.Create(videoFormat);
+
+mediaPacket.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:

+
    +
  1. Call the Prepare() method of the Tizen.Multimedia.StreamRecorder class with a Tizen.Multimedia.StreamRecorderOptions instance: +
    +streamRecorder.Prepare(options);
    +
    +The stream recorder state changes to Ready. +
  2. +
  3. Start recording by calling the Start() method: +
    +streamRecorder.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 the Ready or Paused state. After starting, the state changes to Recording.

    +

    Push the media packet to record audio or video, using the PushBuffer() method:

    +
    +streamRecorder.PushBuffer(mediaPacket);
    +
    +
  4. +
  5. During the recording, you can pause or stop it: +
      +
    • To pause recording, use the Pause() method: +
      +streamRecorder.Pause();
      +
      +

      The stream recorder state changes from Recording to Paused.

      +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 the Tizen.Multimedia.StreamRecorderOptions instance. +
      +streamRecorder.Commit();
      +
      +

      You can only call the Start() method in the Recording or Paused state. After committing, the state changes to Ready.

    • +
    • 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.

      +
      +streamRecorder.Cancel();
      +
      +
    • +
    +
  6. +
  7. When you have finished recording, use the Unprepare() method to reset the stream recorder: +
    +streamRecorder.Unprepare();
    +
    +

    The stream recorder state changes from Ready to Idle.

    +
  8. +
+ + + +
+ + +Go to top + + + + + + + diff --git a/org.tizen.guides/html/images/streamrecorder_states_cs.png b/org.tizen.guides/html/images/streamrecorder_states_cs.png new file mode 100644 index 0000000..c69d38d Binary files /dev/null and b/org.tizen.guides/html/images/streamrecorder_states_cs.png differ