# MultiMedia\_Recorder - [Overview](#section1628426640165625) - [Summary](#section532867802165625) - [Files](#files) - [Data Structures](#nested-classes) - [Enumerations](#enum-members) - [Functions](#func-members) - [Details](#section1184400305165625) - [Enumeration Type](#section1963998659165625) - [DataSourceType](#gaccc05bb178cecd760369ea096dceae4c) - [FileSplitType](#ga8759c7e5a74964a584a716f4ec0b7edb) - [OutputFormatType](#ga3dfe2e61369bf1c081ce569e235354df) - [RecorderErrorType](#ga5132172c298fc1497d12040b6bd511cf) - [RecorderInfoType](#ga0db5cf9cc68d4b468e921a563248ffe0) - [VideoSourceType](#gad252d27f9ce4b6ae0756bfeaa5f34490) - [Function](#section552680935165625) - [GetSurface\(\)](#gad633e33fbbd5efcf4057aff3cc6e2b38) - [OnError\(\)](#ga822c915f1bfab8c380919f24f2ee4f54) - [OnInfo\(\)](#gac1f8bb191d90aac50119ea7ae4108407) - [Pause\(\)](#ga71da5cc2720b336f0daadbe09d61c695) - [Prepare\(\)](#ga15d2f3416bb735a0715e1e79be226387) - [Release\(\)](#ga116583c0d649f447c2dd272aae465cca) - [Reset\(\)](#gaebb808d5dd73b94b769b69e2b464c744) - [Resume\(\)](#gafd32ed157821800936a258a73af936be) - [SetAudioChannels\(\)](#ga77d76e5657cb3359e85521e08a456c7d) - [SetAudioEncoder\(\)](#gab37c9385fa1a56f686beb73c7dcc1b1b) - [SetAudioEncodingBitRate\(\)](#gac21a1a00c40cf58df84f1ba281b79a36) - [SetAudioSampleRate\(\)](#gab2b98616da55ec294053c0c25645c845) - [SetAudioSource\(\)](#gae287f59da8b3f1b6ca9f1c0e58a6565a) - [SetCaptureRate\(\)](#ga4f4a03fe881f48515874a699118fb84a) - [SetFileSplitDuration\(\)](#ga952ce2fada10d701e38e4ee29139e2af) - [SetMaxDuration\(\)](#gaf2806f0fddd17a3e59eb7c5c740470d6) - [SetMaxFileSize\(\)](#gaeed9ee49d9d1ac1497ec79bf9639c0bc) - [SetNextOutputFile\(\)](#ga8545fe87eb4bd399525e4c5fb414d7cb) - [SetOutputFile\(\)](#ga500d2bc895852fe292d7397d8450d091) - [SetOutputFormat\(\)](#gaffb7874aae331570ecedfe609a495468) - [SetOutputPath\(\)](#gaa5c898c1ad051b5c9f115ef15d952f18) - [SetParameter\(\)](#ga05cf279a460418b22d267527c83ede15) - [SetRecorderCallback\(\)](#ga882585460b0538680954ce6692610376) - [SetVideoEncoder\(\)](#gad9be6914af57fcf7acb7a5398118c614) - [SetVideoEncodingBitRate\(\)](#ga4e05a76b50abf790f29f06a0c1d4ecb8) - [SetVideoFrameRate\(\)](#gaeb90d4d75d80040aeaae354abd1d29d7) - [SetVideoSize\(\)](#ga43c0ee5b76f58a12c2c745839184a96b) - [SetVideoSource\(\)](#ga9e12ef9700d06c7620f9e3d7b4d844ca) - [Start\(\)](#gac3aaa32627f0799dea65e51356b91bfb) - [Stop\(\)](#ga1253f753cf9ed01dae5d57a37524dfa7) - [Variable](#section1577650583165625) - [RCORDER\_PRE\_CACHE\_DURATION](#gaaa77dd5c1745b9d5ba4b23c90206e936) ## **Overview** **Description:** Defines the **Recorder** class and provides functions for audio and video recording. **Since:** 1.0 **Version:** 1.0 ## **Summary** ## Files

