未验证 提交 f260fd62 编写于 作者: Z zengyawen 提交者: Gitee

dd nativeapis

Signed-off-by: Nzengyawen <zengyawen1@huawei.com>
上级 51061710
# VideoEncoder
## Overview
Provides the functions and enums for video encoding.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Since:**
9
## Summary
### Files
| Name | Description |
| -------- | -------- |
| [native_avcodec_videoencoder.h](native__avcodec__videoencoder_8h.md) | Declares the native APIs used for video encoding. <br>File to Include: <multimedia/player_framework/native_avcodec_videoencoder.h> |
### Types
| Name | Description |
| -------- | -------- |
| [OH_VideoEncodeBitrateMode](#oh_videoencodebitratemode) | Enumerates the bit rate modes of video encoding. |
### Enums
| Name | Description |
| -------- | -------- |
| [OH_VideoEncodeBitrateMode](#oh_videoencodebitratemode) { CBR = 0, VBR = 1, CQ = 2 } | Enumerates the bit rate modes of video encoding. |
### Functions
| Name | Description |
| -------- | -------- |
| [OH_VideoEncoder_CreateByMime](#oh_videoencoder_createbymime) (const char \*mime) | Creates a video encoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases. |
| [OH_VideoEncoder_CreateByName](#oh_videoencoder_createbyname) (const char \*name) | Creates a video encoder instance based on a video encoder name. To use this API, you must know the exact name of the video encoder. |
| [OH_VideoEncoder_Destroy](#oh_videoencoder_destroy) (OH_AVCodec \*codec) | Clears the internal resources of a video encoder and destroys the video encoder instance. |
| [OH_VideoEncoder_SetCallback](#oh_videoencoder_setcallback) (OH_AVCodec \*codec, [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md) callback, void \*userData) | Sets an asynchronous callback so that your application can respond to events generated by a video encoder. This API must be called prior to **Prepare**. |
| [OH_VideoEncoder_Configure](#oh_videoencoder_configure) (OH_AVCodec \*codec, OH_AVFormat \*format) | Configures a video encoder. Typically, you need to configure the attributes of the video track that can be encoded. This API must be called prior to **Prepare**. |
| [OH_VideoEncoder_Prepare](#oh_videoencoder_prepare) (OH_AVCodec \*codec) | Prepares internal resources for a video encoder. This API must be called after **Configure**. |
| [OH_VideoEncoder_Start](#oh_videoencoder_start) (OH_AVCodec \*codec) | Starts a video encoder. This API can be called only after the encoder is prepared successfully. After being started, the encoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event. |
| [OH_VideoEncoder_Stop](#oh_videoencoder_stop) (OH_AVCodec \*codec) | Stops a video encoder. After the encoder is stopped, you can call **Start** to start it again. |
| [OH_VideoEncoder_Flush](#oh_videoencoder_flush) (OH_AVCodec \*codec) | Clears the input and output data in the internal buffer of a video encoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required. |
| [OH_VideoEncoder_Reset](#oh_videoencoder_reset) (OH_AVCodec \*codec) | Resets a video encoder. To continue encoding, you must call **Configure** and **Start** to configure and start the encoder again. |
| [OH_VideoEncoder_GetOutputDescription](#oh_videoencoder_getoutputdescription) (OH_AVCodec \*codec) | Obtains the attributes of the output data of a video encoder. The **OH_AVFormat** instance in the return value will become invalid when this API is called again or when the **OH_AVCodec** instance is destroyed. |
| [OH_VideoEncoder_SetParameter](#oh_videoencoder_setparameter) (OH_AVCodec \*codec, OH_AVFormat \*format) | Sets dynamic parameters for a video encoder. This API can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure. |
| [OH_VideoEncoder_GetSurface](#oh_videoencoder_getsurface) (OH_AVCodec \*codec, [OHNativeWindow](_native_window.md) \*\*window) | Obtains an input surface from a video encoder. This API must be called prior to **Prepare**. |
| [OH_VideoEncoder_FreeOutputData](#oh_videoencoder_freeoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video encoder. |
| [OH_VideoEncoder_NotifyEndOfStream](#oh_videoencoder_notifyendofstream) (OH_AVCodec \*codec) | Notifies a video encoder that input streams end. This API is recommended in surface mode. |
## Type Description
### OH_VideoEncodeBitrateMode
```
typedef enum OH_VideoEncodeBitrateModeOH_VideoEncodeBitrateMode
```
**Description**<br>
Enumerates the bit rate modes of video encoding.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
## Enum Description
### OH_VideoEncodeBitrateMode
```
enum OH_VideoEncodeBitrateMode
```
**Description**<br>
Enumerates the bit rate modes of video encoding.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
| Name | Description |
| -------- | -------- |
| CBR | Constant bit rate. |
| VBR | Variable bit rate. |
| CQ | Constant quality. |
## Function Description
### OH_VideoEncoder_Configure()
```
OH_AVErrCode OH_VideoEncoder_Configure (OH_AVCodec * codec, OH_AVFormat * format )
```
**Description**<br>
Configures a video encoder. Typically, you need to configure the attributes of the video track that can be encoded. This API must be called prior to **Prepare**.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| format | Indicates the handle to an **OH_AVFormat** instance, which provides the attributes of the video track to be encoded. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_CreateByMime()
```
OH_AVCodec* OH_VideoEncoder_CreateByMime (const char * mime)
```
**Description**<br>
Creates a video encoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| mime | Indicates the pointer to a MIME type. For details, see [OH_AVCODEC_MIMETYPE_VIDEO_AVC](_codec_base.md#oh_avcodec_mimetype_video_avc). |
**Returns**
Returns the pointer to an **OH_AVCodec** instance.
### OH_VideoEncoder_CreateByName()
```
OH_AVCodec* OH_VideoEncoder_CreateByName (const char * name)
```
**Description**<br>
Creates a video encoder instance based on a video encoder name. To use this API, you must know the exact name of the video encoder.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| name | Indicates the pointer to a video encoder name. |
**Returns**
Returns the pointer to an **OH_AVCodec** instance.
### OH_VideoEncoder_Destroy()
```
OH_AVErrCode OH_VideoEncoder_Destroy (OH_AVCodec * codec)
```
**Description**<br>
Clears the internal resources of a video encoder and destroys the video encoder instance.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_Flush()
```
OH_AVErrCode OH_VideoEncoder_Flush (OH_AVCodec * codec)
```
**Description**<br>
Clears the input and output data in the internal buffer of a video encoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_FreeOutputData()
```
OH_AVErrCode OH_VideoEncoder_FreeOutputData (OH_AVCodec * codec, uint32_t index )
```
**Description**<br>
Frees an output buffer of a video encoder.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| index | Indicates the index of an output buffer. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_GetOutputDescription()
```
OH_AVFormat* OH_VideoEncoder_GetOutputDescription (OH_AVCodec * codec)
```
**Description**<br>
Obtains the attributes of the output data of a video encoder. The **OH_AVFormat** instance in the return value will become invalid when this API is called again or when the **OH_AVCodec** instance is destroyed.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns the pointer to an **OH_AVFormat** instance.
### OH_VideoEncoder_GetSurface()
```
OH_AVErrCode OH_VideoEncoder_GetSurface (OH_AVCodec * codec, OHNativeWindow ** window )
```
**Description**<br>
Obtains an input surface from a video encoder. This API must be called prior to **Prepare**.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| window | Indicates the double pointer to an **OHNativeWindow** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_NotifyEndOfStream()
```
OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream (OH_AVCodec * codec)
```
**Description**<br>
Notifies a video encoder that input streams end. This API is recommended in surface mode.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_Prepare()
```
OH_AVErrCode OH_VideoEncoder_Prepare (OH_AVCodec * codec)
```
**Description**<br>
Prepares internal resources for a video encoder. This API must be called after **Configure**.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_Reset()
```
OH_AVErrCode OH_VideoEncoder_Reset (OH_AVCodec * codec)
```
**Description**<br>
Resets a video encoder. To continue encoding, you must call **Configure** and **Start** to configure and start the encoder again.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_SetCallback()
```
OH_AVErrCode OH_VideoEncoder_SetCallback (OH_AVCodec * codec, OH_AVCodecAsyncCallback callback, void * userData )
```
**Description**<br>
Sets an asynchronous callback so that your application can respond to events generated by a video encoder. This API must be called prior to **Prepare**.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| callback | Indicates a collection of all callback functions. For details, see [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md). |
| userData | Indicates the pointer to user-specific data. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_SetParameter()
```
OH_AVErrCode OH_VideoEncoder_SetParameter (OH_AVCodec * codec, OH_AVFormat * format )
```
**Description**<br>
Sets dynamic parameters for a video encoder. This API can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| format | Indicates the handle to an **OH_AVFormat** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_Start()
```
OH_AVErrCode OH_VideoEncoder_Start (OH_AVCodec * codec)
```
**Description**<br>
Starts a video encoder. This API can be called only after the encoder is prepared successfully. After being started, the encoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_VideoEncoder_Stop()
```
OH_AVErrCode OH_VideoEncoder_Stop (OH_AVCodec * codec)
```
**Description**<br>
Stops a video encoder. After the encoder is stopped, you can call **Start** to start it again.
\@syscap SystemCapability.Multimedia.Media.VideoEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册