openharmony 鸿蒙 capi-native-avcodec-videoencoder-h

2026-08-25 浏览 (1)

native_avcodec_videoencoder.h

Overview

The file declares the APIs used for video encoding.

File to include: <multimedia/player_framework/native_avcodec_videoencoder.h>

Library: libnative_media_venc.so

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Related module: VideoEncoder

Sample: AVCodec

The following figures show the APIs supported by each version and the APIs that can be called in different states.

meaning

description of encode api history

Summary

Enums

Nametypedef KeywordDescription
OH_VideoEncodeBitrateModeOH_VideoEncodeBitrateModeEnumerates the bit rate modes of a video encoder. (It is deprecated from API version 14.)

Functions

Nametypedef KeywordDescription
typedef void (*OH_VideoEncoder_OnNeedInputParameter)(OH_AVCodec *codec, uint32_t index, OH_AVFormat *parameter, void *userData)OH_VideoEncoder_OnNeedInputParameterDefines the pointer to the function that is called when new input parameters are required for a frame with the specified index. It takes effect only in surface mode.
OH_AVCodec *OH_VideoEncoder_CreateByMime(const char *mime)-Creates a video encoder instance based on a MIME type. This function is recommended.
OH_AVCodec *OH_VideoEncoder_CreateByName(const char *name)-Creates a video encoder instance based on an encoder name. To use this function, you must know the exact name of the encoder. The encoder name can be obtained through capability query.
OH_AVErrCode OH_VideoEncoder_Destroy(OH_AVCodec *codec)-Clears the internal resources of a video encoder and destroys the encoder instance. You only need to call the function once.
OH_AVErrCode OH_VideoEncoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData)-Sets an OH_AVCodecCallback callback so that your application can respond to events generated by a video encoder. This function must be called prior to OH_VideoEncoder_Prepare. (It is deprecated from API version 11.)
OH_AVErrCode OH_VideoEncoder_RegisterCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData)-Registers an OH_AVCodecCallback callback so that your application can respond to events generated by a video encoder. This function must be called prior to OH_VideoEncoder_Prepare.
OH_AVErrCode OH_VideoEncoder_RegisterParameterCallback(OH_AVCodec *codec, OH_VideoEncoder_OnNeedInputParameter onInputParameter, void *userData)-Registers an OH_AVCodecCallback input parameter callback so that your application can respond to events generated by a video encoder. In surface encoding mode, this function must be called when frame parameters need to be set,
and it must be called before OH_VideoEncoder_Configure.
OH_AVErrCode OH_VideoEncoder_Configure(OH_AVCodec *codec, OH_AVFormat *format)-Configures encoding parameters for a video encoder. Typically, you need to configure the description information about the video frames, such as the frame width, height, and pixel format. This function must be called prior to OH_VideoEncoder_Prepare.
OH_AVErrCode OH_VideoEncoder_Prepare(OH_AVCodec *codec)-Prepares internal resources for a video encoder. This function must be called after OH_VideoEncoder_Configure.
OH_AVErrCode OH_VideoEncoder_Start(OH_AVCodec *codec)-Starts a video encoder. This function should be called after a successful call of OH_VideoEncoder_Prepare. After being started, the encoder starts to report the registered event.
OH_AVErrCode OH_VideoEncoder_Stop(OH_AVCodec *codec)-Stops a video encoder and releases the input and output buffers. After the video encoder is stopped, you can call OH_VideoEncoder_Start to enter the running state again.
OH_AVErrCode OH_VideoEncoder_Flush(OH_AVCodec *codec)-Clears the input and output data and parameters, for example, H.264 PPS/SPS, cached in 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. This function cannot be called consecutively.
OH_AVErrCode OH_VideoEncoder_Reset(OH_AVCodec *codec)-Resets a video encoder. The encoder returns to the initial state. To continue encoding, you must call OH_VideoEncoder_Configure to configure the encoder again.
OH_AVFormat *OH_VideoEncoder_GetOutputDescription(OH_AVCodec *codec)-Obtains the OH_AVFormat information about the output data of a video encoder.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance in the return value.
OH_AVErrCode OH_VideoEncoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format)-Sets the encoder parameter when a video encoder is running.
This function can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure.
OH_AVErrCode OH_VideoEncoder_GetSurface(OH_AVCodec *codec, OHNativeWindow **window)-Obtains the input surface from a video encoder. This function must be called after OH_VideoEncoder_Configure but before OH_VideoEncoder_Prepare.
OH_AVErrCode OH_VideoEncoder_FreeOutputData(OH_AVCodec *codec, uint32_t index)-Frees an output buffer of a video encoder. (It is deprecated from API version 11.)
OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream(OH_AVCodec *codec)-Notifies a video encoder that input streams end. You are advised to use this function for notification. This function is used only in surface mode. In buffer mode, OH_AVBuffer is used to carry the EOS information to notify the end of the input stream.
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. (It is deprecated from API version 11.)
OH_AVErrCode OH_VideoEncoder_PushInputBuffer(OH_AVCodec *codec, uint32_t index)-Pushes the OH_AVBuffer corresponding to the index to a video encoder in buffer mode.
OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t index)-Pushes the parameter configured for a frame with the given index to a video encoder in surface mode.
OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index)-Returns the processed OH_AVBuffer corresponding to the index to a video encoder. You need to call this function to release the output buffer in a timely manner. Otherwise, the encoding process is blocked.
OH_AVFormat *OH_VideoEncoder_GetInputDescription(OH_AVCodec *codec)-Obtains the description of the image received by a video encoder. This function must be called after OH_VideoEncoder_Configure is called.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance in the return value.
OH_AVErrCode OH_VideoEncoder_IsValid(OH_AVCodec *codec, bool *isValid)-Checks whether the encoder service is valid when an encoder instance exists.
OH_AVErrCode OH_VideoEncoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)-Obtains the index of the next available input buffer.
After calling this function, you must call OH_VideoEncoder_GetInputBuffer to obtain the buffer instance and call OH_VideoEncoder_PushInputBuffer to pass the buffer instance to the encoder.
Note that the preceding operations are supported only in synchronous mode.
OH_AVBuffer *OH_VideoEncoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index)-Obtains the instance of the available input buffer.
Note that this function works only in synchronous mode.
OH_AVErrCode OH_VideoEncoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)-Obtains the index of the next available output buffer. Through the buffer instance obtained via OH_VideoEncoder_GetOutputBuffer, you can return the processed output buffer to the encoder by calling OH_VideoEncoder_FreeOutputBuffer.
Note that the preceding operations are supported only in synchronous mode.
OH_AVBuffer *OH_VideoEncoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index)-Obtains the instance of the available output buffer.
Note that this function works only in synchronous mode.

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