File Name

Description

recorder.h

Declares the Recorder class for audio and video recording.

## Data Structures

Data Structure Name

Description

OHOS::Media::RecorderCallback

Provides listeners for recording errors and information events.

OHOS::Media::Recorder

Provides functions for audio and video recording.

## Enumerations

Enumeration Name

Description

OHOS::Media::VideoSourceType : int32_t { OHOS::Media::VIDEO_SOURCE_SURFACE_YUV = 0, OHOS::Media::VIDEO_SOURCE_SURFACE_RGB, OHOS::Media::VIDEO_SOURCE_SURFACE_ES, OHOS::Media::VIDEO_SOURCE_BUTT }

Enumerates video source types.

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

Enumerates data source types.

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

Enumerates output file formats.

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

Enumerates file split types.

OHOS::Media::RecorderCallback::RecorderInfoType : int32_t { OHOS::Media::RecorderCallback::RECORDER_INFO_MAX_DURATION_APPROACHING = 0, OHOS::Media::RecorderCallback::RECORDER_INFO_MAX_FILESIZE_APPROACHING, OHOS::Media::RecorderCallback::RECORDER_INFO_MAX_DURATION_REACHED, OHOS::Media::RecorderCallback::RECORDER_INFO_MAX_FILESIZE_REACHED, OHOS::Media::RecorderCallback::RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED, OHOS::Media::RecorderCallback::RECORDER_INFO_FILE_SPLIT_FINISHED, OHOS::Media::RecorderCallback::RECORDER_INFO_FILE_START_TIME_MS }

Enumerates recording information types.

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

Enumerates recording error types.

## Functions

Function

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.

