1# AVRecorder 2 3 4## Overview 5 6The AVRecorder module provides the APIs for requesting the recording capability. 7 8You can refer to the corresponding development guide and samples based on your development requirements. 9 10- [Using AVRecorder to Record Audio (C/C++)](../../media/media/using-ndk-avrecorder-for-audio-recording.md) 11- [Using AVRecorder to Record Videos (C/C++)](../../media/media/using-ndk-avrecorder-for-video-recording.md) 12 13**System capability**: SystemCapability.Multimedia.Media.AVRecorder 14 15**Since**: 18 16 17 18## Summary 19 20 21### Files 22 23| Name| Description| 24| -------- | -------- | 25| [avrecorder.h](avrecorder_8h.md) | Declares the AVRecorder APIs. Applications can use the APIs to record media data.| 26| [avrecorder_base.h](avrecorder__base_8h.md) | Declares the struct and enums used by the AVRecorder.| 27 28 29### Structs 30 31| Name| Description| 32| -------- | -------- | 33| struct [OH_AVRecorder_Profile](_o_h___a_v_recorder___profile.md) | Describes the parameters used for audio and video recording.<br>You can choose to record only audio or only video by setting the parameters. When **audioBitrate** or **audioChannels** is set to **0**, audio recording is disabled. When **videoFrameWidth** or **videoFrameHeight** is set to **0**, video recording is disabled.| 34| struct [OH_AVRecorder_Location](_o_h___a_v_recorder___location.md) | Describes the geographical location information about a media asset.| 35| struct [OH_AVRecorder_MetadataTemplate](_o_h___a_v_recorder___metadata_template.md) | Describes the basic template of metadata.| 36| struct [OH_AVRecorder_Metadata](_o_h___a_v_recorder___metadata.md) | Describes the metadata.| 37| struct [OH_AVRecorder_Config](_o_h___a_v_recorder___config.md) | Describes the AVRecorder configuration.| 38| struct [OH_AVRecorder_Range](_o_h___a_v_recorder___range.md) | Describes the range.| 39| struct [OH_AVRecorder_EncoderInfo](_o_h___a_v_recorder___encoder_info.md) | Describes the encoder information.| 40 41 42### Types 43 44| Name| Description| 45| -------- | -------- | 46| typedef struct [OH_AVRecorder](#oh_avrecorder) [OH_AVRecorder](#oh_avrecorder) | Defines a struct for the AVRecorder.| 47| typedef enum [OH_AVRecorder_AudioSourceType](#oh_avrecorder_audiosourcetype-1) [OH_AVRecorder_AudioSourceType](#oh_avrecorder_audiosourcetype) | Defines an enum for the audio source types of the AVRecorder.| 48| typedef enum [OH_AVRecorder_VideoSourceType](#oh_avrecorder_videosourcetype-1) [OH_AVRecorder_VideoSourceType](#oh_avrecorder_videosourcetype) | Defines an enum for the video source types of the AVRecorder.| 49| typedef enum [OH_AVRecorder_CodecMimeType](#oh_avrecorder_codecmimetype-1) [OH_AVRecorder_CodecMimeType](#oh_avrecorder_codecmimetype) | Defines an enum for the MIME types of the encoder.| 50| typedef enum [OH_AVRecorder_ContainerFormatType](#oh_avrecorder_containerformattype-1) [OH_AVRecorder_ContainerFormatType](#oh_avrecorder_containerformattype) | Defines an enum for the Container Format Types (CFTs).| 51| typedef enum [OH_AVRecorder_State](#oh_avrecorder_state-1) [OH_AVRecorder_State](#oh_avrecorder_state) | Defines an enum for the AVRecorder states.| 52| typedef enum [OH_AVRecorder_StateChangeReason](#oh_avrecorder_statechangereason-1) [OH_AVRecorder_StateChangeReason](#oh_avrecorder_statechangereason) | Defines an enum for the reasons for AVRecorder state changes.| 53| typedef enum [OH_AVRecorder_FileGenerationMode](#oh_avrecorder_filegenerationmode-1) [OH_AVRecorder_FileGenerationMode](#oh_avrecorder_filegenerationmode) | Defines an enum for the modes available for creating a recording file.| 54| typedef struct [OH_AVRecorder_Profile](_o_h___a_v_recorder___profile.md) [OH_AVRecorder_Profile](#oh_avrecorder_profile) | Defines a struct for the parameters used for audio and video recording.<br>You can choose to record only audio or only video by setting the parameters. When **audioBitrate** or **audioChannels** is set to **0**, audio recording is disabled. When **videoFrameWidth** or **videoFrameHeight** is set to **0**, video recording is disabled.| 55| typedef struct [OH_AVRecorder_Location](_o_h___a_v_recorder___location.md) [OH_AVRecorder_Location](#oh_avrecorder_location) | Defines a struct for the geographical location information about a media asset.| 56| typedef struct [OH_AVRecorder_MetadataTemplate](_o_h___a_v_recorder___metadata_template.md) [OH_AVRecorder_MetadataTemplate](#oh_avrecorder_metadatatemplate) | Defines a struct for the basic template of metadata.| 57| typedef struct [OH_AVRecorder_Metadata](_o_h___a_v_recorder___metadata.md) [OH_AVRecorder_Metadata](#oh_avrecorder_metadata) | Defines a struct for the metadata.| 58| typedef struct [OH_AVRecorder_Config](_o_h___a_v_recorder___config.md) [OH_AVRecorder_Config](#oh_avrecorder_config) | Defines a struct for the AVRecorder configuration.| 59| typedef struct [OH_AVRecorder_Range](_o_h___a_v_recorder___range.md) [OH_AVRecorder_Range](#oh_avrecorder_range) | Defines a struct for the range.| 60| typedef struct [OH_AVRecorder_EncoderInfo](_o_h___a_v_recorder___encoder_info.md) [OH_AVRecorder_EncoderInfo](#oh_avrecorder_encoderinfo) | Defines a struct for the encoder information.| 61| typedef void(\* [OH_AVRecorder_OnStateChange](#oh_avrecorder_onstatechange)) ([OH_AVRecorder](#oh_avrecorder) \*recorder, [OH_AVRecorder_State](#oh_avrecorder_state) state, [OH_AVRecorder_StateChangeReason](#oh_avrecorder_statechangereason) reason, void \*userData) | Defines a callback invoked when the AVRecorder state changes.| 62| typedef void(\* [OH_AVRecorder_OnError](#oh_avrecorder_onerror)) ([OH_AVRecorder](#oh_avrecorder) \*recorder, int32_t errorCode, const char \*errorMsg, void \*userData) | Defines a callback invoked when an error occurs during recording.| 63| typedef void(\* [OH_AVRecorder_OnUri](#oh_avrecorder_onuri)) ([OH_AVRecorder](#oh_avrecorder) \*recorder, OH_MediaAsset \*asset, void \*userData) | Defines a callback invoked when the recording is in OH_AVRecorder_FileGenerationMode.AVRECORDER_AUTO_CREATE_CAMERA_SCENE mode.| 64 65 66### Enums 67 68| Name| Description| 69| -------- | -------- | 70| [OH_AVRecorder_AudioSourceType](#oh_avrecorder_audiosourcetype-1) {<br>AVRECORDER_DEFAULT = 0,<br>AVRECORDER_MIC = 1,<br>AVRECORDER_VOICE_RECOGNITION = 2,<br>AVRECORDER_VOICE_COMMUNICATION = 7,<br>AVRECORDER_VOICE_MESSAGE = 10,<br>AVRECORDER_CAMCORDER = 13<br>} | Enumerates the audio source types of the AVRecorder.| 71| [OH_AVRecorder_VideoSourceType](#oh_avrecorder_videosourcetype-1) {<br>AVRECORDER_SURFACE_YUV = 0,<br>AVRECORDER_SURFACE_ES = 1 } | Enumerates the video source types of the AVRecorder.| 72| [OH_AVRecorder_CodecMimeType](#oh_avrecorder_codecmimetype-1) {<br>AVRECORDER_VIDEO_AVC = 2,<br>AVRECORDER_AUDIO_AAC = 3,<br>AVRECORDER_AUDIO_MP3 = 4,<br>AVRECORDER_AUDIO_G711MU = 5,<br>AVRECORDER_VIDEO_MPEG4 = 6,<br>AVRECORDER_VIDEO_HEVC = 8,<br>AVRECORDER_AUDIO_AMR_NB = 9,<br>AVRECORDER_AUDIO_AMR_WB = 10<br>} | Enumerates the MIME types of the encoder.| 73| [OH_AVRecorder_ContainerFormatType](#oh_avrecorder_containerformattype-1) {<br>AVRECORDER_CFT_MPEG_4 = 2,<br>AVRECORDER_CFT_MPEG_4A = 6,<br>AVRECORDER_CFT_AMR = 8,<br>AVRECORDER_CFT_MP3 = 9,<br>AVRECORDER_CFT_WAV = 10<br>} | Enumerates the CFTs.| 74| [OH_AVRecorder_State](#oh_avrecorder_state-1) {<br>AVRECORDER_IDLE = 0,<br>AVRECORDER_PREPARED = 1,<br>AVRECORDER_STARTED = 2,<br>AVRECORDER_PAUSED = 3,<br>AVRECORDER_STOPPED = 4,<br>AVRECORDER_RELEASED = 5, AVRECORDER_ERROR = 6<br>} | Enumerates the AVRecorder states.| 75| [OH_AVRecorder_StateChangeReason](#oh_avrecorder_statechangereason-1) {<br>AVRECORDER_USER = 0,<br>AVRECORDER_BACKGROUND = 1<br>} | Enumerates the reasons for AVRecorder state changes.| 76| [OH_AVRecorder_FileGenerationMode](#oh_avrecorder_filegenerationmode-1) {<br>AVRECORDER_APP_CREATE = 0, AVRECORDER_AUTO_CREATE_CAMERA_SCENE = 1<br>} | Enumerates the modes available for creating a recording file.| 77 78 79### Functions 80 81| Name| Description| 82| -------- | -------- | 83| [OH_AVRecorder](#oh_avrecorder) \* [OH_AVRecorder_Create](#oh_avrecorder_create) (void) | Creates an AVRecorder instance. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_IDLE state.| 84| OH_AVErrCode [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) ([OH_AVRecorder](#oh_avrecorder) \*recorder, [OH_AVRecorder_Config](_o_h___a_v_recorder___config.md) \*config) | Sets AVRecorder parameters to prepare for recording. This function must be called after [OH_AVRecorder_Start](#oh_avrecorder_start) is successfully triggered. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_PREPARED state.| 85| OH_AVErrCode [OH_AVRecorder_GetAVRecorderConfig](#oh_avrecorder_getavrecorderconfig) ([OH_AVRecorder](#oh_avrecorder) \*recorder, [OH_AVRecorder_Config](_o_h___a_v_recorder___config.md) \*\*config) | Obtains the AVRecorder configuration. This function must be called after the recording preparation is complete. **config** must be set to a null pointer. The framework layer allocates and releases the memory in a unified manner to avoid issues with memory management, such as leaks or double freeing.| 86| OH_AVErrCode [OH_AVRecorder_GetInputSurface](#oh_avrecorder_getinputsurface) ([OH_AVRecorder](#oh_avrecorder) \*recorder, OHNativeWindow \*\*window) | Obtains an input surface. This function must be called after [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) is successfully triggered and before [OH_AVRecorder_Start](#oh_avrecorder_start) is called.| 87| OH_AVErrCode [OH_AVRecorder_UpdateRotation](#oh_avrecorder_updaterotation) ([OH_AVRecorder](#oh_avrecorder) \*recorder, int32_t rotation) | Updates the video rotation angle. This function must be called after [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) is successfully triggered and before [OH_AVRecorder_Start](#oh_avrecorder_start) is called.| 88| OH_AVErrCode [OH_AVRecorder_Start](#oh_avrecorder_start) ([OH_AVRecorder](#oh_avrecorder) \*recorder) | Starts recording. This function must be called after [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) is successfully triggered. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_STARTED state.| 89| OH_AVErrCode [OH_AVRecorder_Pause](#oh_avrecorder_pause) ([OH_AVRecorder](#oh_avrecorder) \*recorder) | Pauses recording. This function must be called after [OH_AVRecorder_Start](#oh_avrecorder_start) is successfully triggered and the AVRecorder is in the AVRECORDER_STARTED state. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_PAUSED state.| 90| OH_AVErrCode [OH_AVRecorder_Resume](#oh_avrecorder_resume) ([OH_AVRecorder](#oh_avrecorder) \*recorder) | Resumes recording. This function must be called after [OH_AVRecorder_Pause](#oh_avrecorder_pause) is successfully triggered and the AVRecorder is in the AVRECORDER_PAUSED state. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_STARTED state.| 91| OH_AVErrCode [OH_AVRecorder_Stop](#oh_avrecorder_stop) ([OH_AVRecorder](#oh_avrecorder) \*recorder) | Stops recording. This function must be called after [OH_AVRecorder_Start](#oh_avrecorder_start) is successfully triggered. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_STOPPED state.| 92| OH_AVErrCode [OH_AVRecorder_Reset](#oh_avrecorder_reset) ([OH_AVRecorder](#oh_avrecorder) \*recorder) | Resets the recording state. This function must be called when the AVRecorder is not in the AVRECORDER_RELEASED state. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_IDLE state.| 93| OH_AVErrCode [OH_AVRecorder_Release](#oh_avrecorder_release) ([OH_AVRecorder](#oh_avrecorder) \*recorder) | Releases recording resources. After this API is successfully called, the AVRecorder transitions to the AVRECORDER_RELEASED state. The recorder memory will be released. The application layer must explicitly set the recorder to a null pointer to avoid access to wild pointers.| 94| OH_AVErrCode [OH_AVRecorder_GetAvailableEncoder](#oh_avrecorder_getavailableencoder) ([OH_AVRecorder](#oh_avrecorder) \*recorder, [OH_AVRecorder_EncoderInfo](_o_h___a_v_recorder___encoder_info.md) \*\*info, int32_t \*length) | Obtains the available encoders and encoder information of the AVRecorder. **info** must be set to a null pointer. The framework layer allocates and releases the memory in a unified manner to avoid issues with memory management, such as leaks or double freeing.| 95| OH_AVErrCode [OH_AVRecorder_SetStateCallback](#oh_avrecorder_setstatecallback) ([OH_AVRecorder](#oh_avrecorder) \*recorder, [OH_AVRecorder_OnStateChange](#oh_avrecorder_onstatechange) callback, void \*userData) | Sets a state callback so that the application can respond to state change events generated by the AVRecorder. This function must be called before [OH_AVRecorder_Start](#oh_avrecorder_start) is called.| 96| OH_AVErrCode [OH_AVRecorder_SetErrorCallback](#oh_avrecorder_seterrorcallback) ([OH_AVRecorder](#oh_avrecorder) \*recorder, [OH_AVRecorder_OnError](#oh_avrecorder_onerror) callback, void \*userData) | Sets an error callback so that the application can respond to error events generated by the AVRecorder. This function must be called before [OH_AVRecorder_Start](#oh_avrecorder_start) is called.| 97| OH_AVErrCode [OH_AVRecorder_SetUriCallback](#oh_avrecorder_seturicallback) ([OH_AVRecorder](#oh_avrecorder) \*recorder, [OH_AVRecorder_OnUri](#oh_avrecorder_onuri) callback, void \*userData) | Sets a URI callback so that the application can respond to URI events generated by the AVRecorder. This function must be called before [OH_AVRecorder_Start](#oh_avrecorder_start) is called.| 98 99 100## Type Description 101 102 103### OH_AVRecorder 104 105``` 106typedef struct OH_AVRecorder OH_AVRecorder 107``` 108 109**Description** 110 111Defines a struct for the AVRecorder. 112 113**System capability**: SystemCapability.Multimedia.Media.AVRecorder 114 115**Since**: 18 116 117 118### OH_AVRecorder_AudioSourceType 119 120``` 121typedef enum OH_AVRecorder_AudioSourceType OH_AVRecorder_AudioSourceType 122``` 123 124**Description** 125 126Defines an enum for the audio source types of the AVRecorder. 127 128**System capability**: SystemCapability.Multimedia.Media.AVRecorder 129 130**Since**: 18 131 132 133### OH_AVRecorder_CodecMimeType 134 135``` 136typedef enum OH_AVRecorder_CodecMimeType OH_AVRecorder_CodecMimeType 137``` 138 139**Description** 140 141Defines an enum for the MIME types of the encoder. 142 143**System capability**: SystemCapability.Multimedia.Media.AVRecorder 144 145**Since**: 18 146 147 148### OH_AVRecorder_Config 149 150``` 151typedef struct OH_AVRecorder_Config OH_AVRecorder_Config 152``` 153 154**Description** 155 156Defines a struct for the AVRecorder configuration. 157 158**System capability**: SystemCapability.Multimedia.Media.AVRecorder 159 160**Since**: 18 161 162 163### OH_AVRecorder_ContainerFormatType 164 165``` 166typedef enum OH_AVRecorder_ContainerFormatType OH_AVRecorder_ContainerFormatType 167``` 168 169**Description** 170 171Defines an enum for the CFTs. 172 173**System capability**: SystemCapability.Multimedia.Media.AVRecorder 174 175**Since**: 18 176 177 178### OH_AVRecorder_EncoderInfo 179 180``` 181typedef struct OH_AVRecorder_EncoderInfo OH_AVRecorder_EncoderInfo 182``` 183 184**Description** 185 186Defines a struct for the encoder information. 187 188**System capability**: SystemCapability.Multimedia.Media.AVRecorder 189 190**Since**: 18 191 192 193### OH_AVRecorder_FileGenerationMode 194 195``` 196typedef enum OH_AVRecorder_FileGenerationMode OH_AVRecorder_FileGenerationMode 197``` 198 199**Description** 200 201Defines an enum for the modes available for creating a recording file. 202 203**System capability**: SystemCapability.Multimedia.Media.AVRecorder 204 205**Since**: 18 206 207 208### OH_AVRecorder_Location 209 210``` 211typedef struct OH_AVRecorder_Location OH_AVRecorder_Location 212``` 213 214**Description** 215 216Defines a struct for the geographical location information about a media asset. 217 218**System capability**: SystemCapability.Multimedia.Media.AVRecorder 219 220**Since**: 18 221 222 223### OH_AVRecorder_Metadata 224 225``` 226typedef struct OH_AVRecorder_Metadata OH_AVRecorder_Metadata 227``` 228 229**Description** 230 231Defines a struct for the metadata. 232 233**System capability**: SystemCapability.Multimedia.Media.AVRecorder 234 235**Since**: 18 236 237 238### OH_AVRecorder_MetadataTemplate 239 240``` 241typedef struct OH_AVRecorder_MetadataTemplate OH_AVRecorder_MetadataTemplate 242``` 243 244**Description** 245 246Defines a struct for the basic template of metadata. 247 248**System capability**: SystemCapability.Multimedia.Media.AVRecorder 249 250**Since**: 18 251 252 253### OH_AVRecorder_OnError 254 255``` 256typedef void (*OH_AVRecorder_OnError)(OH_AVRecorder *recorder, int32_t errorCode, const char *errorMsg, void *userData) 257``` 258 259**Description** 260 261Defines a callback invoked when an error occurs during recording. 262 263**System capability**: SystemCapability.Multimedia.Media.AVRecorder 264 265**Since**: 18 266 267**Parameters** 268 269| Name| Description| 270| -------- | -------- | 271| recorder | Pointer to an **OH_AVRecorder** instance.| 272| errorCode | Error code.| 273| errorMsg | Pointer to the error message.| 274| userData | Pointer to user-defined data.| 275 276 277### OH_AVRecorder_OnStateChange 278 279``` 280typedef void (*OH_AVRecorder_OnStateChange)(OH_AVRecorder *recorder, OH_AVRecorder_State state, OH_AVRecorder_StateChangeReason reason, void *userData) 281``` 282 283**Description** 284 285Defines a callback invoked when the AVRecorder state changes. 286 287**System capability**: SystemCapability.Multimedia.Media.AVRecorder 288 289**Since**: 18 290 291**Parameters** 292 293| Name| Description| 294| -------- | -------- | 295| recorder | Pointer to an **OH_AVRecorder** instance.| 296| state | AVRecorder state. For details, see [OH_AVRecorder_State](#oh_avrecorder_state).| 297| reason | Reason for the AVRecorder state change. For details, see [OH_AVRecorder_StateChangeReason](#oh_avrecorder_statechangereason).| 298| userData | Pointer to user-defined data.| 299 300 301### OH_AVRecorder_OnUri 302 303``` 304typedef void (*OH_AVRecorder_OnUri)(OH_AVRecorder *recorder, OH_MediaAsset *asset, void *userData) 305``` 306 307**Description** 308 309Defines a callback invoked when the recording is in OH_AVRecorder_FileGenerationMode.AVRECORDER_AUTO_CREATE_CAMERA_SCENE mode. 310 311**System capability**: SystemCapability.Multimedia.Media.AVRecorder 312 313**Since**: 18 314 315**Parameters** 316 317| Name| Description| 318| -------- | -------- | 319| recorder | Pointer to an **OH_AVRecorder** instance.| 320| asset | Pointer to an **OH_MediaAsset** instance.| 321| userData | Pointer to user-defined data.| 322 323 324### OH_AVRecorder_Profile 325 326``` 327typedef struct OH_AVRecorder_Profile OH_AVRecorder_Profile 328``` 329 330**Description** 331 332Defines a struct for the parameters used for audio and video recording. 333 334You can choose to record only audio or only video by setting the parameters. When **audioBitrate** or **audioChannels** is set to **0**, audio recording is disabled. When **videoFrameWidth** or **videoFrameHeight** is set to **0**, video recording is disabled. 335 336For details about the value range of each parameter, see [AVRecorderProfile](js-apis-media.md#avrecorderprofile9). 337 338**System capability**: SystemCapability.Multimedia.Media.AVRecorder 339 340**Since**: 18 341 342 343### OH_AVRecorder_Range 344 345``` 346typedef struct OH_AVRecorder_Range OH_AVRecorder_Range 347``` 348 349**Description** 350 351Defines a struct for the range. 352 353**System capability**: SystemCapability.Multimedia.Media.AVRecorder 354 355**Since**: 18 356 357 358### OH_AVRecorder_State 359 360``` 361typedef enum OH_AVRecorder_State OH_AVRecorder_State 362``` 363 364**Description** 365 366Defines an enum for the AVRecorder states. 367 368**System capability**: SystemCapability.Multimedia.Media.AVRecorder 369 370**Since**: 18 371 372 373### OH_AVRecorder_StateChangeReason 374 375``` 376typedef enum OH_AVRecorder_StateChangeReason OH_AVRecorder_StateChangeReason 377``` 378 379**Description** 380 381Defines an enum for the reasons for AVRecorder state changes. 382 383**System capability**: SystemCapability.Multimedia.Media.AVRecorder 384 385**Since**: 18 386 387 388### OH_AVRecorder_VideoSourceType 389 390``` 391typedef enum OH_AVRecorder_VideoSourceType OH_AVRecorder_VideoSourceType 392``` 393 394**Description** 395 396Defines an enum for the video source types of the AVRecorder. 397 398**System capability**: SystemCapability.Multimedia.Media.AVRecorder 399 400**Since**: 18 401 402 403## Enum Description 404 405 406### OH_AVRecorder_AudioSourceType 407 408``` 409enum OH_AVRecorder_AudioSourceType 410``` 411 412**Description** 413 414Enumerates the audio source types of the AVRecorder. 415 416**System capability**: SystemCapability.Multimedia.Media.AVRecorder 417 418**Since**: 18 419 420| Value| Description| 421| -------- | -------- | 422| AVRECORDER_DEFAULT | Default audio source.| 423| AVRECORDER_MIC | Microphone audio source.| 424| AVRECORDER_VOICE_RECOGNITION | Audio source in speech recognition scenarios.| 425| AVRECORDER_VOICE_COMMUNICATION | Voice communication source.| 426| AVRECORDER_VOICE_MESSAGE | Voice message source.| 427| AVRECORDER_CAMCORDER | Audio source in camera recording scenarios.| 428 429 430### OH_AVRecorder_CodecMimeType 431 432``` 433enum OH_AVRecorder_CodecMimeType 434``` 435 436**Description** 437 438Enumerates the MIME types of the encoder. 439 440**System capability**: SystemCapability.Multimedia.Media.AVRecorder 441 442**Since**: 18 443 444| Value| Description| 445| -------- | -------- | 446| AVRECORDER_VIDEO_AVC | MIME type of the H.264 encoder.| 447| AVRECORDER_AUDIO_AAC | MIME type of the AAC encoder.| 448| AVRECORDER_AUDIO_MP3 | MIME type of the MP3 encoder.| 449| AVRECORDER_AUDIO_G711MU | MIME type of the G711-mulaw encoder.| 450| AVRECORDER_VIDEO_MPEG4 | MIME type of the MPEG4 encoder.| 451| AVRECORDER_VIDEO_HEVC | MIME type of the H.265 encoder.| 452| AVRECORDER_AUDIO_AMR_NB | MIME type of the AMR-NB codec.| 453| AVRECORDER_AUDIO_AMR_WB | MIME type of the AMR-WB codec.| 454 455 456### OH_AVRecorder_ContainerFormatType 457 458``` 459enum OH_AVRecorder_ContainerFormatType 460``` 461 462**Description** 463 464Enumerates the CFTs. 465 466**System capability**: SystemCapability.Multimedia.Media.AVRecorder 467 468**Since**: 18 469 470| Value| Description| 471| -------- | -------- | 472| AVRECORDER_CFT_MPEG_4 | Video container format mp4.| 473| AVRECORDER_CFT_MPEG_4A | Audio container format m4a.| 474| AVRECORDER_CFT_AMR | Audio container format amr.| 475| AVRECORDER_CFT_MP3 | Audio container format mp3.| 476| AVRECORDER_CFT_WAV | Audio container format wav.| 477 478 479### OH_AVRecorder_FileGenerationMode 480 481``` 482enum OH_AVRecorder_FileGenerationMode 483``` 484 485**Description** 486 487Enumerates the modes available for creating a recording file. 488 489**System capability**: SystemCapability.Multimedia.Media.AVRecorder 490 491**Since**: 18 492 493| Value| Description| 494| -------- | -------- | 495| AVRECORDER_APP_CREATE | The application creates a media file in the sandbox.| 496| AVRECORDER_AUTO_CREATE_CAMERA_SCENE | The system creates a media file. This value is valid only in camera recording scenarios.| 497 498 499### OH_AVRecorder_State 500 501``` 502enum OH_AVRecorder_State 503``` 504 505**Description** 506 507Enumerates the AVRecorder states. 508 509**System capability**: SystemCapability.Multimedia.Media.AVRecorder 510 511**Since**: 18 512 513| Value| Description| 514| -------- | -------- | 515| AVRECORDER_IDLE | Idle. In this state, you can call **OH_AVRecorder_Prepare()** to set recording parameters, and the AVRecorder transitions to the AVRECORDER_PREPARED state.| 516| AVRECORDER_PREPARED | Prepared. After the parameters are set, you can call **OH_AVRecorder_Start()** to start recording, and the AVRecorder transitions to the AVRECORDER_STARTED state.| 517| AVRECORDER_STARTED | Started. Recording is in progress. In this case, you can call **OH_AVRecorder_Pause()** to pause recording, and the AVRecorder transitions to the AVRECORDER_PAUSED state. You can also call **OH_AVRecorder_Stop()** to stop recording, and the AVRecorder transitions to the AVRECORDER_STOPPED state.| 518| AVRECORDER_PAUSED | Paused. In this state, you can call **OH_AVRecorder_Resume()** to resume recording, and the AVRecorder transitions to the AVRECORDER_STARTED state. You can also call **OH_AVRecorder_Stop()** to stop recording, and the AVRecorder transitions to the AVRECORDER_STOPPED state.| 519| AVRECORDER_STOPPED | Stopped. In this state, you can call **OH_AVRecorder_Prepare()** to set recording parameters, and the AVRecorder transitions to the AVRECORDER_PREPARED state again.| 520| AVRECORDER_RELEASED | Released. The recording resources are released. No operation can be performed at this time. In any other state, you can call **OH_AVRecorder_Release()** to transition to the AVRECORDER_RELEASED state.| 521| AVRECORDER_ERROR | Error state. The AVRecorder transitions to this state when an irreversible error occurs in the instance. In this state, the OH_AVRecorder_OnError event is reported, with the detailed error cause. You should call **OH_AVRecorder_Reset()** to reset the AVRecorder instance or call **OH_AVRecorder_Release()** to release resources.| 522 523 524### OH_AVRecorder_StateChangeReason 525 526``` 527enum OH_AVRecorder_StateChangeReason 528``` 529 530**Description** 531 532Enumerates the reasons for AVRecorder state changes. 533 534**System capability**: SystemCapability.Multimedia.Media.AVRecorder 535 536**Since**: 18 537 538| Value| Description| 539| -------- | -------- | 540| AVRECORDER_USER | The state change is caused by user operations.| 541| AVRECORDER_BACKGROUND | The state change is caused by background operations.| 542 543 544### OH_AVRecorder_VideoSourceType 545 546``` 547enum OH_AVRecorder_VideoSourceType 548``` 549 550**Description** 551 552Enumerates the video source types of the AVRecorder. 553 554**System capability**: SystemCapability.Multimedia.Media.AVRecorder 555 556**Since**: 18 557 558| Value| Description| 559| -------- | -------- | 560| AVRECORDER_SURFACE_YUV | Raw data surface.| 561| AVRECORDER_SURFACE_ES | ES data surface.| 562 563 564## Function Description 565 566 567### OH_AVRecorder_Create() 568 569``` 570OH_AVRecorder *OH_AVRecorder_Create(void) 571``` 572 573**Description** 574 575Creates an AVRecorder instance. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_IDLE state. 576 577**System capability**: SystemCapability.Multimedia.Media.AVRecorder 578 579**Since**: 18 580 581**Returns** 582 583Returns the pointer to the **OH_AVRecorder** instance created if the operation is successful; returns a null pointer otherwise. 584 585 586### OH_AVRecorder_Prepare() 587 588``` 589OH_AVErrCode OH_AVRecorder_Prepare(OH_AVRecorder *recorder, OH_AVRecorder_Config *config) 590``` 591 592**Description** 593 594Sets AVRecorder parameters to prepare for recording. This function must be called after [OH_AVRecorder_Start](#oh_avrecorder_start) is successfully triggered. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_PREPARED state. 595 596To record only audio, you do not need to set video parameters. Similarly, to record only video, you do not need to set audio parameters. 597 598**System capability**: SystemCapability.Multimedia.Media.AVRecorder 599 600**Since**: 18 601 602**Parameters** 603 604| Name| Description| 605| -------- | -------- | 606| recorder | Pointer to an **OH_AVRecorder** instance.| 607| config | Pointer to an [OH_AVRecorder_Config](_o_h___a_v_recorder___config.md) instance. For details, see [OH_AVRecorder_Config](_o_h___a_v_recorder___config.md).| 608 609**Returns** 610 611Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 612 613**AV_ERR_OK**: The operation is successful. 614 615**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer or the preparation fails. 616 617 618### OH_AVRecorder_GetAVRecorderConfig() 619 620``` 621OH_AVErrCode OH_AVRecorder_GetAVRecorderConfig(OH_AVRecorder *recorder, OH_AVRecorder_Config **config) 622``` 623 624**Description** 625 626Obtains the AVRecorder configuration. This function must be called after the recording preparation is complete. **config** must be set to a null pointer. The framework layer allocates and releases the memory in a unified manner to avoid issues with memory management, such as leaks or double freeing. 627 628**System capability**: SystemCapability.Multimedia.Media.AVRecorder 629 630**Since**: 18 631 632**Parameters** 633 634| Name| Description| 635| -------- | -------- | 636| recorder | Pointer to an **OH_AVRecorder** instance.| 637| config | Double pointer to the [OH_AVRecorder_Config](_o_h___a_v_recorder___config.md) instance. For details, see [OH_AVRecorder_Config](_o_h___a_v_recorder___config.md).| 638 639**Returns** 640 641Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 642 643**AV_ERR_OK**: The operation is successful. 644 645**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer or **config** is not a null pointer. 646 647**AV_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory. 648 649 650### OH_AVRecorder_GetInputSurface() 651 652``` 653OH_AVErrCode OH_AVRecorder_GetInputSurface(OH_AVRecorder *recorder, OHNativeWindow **window) 654``` 655 656**Description** 657 658Obtains an input surface. This function must be called after [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) is successfully triggered and before [OH_AVRecorder_Start](#oh_avrecorder_start) is called. 659 660The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding video data. 661 662**System capability**: SystemCapability.Multimedia.Media.AVRecorder 663 664**Since**: 18 665 666**Parameters** 667 668| Name| Description| 669| -------- | -------- | 670| recorder | Pointer to an **OH_AVRecorder** instance.| 671| window | Double pointer to an **OHNativeWindow** instance. For details, see **OHNativeWindow**.| 672 673**Returns** 674 675Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 676 677**AV_ERR_OK**: The operation is successful. 678 679**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer. 680 681 682### OH_AVRecorder_UpdateRotation() 683 684``` 685OH_AVErrCode OH_AVRecorder_UpdateRotation(OH_AVRecorder *recorder, int32_t rotation) 686``` 687 688**Description** 689 690Updates the video rotation angle. This function must be called after [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) is successfully triggered and before [OH_AVRecorder_Start](#oh_avrecorder_start) is called. 691 692**System capability**: SystemCapability.Multimedia.Media.AVRecorder 693 694**Since**: 18 695 696**Parameters** 697 698| Name| Description| 699| -------- | -------- | 700| recorder | Pointer to an **OH_AVRecorder** instance.| 701| rotation | Video rotation angle. The value must be an integer in the range [0, 90, 180, 270].| 702 703**Returns** 704 705Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 706 707**AV_ERR_OK**: The operation is successful. 708 709**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer, **rotation** is invalid, or the update operation fails. 710 711 712### OH_AVRecorder_Start() 713 714``` 715OH_AVErrCode OH_AVRecorder_Start(OH_AVRecorder *recorder) 716``` 717 718**Description** 719 720Starts recording. This function must be called after [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) is successfully triggered. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_STARTED state. 721 722**System capability**: SystemCapability.Multimedia.Media.AVRecorder 723 724**Since**: 18 725 726**Parameters** 727 728| Name| Description| 729| -------- | -------- | 730| recorder | Pointer to an **OH_AVRecorder** instance.| 731 732**Returns** 733 734Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 735 736**AV_ERR_OK**: The operation is successful. 737 738**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer or recording fails to start. 739 740(Note: Do not use error codes that are not declared in this document.) 741 742### OH_AVRecorder_Pause() 743 744``` 745OH_AVErrCode OH_AVRecorder_Pause(OH_AVRecorder *recorder) 746``` 747 748**Description** 749 750Pauses recording. This function must be called after [OH_AVRecorder_Start](#oh_avrecorder_start) is successfully triggered and the AVRecorder is in the AVRECORDER_STARTED state. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_PAUSED state. 751 752Then, you can call [OH_AVRecorder_Resume](#oh_avrecorder_resume) to resume recording, and the AVRecorder transitions the AVRECORDER_STARTED state again. 753 754**System capability**: SystemCapability.Multimedia.Media.AVRecorder 755 756**Since**: 18 757 758**Parameters** 759 760| Name| Description| 761| -------- | -------- | 762| recorder | Pointer to an **OH_AVRecorder** instance.| 763 764**Returns** 765 766Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 767 768**AV_ERR_OK**: The operation is successful. 769 770**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer or the pause operation fails. 771 772 773### OH_AVRecorder_Resume() 774 775``` 776OH_AVErrCode OH_AVRecorder_Resume(OH_AVRecorder *recorder) 777``` 778 779**Description** 780 781Resumes recording. This function must be called after [OH_AVRecorder_Pause](#oh_avrecorder_pause) is successfully triggered and the AVRecorder is in the AVRECORDER_PAUSED state. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_STARTED state. 782 783**System capability**: SystemCapability.Multimedia.Media.AVRecorder 784 785**Since**: 18 786 787**Parameters** 788 789| Name| Description| 790| -------- | -------- | 791| recorder | Pointer to an **OH_AVRecorder** instance.| 792 793**Returns** 794 795Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 796 797**AV_ERR_OK**: The operation is successful. 798 799**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer or the resumption operation fails. 800 801 802### OH_AVRecorder_Stop() 803 804``` 805OH_AVErrCode OH_AVRecorder_Stop(OH_AVRecorder *recorder) 806``` 807 808**Description** 809 810Stops recording. This function must be called after [OH_AVRecorder_Start](#oh_avrecorder_start) is successfully triggered. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_STOPPED state. 811 812For audio-only recording, you can call [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) again for re-recording. For video-only recording or audio and video recording, you can call [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) and [OH_AVRecorder_GetInputSurface](#oh_avrecorder_getinputsurface) again for re-recording. 813 814**System capability**: SystemCapability.Multimedia.Media.AVRecorder 815 816**Since**: 18 817 818**Parameters** 819 820| Name| Description| 821| -------- | -------- | 822| recorder | Pointer to an **OH_AVRecorder** instance.| 823 824**Returns** 825 826Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 827 828**AV_ERR_OK**: The operation is successful. 829 830**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer or recording fails to stop. 831 832 833### OH_AVRecorder_Reset() 834 835``` 836OH_AVErrCode OH_AVRecorder_Reset(OH_AVRecorder *recorder) 837``` 838 839**Description** 840 841Resets the recording state. This function must be called when the AVRecorder is not in the AVRECORDER_RELEASED state. After this function is successfully called, the AVRecorder transitions to the AVRECORDER_IDLE state. 842 843For audio-only recording, you can call [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) again for re-recording. For video-only recording or audio and video recording, you can call [OH_AVRecorder_Prepare](#oh_avrecorder_prepare) and [OH_AVRecorder_GetInputSurface](#oh_avrecorder_getinputsurface) again for re-recording. 844 845**System capability**: SystemCapability.Multimedia.Media.AVRecorder 846 847**Since**: 18 848 849**Parameters** 850 851| Name| Description| 852| -------- | -------- | 853| recorder | Pointer to an **OH_AVRecorder** instance.| 854 855**Returns** 856 857Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 858 859**AV_ERR_OK**: The operation is successful. 860 861**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer or the resetting operation fails. 862 863 864### OH_AVRecorder_Release() 865 866``` 867OH_AVErrCode OH_AVRecorder_Release(OH_AVRecorder *recorder) 868``` 869 870**Description** 871 872Releases recording resources. After this API is successfully called, the AVRecorder transitions to the AVRECORDER_RELEASED state. The recorder memory will be released. The application layer must explicitly set the recorder to a null pointer to avoid access to wild pointers. 873 874 After the resources are released, you can no longer perform any operation on the **OH_AVRecorder** instance. 875 876**System capability**: SystemCapability.Multimedia.Media.AVRecorder 877 878**Since**: 18 879 880**Parameters** 881 882| Name| Description| 883| -------- | -------- | 884| recorder | Pointer to an **OH_AVRecorder** instance.| 885 886**Returns** 887 888Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 889 890**AV_ERR_OK**: The operation is successful. 891 892**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer or the release operation fails. 893 894 895### OH_AVRecorder_GetAvailableEncoder() 896 897``` 898OH_AVErrCode OH_AVRecorder_GetAvailableEncoder(OH_AVRecorder *recorder, OH_AVRecorder_EncoderInfo **info, int32_t *length) 899``` 900 901**Description** 902 903Obtains the available encoders and encoder information of the AVRecorder. **info** must be set to a null pointer. The framework layer allocates and releases the memory in a unified manner to avoid issues with memory management, such as leaks or double freeing. 904 905**System capability**: SystemCapability.Multimedia.Media.AVRecorder 906 907**Since**: 18 908 909**Parameters** 910 911| Name| Description| 912| -------- | -------- | 913| recorder | Pointer to an **OH_AVRecorder** instance.| 914| info | Double pointer to an [OH_AVRecorder_EncoderInfo](_o_h___a_v_recorder___encoder_info.md) instance. For details, see [OH_AVRecorder_EncoderInfo](_o_h___a_v_recorder___encoder_info.md).| 915| length | Pointer to the number of available encoders.| 916 917**Returns** 918 919Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 920 921**AV_ERR_OK**: The operation is successful. 922 923**AV_ERR_INVALID_VAL**: The input parameter **recorder** is a null pointer. 924 925**AV_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory. 926 927 928### OH_AVRecorder_SetStateCallback() 929 930``` 931OH_AVErrCode OH_AVRecorder_SetStateCallback( OH_AVRecorder *recorder, OH_AVRecorder_OnStateChange callback, void *userData) 932``` 933 934**Description** 935 936Sets a state callback so that the application can respond to state change events generated by the AVRecorder. This function must be called before [OH_AVRecorder_Start](#oh_avrecorder_start) is called. 937 938**System capability**: SystemCapability.Multimedia.Media.AVRecorder 939 940**Since**: 18 941 942**Parameters** 943 944| Name| Description| 945| -------- | -------- | 946| recorder | Pointer to an **OH_AVRecorder** instance.| 947| callback | State callback. For details, see [OH_AVRecorder_OnStateChange](#oh_avrecorder_onstatechange).| 948| userData | Pointer to user-defined data.| 949 950**Returns** 951 952Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 953 954**AV_ERR_OK**: The operation is successful. 955 956**AV_ERR_INVALID_VAL**: The input parameter **recorder** or **callback** is a null pointer. 957 958 959### OH_AVRecorder_SetErrorCallback() 960 961``` 962OH_AVErrCode OH_AVRecorder_SetErrorCallback(OH_AVRecorder *recorder, OH_AVRecorder_OnError callback, void *userData) 963``` 964 965**Description** 966 967Sets an error callback so that the application can respond to error events generated by the AVRecorder. This function must be called before [OH_AVRecorder_Start](#oh_avrecorder_start) is called. 968 969**System capability**: SystemCapability.Multimedia.Media.AVRecorder 970 971**Since**: 18 972 973**Parameters** 974 975| Name| Description| 976| -------- | -------- | 977| recorder | Pointer to an **OH_AVRecorder** instance.| 978| callback | Error callback. For details, see [OH_AVRecorder_OnError](#oh_avrecorder_onerror).| 979| userData | Pointer to user-defined data.| 980 981**Returns** 982 983Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 984 985**AV_ERR_OK**: The operation is successful. 986 987**AV_ERR_INVALID_VAL**: The input parameter **recorder** or **callback** is a null pointer. 988 989 990### OH_AVRecorder_SetUriCallback() 991 992``` 993OH_AVErrCode OH_AVRecorder_SetUriCallback(OH_AVRecorder *recorder, OH_AVRecorder_OnUri callback, void *userData) 994``` 995 996**Description** 997 998Sets a URI callback so that the application can respond to URI events generated by the AVRecorder. This function must be called before [OH_AVRecorder_Start](#oh_avrecorder_start) is called. 999 1000**System capability**: SystemCapability.Multimedia.Media.AVRecorder 1001 1002**Since**: 18 1003 1004**Parameters** 1005 1006| Name| Description| 1007| -------- | -------- | 1008| recorder | Pointer to an **OH_AVRecorder** instance.| 1009| callback | URI callback. For details, see [OH_AVRecorder_OnUri](#oh_avrecorder_onuri).| 1010| userData | Pointer to user-defined data.| 1011 1012**Returns** 1013 1014Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1015 1016**AV_ERR_OK**: The operation is successful. 1017 1018**AV_ERR_INVALID_VAL**: The input parameter **recorder** or **callback** is a null pointer. 1019