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 | Declares the native APIs used for video encoding. File to Include: <multimedia/player_framework/native_avcodec_videoencoder.h> |
Types
Name | Description |
---|---|
OH_VideoEncodeBitrateMode | Enumerates the bit rate modes of video encoding. |
Enums
Name | Description |
---|---|
OH_VideoEncodeBitrateMode { CBR = 0, VBR = 1, CQ = 2 } | Enumerates the bit rate modes of video encoding. |
Functions
Name | Description |
---|---|
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 (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_AVCodec *codec) | Clears the internal resources of a video encoder and destroys the video encoder instance. |
OH_VideoEncoder_SetCallback (OH_AVCodec *codec, OH_AVCodecAsyncCallback 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_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_AVCodec *codec) | Prepares internal resources for a video encoder. This API must be called after Configure. |
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 event. |
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_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_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_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_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_AVCodec *codec, OHNativeWindow **window) | Obtains an input surface from a video encoder. This API must be called prior to Prepare. |
OH_VideoEncoder_FreeOutputData (OH_AVCodec *codec, uint32_t index) | Frees an output buffer of a video encoder. |
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
Enumerates the bit rate modes of video encoding.
@syscap SystemCapability.Multimedia.Media.VideoEncoder
Enum Description
OH_VideoEncodeBitrateMode
enum OH_VideoEncodeBitrateMode
Description
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
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 if the operation fails.
OH_VideoEncoder_CreateByMime()
OH_AVCodec* OH_VideoEncoder_CreateByMime (const char * mime)
Description
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. |
Returns
Returns the pointer to an OH_AVCodec instance.
OH_VideoEncoder_CreateByName()
OH_AVCodec* OH_VideoEncoder_CreateByName (const char * name)
Description
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
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 if the operation fails.
OH_VideoEncoder_Flush()
OH_AVErrCode OH_VideoEncoder_Flush (OH_AVCodec * codec)
Description
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 if the operation fails.
OH_VideoEncoder_FreeOutputData()
OH_AVErrCode OH_VideoEncoder_FreeOutputData (OH_AVCodec * codec, uint32_t index )
Description
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 if the operation fails.
OH_VideoEncoder_GetOutputDescription()
OH_AVFormat* OH_VideoEncoder_GetOutputDescription (OH_AVCodec * codec)
Description
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
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 if the operation fails.
OH_VideoEncoder_NotifyEndOfStream()
OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream (OH_AVCodec * codec)
Description
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 if the operation fails.
OH_VideoEncoder_Prepare()
OH_AVErrCode OH_VideoEncoder_Prepare (OH_AVCodec * codec)
Description
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 if the operation fails.
OH_VideoEncoder_Reset()
OH_AVErrCode OH_VideoEncoder_Reset (OH_AVCodec * codec)
Description
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 if the operation fails.
OH_VideoEncoder_SetCallback()
OH_AVErrCode OH_VideoEncoder_SetCallback (OH_AVCodec * codec, OH_AVCodecAsyncCallback callback, void * userData )
Description
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. |
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 if the operation fails.
OH_VideoEncoder_SetParameter()
OH_AVErrCode OH_VideoEncoder_SetParameter (OH_AVCodec * codec, OH_AVFormat * format )
Description
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 if the operation fails.
OH_VideoEncoder_Start()
OH_AVErrCode OH_VideoEncoder_Start (OH_AVCodec * codec)
Description
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 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 if the operation fails.
OH_VideoEncoder_Stop()
OH_AVErrCode OH_VideoEncoder_Stop (OH_AVCodec * codec)
Description
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 if the operation fails.