OHOS::Media::RecorderCallback::OnInfo (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 (VideoSourceType source, int32_t &sourceId)

int32_t

Sets a video source for recording.

OHOS::Media::Recorder::SetVideoEncoder (int32_t sourceId, VideoCodecFormat 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.

OHOS::Media::Recorder::SetVideoFrameRate (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.

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

int32_t

Sets the video capture rate.

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

std::shared_ptr< OHOS::Surface >

Obtains the surface of the video source.

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

int32_t

Sets the audio source for recording.

OHOS::Media::Recorder::SetAudioEncoder (int32_t sourceId, AudioCodecFormat 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.

OHOS::Media::Recorder::SetAudioChannels (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.

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

int32_t

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

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

int32_t

Sets the output file format.

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

int32_t

Sets the output file path.

OHOS::Media::Recorder::SetOutputFile (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.

OHOS::Media::Recorder::SetMaxFileSize (int64_t size)

int32_t

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

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

int32_t

Registers a recording listener.

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

int32_t

Prepares for recording.

OHOS::Media::Recorder::Start ()

int32_t

Starts recording.

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

int32_t

Pauses recording.

OHOS::Media::Recorder::Resume ()

int32_t

Resumes recording.

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

int32_t

Stops recording.

OHOS::Media::Recorder::Reset ()

int32_t

Resets the recording.

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

int32_t

Releases recording resources.

OHOS::Media::Recorder::SetFileSplitDuration (FileSplitType type, int64_t timestamp, uint32_t duration)

int32_t

Manually splits a video.

OHOS::Media::Recorder::SetParameter (int32_t sourceId, const Format &format)

int32_t

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

## **Details** ## **Enumeration Type ** ## DataSourceType ``` enum [OHOS::Media::DataSourceType](MultiMedia_Recorder.md#gaccc05bb178cecd760369ea096dceae4c) : int32_t ``` **Description:** Enumerates data source types.

Enumerator

Description

IMAGE

Image data source

## FileSplitType ``` enum [OHOS::Media::FileSplitType](MultiMedia_Recorder.md#ga8759c7e5a74964a584a716f4ec0b7edb) : int32_t ``` **Description:** Enumerates file split types.

Enumerator

Description

FILE_SPLIT_POST

Delayed/Backward split

FILE_SPLIT_PRE

Advanced/Forward split

FILE_SPLIT_NORMAL

Normal split

## OutputFormatType ``` enum [OHOS::Media::OutputFormatType](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 ``` enum [OHOS::Media::RecorderCallback::RecorderErrorType](MultiMedia_Recorder.md#ga5132172c298fc1497d12040b6bd511cf) : int32_t ``` **Description:** Enumerates recording error types.

Enumerator

Description

RECORDER_ERROR_UNKNOWN

Unknown error

## RecorderInfoType ``` enum [OHOS::Media::RecorderCallback::RecorderInfoType](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 ``` enum [OHOS::Media::VideoSourceType](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 Surface

VIDEO_SOURCE_SURFACE_ES

Raw encoded data provided through Surface

VIDEO_SOURCE_BUTT

Invalid value

## **Function ** ## GetSurface\(\) ``` std::shared_ptr<[OHOS::Surface](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 SetVideoSource.
**Returns:** Returns the pointer to the surface. ## OnError\(\) ``` virtual void OHOS::Media::RecorderCallback::OnError (int32_t errorType, int32_t errorCode ) ``` **Description:** Called when an error occurs during recording. This callback is used to report recording errors. **Parameters:**

Name

Description

errorType Indicates the error type. For details, see RecorderErrorType.
errorCode Indicates the error code.
## OnInfo\(\) ``` 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\(\) ``` int32_t OHOS::Media::Recorder::Pause () ``` **Description:** Pauses recording. After [Start](MultiMedia_Recorder.md#gac3aaa32627f0799dea65e51356b91bfb) 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 [media\_errors.h](media_errors-h.md) otherwise. ## Prepare\(\) ``` int32_t OHOS::Media::Recorder::Prepare () ``` **Description:** Prepares for recording. This function must be called before [Start](MultiMedia_Recorder.md#gac3aaa32627f0799dea65e51356b91bfb). **Returns:** Returns **SUCCESS** if the preparation is successful; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## Release\(\) ``` 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](media_errors-h.md) otherwise. ## Reset\(\) ``` int32_t OHOS::Media::Recorder::Reset () ``` **Description:** Resets the recording. After the function is called, add a recording source by calling [SetVideoSource](MultiMedia_Recorder.md#ga9e12ef9700d06c7620f9e3d7b4d844ca) or [SetAudioSource](MultiMedia_Recorder.md#gae287f59da8b3f1b6ca9f1c0e58a6565a), set related parameters, and call [Start](MultiMedia_Recorder.md#gac3aaa32627f0799dea65e51356b91bfb) to start recording again after [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387) is called. **Returns:** Returns **SUCCESS** if the recording is reset; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## Resume\(\) ``` int32_t OHOS::Media::Recorder::Resume () ``` **Description:** Resumes recording. You can call this function to resume recording after [Pause](MultiMedia_Recorder.md#ga71da5cc2720b336f0daadbe09d61c695) is called. **Returns:** Returns **SUCCESS** if the recording is resumed; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## SetAudioChannels\(\) ``` 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 [SetAudioSource](MultiMedia_Recorder.md#gae287f59da8b3f1b6ca9f1c0e58a6565a) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **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 [media\_errors.h](media_errors-h.md) otherwise. ## SetAudioEncoder\(\) ``` int32_t OHOS::Media::Recorder::SetAudioEncoder (int32_t sourceId, [AudioCodecFormat](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 [SetAudioSource](MultiMedia_Recorder.md#gae287f59da8b3f1b6ca9f1c0e58a6565a) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **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 [media\_errors.h](media_errors-h.md) otherwise. ## SetAudioEncodingBitRate\(\) ``` 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 [SetAudioSource](MultiMedia_Recorder.md#gae287f59da8b3f1b6ca9f1c0e58a6565a) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **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 [media\_errors.h](media_errors-h.md) otherwise. ## SetAudioSampleRate\(\) ``` 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 [SetAudioSource](MultiMedia_Recorder.md#gae287f59da8b3f1b6ca9f1c0e58a6565a) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **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 [media\_errors.h](media_errors-h.md) otherwise. ## SetAudioSource\(\) ``` int32_t OHOS::Media::Recorder::SetAudioSource ([AudioSourceType](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 [media\_errors.h](media_errors-h.md) otherwise. ## SetCaptureRate\(\) ``` int32_t OHOS::Media::Recorder::SetCaptureRate (int32_t sourceId, double fps ) ``` **Description:** Sets the video capture rate. This function must be called after [SetVideoSource](MultiMedia_Recorder.md#ga9e12ef9700d06c7620f9e3d7b4d844ca) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). 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 [media\_errors.h](media_errors-h.md) otherwise. ## SetFileSplitDuration\(\) ``` int32_t OHOS::Media::Recorder::SetFileSplitDuration ([FileSplitType](MultiMedia_Recorder.md#ga8759c7e5a74964a584a716f4ec0b7edb) type, int64_t timestamp, uint32_t duration ) ``` **Description:** Manually splits a video. This function must be called after [Start](MultiMedia_Recorder.md#gac3aaa32627f0799dea65e51356b91bfb). After this function is called, the file is split based on the manual split type. After the manual split is complete, the initial split type is used. This function can be called again only after **RECORDER\_INFO\_FILE\_SPLIT\_FINISHED** is reported. **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](media_errors-h.md) otherwise. ## SetMaxDuration\(\) ``` 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 [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). If the setting is valid, **RECORDER\_INFO\_MAX\_DURATION\_APPROACHING** is reported through **OnInfo** in the [RecorderCallback](OHOS-Media-RecorderCallback.md) class when only one second or 10% is left to reach the allowed duration. If the recording output file is set by calling [SetOutputFile](MultiMedia_Recorder.md#ga500d2bc895852fe292d7397d8450d091), call [SetNextOutputFile](MultiMedia_Recorder.md#ga8545fe87eb4bd399525e4c5fb414d7cb) 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](media_errors-h.md) otherwise. ## SetMaxFileSize\(\) ``` 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](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). If the setting is valid, **RECORDER\_INFO\_MAX\_DURATION\_APPROACHING** is reported through **OnInfo** in the [RecorderCallback](OHOS-Media-RecorderCallback.md) class when only 100 KB or 10% is left to reach the allowed size. If the recording output file is set by calling [SetOutputFile](MultiMedia_Recorder.md#ga500d2bc895852fe292d7397d8450d091), call [SetNextOutputFile](MultiMedia_Recorder.md#ga8545fe87eb4bd399525e4c5fb414d7cb) 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](MultiMedia_Recorder.md#gaf2806f0fddd17a3e59eb7c5c740470d6), **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](media_errors-h.md) otherwise. ## SetNextOutputFile\(\) ``` int32_t OHOS::Media::Recorder::SetNextOutputFile (int32_t fd) ``` **Description:** Sets the FD of the next output file. If [SetOutputFile](MultiMedia_Recorder.md#ga500d2bc895852fe292d7397d8450d091) 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:**

Name

Description

fd Indicates the FD of the next output file.
**Returns:** Returns **SUCCESS** if the setting is successful; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## SetOutputFile\(\) ``` int32_t OHOS::Media::Recorder::SetOutputFile (int32_t fd) ``` **Description:** Sets the file descriptor \(FD\) of the output file. This function must be called before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **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](media_errors-h.md) otherwise. ## SetOutputFormat\(\) ``` int32_t OHOS::Media::Recorder::SetOutputFormat ([OutputFormatType](MultiMedia_Recorder.md#ga3dfe2e61369bf1c081ce569e235354df) format) ``` **Description:** Sets the output file format. This function must be called before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **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](media_errors-h.md) otherwise. ## SetOutputPath\(\) ``` int32_t OHOS::Media::Recorder::SetOutputPath (const string & path) ``` **Description:** Sets the output file path. This function must be called before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387) and One of them [SetOutputFile](MultiMedia_Recorder.md#ga500d2bc895852fe292d7397d8450d091) 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 [media\_errors.h](media_errors-h.md) otherwise. ## SetParameter\(\) ``` int32_t OHOS::Media::Recorder::SetParameter (int32_t sourceId, const [Format](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 [media\_errors.h](media_errors-h.md) otherwise. ## SetRecorderCallback\(\) ``` int32_t OHOS::Media::Recorder::SetRecorderCallback (const std::shared_ptr< [RecorderCallback](OHOS-Media-RecorderCallback.md) > & callback) ``` **Description:** Registers a recording listener. This function must be called before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **Parameters:**

Name

Description

callback Indicates the recording listener to register. For details, see RecorderCallback.
**Returns:** Returns **SUCCESS** if the listener is registered; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## SetVideoEncoder\(\) ``` int32_t OHOS::Media::Recorder::SetVideoEncoder (int32_t sourceId, [VideoCodecFormat](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](MultiMedia_Recorder.md#ga9e12ef9700d06c7620f9e3d7b4d844ca) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **Parameters:**

Name

Description

sourceId Indicates the video source ID, which can be obtained from SetVideoSource.
encoder Indicates the video encoder to set.
**Returns:** Returns **SUCCESS** if the setting is successful; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## SetVideoEncodingBitRate\(\) ``` 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](MultiMedia_Recorder.md#ga9e12ef9700d06c7620f9e3d7b4d844ca) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **Parameters:**

Name

Description

sourceId Indicates the video source ID, which can be obtained from SetVideoSource.
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](media_errors-h.md) otherwise. ## SetVideoFrameRate\(\) ``` 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](MultiMedia_Recorder.md#ga9e12ef9700d06c7620f9e3d7b4d844ca) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **Parameters:**

Name

Description

sourceId Indicates the video source ID, which can be obtained from SetVideoSource.
frameRate Indicates the frame rate to set.
**Returns:** Returns **SUCCESS** if the setting is successful; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## SetVideoSize\(\) ``` 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](MultiMedia_Recorder.md#ga9e12ef9700d06c7620f9e3d7b4d844ca) but before [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **Parameters:**

Name

Description

sourceId Indicates the video source ID, which can be obtained from SetVideoSource.
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](media_errors-h.md) otherwise. ## SetVideoSource\(\) ``` int32_t OHOS::Media::Recorder::SetVideoSource ([VideoSourceType](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 [media\_errors.h](media_errors-h.md) otherwise. ## Start\(\) ``` int32_t OHOS::Media::Recorder::Start () ``` **Description:** Starts recording. This function must be called after [Prepare](MultiMedia_Recorder.md#ga15d2f3416bb735a0715e1e79be226387). **Returns:** Returns **SUCCESS** if the recording is started; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## Stop\(\) ``` int32_t OHOS::Media::Recorder::Stop (bool block) ``` **Description:** Stops recording. **Parameters:**

Name

Description

block Indicates the stop mode. The value true indicates that the processing stops after all caches are processed, and false indicates that the processing stops immediately and all caches are discarded.
**Returns:** Returns **SUCCESS** if the recording is stopped; returns an error code defined in [media\_errors.h](media_errors-h.md) otherwise. ## **Variable ** ## RCORDER\_PRE\_CACHE\_DURATION ``` const string OHOS::Media::RCORDER_PRE_CACHE_DURATION = "pre-cache-duration" ``` **Description:** This constant can be used as the value of [Format](OHOS-Media-Format.md) in [SetParameter](Parameter.md#ga2779b5e59d43308c51f7be38b9c98ddb) to configure the duration for storing recorded data in the cache.