VideoEncoder
Overview
The VideoEncoder module provides the functions for video encoding.
System capability: SystemCapability.Multimedia.VideoEncoder
Since: 9
Summary
Files
Name | Description |
---|---|
native_avcodec_videoencoder.h | Declares the native APIs used for video encoding. |
Types
Name | Description |
---|---|
typedef enum OH_VideoEncodeBitrateMode OH_VideoEncodeBitrateMode | Defines an enum that enumerates the bit rate modes of a video encoder. |
Enums
Name | Description |
---|---|
OH_VideoEncodeBitrateMode { CBR = 0, VBR = 1, CQ = 2 } | Enumerates the bit rate modes of a video encoder. |
Functions
Name | Description |
---|---|
OH_AVCodec * OH_VideoEncoder_CreateByMime (const char *mime) | Creates a video encoder instance based on a Multipurpose Internet Mail Extension (MIME) type. |
OH_AVCodec * OH_VideoEncoder_CreateByName (const char *name) | Creates a video encoder instance based on an encoder name. |
OH_AVErrCode OH_VideoEncoder_Destroy (OH_AVCodec *codec) | Clears the internal resources of a video encoder and destroys the encoder instance. |
OH_AVErrCode 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. |
OH_AVErrCode OH_VideoEncoder_RegisterCallback (OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData) | Registers an asynchronous callback so that your application can respond to events generated by a video encoder. |
OH_AVErrCode OH_VideoEncoder_Configure (OH_AVCodec *codec, OH_AVFormat *format) | Configures a video encoder. Typically, you need to configure the description information about the video track to be encoded. |
OH_AVErrCode OH_VideoEncoder_Prepare (OH_AVCodec *codec) | Prepares internal resources for a video encoder. |
OH_AVErrCode OH_VideoEncoder_Start (OH_AVCodec *codec) | Starts a video encoder. This function can be called only after the encoder is prepared. |
OH_AVErrCode OH_VideoEncoder_Stop (OH_AVCodec *codec) | Stops a video encoder. |
OH_AVErrCode OH_VideoEncoder_Flush (OH_AVCodec *codec) | Clears the input and output data in the internal buffer of a video encoder. |
OH_AVErrCode OH_VideoEncoder_Reset (OH_AVCodec *codec) | Resets a video encoder. |
OH_AVFormat * OH_VideoEncoder_GetOutputDescription (OH_AVCodec *codec) | Obtains the description information about the output data of a video encoder. |
OH_AVErrCode OH_VideoEncoder_SetParameter (OH_AVCodec *codec, OH_AVFormat *format) | Sets dynamic parameters for a video encoder. |
OH_AVErrCode OH_VideoEncoder_GetSurface (OH_AVCodec *codec, OHNativeWindow **window) | Obtains the input surface from a video encoder. |
OH_AVErrCode OH_VideoEncoder_FreeOutputData (OH_AVCodec *codec, uint32_t index) | Frees an output buffer of a video encoder. |
OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream (OH_AVCodec *codec) | Notifies a video encoder that input streams end. |
OH_AVErrCode OH_VideoEncoder_PushInputData (OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr) | Pushes the input buffer filled with data to a video encoder. |
OH_AVErrCode OH_VideoEncoder_PushInputBuffer (OH_AVCodec *codec, uint32_t index) | Pushes the input buffer filled with data to a video encoder. |
OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer (OH_AVCodec *codec, uint32_t index) | Frees an output buffer of a video encoder. |
OH_AVFormat * OH_VideoEncoder_GetInputDescription (OH_AVCodec *codec) | Obtains the description information received by a video encoder. |
OH_AVErrCode OH_VideoEncoder_IsValid (OH_AVCodec *codec, bool *isValid) | Checks whether a video encoder instance is valid. |
Type Description
OH_VideoEncodeBitrateMode
typedef enum OH_VideoEncodeBitrateMode OH_VideoEncodeBitrateMode
Description
Defines an enum that enumerates the bit rate modes of a video encoder.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Enum Description
OH_VideoEncodeBitrateMode
enum OH_VideoEncodeBitrateMode
Description
Enumerates the bit rate modes of a video encoder.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Value | 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 description information about the video track to be encoded. This function must be called prior to Prepare.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
format | Pointer to an OH_AVFormat instance, which provides the description information about the video track to be encoded. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_CreateByMime()
OH_AVCodec* OH_VideoEncoder_CreateByMime (const char *mime)
Description
Creates a video encoder instance based on a MIME type. This function is recommended in most cases.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
mime | Pointer to a string that describes the MIME type. For details, see AVCODEC_MIMETYPE. |
Returns
Returns the pointer to the video encoder instance created if the operation is successful; returns a null pointer otherwise.
OH_VideoEncoder_CreateByName()
OH_AVCodec* OH_VideoEncoder_CreateByName (const char *name)
Description
Creates a video encoder instance based on an encoder name. To use this function, you must know the exact name of the encoder.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
name | Pointer to a video encoder name. |
Returns
Returns the pointer to the video encoder instance created if the operation is successful; returns a null pointer otherwise.
OH_VideoEncoder_Destroy()
OH_AVErrCode OH_VideoEncoder_Destroy (OH_AVCodec *codec)
Description
Clears the internal resources of a video encoder and destroys the encoder instance.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encoder instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
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 function invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this function, ensure that the buffers with the specified indexes are no longer required.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_FreeOutputBuffer()
OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer (OH_AVCodec *codec, uint32_t index )
Description
Frees an output buffer of a video encoder.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 11
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
index | Index of the output buffer. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_FreeOutputData()
OH_AVErrCode OH_VideoEncoder_FreeOutputData (OH_AVCodec *codec, uint32_t index )
Description
Frees an output buffer of a video encoder.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Deprecated from: 11
Substitute API: OH_VideoEncoder_FreeOutputBuffer
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
index | Index of the output buffer. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_GetInputDescription()
OH_AVFormat* OH_VideoEncoder_GetInputDescription (OH_AVCodec *codec)
Description
Obtains the description information received by a video encoder. This function must be called after OH_VideoEncoder_Configure. The caller must call OH_AVFormat_Destroy to manually release the OH_AVFormat instance in the return value.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 10
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
Returns
Returns the pointer to an OH_AVFormat instance.
OH_VideoEncoder_GetOutputDescription()
OH_AVFormat* OH_VideoEncoder_GetOutputDescription (OH_AVCodec *codec)
Description
Obtains the description information about the output data of a video encoder.
The caller must manually release the OH_AVFormat instance in the return value.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
Returns
Returns the pointer to an OH_AVFormat instance.
OH_VideoEncoder_GetSurface()
OH_AVErrCode OH_VideoEncoder_GetSurface (OH_AVCodec *codec, OHNativeWindow ** window )
Description
Sets an input surface for a video encoder. This function must be called prior to Prepare.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
window | Pointer to an OHNativeWindow instance. The application manages the lifecycle of the window and calls OH_NativeWindow_DestroyNativeWindow to release the window when the lifecycle ends. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_IsValid()
OH_AVErrCode OH_VideoEncoder_IsValid (OH_AVCodec *codec, bool *isValid )
Description
Checks whether a video encoder instance is valid.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 10
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
isValid | Pointer to an instance of the Boolean type. The value true means that the encoder instance is valid and false means the opposite. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_NotifyEndOfStream()
OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream (OH_AVCodec *codec)
Description
Notifies a video encoder that input streams end. You are advised to use this function for notification. This function is recommended in surface mode.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_Prepare()
OH_AVErrCode OH_VideoEncoder_Prepare (OH_AVCodec *codec)
Description
Prepares internal resources for a video encoder. This function must be called after Configure.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_PushInputBuffer()
OH_AVErrCode OH_VideoEncoder_PushInputBuffer (OH_AVCodec *codec, uint32_t index )
Description
Pushes the input buffer filled with data to a video encoder.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 11
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
index | Index of the input buffer. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_PushInputData()
OH_AVErrCode OH_VideoEncoder_PushInputData (OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr )
Description
Pushes the input buffer filled with data to a video encoder.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 10
Deprecated from: 11
Substitute API: OH_VideoEncoder_PushInputBuffer
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
index | Index of the input buffer. |
attr | Description of the data contained in the buffer. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_RegisterCallback()
OH_AVErrCode OH_VideoEncoder_RegisterCallback (OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData )
Description
Registers an asynchronous callback so that your application can respond to events generated by a video encoder. This function must be called prior to Prepare.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 11
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
callback | Callback function to set. For details, see OH_AVCodecCallback. |
userData | User-specific data. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_Reset()
OH_AVErrCode OH_VideoEncoder_Reset (OH_AVCodec *codec)
Description
Resets a video encoder. To continue encoding, you must call Configure to configure the encoder again.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
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 function must be called prior to Prepare.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Deprecated from: 11
Substitute API: OH_VideoEncoder_RegisterCallback
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
callback | Callback function to set. For details, see OH_AVCodecAsyncCallback. |
userData | User-specific data. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_SetParameter()
OH_AVErrCode OH_VideoEncoder_SetParameter (OH_AVCodec *codec, OH_AVFormat *format )
Description
Sets dynamic parameters for a video encoder. This function can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
format | Pointer to an OH_AVFormat instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_VideoEncoder_Start()
OH_AVErrCode OH_VideoEncoder_Start (OH_AVCodec *codec)
Description
Starts a video encoder. This function can be called only after the encoder is prepared. After being started, the encoder starts to report the registered event.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
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.
System capability: SystemCapability.Multimedia.Media.VideoEncoder
Since: 9
Parameters
Name | Description |
---|---|
codec | Pointer to a video encorder instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.