• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# native_avcodec_videoencoder.h
2<!--Kit: AVCodec Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @zhanghongran-->
5<!--Designer: @dpy2650--->
6<!--Tester: @cyakee-->
7<!--Adviser: @zengyawen-->
8
9## Overview
10
11The file declares the APIs used for video encoding.
12
13**File to include**: <multimedia/player_framework/native_avcodec_videoencoder.h>
14
15**Library**: libnative_media_venc.so
16
17**System capability**: SystemCapability.Multimedia.VideoEncoder
18
19**Since**: 9
20
21**Related module**: [VideoEncoder](capi-videoencoder.md)
22
23**Sample**: [AVCodec](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/Media/AVCodec)
24
25The following figures show the APIs supported by each version and the APIs that can be called in different states.
26
27![meaning](figures/meaning.PNG)
28
29![desciption of encode api history](figures/video-encode-api.PNG)
30
31## Summary
32
33### Enums
34
35| Name| typedef Keyword| Description|
36| -- | -- | -- |
37| [OH_VideoEncodeBitrateMode](#oh_videoencodebitratemode) | OH_VideoEncodeBitrateMode | Enumerates the bit rate modes of a video encoder.|
38
39### Functions
40
41| Name| typedef Keyword| Description|
42| -- | -- | -- |
43| [typedef void (\*OH_VideoEncoder_OnNeedInputParameter)(OH_AVCodec *codec, uint32_t index, OH_AVFormat *parameter,void *userData)](#oh_videoencoder_onneedinputparameter) | OH_VideoEncoder_OnNeedInputParameter | Defines 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.|
44| [OH_AVCodec *OH_VideoEncoder_CreateByMime(const char *mime)](#oh_videoencoder_createbymime) | - | Creates a video encoder instance based on a MIME type. This function is recommended.|
45| [OH_AVCodec *OH_VideoEncoder_CreateByName(const char *name)](#oh_videoencoder_createbyname) | - | 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. |
46| [OH_AVErrCode OH_VideoEncoder_Destroy(OH_AVCodec *codec)](#oh_videoencoder_destroy) | - | Clears the internal resources of a video encoder and destroys the encoder instance. You only need to call the function once.|
47| [OH_AVErrCode OH_VideoEncoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData)](#oh_videoencoder_setcallback) | - | 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**.|
48| [OH_AVErrCode OH_VideoEncoder_RegisterCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData)](#oh_videoencoder_registercallback) | - | 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**.|
49| [OH_AVErrCode OH_VideoEncoder_RegisterParameterCallback(OH_AVCodec *codec,OH_VideoEncoder_OnNeedInputParameter onInputParameter,void *userData)](#oh_videoencoder_registerparametercallback) | - | 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_videoencoder_configure).|
50| [OH_AVErrCode OH_VideoEncoder_Configure(OH_AVCodec *codec, OH_AVFormat *format)](#oh_videoencoder_configure) | - | Configures a video encoder. Typically, you need to configure the description information about the video track to be encoded, such as the width, height, and pixel format. This function must be called prior to **OH_VideoEncoder_Prepare**.|
51| [OH_AVErrCode OH_VideoEncoder_Prepare(OH_AVCodec *codec)](#oh_videoencoder_prepare) | - | Prepares internal resources for a video encoder. This function must be called after **OH_VideoEncoder_Configure**.|
52| [OH_AVErrCode OH_VideoEncoder_Start(OH_AVCodec *codec)](#oh_videoencoder_start) | - | Starts a video encoder. This function should be called after a successful call of [OH_VideoEncoder_Prepare](#oh_videoencoder_prepare). After being started, the encoder starts to report the registered event.|
53| [OH_AVErrCode OH_VideoEncoder_Stop(OH_AVCodec *codec)](#oh_videoencoder_stop) | - | 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.|
54| [OH_AVErrCode OH_VideoEncoder_Flush(OH_AVCodec *codec)](#oh_videoencoder_flush) | - | 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.|
55| [OH_AVErrCode OH_VideoEncoder_Reset(OH_AVCodec *codec)](#oh_videoencoder_reset) | - | 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.|
56| [OH_AVFormat *OH_VideoEncoder_GetOutputDescription(OH_AVCodec *codec)](#oh_videoencoder_getoutputdescription) | - | Obtains the OH_AVFormat information about the output data of a video encoder. For details, see {@link OH_AVFormat}. The caller must call **OH_AVFormat_Destroy()** to release the **OH_AVFormat** instance in the return value.|
57| [OH_AVErrCode OH_VideoEncoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format)](#oh_videoencoder_setparameter) | - | 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.|
58| [OH_AVErrCode OH_VideoEncoder_GetSurface(OH_AVCodec *codec, OHNativeWindow **window)](#oh_videoencoder_getsurface) | - | Obtains the input surface from a video encoder. This function must be called prior to **OH_VideoEncoder_Prepare**.|
59| [OH_AVErrCode OH_VideoEncoder_FreeOutputData(OH_AVCodec *codec, uint32_t index)](#oh_videoencoder_freeoutputdata) | - | Frees an output buffer of a video encoder.|
60| [OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream(OH_AVCodec *codec)](#oh_videoencoder_notifyendofstream) | - | 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.|
61| [OH_AVErrCode OH_VideoEncoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr)](#oh_videoencoder_pushinputdata) | - | Pushes the input buffer filled with data to a video encoder.|
62| [OH_AVErrCode OH_VideoEncoder_PushInputBuffer(OH_AVCodec *codec, uint32_t index)](#oh_videoencoder_pushinputbuffer) | - | Pushes the OH_AVBuffer corresponding to the index to a video encoder in buffer mode.|
63| [OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t index)](#oh_videoencoder_pushinputparameter) | - | Pushes the parameter configured for a frame with the given index to a video encoder in surface mode.|
64| [OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index)](#oh_videoencoder_freeoutputbuffer) | - | 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.|
65| [OH_AVFormat *OH_VideoEncoder_GetInputDescription(OH_AVCodec *codec)](#oh_videoencoder_getinputdescription) | - | Obtains the description of the image received by a video encoder. This function must be called after [OH_VideoEncoder_Configure](#oh_videoencoder_configure). For details, see **OH_AVFormat**. You must call [OH_AVFormat_Destroy](capi-native-avformat-h.md#oh_avformat_destroy) to manually release the OH_AVFormat instance in the return value.|
66| [OH_AVErrCode OH_VideoEncoder_IsValid(OH_AVCodec *codec, bool *isValid)](#oh_videoencoder_isvalid) | - | Checks whether a video encoder instance is valid.|
67| [OH_AVErrCode OH_VideoEncoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)](#oh_videoencoder_queryinputbuffer) | - | Obtains the index of the next available input buffer. After calling this function, you must call [OH_VideoEncoder_GetInputBuffer](#oh_videoencoder_getinputbuffer) to obtain the buffer instance and call [OH_VideoEncoder_PushInputBuffer](#oh_videoencoder_pushinputbuffer) to pass the buffer instance to the encoder.<br>Note that the preceding operations are supported only in synchronous mode.|
68| [OH_AVBuffer *OH_VideoEncoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index)](#oh_videoencoder_getinputbuffer) | - | Obtains the instance of the available input buffer. Note that this function works only in synchronous mode.|
69| [OH_AVErrCode OH_VideoEncoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)](#oh_videoencoder_queryoutputbuffer) | - | Obtains the index of the next available output buffer. Through the buffer instance obtained via [OH_VideoEncoder_GetOutputBuffer](#oh_videoencoder_getoutputbuffer), you can return the processed output buffer to the encoder by calling [OH_VideoEncoder_FreeOutputBuffer](#oh_videoencoder_freeoutputbuffer).<br>Note that the preceding operations are supported only in synchronous mode.|
70| [OH_AVBuffer *OH_VideoEncoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index)](#oh_videoencoder_getoutputbuffer) | - | Obtains the instance of the available output buffer. Note that this function works only in synchronous mode.|
71
72## Enum Description
73
74### OH_VideoEncodeBitrateMode
75
76```
77enum OH_VideoEncodeBitrateMode
78```
79
80**Description**
81
82Enumerates the bit rate modes of a video encoder.
83
84**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
85
86**Since**: 9
87
88**Deprecated from**: 14
89
90**Substitute**: [OH_BitrateMode](capi-native-avcodec-base-h.md#oh_bitratemode)
91
92| Value| Description|
93| -- | -- |
94| CBR = 0 | Constant bit rate.<br>**Deprecated from**: 14<br>**Substitute**: [BITRATE_MODE_CBR](capi-native-avcodec-base-h.md#oh_bitratemode)|
95| VBR = 1 | Variable bit rate.<br>**Deprecated from**: 14<br>**Substitute**: [BITRATE_MODE_VBR](capi-native-avcodec-base-h.md#oh_bitratemode)|
96| CQ = 2 | Constant quality.<br>**Deprecated from**: 14<br>**Substitute**: [BITRATE_MODE_CQ](capi-native-avcodec-base-h.md#oh_bitratemode)|
97
98
99## Function Description
100
101### OH_VideoEncoder_OnNeedInputParameter()
102
103```
104typedef void (*OH_VideoEncoder_OnNeedInputParameter)(OH_AVCodec *codec, uint32_t index, OH_AVFormat *parameter,void *userData)
105```
106
107**Description**
108
109Defines the pointer to the function that is called when new input parameters are required for a frame with the specified index.
110
111This callback can be used only in surface mode after it is registered by calling OH_VideoEncoder_RegisterParameterCallback.
112
113In 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.
114
115**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
116
117**Since**: 12
118
119
120**Parameters**
121
122| Name| Description|
123| -- | -- |
124| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
125|  uint32_t index | Index of the frame to encode.|
126|  [OH_AVFormat](capi-core-oh-avformat.md) *parameter |  Pointer to the encoding parameter|
127| void *userData | Pointer to the data on which the caller depends when executing the callback.|
128
129### OH_VideoEncoder_CreateByMime()
130
131```
132OH_AVCodec *OH_VideoEncoder_CreateByMime(const char *mime)
133```
134
135**Description**
136
137Creates a video encoder instance based on a MIME type. This function is recommended.
138
139**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
140
141**Since**: 9
142
143
144**Parameters**
145
146| Name| Description|
147| -- | -- |
148| const char *mime | Pointer to a string that describes the MIME type. For details, see [AVCODEC_MIME_TYPE](capi-native-avcodec-base-h.md#variables).|
149
150**Returns**
151
152| Type| Description|
153| -- | -- |
154| [OH_AVCodec](capi-codecbase-oh-avcodec.md) * | Pointer to the video encoder instance created.<br>If the encoder type is not supported or the memory is insufficient, NULL is returned.|
155
156### OH_VideoEncoder_CreateByName()
157
158```
159OH_AVCodec *OH_VideoEncoder_CreateByName(const char *name)
160```
161
162**Description**
163
164Creates a video encoder instance based on an encoder name.
165
166To 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](../../media/avcodec/obtain-supported-codecs.md#creating-a-codec-with-the-specified-name).
167
168**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
169
170**Since**: 9
171
172
173**Parameters**
174
175| Name| Description|
176| -- | -- |
177| const char *name | Pointer to a video encoder name.|
178
179**Returns**
180
181| Type| Description|
182| -- | -- |
183| [OH_AVCodec](capi-codecbase-oh-avcodec.md) * | Pointer to the video encoder instance created.<br>If the encoder name is not supported or the memory is insufficient, NULL is returned.|
184
185### OH_VideoEncoder_Destroy()
186
187```
188OH_AVErrCode OH_VideoEncoder_Destroy(OH_AVCodec *codec)
189```
190
191**Description**
192
193Clears the internal resources of a video encoder and destroys the encoder instance. You only need to call the function once.
194
195**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
196
197**Since**: 9
198
199
200**Parameters**
201
202| Name| Description|
203| -- | -- |
204| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
205
206**Returns**
207
208| Type| Description|
209| -- | -- |
210| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.|
211
212### OH_VideoEncoder_SetCallback()
213
214```
215OH_AVErrCode OH_VideoEncoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData)
216```
217
218**Description**
219
220Sets 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**.
221
222**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
223
224**Since**: 9
225
226**Deprecated from**: 11
227
228**Substitute**: [OH_VideoEncoder_RegisterCallback](#oh_videoencoder_registercallback)
229
230
231**Parameters**
232
233| Name| Description|
234| -- | -- |
235| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
236| [OH_AVCodecAsyncCallback](capi-codecbase-oh-avcodecasynccallback.md) callback | Callback function.|
237| void *userData | Pointer to the data on which the caller depends when executing the callback.|
238
239**Returns**
240
241| Type| Description|
242| -- | -- |
243| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is not called prior to **OH_VideoEncoder_Prepare**.|
244
245### OH_VideoEncoder_RegisterCallback()
246
247```
248OH_AVErrCode OH_VideoEncoder_RegisterCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData)
249```
250
251**Description**
252
253Registers 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**.
254
255**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
256
257**Since**: 11
258
259
260**Parameters**
261
262| Name| Description|
263| -- | -- |
264| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
265| [OH_AVCodecCallback](capi-codecbase-oh-avcodeccallback.md) callback | Callback function.|
266| void *userData | Pointer to the data on which the caller depends when executing the callback.|
267
268**Returns**
269
270| Type| Description|
271| -- | -- |
272| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is not called prior to **OH_VideoEncoder_Prepare**.|
273
274### OH_VideoEncoder_RegisterParameterCallback()
275
276```
277OH_AVErrCode OH_VideoEncoder_RegisterParameterCallback(OH_AVCodec *codec,OH_VideoEncoder_OnNeedInputParameter onInputParameter,void *userData)
278```
279
280**Description**
281
282Registers 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_videoencoder_configure).
283
284**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
285
286**Since**: 12
287
288
289**Parameters**
290
291| Name| Description|
292| -- | -- |
293| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
294| [OH_VideoEncoder_OnNeedInputParameter](#oh_videoencoder_onneedinputparameter) onInputParameter | Pointer to the input parameter callback.|
295| void *userData | Pointer to the data on which the caller depends when executing the callback.|
296
297**Returns**
298
299| Type| Description|
300| -- | -- |
301| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is not called prior to **OH_VideoEncoder_Prepare**.|
302
303### OH_VideoEncoder_Configure()
304
305```
306OH_AVErrCode OH_VideoEncoder_Configure(OH_AVCodec *codec, OH_AVFormat *format)
307```
308
309**Description**
310
311Configures a video encoder. Typically, you need to configure the description information about the video track to be encoded, such as the width, height, and pixel format. This function must be called prior to **OH_VideoEncoder_Prepare**.
312
313This 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:
314
315- The value ranges of the following parameters can be obtained from [Capability Query](../../media/avcodec/obtain-supported-codecs.md). All the values of **OH_MD_KEY_I_FRAME_INTERVAL** are supported.
316- If the current platform does not support **OH_MD_KEY_VIDEO_ENCODER_ENABLE_TEMPORAL_SCALABILITY** or **OH_MD_KEY_VIDEO_ENCODER_LTR_FRAME_COUNT**, no error is reported and the normal encoding process is used.
317
318Parameter verification rules are as follows:
319
320| Key     | Value Within the Range| Value Out of Range| No Value Configured|
321| ------- | -------- | -------- | ------ |
322| OH_MD_KEY_WIDTH         | AV_ERR_OK       | AV_ERR_INVALID_VAL       | AV_ERR_INVALID_VAL     |
323| OH_MD_KEY_HEIGHT        | AV_ERR_OK       | AV_ERR_INVALID_VAL       | AV_ERR_INVALID_VAL     |
324| OH_MD_KEY_PIXEL_FORMAT<br>For details, see [OH_AVPixelFormat](_core.md#oh_avpixelformat-1).| AV_ERR_OK       | AV_ERR_UNSUPPORT       | AV_ERR_OK    |
325| OH_MD_KEY_FRAME_RATE     | AV_ERR_OK       | AV_ERR_INVALID_VAL       |AV_ERR_OK        |
326| OH_MD_KEY_PROFILE<br>For details, see [OH_MD_KEY_PROFILE](_codec_base.md#oh_md_key_profile).   | AV_ERR_OK       | AV_ERR_INVALID_VAL       |AV_ERR_OK       |
327| OH_MD_KEY_I_FRAME_INTERVAL       | AV_ERR_OK       | \\       | AV_ERR_OK       |
328
329| OH_MD_KEY_<br>BITRATE | OH_MD_KEY_<br>QUALITY | OH_MD_KEY_<br>VIDEO_ENCODER_BITRATE_MODE | Return Value| Description    |
330| :-------- | :---------| :---------- | ---- | ---------- |
331| \\      | \\      | \\           |  AV_ERR_OK    | The default value of the encoder is used.|
332| Out of range   | Out of range   | Unsupported mode      | AV_ERR_INVALID_VAL   | An error is reported for all abnormal values.  |
333| Normal value    | Normal value    | \\           | AV_ERR_INVALID_VAL   | The bit rate conflicts with the quality.  |
334| Normal value    | \\      | \\           | AV_ERR_OK     | The default bit rate control mode is enabled.|
335| Normal value    | \\      | BITRATE_MODE_VBR and BITRATE_MODE_CBR     | AV_ERR_OK     |          |
336| Normal value    | \\      | BITRATE_MODE_CQ           | AV_ERR_INVALID_VAL   | The bit rate conflicts with the CQ mode.     |
337| \\      | Normal value    | \\           | AV_ERR_OK     | The CQ mode is enabled.|
338| \\      | Normal value    | BITRATE_MODE_CQ           | AV_ERR_OK     |          |
339| \\      | Normal value    | BITRATE_MODE_VBR and BITRATE_MODE_CBR     | AV_ERR_INVALID_VAL   | The quality conflicts with the VBR or CBR mode.|
340| \\      | \\      | BITRATE_MODE_VBR and BITRATE_MODE_CBR     | AV_ERR_OK     | The default bit rate of the encoder is used.|
341| \\      | \\      | BITRATE_MODE_CQ           | AV_ERR_OK    | The default quality is used. |
342
343**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
344
345**Since**: 9
346
347
348**Parameters**
349
350| Name| Description|
351| -- | -- |
352| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
353| [OH_AVFormat](capi-core-oh-avformat.md) *format | Pointer to an OH_AVFormat instance, which provides the description information about the video track to be encoded.|
354
355**Returns**
356
357| Type| Description|
358| -- | -- |
359| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**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.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is not called prior to **OH_VideoEncoder_Prepare**.|
360
361### OH_VideoEncoder_Prepare()
362
363```
364OH_AVErrCode OH_VideoEncoder_Prepare(OH_AVCodec *codec)
365```
366
367**Description**
368
369Prepares internal resources for a video encoder. This function must be called after **OH_VideoEncoder_Configure**.
370
371**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
372
373**Since**: 9
374
375
376**Parameters**
377
378| Name| Description|
379| -- | -- |
380| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
381
382**Returns**
383
384| Type| Description|
385| -- | -- |
386| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.|
387
388### OH_VideoEncoder_Start()
389
390```
391OH_AVErrCode OH_VideoEncoder_Start(OH_AVCodec *codec)
392```
393
394**Description**
395
396Starts a video encoder. This function should be called after a successful call of [OH_VideoEncoder_Prepare](#oh_videoencoder_prepare). After being started, the encoder starts to report the registered event.
397
398In surface mode, when there is a correct input on the surface, **OnNewOutputBuffer** is triggered each time a frame is encoded.
399
400In 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.
401
402**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
403
404**Since**: 9
405
406
407**Parameters**
408
409| Name| Description|
410| -- | -- |
411| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
412
413**Returns**
414
415| Type| Description|
416| -- | -- |
417| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
418
419### OH_VideoEncoder_Stop()
420
421```
422OH_AVErrCode OH_VideoEncoder_Stop(OH_AVCodec *codec)
423```
424
425**Description**
426
427Stops 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.
428
429**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
430
431**Since**: 9
432
433
434**Parameters**
435
436| Name| Description|
437| -- | -- |
438| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
439
440**Returns**
441
442| Type| Description|
443| -- | -- |
444| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
445
446### OH_VideoEncoder_Flush()
447
448```
449OH_AVErrCode OH_VideoEncoder_Flush(OH_AVCodec *codec)
450```
451
452**Description**
453
454Clears the input and output data and parameters, for example, H.264 PPS/SPS, cached in a video encoder.
455
456This 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.
457
458**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
459
460**Since**: 9
461
462
463**Parameters**
464
465| Name| Description|
466| -- | -- |
467| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
468
469**Returns**
470
471| Type| Description|
472| -- | -- |
473| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
474
475### OH_VideoEncoder_Reset()
476
477```
478OH_AVErrCode OH_VideoEncoder_Reset(OH_AVCodec *codec)
479```
480
481**Description**
482
483Resets a video encoder. The encoder returns to the initial state. To continue encoding, you must call **OH_VideoEncoder_Configure** to configure the encoder again.
484
485**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
486
487**Since**: 9
488
489
490**Parameters**
491
492| Name| Description|
493| -- | -- |
494| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
495
496**Returns**
497
498| Type| Description|
499| -- | -- |
500| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.|
501
502### OH_VideoEncoder_GetOutputDescription()
503
504```
505OH_AVFormat *OH_VideoEncoder_GetOutputDescription(OH_AVCodec *codec)
506```
507
508**Description**
509
510Obtains the OH_AVFormat information about the output data of a video encoder.
511
512You must call [OH_AVFormat_Destroy](capi-native-avformat-h.md#oh_avformat_destroy) to release the OH_AVFormat instance in the return value.
513
514**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
515
516**Since**: 9
517
518
519**Parameters**
520
521| Name| Description|
522| -- | -- |
523| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
524
525**Returns**
526
527| Type| Description|
528| -- | -- |
529| [OH_AVFormat](capi-core-oh-avformat.md) * | Pointer to an OH_AVFormat instance.<br>If the value of **codec** is nullptr or does not point to an encoder instance, NULL is returned.|
530
531### OH_VideoEncoder_SetParameter()
532
533```
534OH_AVErrCode OH_VideoEncoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format)
535```
536
537**Description**
538
539Sets the encoder parameter when a video encoder is running.
540
541This function can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure.
542
543**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
544
545**Since**: 9
546
547
548**Parameters**
549
550| Name| Description|
551| -- | -- |
552| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
553| [OH_AVFormat](capi-core-oh-avformat.md) *format | Pointer to an OH_AVFormat instance.|
554
555**Returns**
556
557| Type| Description|
558| -- | -- |
559| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**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.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
560
561### OH_VideoEncoder_GetSurface()
562
563```
564OH_AVErrCode OH_VideoEncoder_GetSurface(OH_AVCodec *codec, OHNativeWindow **window)
565```
566
567**Description**
568
569Obtains the input surface from a video encoder. This function must be called after **OH_VideoEncoder_Configure** but before **OH_VideoEncoder_Prepare**.
570
571**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
572
573**Since**: 9
574
575
576**Parameters**
577
578| Name| Description|
579| -- | -- |
580| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
581| [OHNativeWindow](../apis-arkgraphics2d/capi-nativewindow-nativewindow.md) **window | Double pointer to an OHNativeWindow instance. The application manages the lifecycle of the window and calls [OH_NativeWindow_DestroyNativeWindow](../apis-arkgraphics2d/capi-external-window-h.md#oh_nativewindow_destroynativewindow) to release the window when the lifecycle ends.|
582
583**Returns**
584
585| Type| Description|
586| -- | -- |
587| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.|
588
589### OH_VideoEncoder_FreeOutputData()
590
591```
592OH_AVErrCode OH_VideoEncoder_FreeOutputData(OH_AVCodec *codec, uint32_t index)
593```
594
595**Description**
596
597Frees an output buffer of a video encoder.
598
599**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
600
601**Since**: 9
602
603**Deprecated from**: 11
604
605**Substitute**: [OH_VideoEncoder_FreeOutputBuffer](#oh_videoencoder_freeoutputbuffer)
606
607
608**Parameters**
609
610| Name| Description|
611| -- | -- |
612| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
613| uint32_t index | Index of the output buffer. The value is provided by [OH_AVCodecOnNewOutputData](capi-native-avcodec-base-h.md#oh_avcodeconnewoutputdata).|
614
615**Returns**
616
617| Type| Description|
618| -- | -- |
619| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
620
621### OH_VideoEncoder_NotifyEndOfStream()
622
623```
624OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream(OH_AVCodec *codec)
625```
626
627**Description**
628
629Notifies 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.
630
631**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
632
633**Since**: 9
634
635
636**Parameters**
637
638| Name| Description|
639| -- | -- |
640| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
641
642**Returns**
643
644| Type| Description|
645| -- | -- |
646| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
647
648### OH_VideoEncoder_PushInputData()
649
650```
651OH_AVErrCode OH_VideoEncoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr)
652```
653
654**Description**
655
656Pushes the input buffer filled with data to a video encoder.
657
658**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
659
660**Since**: 10
661
662**Deprecated from**: 11
663
664**Substitute**: [OH_VideoEncoder_PushInputBuffer](#oh_videoencoder_pushinputbuffer)
665
666
667**Parameters**
668
669| Name| Description|
670| -- | -- |
671| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
672| uint32_t index | Index of the input buffer. The value is provided by [OH_AVCodecOnNeedInputData](capi-native-avcodec-base-h.md#oh_avcodeconneedinputdata).|
673| [OH_AVCodecBufferAttr](capi-core-oh-avcodecbufferattr.md) attr | Description of the data contained in the buffer.|
674
675**Returns**
676
677| Type| Description|
678| -- | -- |
679| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
680
681### OH_VideoEncoder_PushInputBuffer()
682
683```
684OH_AVErrCode OH_VideoEncoder_PushInputBuffer(OH_AVCodec *codec, uint32_t index)
685```
686
687**Description**
688
689Pushes the OH_AVBuffer corresponding to the index to a video encoder in buffer mode.
690
691**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
692
693**Since**: 11
694
695
696**Parameters**
697
698| Name| Description|
699| -- | -- |
700| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
701| uint32_t index | Index of the input buffer. The value is provided by [OH_AVCodecOnNeedInputBuffer](capi-native-avcodec-base-h.md#oh_avcodeconneedinputbuffer).|
702
703**Returns**
704
705| Type| Description|
706| -- | -- |
707| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**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.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
708
709### OH_VideoEncoder_PushInputParameter()
710
711```
712OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t index)
713```
714
715**Description**
716
717Pushes the parameter configured for a frame with the given index to a video encoder in surface mode.
718
719**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
720
721**Since**: 12
722
723
724**Parameters**
725
726| Name| Description|
727| -- | -- |
728| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
729| uint32_t index | Index of the input parameter buffer. The value is provided by [OH_AVCodecOnNeedInputBuffer](capi-native-avcodec-base-h.md#oh_avcodeconneedinputbuffer).|
730
731**Returns**
732
733| Type| Description|
734| -- | -- |
735| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.|
736
737### OH_VideoEncoder_FreeOutputBuffer()
738
739```
740OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index)
741```
742
743**Description**
744
745Returns the processed OH_AVBuffer corresponding to the index to a video encoder.
746
747You 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](../../media/avcodec/video-encoding.md).
748
749**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
750
751**Since**: 11
752
753
754**Parameters**
755
756| Name| Description|
757| -- | -- |
758| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
759| uint32_t index | Index of the output buffer. The value is provided by [OH_AVCodecOnNeedInputBuffer](capi-native-avcodec-base-h.md#oh_avcodeconneedinputbuffer).|
760
761**Returns**
762
763| Type| Description|
764| -- | -- |
765| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: An internal exception occurs in the encoder instance, for example, an unexpected nullptr.<br>**AV_ERR_INVALID_VAL**:<br>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.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state. |
766
767### OH_VideoEncoder_GetInputDescription()
768
769```
770OH_AVFormat *OH_VideoEncoder_GetInputDescription(OH_AVCodec *codec)
771```
772
773**Description**
774
775Obtains the description of the image received by a video encoder. This function must be called after [OH_VideoEncoder_Configure](#oh_videoencoder_configure) is called.
776
777You must call [OH_AVFormat_Destroy](capi-native-avformat-h.md#oh_avformat_destroy) to release the OH_AVFormat instance in the return value.
778
779**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
780
781**Since**: 10
782
783
784**Parameters**
785
786| Name| Description|
787| -- | -- |
788| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
789
790**Returns**
791
792| Type| Description|
793| -- | -- |
794| [OH_AVFormat](capi-core-oh-avformat.md) * | Pointer to an OH_AVFormat instance.<br> If the value of **codec** is nullptr or does not point to an encoder instance, NULL is returned.|
795
796### OH_VideoEncoder_IsValid()
797
798```
799OH_AVErrCode OH_VideoEncoder_IsValid(OH_AVCodec *codec, bool *isValid)
800```
801
802**Description**
803
804Checks whether the encoder service is valid when an encoder instance exists.
805
806**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
807
808**Since**: 10
809
810
811**Parameters**
812
813| Name| Description|
814| -- | -- |
815| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
816| bool *isValid | Pointer 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**.|
817
818**Returns**
819
820| Type| Description|
821| -- | -- |
822| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.|
823
824### OH_VideoEncoder_QueryInputBuffer()
825
826```
827OH_AVErrCode OH_VideoEncoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)
828```
829
830**Description**
831
832Obtains the index of the next available input buffer.
833
834After calling this function, you must call [OH_VideoEncoder_GetInputBuffer](#oh_videoencoder_getinputbuffer) to obtain the buffer instance and call [OH_VideoEncoder_PushInputBuffer](#oh_videoencoder_pushinputbuffer) to pass the buffer instance to the encoder.
835
836Note that the preceding operations are supported only in synchronous mode.
837
838**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
839
840**Since**: 20
841
842
843**Parameters**
844
845| Name| Description|
846| -- | -- |
847| [struct OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
848| uint32_t *index | Pointer to the index of the input buffer.|
849| int64_t timeoutUs | Timeout 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.|
850
851**Returns**
852
853| Type| Description|
854| -- | -- |
855| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: The encoder instance has been destroyed.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_SERVICE_DIED**: The codec service has been terminated.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br>**AV_ERR_OPERATE_NOT_PERMIT**: This function is called in asynchronous mode.<br>**AV_ERR_TRY_AGAIN_LATER**: The query fails. Try again after a short interval.|
856
857### OH_VideoEncoder_GetInputBuffer()
858
859```
860OH_AVBuffer *OH_VideoEncoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index)
861```
862
863**Description**
864
865Obtains the instance of the available input buffer.
866
867Note that this function works only in synchronous mode.
868
869**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
870
871**Since**: 20
872
873
874**Parameters**
875
876| Name| Description|
877| -- | -- |
878| [struct OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
879| uint32_t index | Index of the input buffer. It can be obtained by calling [OH_VideoEncoder_QueryInputBuffer](#oh_videoencoder_queryinputbuffer).|
880
881**Returns**
882
883| Type| Description|
884| -- | -- |
885| [OH_AVBuffer](capi-core-oh-avbuffer.md) * | Pointer to the OH_AVBuffer instance created. If the operation fails, NULL is returned.|
886
887### OH_VideoEncoder_QueryOutputBuffer()
888
889```
890OH_AVErrCode OH_VideoEncoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)
891```
892
893**Description**
894
895Obtains the index of the next available output buffer.
896
897Through the buffer instance obtained via [OH_VideoEncoder_GetOutputBuffer](#oh_videoencoder_getoutputbuffer), you can return the processed output buffer to the encoder by calling [OH_VideoEncoder_FreeOutputBuffer](#oh_videoencoder_freeoutputbuffer).
898
899Note that the preceding operations are supported only in synchronous mode.
900
901**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
902
903**Since**: 20
904
905
906**Parameters**
907
908| Name| Description|
909| -- | -- |
910| [struct OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
911| uint32_t *index | Pointer to the index of the output buffer.|
912| int64_t timeoutUs | Timeout 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.|
913
914**Returns**
915
916| Type| Description|
917| -- | -- |
918| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: The encoder instance has been destroyed.<br>**AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to an encoder instance.<br>**AV_ERR_UNKNOWN**: An unknown error occurs.<br>**AV_ERR_SERVICE_DIED**: The codec service has been terminated.<br>**AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br>**AV_ERR_OPERATE_NOT_PERMIT**: This function is called in asynchronous mode.<br>**AV_ERR_STREAM_CHANGED**: The stream format has changed. You can call [OH_VideoEncoder_GetOutputDescription](#oh_videoencoder_getoutputdescription) to obtain the new stream information.<br>**AV_ERR_TRY_AGAIN_LATER**: The query fails. Try again after a short interval.|
919
920### OH_VideoEncoder_GetOutputBuffer()
921
922```
923OH_AVBuffer *OH_VideoEncoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index)
924```
925
926**Description**
927
928Obtains the instance of the available output buffer.
929
930Note that this function works only in synchronous mode.
931
932**System capability**: SystemCapability.Multimedia.Media.VideoEncoder
933
934**Since**: 20
935
936
937**Parameters**
938
939| Name| Description|
940| -- | -- |
941| struct [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video encoder instance.|
942| uint32_t index | Index of the output buffer. It can be obtained by calling [OH_VideoEncoder_QueryOutputBuffer](#oh_videoencoder_queryoutputbuffer).|
943
944**Returns**
945
946| Type| Description|
947| -- | -- |
948| [OH_AVBuffer](capi-core-oh-avbuffer.md) * | Pointer to the OH_AVBuffer instance created. If the operation fails, NULL is returned.|
949
950<!--no_check-->