Deprecated from: 14

Substitute: OH_BitrateMode

ValueDescription
CBR = 0Constant bit rate.
Substitute: BITRATE_MODE_CBR
VBR = 1Variable bit rate.
Substitute: BITRATE_MODE_VBR
CQ = 2Constant quality.
Substitute: BITRATE_MODE_CQ

Function Description

OH_VideoEncoder_OnNeedInputParameter()

typedef void (*OH_VideoEncoder_OnNeedInputParameter)(OH_AVCodec *codec, uint32_t index, OH_AVFormat *parameter, void *userData)

Description

Defines the pointer to the function that is called when new input parameters are required for a frame with the specified index.
This callback can be used only in surface mode after it is registered by calling OH_VideoEncoder_RegisterParameterCallback.
In buffer mode, OH_AVBuffer can directly carry the encoding parameter associated with each frame. Currently, it can manage parameters, including QPMin, QPMax, and reference frames for Long Term Reference (LTR), on a per-frame basis.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 12

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
uint32_t indexIndex of the frame to encode.
OH_AVFormat *parameterPointer to the encoding parameter
void *userDataPointer to the data on which the caller depends when executing the callback.

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.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
const char *mimePointer to a string that describes the MIME type. For details, see AVCODEC_MIME_TYPE.

Returns

TypeDescription
OH_AVCodec *Pointer to the video encoder instance created.
If the encoder type is not supported or the memory is insufficient, NULL is returned.

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. The encoder name can be obtained through capability query.
For details, see Obtaining Supported Codecs.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
const char *namePointer to a video encoder name.

Returns

TypeDescription
OH_AVCodec *Pointer to the video encoder instance created.
If the encoder name is not supported or the memory is insufficient, NULL is returned.

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. You only need to call the function once.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.

OH_VideoEncoder_SetCallback()

OH_AVErrCode OH_VideoEncoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData)

Description

Sets an OH_AVCodecCallback callback so that your application can respond to events generated by a video encoder. This function must be called prior to OH_VideoEncoder_Prepare.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Deprecated from: 11

Substitute: OH_VideoEncoder_RegisterCallback

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
OH_AVCodecAsyncCallback callbackCallback function.
void *userDataPointer to the data on which the caller depends when executing the callback.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.

OH_VideoEncoder_RegisterCallback()

OH_AVErrCode OH_VideoEncoder_RegisterCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData)

Description

Registers an OH_AVCodecCallback callback so that your application can respond to events generated by a video encoder. This function must be called prior to OH_VideoEncoder_Prepare.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 11

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
OH_AVCodecCallback callbackCallback function.
void *userDataPointer to the data on which the caller depends when executing the callback.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.

OH_VideoEncoder_RegisterParameterCallback()

OH_AVErrCode OH_VideoEncoder_RegisterParameterCallback(OH_AVCodec *codec, OH_VideoEncoder_OnNeedInputParameter onInputParameter, void *userData)

Description

Registers an OH_AVCodecCallback input parameter callback so that your application can respond to events generated by a video encoder. In surface encoding mode, this function must be called when frame parameters need to be set,
and it must be called before OH_VideoEncoder_Configure.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 12

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
OH_VideoEncoder_OnNeedInputParameter onInputParameterPointer to the input parameter callback.
void *userDataPointer to the data on which the caller depends when executing the callback.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: The function is not called prior to OH_VideoEncoder_Prepare.

OH_VideoEncoder_Configure()

OH_AVErrCode OH_VideoEncoder_Configure(OH_AVCodec *codec, OH_AVFormat *format)

Description

Configures encoding parameters for a video encoder. Typically, you need to configure the description information about the video frames, such as the frame width, height, and pixel format. This function must be called prior to OH_VideoEncoder_Prepare.
This function is used to verify the validity of configuration parameters. Some invalid parameters are not forcibly verified. The default values are used or discarded. Some invalid parameters are forcibly verified. The rules are as follows:
The value ranges of the following parameters can be obtained through capability query. OH_MD_KEY_I_FRAME_INTERVAL does not support capability query currently.
When attempting to set the OH_MD_KEY_VIDEO_ENCODER_ENABLE_TEMPORAL_SCALABILITY or OH_MD_KEY_VIDEO_ENCODER_LTR_FRAME_COUNT parameter on an unsupported platform, this API will not return an error; instead, it will follow its normal execution path.

Parameter verification rules are as follows:

KeyValue Within the RangeValue Out of RangeNo Value Configured
OH_MD_KEY_WIDTHAV_ERR_OKAV_ERR_INVALID_VALAV_ERR_INVALID_VAL
OH_MD_KEY_HEIGHTAV_ERR_OKAV_ERR_INVALID_VALAV_ERR_INVALID_VAL
OH_MD_KEY_PIXEL_FORMAT OH_AVPixelFormatAV_ERR_OKAV_ERR_UNSUPPORTAV_ERR_OK
OH_MD_KEY_FRAME_RATEAV_ERR_OKAV_ERR_INVALID_VALAV_ERR_OK
OH_MD_KEY_PROFILE OH_MD_KEY_PROFILEAV_ERR_OKAV_ERR_INVALID_VALAV_ERR_OK
OH_MD_KEY_I_FRAME_INTERVALAV_ERR_OK\AV_ERR_OK
OH_MD_KEY_
BITRATE
OH_MD_KEY_
QUALITY
OH_MD_KEY_
VIDEO_ENCODER_BITRATE_MODE
Return ValueDescription
\\\AV_ERR_OKThe default value of the encoder is used.
Out of rangeOut of rangeUnsupported modeAV_ERR_INVALID_VALAn error is reported for all abnormal values.
Normal valueNormal value\AV_ERR_INVALID_VALThe bit rate conflicts with the quality.
Normal value\\AV_ERR_OKThe default bit rate control mode is enabled.
Normal value\BITRATE_MODE_VBR and BITRATE_MODE_CBRAV_ERR_OK-
Normal value\BITRATE_MODE_CQAV_ERR_INVALID_VALThe bit rate conflicts with the CQ mode.
\Normal value\AV_ERR_OKThe CQ mode is enabled.
\Normal valueBITRATE_MODE_CQAV_ERR_OK-
\Normal valueBITRATE_MODE_VBR and BITRATE_MODE_CBRAV_ERR_INVALID_VALThe quality conflicts with the VBR or CBR mode.
\\BITRATE_MODE_VBR and BITRATE_MODE_CBRAV_ERR_OKThe default bit rate of the encoder is used.
\\BITRATE_MODE_CQAV_ERR_OKThe default quality is used.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
OH_AVFormat *formatPointer to an OH_AVFormat instance, which provides the description information about the video track to be encoded.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: 1. The value of codec is nullptr or does not point to an encoder instance. 2. The format is not supported.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: The function is not called prior to OH_VideoEncoder_Prepare.

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 OH_VideoEncoder_Configure.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal error occurs in the input encoder instance.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_Start()

OH_AVErrCode OH_VideoEncoder_Start(OH_AVCodec *codec)

Description

Starts a video encoder. This function should be called after a successful call of OH_VideoEncoder_Prepare. After being started, the encoder starts to report the registered event.
In surface mode, when there is a correct input on the surface, OnNewOutputBuffer is triggered each time a frame is encoded.
In buffer mode, the encoder immediately triggers the input callback. Each time the caller completes an input, the encoder performs encoding. OnNewOutputBuffer is triggered each time a frame is encoded.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_Stop()

OH_AVErrCode OH_VideoEncoder_Stop(OH_AVCodec *codec)

Description

Stops a video encoder and releases the input and output buffers. After the video encoder is stopped, you can call OH_VideoEncoder_Start to enter the running state again.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_Flush()

OH_AVErrCode OH_VideoEncoder_Flush(OH_AVCodec *codec)

Description

Clears the input and output data and parameters, for example, H.264 PPS/SPS, cached in 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. This function cannot be called consecutively.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_Reset()

OH_AVErrCode OH_VideoEncoder_Reset(OH_AVCodec *codec)

Description

Resets a video encoder. The encoder returns to the initial state. To continue encoding, you must call OH_VideoEncoder_Configure to configure the encoder again.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.

OH_VideoEncoder_GetOutputDescription()

OH_AVFormat *OH_VideoEncoder_GetOutputDescription(OH_AVCodec *codec)

Description

Obtains the OH_AVFormat information about the output data of a video encoder.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance in the return value.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVFormat *Pointer to an OH_AVFormat instance.
If the value of codec is nullptr or does not point to an encoder instance, NULL is returned.

OH_VideoEncoder_SetParameter()

OH_AVErrCode OH_VideoEncoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format)

