MultiMedia_Recorder

    Since:

    1.0

    Version:

    1.0

    Summary

    Files

    Data Structures

    Data Structure Name

    Description

    Provides listeners for recording errors and information events.

    OHOS::Media::Recorder

    Provides functions for audio and video recording.

    Enumerations

    Enumeration Name

    Description

    : int32_t { OHOS::Media::VIDEO_SOURCE_SURFACE_YUV = 0, , OHOS::Media::VIDEO_SOURCE_SURFACE_ES, }

    Enumerates video source types.

    OHOS::Media::DataSourceType : int32_t { = 0 }

    Enumerates data source types.

    OHOS::Media::OutputFormatType : int32_t { = 0, OHOS::Media::FORMAT_MPEG_4, }

    Enumerates output file formats.

    OHOS::Media::FileSplitType : int32_t { = 0, OHOS::Media::FILE_SPLIT_PRE, }

    Enumerates file split types.

    OHOS::Media::RecorderCallback::RecorderInfoType : int32_t {    = 0, OHOS::Media::RecorderCallback::RECORDER_INFO_MAX_FILESIZE_APPROACHING, , OHOS::Media::RecorderCallback::RECORDER_INFO_MAX_FILESIZE_REACHED,   , OHOS::Media::RecorderCallback::RECORDER_INFO_FILE_SPLIT_FINISHED, }

    Enumerates recording information types.

    OHOS::Media::RecorderCallback::RecorderErrorType : int32_t { = 0 }

    Enumerates recording error types.

    Functions

    Function Name

    Description

    OHOS::Media::RecorderCallback::OnError (int32_t errorType, int32_t errorCode)=0

    virtual void 

    Called when an error occurs during recording. This callback is used to report recording errors.

    (int32_t type, int32_t extra)=0

    virtual void 

    Called when an information event occurs during recording. This callback is used to report recording information.

    OHOS::Media::Recorder::SetVideoSource ( source, int32_t &sourceId)

    int32_t 

    Sets a video source for recording.

    OHOS::Media::Recorder::SetVideoEncoder (int32_t sourceId, encoder)

    int32_t 

    Sets a video encoder for recording.

    OHOS::Media::Recorder::SetVideoSize (int32_t sourceId, int32_t width, int32_t height)

    int32_t 

    Sets the width and height of the video to record.

    (int32_t sourceId, int32_t frameRate)

    int32_t 

    Sets the frame rate of the video to record.

    OHOS::Media::Recorder::SetVideoEncodingBitRate (int32_t sourceId, int32_t rate)

    int32_t 

    Sets the encoding bit rate of the video to record.

    (int32_t sourceId, double fps)

    int32_t 

    Sets the video capture rate.

    OHOS::Media::Recorder::GetSurface (int32_t sourceId)

    std::shared_ptr< > 

    Obtains the surface of the video source.

    OHOS::Media::Recorder::SetAudioSource ( source, int32_t &sourceId)

    int32_t 

    Sets the audio source for recording.

    OHOS::Media::Recorder::SetAudioEncoder (int32_t sourceId, encoder)

    int32_t 

    Sets an audio encoder for recording.

    OHOS::Media::Recorder::SetAudioSampleRate (int32_t sourceId, int32_t rate)

    int32_t 

    Sets the audio sampling rate for recording.

    (int32_t sourceId, int32_t num)

    int32_t 

    Sets the number of audio channels to record.

    OHOS::Media::Recorder::SetAudioEncodingBitRate (int32_t sourceId, int32_t bitRate)

    int32_t 

    Sets the encoding bit rate of the audio to record.

    (int32_t duration)

    int32_t 

    Sets the maximum duration of a recorded file, in seconds.

    OHOS::Media::Recorder::SetOutputFormat ( format)

    int32_t 

    Sets the output file format.

    OHOS::Media::Recorder::SetOutputPath (const string &path)

    int32_t 

    Sets the output file path.

    (int32_t fd)

    int32_t 

    Sets the file descriptor (FD) of the output file.

    OHOS::Media::Recorder::SetNextOutputFile (int32_t fd)

    int32_t 

    Sets the FD of the next output file.

    (int64_t size)

    int32_t 

    Sets the maximum size of a recorded file, in bytes.

    OHOS::Media::Recorder::SetRecorderCallback (const std::shared_ptr< > &callback)

    int32_t 

    Registers a recording listener.

    OHOS::Media::Recorder::Prepare ()

    int32_t 

    Prepares for recording.

    ()

    int32_t 

    Starts recording.

    OHOS::Media::Recorder::Pause ()

    int32_t 

    Pauses recording.

    ()

    int32_t 

    Resumes recording.

    OHOS::Media::Recorder::Stop (bool block)

    int32_t 

    Stops recording.

    ()

    int32_t 

    Resets the recording.

    OHOS::Media::Recorder::Release ()

    int32_t 

    Releases recording resources.

    (FileSplitType type, int64_t timestamp, uint32_t duration)

    int32_t 

    Manually splits a video.

    (int32_t sourceId, const Format &format)

    int32_t 

    Sets an extended parameter for recording, for example, RCORDER_PRE_CACHE_DURATION.

    Details

    Enumeration Type Documentation

    DataSourceType

    Description:

    Enumerates data source types.

    Enumerator

    Description

    IMAGE 

    data source

    FileSplitType

    Description:

    Enumerates file split types.

    Enumerator

    Description

    FILE_SPLIT_POST 

    Delayed/Backward split

    FILE_SPLIT_PRE 
    FILE_SPLIT_NORMAL 

    Normal split

    OutputFormatType

    1. enum [OHOS::Media::OutputFormatType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga3dfe2e61369bf1c081ce569e235354df) : int32_t

    Description:

    Enumerates output file formats.

    Enumerator

    Description

    FORMAT_DEFAULT 

    Default format

    FORMAT_MPEG_4 

    MPEG4 format

    FORMAT_TS 

    TS format

    RecorderErrorType

    1. enum [OHOS::Media::RecorderCallback::RecorderErrorType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga5132172c298fc1497d12040b6bd511cf) : int32_t

    Description:

    Enumerates recording error types.

    Enumerator

    Description

    RECORDER_ERROR_UNKNOWN 

    Unknown error

    RecorderInfoType

    1. enum [OHOS::Media::RecorderCallback::RecorderInfoType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga0db5cf9cc68d4b468e921a563248ffe0) : int32_t

    Description:

    Enumerates recording information types.

    Enumerator

    Description

    RECORDER_INFO_MAX_DURATION_APPROACHING 

    The recording duration is reaching the threshold specified by SetMaxDuration. This type of information is reported when only one second or 10% is left to reach the allowed duration.

    RECORDER_INFO_MAX_FILESIZE_APPROACHING 

    The recorded file size is reaching the threshold specified by SetMaxFileSize. This type of information is reported when only 100 KB or 10% is left to reach the allowed size.

    RECORDER_INFO_MAX_DURATION_REACHED 

    The threshold specified by SetMaxDuration is reached, and the recording ends. Before calling SetOutputFile, you must close the file.

    RECORDER_INFO_MAX_FILESIZE_REACHED 

    The threshold specified by SetMaxFileSize is reached, and the recording ends. Before calling SetOutputFile, you must close the file.

    RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED 

    Recording started for the next output file.

    RECORDER_INFO_FILE_SPLIT_FINISHED 

    Manual file split completed.

    RECORDER_INFO_FILE_START_TIME_MS 

    The start time position of the recording file is not supported.

    VideoSourceType

    1. enum [OHOS::Media::VideoSourceType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#gad252d27f9ce4b6ae0756bfeaa5f34490) : int32_t

    Description:

    Enumerates video source types.

    Enumerator

    Description

    VIDEO_SOURCE_SURFACE_YUV 

    YUV video data provided through Surface

    VIDEO_SOURCE_SURFACE_RGB 

    RGB video data provided through

    VIDEO_SOURCE_SURFACE_ES 

    Raw encoded data provided through Surface

    VIDEO_SOURCE_BUTT 

    Invalid value

    Function Documentation

    1. std::shared_ptr<[OHOS::Surface]($api-api-SmartVision-Devices-OHOS-Surface.md)> OHOS::Media::Recorder::GetSurface (int32_t sourceId)

    Description:

    Obtains the surface of the video source.

    Parameters:

    Name

    Description

    sourceId Indicates the video source ID, which can be obtained from .

    Returns:

    Returns the pointer to the surface.

    OnError()

      Description:

      Called when an error occurs during recording. This callback is used to report recording errors.

      Parameters:

      OnInfo()

      1. virtual void OHOS::Media::RecorderCallback::OnInfo (int32_t type, int32_t extra )

      Description:

      Called when an information event occurs during recording. This callback is used to report recording information.

      Parameters:

      Name

      Description

      type Indicates the information type. For details, see RecorderInfoType.
      extra Indicates other information, for example, the start time position of a recording file.

      Pause()

      1. int32_t OHOS::Media::Recorder::Pause ()

      Description:

      Pauses recording.

      After Start is called, you can call this function to pause recording. The audio and video source streams are not paused, and source data is discarded.

      Returns:

      Returns SUCCESS if the recording is paused; returns an error code defined in otherwise.

      Prepare()

      1. int32_t OHOS::Media::Recorder::Prepare ()

      Description:

      Prepares for recording.

      This function must be called before .

      Returns:

      Returns SUCCESS if the preparation is successful; returns an error code defined in media_errors.h otherwise.

      Release()

      1. int32_t OHOS::Media::Recorder::Release ()

      Description:

      Releases recording resources.

      Returns:

      Returns SUCCESS if recording resources are released; returns an error code defined in media_errors.h otherwise.

      Reset()

      Description:

      Resets the recording.

      After the function is called, add a recording source by calling SetVideoSource or , set related parameters, and call Start to start recording again after is called.

      Returns:

      Returns SUCCESS if the recording is reset; returns an error code defined in media_errors.h otherwise.

      Resume()

      Description:

      Resumes recording.

      You can call this function to resume recording after Pause is called.

      Returns:

      Returns SUCCESS if the recording is resumed; returns an error code defined in otherwise.

      SetAudioChannels()

      1. int32_t OHOS::Media::Recorder::SetAudioChannels (int32_t sourceId, int32_t num )

      Description:

      Sets the number of audio channels to record.

      This function must be called after but before Prepare.

      Parameters:

      Name

      Description

      sourceId Indicates the audio source ID, which can be obtained from SetAudioSource.
      num Indicates the number of audio channels to set.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      SetAudioEncoder()

      1. int32_t OHOS::Media::Recorder::SetAudioEncoder (int32_t sourceId, [AudioCodecFormat]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#gaa4ea6f314644ed287e0704be26c768b7) encoder )

      Description:

      Sets an audio encoder for recording.

      If this function is not called, the output file does not contain the audio track. This function must be called after but before Prepare.

      Parameters:

      Name

      Description

      sourceId Indicates the audio source ID, which can be obtained from SetAudioSource.
      encoder Indicates the audio encoder to set.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      SetAudioEncodingBitRate()

      1. int32_t OHOS::Media::Recorder::SetAudioEncodingBitRate (int32_t sourceId, int32_t bitRate )

      Description:

      Sets the encoding bit rate of the audio to record.

      This function must be called after but before Prepare.

      Parameters:

      Name

      Description

      sourceId Indicates the audio source ID, which can be obtained from SetAudioSource.
      bitRate Indicates the audio encoding bit rate, in bit/s.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      SetAudioSampleRate()

      1. int32_t OHOS::Media::Recorder::SetAudioSampleRate (int32_t sourceId, int32_t rate )

      Description:

      Sets the audio sampling rate for recording.

      This function must be called after but before Prepare.

      Parameters:

      Name

      Description

      sourceId Indicates the audio source ID, which can be obtained from SetAudioSource.
      rate Indicates the sampling rate of the audio per second.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      SetAudioSource()

      1. int32_t OHOS::Media::Recorder::SetAudioSource ([AudioSourceType]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#gadc3158e093b995ca7b9b6aa32388ccdd) source, int32_t & sourceId )

      Description:

      Sets the audio source for recording.

      If this function is not called, the output file does not contain the audio track.

      Parameters:

      Name

      Description

      source Indicates the audio source type. For details, see AudioSourceType.
      sourceId Indicates the audio source ID. The value -1 indicates an invalid ID and the setting fails.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      SetCaptureRate()

      1. int32_t OHOS::Media::Recorder::SetCaptureRate (int32_t sourceId, double fps )

      Description:

      Sets the video capture rate.

      This function must be called after but before Prepare. It is valid when the video source is YUV or RGB.

      Parameters:

      Name

      Description

      sourceId Indicates the video source ID, which can be obtained from SetVideoSource.
      fps Indicates the rate at which frames are captured per second.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      SetFileSplitDuration()

      1. int32_t OHOS::Media::Recorder::SetFileSplitDuration ([FileSplitType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga8759c7e5a74964a584a716f4ec0b7edb) type, int64_t timestamp, uint32_t duration )

      Description:

      Manually splits a video.

      Parameters:

      Name

      Description

      type Indicates the file split type. For details, see FileSplitType.
      timestamp Indicates the file split timestamp. This parameter is not supported currently and can be set to -1. The recording module splits a file based on the call time.
      duration Indicates the duration for splitting the file.

      Returns:

      Returns SUCCESS if the video is manually split; returns an error code defined in media_errors.h otherwise.

      1. int32_t OHOS::Media::Recorder::SetMaxDuration (int32_t duration)

      Description:

      Sets the maximum duration of a recorded file, in seconds.

      This method must be called before . If the setting is valid, RECORDER_INFO_MAX_DURATION_APPROACHING is reported through OnInfo in the RecorderCallback class when only one second or 10% is left to reach the allowed duration. If the recording output file is set by calling , call SetNextOutputFile to set the next output file. Otherwise, the current file will be overwritten when the allowed duration is reached.

      Parameters:

      Name

      Description

      duration Indicates the maximum recording duration to set. If the value is 0 or a negative number, a failure message is returned. The default duration is 60s.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetMaxFileSize()

      1. int32_t OHOS::Media::Recorder::SetMaxFileSize (int64_t size)

      Description:

      Sets the maximum size of a recorded file, in bytes.

      This function must be called before Prepare. If the setting is valid, RECORDER_INFO_MAX_DURATION_APPROACHING is reported through OnInfo in the class when only 100 KB or 10% is left to reach the allowed size. If the recording output file is set by calling SetOutputFile, call to set the next output file. Otherwise, when the allowed size is reached, the current file will be overwritten. If MaxDuration is also set by calling SetMaxDuration, MaxDuration or MaxFileSize prevails depending on which of them is first satisfied.

      Parameters:

      Name

      Description

      size Indicates the maximum file size to set. If the value is 0 or a negative number, a failure message is returned. By default, the maximum size of a single file supported by the current file system is used as the limit.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetNextOutputFile()

      1. int32_t OHOS::Media::Recorder::SetNextOutputFile (int32_t fd)

      Description:

      Sets the FD of the next output file.

      If SetOutputFile is successful, call this function to set the FD of the next output file after RECORDER_INFO_MAX_DURATION_APPROACHING or RECORDER_INFO_MAX_FILESIZE_APPROACHING is received.

      Parameters:

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetOutputFile()

      Description:

      Sets the file descriptor (FD) of the output file.

      This function must be called before Prepare.

      Parameters:

      Name

      Description

      fd Indicates the FD of the file.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetOutputFormat()

      Description:

      Sets the output file format.

      This function must be called before Prepare.

      Parameters:

      Name

      Description

      format Indicates the output file format. For details, see OutputFormatType.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetOutputPath()

      1. int32_t OHOS::Media::Recorder::SetOutputPath (const string & path)

      Description:

      Sets the output file path.

      This function must be called before Prepare and One of them must be set.

      Parameters:

      Name

      Description

      path Indicates the output file path.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      SetParameter()

      1. int32_t OHOS::Media::Recorder::SetParameter (int32_t sourceId, const [Format]($api-api-SmartVision-Devices-OHOS-Media-Format.md) & format )

      Description:

      Sets an extended parameter for recording, for example, RCORDER_PRE_CACHE_DURATION.

      Parameters:

      Name

      Description

      sourceId Indicates the data source ID. The value -1 indicates all sources.
      format Indicates the string key and value. For details, see Format and RCORDER_PRE_CACHE_DURATION.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      SetRecorderCallback()

      1. int32_t OHOS::Media::Recorder::SetRecorderCallback (const std::shared_ptr< [RecorderCallback]($api-api-SmartVision-Devices-OHOS-Media-RecorderCallback.md) > & callback)

      Description:

      Registers a recording listener.

      This function must be called before .

      Parameters:

      Name

      Description

      callback Indicates the recording listener to register. For details, see .

      Returns:

      Returns SUCCESS if the listener is registered; returns an error code defined in media_errors.h otherwise.

      SetVideoEncoder()

      1. int32_t OHOS::Media::Recorder::SetVideoEncoder (int32_t sourceId, [VideoCodecFormat]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#ga797e6c5e38e23e730eff5bcc41427d7e) encoder )

      Description:

      Sets a video encoder for recording.

      If this function is not called, the output file does not contain the video track. This function must be called after SetVideoSource but before .

      Parameters:

      Name

      Description

      sourceId Indicates the video source ID, which can be obtained from .
      encoder Indicates the video encoder to set.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetVideoEncodingBitRate()

      1. int32_t OHOS::Media::Recorder::SetVideoEncodingBitRate (int32_t sourceId, int32_t rate )

      Description:

      Sets the encoding bit rate of the video to record.

      This function must be called after SetVideoSource but before .

      Parameters:

      Name

      Description

      sourceId Indicates the video source ID, which can be obtained from .
      rate Indicates the encoding bit rate to set.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetVideoFrameRate()

      1. int32_t OHOS::Media::Recorder::SetVideoFrameRate (int32_t sourceId, int32_t frameRate )

      Description:

      Sets the frame rate of the video to record.

      This function must be called after SetVideoSource but before .

      Parameters:

      Name

      Description

      sourceId Indicates the video source ID, which can be obtained from .
      frameRate Indicates the frame rate to set.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetVideoSize()

      1. int32_t OHOS::Media::Recorder::SetVideoSize (int32_t sourceId, int32_t width, int32_t height )

      Description:

      Sets the width and height of the video to record.

      This function must be called after SetVideoSource but before .

      Parameters:

      Name

      Description

      sourceId Indicates the video source ID, which can be obtained from .
      width Indicates the video width to set.
      height Indicates the video height to set.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.

      SetVideoSource()

      1. int32_t OHOS::Media::Recorder::SetVideoSource ([VideoSourceType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#gad252d27f9ce4b6ae0756bfeaa5f34490) source, int32_t & sourceId )

      Description:

      Sets a video source for recording.

      If this function is not called, the output file does not contain the video track.

      Parameters:

      Name

      Description

      source Indicates the video source type. For details, see VideoSourceType.
      sourceId Indicates the video source ID. The value -1 indicates an invalid ID and the setting fails.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      Start()

      1. int32_t OHOS::Media::Recorder::Start ()

      Description:

      Starts recording.

      This function must be called after .

      Returns:

      Returns SUCCESS if the recording is started; returns an error code defined in media_errors.h otherwise.

      Stop()

      1. int32_t OHOS::Media::Recorder::Stop (bool block)

      Description:

      Stops recording.

      Parameters:

      Returns:

      Returns SUCCESS if the recording is stopped; returns an error code defined in otherwise.

      RCORDER_PRE_CACHE_DURATION

      Description: