1# avtranscoder.h 2<!--Kit: Media Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @wang-haizhou6--> 5<!--Designer: @HmQQQ--> 6<!--Tester: @xchaosioda--> 7<!--Adviser: @zengyawen--> 8 9## Overview 10 11The file declares the native APIs provided by the AVTranscoder. You can use the APIs to transcode a source video file into a new video file. 12 13**File to include**: <multimedia/player_framework/avtranscoder.h> 14 15**Library**: libavtranscoder.so 16 17**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 18 19**Since**: 20 20 21**Related module**: [AVTranscoder](capi-avtranscoder.md) 22 23**Sample**: [AVPlayerNDKVideo](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/DocsSample/Media/AVPlayer/AVPlayerNDK) 24 25## Summary 26 27### Functions 28 29| Name| Description| 30| -- | -- | 31| [OH_AVTranscoder_Config *OH_AVTranscoderConfig_Create()](#oh_avtranscoderconfig_create) | Creates an instance of the transcoding configuration parameters.| 32| [OH_AVErrCode OH_AVTranscoderConfig_Release(OH_AVTranscoder_Config* config)](#oh_avtranscoderconfig_release) | Releases the resources of the transcoding configuration parameters.<br>After a successful call, the instance specified by **config** is released and set to nullptr.| 33| [OH_AVErrCode OH_AVTranscoderConfig_SetSrcFD(OH_AVTranscoder_Config *config, int32_t srcFd, int64_t srcOffset, int64_t length)](#oh_avtranscoderconfig_setsrcfd) | Sets the file descriptor of the source video for transcoding.<br>This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare).| 34| [OH_AVErrCode OH_AVTranscoderConfig_SetDstFD(OH_AVTranscoder_Config *config, int32_t dstFd)](#oh_avtranscoderconfig_setdstfd) | Sets the file descriptor of the output video for transcoding.<br>This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare).| 35| [OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoType(OH_AVTranscoder_Config *config, const char *mimeType)](#oh_avtranscoderconfig_setdstvideotype) | Sets the encoding format of the output video for transcoding.<br>Currently, only AVC and HEVC are supported. If the source video is in HEVC format, the default value is **HEVC**. Otherwise, the default value is **AVC**.<br>This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare).| 36| [OH_AVErrCode OH_AVTranscoderConfig_SetDstAudioType(OH_AVTranscoder_Config *config, const char *mimeType)](#oh_avtranscoderconfig_setdstaudiotype) | Sets the encoding format of the output audio for transcoding.<br>Currently, only AAC is supported. If this parameter is not set, AAC is used by default.<br>This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare).| 37| [OH_AVErrCode OH_AVTranscoderConfig_SetDstFileType(OH_AVTranscoder_Config *config, OH_AVOutputFormat mimeType)](#oh_avtranscoderconfig_setdstfiletype) | Sets the container format of the output video file for transcoding.<br>Currently, only MP4 is supported.<br>This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare).| 38| [OH_AVErrCode OH_AVTranscoderConfig_SetDstAudioBitrate(OH_AVTranscoder_Config *config, int32_t bitrate)](#oh_avtranscoderconfig_setdstaudiobitrate) | Sets the bit rate of the output audio for transcoding.<br>This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare).| 39| [OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoBitrate(OH_AVTranscoder_Config *config, int32_t bitrate)](#oh_avtranscoderconfig_setdstvideobitrate) | Sets the bit rate of the output video for transcoding.<br>This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare).| 40| [OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoResolution(OH_AVTranscoder_Config *config, int32_t width, int32_t height)](#oh_avtranscoderconfig_setdstvideoresolution) | Sets the resolution of the output video for transcoding, in px, where **width** is the width of the output video frame and **height** is the height of the output video frame.<br>This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare).| 41| [OH_AVErrCode OH_AVTranscoderConfig_EnableBFrame(OH_AVTranscoder_Config *config, bool enabled)](#oh_avtranscoderconfig_enablebframe) | Enables B-frame encoding for the output video during transcoding.<br>For details about the constraints on B-frame video encoding, see [Constraints in B-Frame Video Encoding](../../media/avcodec/video-encoding-b-frame.md#constraints).<br>If the current environment does not meet these constraints, B-frames will be skipped, and encoding will proceed as if B-frame video encoding were not enabled.| 42| [OH_AVTranscoder *OH_AVTranscoder_Create(void)](#oh_avtranscoder_create) | Creates an AVTranscoder instance.| 43| [OH_AVErrCode OH_AVTranscoder_Prepare(OH_AVTranscoder *transcoder, OH_AVTranscoder_Config *config)](#oh_avtranscoder_prepare) | Sets the parameters for video transcoding and prepares for transcoding.<br>This function must be called before [OH_AVTranscoder_Start](#oh_avtranscoder_start). Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_PREPARED state.| 44| [OH_AVErrCode OH_AVTranscoder_Start(OH_AVTranscoder *transcoder)](#oh_avtranscoder_start) | Starts transcoding.<br>This function must be called after a successful call to [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_STARTED state.| 45| [OH_AVErrCode OH_AVTranscoder_Pause(OH_AVTranscoder *transcoder)](#oh_avtranscoder_pause) | Pauses transcoding.<br>This function must be called when the AVTranscoder is in the AVTRANSCODER_STARTED state. Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_PAUSED state.| 46| [OH_AVErrCode OH_AVTranscoder_Resume(OH_AVTranscoder *transcoder)](#oh_avtranscoder_resume) | Resumes transcoding.<br>This function must be called when the AVTranscoder is in the AVTRANSCODER_PAUSED state. Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_STARTED state again.| 47| [OH_AVErrCode OH_AVTranscoder_Cancel(OH_AVTranscoder *transcoder)](#oh_avtranscoder_cancel) | Cancels transcoding.<br>This function must be called when the AVTranscoder is in the AVTRANSCODER_STARTED or AVTRANSCODER_PAUSED state. Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_CANCELLED state.| 48| [OH_AVErrCode OH_AVTranscoder_Release(OH_AVTranscoder *transcoder)](#oh_avtranscoder_release) | Releases an AVTranscoder instance.| 49| [OH_AVErrCode OH_AVTranscoder_SetStateCallback(OH_AVTranscoder *transcoder, OH_AVTranscoder_OnStateChange callback, void *userData)](#oh_avtranscoder_setstatecallback) | Registers a callback for transcoding state change events.<br>This callback is invoked when the state of the transcoding process changes.<br>An application can subscribe to only one transcoding state change event. When the application initiates multiple subscriptions to this event, the last subscription is applied.<br>The callback must be registered before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare) is called.| 50| [OH_AVErrCode OH_AVTranscoder_SetErrorCallback(OH_AVTranscoder *transcoder, OH_AVTranscoder_OnError callback, void *userData)](#oh_avtranscoder_seterrorcallback) | Registers a callback for transcoding error events.<br>This callback is invoked when an error occurs during the transcoding process.<br>If this event is reported, call [OH_AVTranscoder_Release](#oh_avtranscoder_release) to exit the transcoding.<br>An application can subscribe to only one transcoding error event. When the application initiates multiple subscriptions to this event, the last subscription is applied.<br>The callback must be registered before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare) is called.| 51| [OH_AVErrCode OH_AVTranscoder_SetProgressUpdateCallback(OH_AVTranscoder *transcoder, OH_AVTranscoder_OnProgressUpdate callback, void *userData)](#oh_avtranscoder_setprogressupdatecallback) | Registers a callback for transcoding progress update events.<br>This callback is invoked when the progress of the transcoding process is updated.<br>An application can subscribe to only one transcoding error event. When the application initiates multiple subscriptions to this event, the last subscription is applied.<br>The callback must be registered before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare) is called.| 52 53## Function Description 54 55### OH_AVTranscoderConfig_Create() 56 57``` 58OH_AVTranscoder_Config *OH_AVTranscoderConfig_Create() 59``` 60 61**Description** 62 63Creates an instance of the transcoding configuration parameters. 64 65**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 66 67**Since**: 20 68 69**Returns** 70 71| Type| Description| 72| -- | -- | 73| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) * | Pointer to the OH_AVTranscoder_Config instance created. If the operation fails, nullptr is returned.| 74 75### OH_AVTranscoderConfig_Release() 76 77``` 78OH_AVErrCode OH_AVTranscoderConfig_Release(OH_AVTranscoder_Config* config) 79``` 80 81**Description** 82 83Releases the resources of the transcoding configuration parameters. 84 85After a successful call, the instance specified by **config** is released and set to nullptr. 86 87**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 88 89**Since**: 20 90 91 92**Parameters** 93 94| Name| Description| 95| -- | -- | 96| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md)* config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 97 98**Returns** 99 100| Type| Description| 101| -- | -- | 102| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The release operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr.| 103 104### OH_AVTranscoderConfig_SetSrcFD() 105 106``` 107OH_AVErrCode OH_AVTranscoderConfig_SetSrcFD(OH_AVTranscoder_Config *config, int32_t srcFd, int64_t srcOffset, int64_t length) 108``` 109 110**Description** 111 112Sets the file descriptor of the source video for transcoding. 113 114This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). 115 116**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 117 118**Since**: 20 119 120 121**Parameters** 122 123| Name| Description| 124| -- | -- | 125| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 126| int32_t srcFd | File descriptor of the source video.| 127| int64_t srcOffset | Offset of the source video in the file descriptor, in bytes.| 128| int64_t length | Size of the source video, in bytes.| 129 130**Returns** 131 132| Type| Description| 133| -- | -- | 134| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr, or the parameters related to the source video file are incorrect.| 135 136### OH_AVTranscoderConfig_SetDstFD() 137 138``` 139OH_AVErrCode OH_AVTranscoderConfig_SetDstFD(OH_AVTranscoder_Config *config, int32_t dstFd) 140``` 141 142**Description** 143 144Sets the file descriptor of the output video for transcoding. 145 146This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). 147 148**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 149 150**Since**: 20 151 152 153**Parameters** 154 155| Name| Description| 156| -- | -- | 157| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 158| int32_t dstFd | File descriptor of the output video.| 159 160**Returns** 161 162| Type| Description| 163| -- | -- | 164| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr, or the output video file descriptor is invalid.| 165 166### OH_AVTranscoderConfig_SetDstVideoType() 167 168``` 169OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoType(OH_AVTranscoder_Config *config, const char *mimeType) 170``` 171 172**Description** 173 174Sets the encoding format of the output video for transcoding. 175 176Currently, only AVC and HEVC are supported. If the source video is in HEVC format, the default value is **HEVC**. Otherwise, the default value is **AVC**. 177 178This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). 179 180**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 181 182**Since**: 20 183 184 185**Parameters** 186 187| Name| Description| 188| -- | -- | 189| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 190| const char *mimeType | Pointer to the encoding format of the output video. For details, see [native_avcodec_base.h](../apis-avcodec-kit/native__avcodec__base_8h.md#variables).| 191 192**Returns** 193 194| Type| Description| 195| -- | -- | 196| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr, or the value of **mimeType** is not allowed.| 197 198### OH_AVTranscoderConfig_SetDstAudioType() 199 200``` 201OH_AVErrCode OH_AVTranscoderConfig_SetDstAudioType(OH_AVTranscoder_Config *config, const char *mimeType) 202``` 203 204**Description** 205 206Sets the encoding format of the output audio for transcoding. 207 208Currently, only AAC is supported. If this parameter is not set, AAC is used by default. 209 210This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). 211 212**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 213 214**Since**: 20 215 216 217**Parameters** 218 219| Name| Description| 220| -- | -- | 221| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 222| const char *mimeType | Pointer to the encoding format of the output audio. For details, see [native_avcodec_base.h](../apis-avcodec-kit/native__avcodec__base_8h.md#variables).| 223 224**Returns** 225 226| Type| Description| 227| -- | -- | 228| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr, or the value of **mimeType** is not allowed.| 229 230### OH_AVTranscoderConfig_SetDstFileType() 231 232``` 233OH_AVErrCode OH_AVTranscoderConfig_SetDstFileType(OH_AVTranscoder_Config *config, OH_AVOutputFormat mimeType) 234``` 235 236**Description** 237 238Sets the container format of the output video file for transcoding. 239 240Currently, only MP4 is supported. 241 242This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). 243 244**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 245 246**Since**: 20 247 248 249**Parameters** 250 251| Name| Description| 252| -- | -- | 253| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 254| [OH_AVOutputFormat](../apis-avcodec-kit/_codec_base.md#oh_avoutputformat-1) mimeType | Container format of the output video. For details, see [native_avcodec_base.h](../apis-avcodec-kit/native__avcodec__base_8h.md#variables).| 255 256**Returns** 257 258| Type| Description| 259| -- | -- | 260| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr, or the value of **mimeType** is invalid.| 261 262### OH_AVTranscoderConfig_SetDstAudioBitrate() 263 264``` 265OH_AVErrCode OH_AVTranscoderConfig_SetDstAudioBitrate(OH_AVTranscoder_Config *config, int32_t bitrate) 266``` 267 268**Description** 269 270Sets the bit rate of the output audio for transcoding. 271 272This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). 273 274**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 275 276**Since**: 20 277 278 279**Parameters** 280 281| Name| Description| 282| -- | -- | 283| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 284| int32_t bitrate | Bit rate of the output audio, in bit/s. The value range is [1, 500000]. The default value is 48 kbit/s.| 285 286**Returns** 287 288| Type| Description| 289| -- | -- | 290| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr, or the value of **bitrate** is invalid.| 291 292### OH_AVTranscoderConfig_SetDstVideoBitrate() 293 294``` 295OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoBitrate(OH_AVTranscoder_Config *config, int32_t bitrate) 296``` 297 298**Description** 299 300Sets the bit rate of the output video for transcoding. 301 302This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). 303 304**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 305 306**Since**: 20 307 308 309**Parameters** 310 311| Name| Description| 312| -- | -- | 313| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 314| int32_t bitrate | Bit rate of the output video, in bit/s. The default bit rate is set according to the resolution of the output video.<br>For the resolution range [240p, 480p], the default bit rate is 1 Mbit/s.<br>For the resolution range (480p, 720p], the default bit rate is 2 Mbit/s.<br>For the resolution range (240p, 1080p], the default bit rate is 4 Mbit/s.<br>For the resolution 1080p or above, the default bit rate is 8 Mbit/s.| 315 316**Returns** 317 318| Type| Description| 319| -- | -- | 320| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr, or the value of **bitrate** is invalid.| 321 322### OH_AVTranscoderConfig_SetDstVideoResolution() 323 324``` 325OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoResolution(OH_AVTranscoder_Config *config, int32_t width, int32_t height) 326``` 327 328**Description** 329 330Sets the resolution of the output video for transcoding, in px, where **width** is the width of the output video frame and **height** is the height of the output video frame. 331 332This function must be called before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). 333 334**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 335 336**Since**: 20 337 338 339**Parameters** 340 341| Name| Description| 342| -- | -- | 343| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 344| int32_t width | Width of the output video frame. The value range is [240, 3840]. The default value is the width of the source video frame.| 345| int32_t height | Height of the output video frame. The value range is [240, 2160]. The default value is the height of the source video frame.| 346 347**Returns** 348 349| Type| Description| 350| -- | -- | 351| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr, or the value of **width** or **height** is invalid.| 352 353### OH_AVTranscoderConfig_EnableBFrame() 354 355``` 356OH_AVErrCode OH_AVTranscoderConfig_EnableBFrame(OH_AVTranscoder_Config *config, bool enabled) 357``` 358 359**Description** 360 361Enables B-frame encoding for the output video during transcoding. 362 363For details about the constraints on B-frame video encoding, see [Constraints in B-Frame Video Encoding](../../media/avcodec/video-encoding-b-frame.md#constraints). 364 365If the current environment does not meet these constraints, B-frames will be skipped, and encoding will proceed as if B-frame video encoding were not enabled. 366 367**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 368 369**Since**: 20 370 371 372**Parameters** 373 374| Name| Description| 375| -- | -- | 376| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance, which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 377| bool enabled | Whether to enable B-frame encoding. **true** to enable, **false** otherwise.| 378 379**Returns** 380 381| Type| Description| 382| -- | -- | 383| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **config** is nullptr.| 384 385### OH_AVTranscoder_Create() 386 387``` 388OH_AVTranscoder *OH_AVTranscoder_Create(void) 389``` 390 391**Description** 392 393Creates an AVTranscoder instance. 394 395**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 396 397**Since**: 20 398 399**Returns** 400 401| Type| Description| 402| -- | -- | 403| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) * | Pointer to the OH_AVTranscoder instance created. If the operation fails, nullptr is returned.| 404 405### OH_AVTranscoder_Prepare() 406 407``` 408OH_AVErrCode OH_AVTranscoder_Prepare(OH_AVTranscoder *transcoder, OH_AVTranscoder_Config *config) 409``` 410 411**Description** 412 413Sets the parameters for video transcoding and prepares for transcoding. 414 415This function must be called before [OH_AVTranscoder_Start](#oh_avtranscoder_start). Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_PREPARED state. 416 417**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 418 419**Since**: 20 420 421 422**Parameters** 423 424| Name| Description| 425| -- | -- | 426| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 427| [OH_AVTranscoder_Config](capi-avtranscoder-oh-avtranscoder-config.md) *config | Pointer to an OH_AVTranscoder_Config instance,<br> which is created by running [OH_AVTranscoderConfig_Create](#oh_avtranscoderconfig_create).| 428 429**Returns** 430 431| Type| Description| 432| -- | -- | 433| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The video transcoding parameters are set successfully, and the AVTranscoder enters the AVTRANSCODER_PREPARED state.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** is nullptr, or the Prepare operation fails.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The Prepare operation is not allowed in the current state, or the format is not supported.<br>**AV_ERR_IO**: An I/O access error occurs.<br>**AV_ERR_SERVICE_DIED**: The media service is stopped.| 434 435### OH_AVTranscoder_Start() 436 437``` 438OH_AVErrCode OH_AVTranscoder_Start(OH_AVTranscoder *transcoder) 439``` 440 441**Description** 442 443Starts transcoding. 444 445This function must be called after a successful call to [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare). Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_STARTED state. 446 447**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 448 449**Since**: 20 450 451 452**Parameters** 453 454| Name| Description| 455| -- | -- | 456| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 457 458**Returns** 459 460| Type| Description| 461| -- | -- | 462| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: Transcoding starts successfully, and the AVTranscoder enters the AVTRANSCODER_STARTED state.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** is nullptr, or the Start operation fails.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The Start operation is not allowed in the current state.<br>**AV_ERR_IO**: An I/O access error occurs.<br>**AV_ERR_SERVICE_DIED**: The media service is stopped.| 463 464### OH_AVTranscoder_Pause() 465 466``` 467OH_AVErrCode OH_AVTranscoder_Pause(OH_AVTranscoder *transcoder) 468``` 469 470**Description** 471 472Pauses transcoding. 473 474This function must be called when the AVTranscoder is in the AVTRANSCODER_STARTED state. Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_PAUSED state. 475 476**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 477 478**Since**: 20 479 480 481**Parameters** 482 483| Name| Description| 484| -- | -- | 485| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 486 487**Returns** 488 489| Type| Description| 490| -- | -- | 491| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: Transcoding is paused successfully, and the AVTranscoder enters the AVTRANSCODER_PAUSED state.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** is nullptr, or the Pause operation fails.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The Pause operation is not allowed in the current state.<br>**AV_ERR_IO**: An I/O access error occurs.<br>**AV_ERR_SERVICE_DIED**: The media service is stopped.| 492 493### OH_AVTranscoder_Resume() 494 495``` 496OH_AVErrCode OH_AVTranscoder_Resume(OH_AVTranscoder *transcoder) 497``` 498 499**Description** 500 501Resumes transcoding. 502 503This function must be called when the AVTranscoder is in the AVTRANSCODER_PAUSED state. Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_STARTED state again. 504 505**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 506 507**Since**: 20 508 509 510**Parameters** 511 512| Name| Description| 513| -- | -- | 514| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 515 516**Returns** 517 518| Type| Description| 519| -- | -- | 520| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: Transcoding is resumed successfully, and the AVTranscoder enters the AVTRANSCODER_STARTED state.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** is nullptr, or the Resume operation fails.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The Resume operation is not allowed in the current state.<br>**AV_ERR_IO**: An I/O access error occurs.<br>**AV_ERR_SERVICE_DIED**: The media service is stopped.| 521 522### OH_AVTranscoder_Cancel() 523 524``` 525OH_AVErrCode OH_AVTranscoder_Cancel(OH_AVTranscoder *transcoder) 526``` 527 528**Description** 529 530Cancels transcoding. 531 532This function must be called when the AVTranscoder is in the AVTRANSCODER_STARTED or AVTRANSCODER_PAUSED state. Upon a successful call to this function, the AVTranscoder enters the AVTRANSCODER_CANCELLED state. 533 534**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 535 536**Since**: 20 537 538 539**Parameters** 540 541| Name| Description| 542| -- | -- | 543| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 544 545**Returns** 546 547| Type| Description| 548| -- | -- | 549| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: Transcoding is canceled successfully, and the AVTranscoder enters the AVTRANSCODER_CANCELLED state.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** is nullptr, or the Cancel operation fails.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The Cancel operation is not allowed in the current state.<br>**AV_ERR_IO**: An I/O access error occurs.<br>**AV_ERR_SERVICE_DIED**: The media service is stopped.| 550 551### OH_AVTranscoder_Release() 552 553``` 554OH_AVErrCode OH_AVTranscoder_Release(OH_AVTranscoder *transcoder) 555``` 556 557**Description** 558 559Releases an AVTranscoder instance. 560 561**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 562 563**Since**: 20 564 565 566**Parameters** 567 568| Name| Description| 569| -- | -- | 570| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 571 572**Returns** 573 574| Type| Description| 575| -- | -- | 576| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | AV_ERR_OK: The AVTranscoder instance is successfully released.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** is nullptr, or the Release operation fails.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The Release operation is not allowed in the current state.<br>**AV_ERR_IO**: An I/O access error occurs.<br>**AV_ERR_SERVICE_DIED**: The media service is stopped.| 577 578### OH_AVTranscoder_SetStateCallback() 579 580``` 581OH_AVErrCode OH_AVTranscoder_SetStateCallback(OH_AVTranscoder *transcoder, OH_AVTranscoder_OnStateChange callback, void *userData) 582``` 583 584**Description** 585 586Registers a callback for transcoding state change events. 587 588This callback is invoked when the state of the transcoding process changes. 589 590An application can subscribe to only one transcoding state change event. When the application initiates multiple subscriptions to this event, the last subscription is applied. 591 592The callback must be registered before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare) is called. 593 594**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 595 596**Since**: 20 597 598 599**Parameters** 600 601| Name| Description| 602| -- | -- | 603| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 604| [OH_AVTranscoder_OnStateChange](capi-avtranscoder-base-h.md#oh_avtranscoder_onstatechange) callback | Callback invoked when the state of the transcoding process changes. For details, see [OH_AVTranscoder_OnStateChange](capi-avtranscoder-base-h.md#oh_avtranscoder_onstatechange).| 605| void *userData | Pointer to user-defined data.| 606 607**Returns** 608 609| Type| Description| 610| -- | -- | 611| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The registration is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** or **callback** is nullptr.| 612 613### OH_AVTranscoder_SetErrorCallback() 614 615``` 616OH_AVErrCode OH_AVTranscoder_SetErrorCallback(OH_AVTranscoder *transcoder, OH_AVTranscoder_OnError callback, void *userData) 617``` 618 619**Description** 620 621Registers a callback for transcoding error events. 622 623This callback is invoked when an error occurs during the transcoding process. 624 625If this event is reported, call [OH_AVTranscoder_Release](#oh_avtranscoder_release) to exit the transcoding. 626 627An application can subscribe to only one transcoding error event. When the application initiates multiple subscriptions to this event, the last subscription is applied. 628 629The callback must be registered before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare) is called. 630 631**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 632 633**Since**: 20 634 635 636**Parameters** 637 638| Name| Description| 639| -- | -- | 640| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 641| [OH_AVTranscoder_OnError](capi-avtranscoder-base-h.md#oh_avtranscoder_onerror) callback | Callback invoked when an error occurs during the transcoding process. For details, see [OH_AVTranscoder_OnError](capi-avtranscoder-base-h.md#oh_avtranscoder_onerror).| 642| void *userData | Pointer to user-defined data.| 643 644**Returns** 645 646| Type| Description| 647| -- | -- | 648| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The registration is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** or **callback** is nullptr.| 649 650### OH_AVTranscoder_SetProgressUpdateCallback() 651 652``` 653OH_AVErrCode OH_AVTranscoder_SetProgressUpdateCallback(OH_AVTranscoder *transcoder, OH_AVTranscoder_OnProgressUpdate callback, void *userData) 654``` 655 656**Description** 657 658Registers a callback for transcoding progress update events. 659 660This callback is invoked when the progress of the transcoding process is updated. 661 662An application can subscribe to only one transcoding error event. When the application initiates multiple subscriptions to this event, the last subscription is applied. 663 664The callback must be registered before [OH_AVTranscoder_Prepare](#oh_avtranscoder_prepare) is called. 665 666**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 667 668**Since**: 20 669 670 671**Parameters** 672 673| Name| Description| 674| -- | -- | 675| [OH_AVTranscoder](capi-avtranscoder-oh-avtranscoder.md) *transcoder | Pointer to an OH_AVTranscoder instance, which is created by running [OH_AVTranscoder_Create](#oh_avtranscoder_create).| 676| [OH_AVTranscoder_OnProgressUpdate](capi-avtranscoder-base-h.md#oh_avtranscoder_onprogressupdate) callback | Callback invoked when the progress of the transcoding process is updated. For details, see [OH_AVTranscoder_OnProgressUpdate](capi-avtranscoder-base-h.md#oh_avtranscoder_onprogressupdate).| 677| void *userData | Pointer to user-defined data.| 678 679**Returns** 680 681| Type| Description| 682| -- | -- | 683| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The registration is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **transcoder** or **callback** is nullptr.| 684