Description

Sets the encoder parameter when a video encoder is running.
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

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
OH_AVFormat *formatPointer to an OH_AVFormat instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: 1. The value of codec is nullptr or does not point to an encoder instance. 2. The format is not supported.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_GetSurface()

OH_AVErrCode OH_VideoEncoder_GetSurface(OH_AVCodec *codec, OHNativeWindow **window)

Description

Obtains the input surface from a video encoder. This function must be called after OH_VideoEncoder_Configure but before OH_VideoEncoder_Prepare.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
OHNativeWindow **windowDouble 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

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.

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: OH_VideoEncoder_FreeOutputBuffer

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
uint32_t indexIndex of the output buffer. The value is provided by OH_AVCodecOnNewOutputData.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

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 used only in surface mode. In buffer mode, OH_AVBuffer is used to carry the EOS information to notify the end of the input stream.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 9

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

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: OH_VideoEncoder_PushInputBuffer

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
uint32_t indexIndex of the input buffer. The value is provided by OH_AVCodecOnNeedInputData.
OH_AVCodecBufferAttr attrDescription of the data contained in the buffer.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_PushInputBuffer()

OH_AVErrCode OH_VideoEncoder_PushInputBuffer(OH_AVCodec *codec, uint32_t index)

Description

Pushes the OH_AVBuffer corresponding to the index to a video encoder in buffer mode.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 11

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
uint32_t indexIndex of the input buffer. The value is provided by OH_AVCodecOnNeedInputBuffer.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: 1. The value of codec is nullptr or does not point to an encoder instance. 2. The format is not supported.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_PushInputParameter()

OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t index)

Description

Pushes the parameter configured for a frame with the given index to a video encoder in surface mode.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 12

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
uint32_t indexIndex of the input parameter buffer. The value is provided by OH_AVCodecOnNeedInputBuffer.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_FreeOutputBuffer()

OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index)

Description

Returns the processed OH_AVBuffer corresponding to the index to a video encoder. You need to call this function to release the output buffer in a timely manner. Otherwise, the encoding process is blocked.
For details, see step 13 in surface mode or step 11 in buffer mode in Video Encoding.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 11

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
uint32_t indexIndex of the output buffer. The value is provided by OH_AVCodecOnNeedInputBuffer.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.
AV_ERR_INVALID_VAL:
1. The value of codec is nullptr or does not point to an encoder instance.
2. The format is not supported.
3. The index is invalid or the same index is used consecutively. This error does not affect the subsequent encoding process.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_OPERATE_NOT_PERMIT: An internal execution error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.

OH_VideoEncoder_GetInputDescription()

OH_AVFormat *OH_VideoEncoder_GetInputDescription(OH_AVCodec *codec)

Description

Obtains the description of the image received by a video encoder. This function must be called after OH_VideoEncoder_Configure is called.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance in the return value.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 10

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.

Returns

TypeDescription
OH_AVFormat *Pointer to an OH_AVFormat instance.
If the value of codec is nullptr or does not point to an encoder instance, NULL is returned.

OH_VideoEncoder_IsValid()

OH_AVErrCode OH_VideoEncoder_IsValid(OH_AVCodec *codec, bool *isValid)

Description

Checks whether the encoder service is valid when an encoder instance exists.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 10

Parameters

NameDescription
OH_AVCodec *codecPointer to a video encoder instance.
bool *isValidPointer of the Boolean type. The value indicates the validity of the encoder service only when the function returns AV_ERR_OK. The value true means that the encoder service is valid, and false means the opposite. It is recommended that you initialize isValid to false.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.

OH_VideoEncoder_QueryInputBuffer()

OH_AVErrCode OH_VideoEncoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)

Description

Obtains the index of the next available input buffer.
After calling this function, you must call OH_VideoEncoder_GetInputBuffer to obtain the buffer instance and call OH_VideoEncoder_PushInputBuffer to pass the buffer instance to the encoder.
Note that the preceding operations are supported only in synchronous mode.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 20

Parameters

NameDescription
struct OH_AVCodec *codecPointer to a video encoder instance.
uint32_t *indexPointer to the index of the input buffer.
int64_t timeoutUsTimeout duration, in microseconds. A negative value means to wait infinitely. The value 0 means to return immediately. A positive value means to wait for the specified time before exiting.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: The encoder instance has been destroyed.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.
AV_ERR_OPERATE_NOT_PERMIT: This function is called in asynchronous mode.
AV_ERR_TRY_AGAIN_LATER: The query fails. Try again after a short interval.

OH_VideoEncoder_GetInputBuffer()

OH_AVBuffer *OH_VideoEncoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index)

Description

Obtains the instance of the available input buffer.
Note that this function works only in synchronous mode.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 20

Parameters

NameDescription
struct OH_AVCodec *codecPointer to a video encoder instance.
uint32_t indexIndex of the input buffer. It can be obtained by calling OH_VideoEncoder_QueryInputBuffer.

Returns

TypeDescription
OH_AVBuffer *Pointer to the OH_AVBuffer instance created. If the operation fails, NULL is returned.

OH_VideoEncoder_QueryOutputBuffer()

OH_AVErrCode OH_VideoEncoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)

Description

Obtains the index of the next available output buffer. Through the buffer instance obtained via OH_VideoEncoder_GetOutputBuffer, you can return the processed output buffer to the encoder by calling OH_VideoEncoder_FreeOutputBuffer.
Note that the preceding operations are supported only in synchronous mode.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 20

Parameters

NameDescription
struct OH_AVCodec *codecPointer to a video encoder instance.
uint32_t *indexPointer to the index of the output buffer.
int64_t timeoutUsTimeout duration, in microseconds. A negative value means to wait infinitely. The value 0 means to return immediately. A positive value means to wait for the specified time before exiting.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: The encoder instance has been destroyed.
AV_ERR_INVALID_VAL: The value of codec is nullptr or does not point to an encoder instance.
AV_ERR_UNKNOWN: An unknown error occurs.
AV_ERR_INVALID_STATE: This API cannot be called in the current encoder state.
AV_ERR_OPERATE_NOT_PERMIT: This function is called in asynchronous mode.
AV_ERR_STREAM_CHANGED: The stream format has changed. You can call OH_VideoEncoder_GetOutputDescription to obtain the new stream information.
AV_ERR_TRY_AGAIN_LATER: The query fails. Try again after a short interval.

OH_VideoEncoder_GetOutputBuffer()

OH_AVBuffer *OH_VideoEncoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index)

Description

Obtains the instance of the available output buffer.
Note that this function works only in synchronous mode.

System capability: SystemCapability.Multimedia.Media.VideoEncoder

Since: 20

Parameters

NameDescription
struct OH_AVCodec *codecPointer to a video encoder instance.
uint32_t indexIndex of the output buffer. It can be obtained by calling OH_VideoEncoder_QueryOutputBuffer.

Returns

TypeDescription
OH_AVBuffer *Pointer to the OH_AVBuffer instance created. If the operation fails, NULL is returned.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-native-avcodec-audiocodec-h

openharmony 鸿蒙 capi-avsource-oh-avsource

openharmony 鸿蒙 capi-native-cencinfo-h

openharmony 鸿蒙 capi-avmuxer

openharmony 鸿蒙 capi-multimedia-drm-oh-avcencinfo

openharmony 鸿蒙 capi-native-avdemuxer-h

openharmony 鸿蒙 capi-media-types-h

openharmony 鸿蒙 capi-native-audio-channel-layout-h

openharmony 鸿蒙 capi-native-avbuffer-info-h

openharmony 鸿蒙 capi-codecbase-oh-avcodecasynccallback

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/IVYMYn20