• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# VideoEncoder
2
3
4## Overview
5
6Provides the functions and enums for video encoding.
7
8\@syscap SystemCapability.Multimedia.Media.VideoEncoder
9
10**Since:**
119
12
13
14## Summary
15
16
17### Files
18
19| Name | Description |
20| -------- | -------- |
21| [native_avcodec_videoencoder.h](native__avcodec__videoencoder_8h.md) | Declares the native APIs used for video encoding. <br>File to Include: <multimedia/player_framework/native_avcodec_videoencoder.h> |
22
23
24### Types
25
26| Name | Description |
27| -------- | -------- |
28| [OH_VideoEncodeBitrateMode](#oh_videoencodebitratemode) | Enumerates the bit rate modes of video encoding.  |
29
30
31### Enums
32
33| Name | Description |
34| -------- | -------- |
35| [OH_VideoEncodeBitrateMode](#oh_videoencodebitratemode) { CBR = 0, VBR = 1, CQ = 2 } | Enumerates the bit rate modes of video encoding.  |
36
37
38### Functions
39
40| Name | Description |
41| -------- | -------- |
42| [OH_VideoEncoder_CreateByMime](#oh_videoencoder_createbymime) (const char \*mime) | Creates a video encoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases.  |
43| [OH_VideoEncoder_CreateByName](#oh_videoencoder_createbyname) (const char \*name) | Creates a video encoder instance based on a video encoder name. To use this API, you must know the exact name of the video encoder.  |
44| [OH_VideoEncoder_Destroy](#oh_videoencoder_destroy) (OH_AVCodec \*codec) | Clears the internal resources of a video encoder and destroys the video encoder instance.  |
45| [OH_VideoEncoder_SetCallback](#oh_videoencoder_setcallback) (OH_AVCodec \*codec, [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md) callback, void \*userData) | Sets an asynchronous callback so that your application can respond to events generated by a video encoder. This API must be called prior to **Prepare**.  |
46| [OH_VideoEncoder_Configure](#oh_videoencoder_configure) (OH_AVCodec \*codec, OH_AVFormat \*format) | Configures a video encoder. Typically, you need to configure the attributes of the video track that can be encoded. This API must be called prior to **Prepare**.  |
47| [OH_VideoEncoder_Prepare](#oh_videoencoder_prepare) (OH_AVCodec \*codec) | Prepares internal resources for a video encoder. This API must be called after **Configure**.  |
48| [OH_VideoEncoder_Start](#oh_videoencoder_start) (OH_AVCodec \*codec) | Starts a video encoder. This API can be called only after the encoder is prepared successfully. After being started, the encoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event.  |
49| [OH_VideoEncoder_Stop](#oh_videoencoder_stop) (OH_AVCodec \*codec) | Stops a video encoder. After the encoder is stopped, you can call **Start** to start it again.  |
50| [OH_VideoEncoder_Flush](#oh_videoencoder_flush) (OH_AVCodec \*codec) | Clears the input and output data in the internal buffer of a video encoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required.  |
51| [OH_VideoEncoder_Reset](#oh_videoencoder_reset) (OH_AVCodec \*codec) | Resets a video encoder. To continue encoding, you must call **Configure** and **Start** to configure and start the encoder again.  |
52| [OH_VideoEncoder_GetOutputDescription](#oh_videoencoder_getoutputdescription) (OH_AVCodec \*codec) | Obtains the attributes of the output data of a video encoder. The **OH_AVFormat** instance in the return value will become invalid when this API is called again or when the **OH_AVCodec** instance is destroyed.  |
53| [OH_VideoEncoder_SetParameter](#oh_videoencoder_setparameter) (OH_AVCodec \*codec, OH_AVFormat \*format) | Sets dynamic parameters for a video encoder. This API can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure.  |
54| [OH_VideoEncoder_GetSurface](#oh_videoencoder_getsurface) (OH_AVCodec \*codec, [OHNativeWindow](_native_window.md) \*\*window) | Obtains an input surface from a video encoder. This API must be called prior to **Prepare**.  |
55| [OH_VideoEncoder_FreeOutputData](#oh_videoencoder_freeoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video encoder.  |
56| [OH_VideoEncoder_NotifyEndOfStream](#oh_videoencoder_notifyendofstream) (OH_AVCodec \*codec) | Notifies a video encoder that input streams end. This API is recommended in surface mode.  |
57
58
59## Type Description
60
61
62### OH_VideoEncodeBitrateMode
63
64
65```
66typedef enum OH_VideoEncodeBitrateModeOH_VideoEncodeBitrateMode
67```
68**Description**<br>
69Enumerates the bit rate modes of video encoding.
70
71\@syscap SystemCapability.Multimedia.Media.VideoEncoder
72
73
74## Enum Description
75
76
77### OH_VideoEncodeBitrateMode
78
79
80```
81enum OH_VideoEncodeBitrateMode
82```
83**Description**<br>
84Enumerates the bit rate modes of video encoding.
85
86\@syscap SystemCapability.Multimedia.Media.VideoEncoder
87
88| Name | Description |
89| -------- | -------- |
90| CBR  | Constant bit rate. |
91| VBR  | Variable bit rate. |
92| CQ  | Constant quality. |
93
94
95## Function Description
96
97
98### OH_VideoEncoder_Configure()
99
100
101```
102OH_AVErrCode OH_VideoEncoder_Configure (OH_AVCodec * codec, OH_AVFormat * format )
103```
104**Description**<br>
105Configures a video encoder. Typically, you need to configure the attributes of the video track that can be encoded. This API must be called prior to **Prepare**.
106
107\@syscap SystemCapability.Multimedia.Media.VideoEncoder
108
109 **Parameters**
110
111| Name | Description |
112| -------- | -------- |
113| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
114| format | Indicates the handle to an **OH_AVFormat** instance, which provides the attributes of the video track to be encoded.  |
115
116**Returns**
117
118Returns **AV_ERR_OK** if the operation is successful.
119
120Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
121
122
123### OH_VideoEncoder_CreateByMime()
124
125
126```
127OH_AVCodec* OH_VideoEncoder_CreateByMime (const char * mime)
128```
129**Description**<br>
130Creates a video encoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases.
131
132\@syscap SystemCapability.Multimedia.Media.VideoEncoder
133
134 **Parameters**
135
136| Name | Description |
137| -------- | -------- |
138| mime | Indicates the pointer to a MIME type. For details, see [OH_AVCODEC_MIMETYPE_VIDEO_AVC](_codec_base.md#oh_avcodec_mimetype_video_avc).  |
139
140**Returns**
141
142Returns the pointer to an **OH_AVCodec** instance.
143
144
145### OH_VideoEncoder_CreateByName()
146
147
148```
149OH_AVCodec* OH_VideoEncoder_CreateByName (const char * name)
150```
151**Description**<br>
152Creates a video encoder instance based on a video encoder name. To use this API, you must know the exact name of the video encoder.
153
154\@syscap SystemCapability.Multimedia.Media.VideoEncoder
155
156 **Parameters**
157
158| Name | Description |
159| -------- | -------- |
160| name | Indicates the pointer to a video encoder name.  |
161
162**Returns**
163
164Returns the pointer to an **OH_AVCodec** instance.
165
166
167### OH_VideoEncoder_Destroy()
168
169
170```
171OH_AVErrCode OH_VideoEncoder_Destroy (OH_AVCodec * codec)
172```
173**Description**<br>
174Clears the internal resources of a video encoder and destroys the video encoder instance.
175
176\@syscap SystemCapability.Multimedia.Media.VideoEncoder
177
178 **Parameters**
179
180| Name | Description |
181| -------- | -------- |
182| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
183
184**Returns**
185
186Returns **AV_ERR_OK** if the operation is successful.
187
188Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
189
190
191### OH_VideoEncoder_Flush()
192
193
194```
195OH_AVErrCode OH_VideoEncoder_Flush (OH_AVCodec * codec)
196```
197**Description**<br>
198Clears the input and output data in the internal buffer of a video encoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required.
199
200\@syscap SystemCapability.Multimedia.Media.VideoEncoder
201
202 **Parameters**
203
204| Name | Description |
205| -------- | -------- |
206| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
207
208**Returns**
209
210Returns **AV_ERR_OK** if the operation is successful.
211
212Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
213
214
215### OH_VideoEncoder_FreeOutputData()
216
217
218```
219OH_AVErrCode OH_VideoEncoder_FreeOutputData (OH_AVCodec * codec, uint32_t index )
220```
221**Description**<br>
222Frees an output buffer of a video encoder.
223
224\@syscap SystemCapability.Multimedia.Media.VideoEncoder
225
226 **Parameters**
227
228| Name | Description |
229| -------- | -------- |
230| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
231| index | Indicates the index of an output buffer.  |
232
233**Returns**
234
235Returns **AV_ERR_OK** if the operation is successful.
236
237Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
238
239
240### OH_VideoEncoder_GetOutputDescription()
241
242
243```
244OH_AVFormat* OH_VideoEncoder_GetOutputDescription (OH_AVCodec * codec)
245```
246**Description**<br>
247Obtains the attributes of the output data of a video encoder. The **OH_AVFormat** instance in the return value will become invalid when this API is called again or when the **OH_AVCodec** instance is destroyed.
248
249\@syscap SystemCapability.Multimedia.Media.VideoEncoder
250
251 **Parameters**
252
253| Name | Description |
254| -------- | -------- |
255| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
256
257**Returns**
258
259Returns the pointer to an **OH_AVFormat** instance.
260
261
262### OH_VideoEncoder_GetSurface()
263
264
265```
266OH_AVErrCode OH_VideoEncoder_GetSurface (OH_AVCodec * codec, OHNativeWindow ** window )
267```
268**Description**<br>
269Obtains an input surface from a video encoder. This API must be called prior to **Prepare**.
270
271\@syscap SystemCapability.Multimedia.Media.VideoEncoder
272
273 **Parameters**
274
275| Name | Description |
276| -------- | -------- |
277| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
278| window | Indicates the double pointer to an **OHNativeWindow** instance.  |
279
280**Returns**
281
282Returns **AV_ERR_OK** if the operation is successful.
283
284Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
285
286
287### OH_VideoEncoder_NotifyEndOfStream()
288
289
290```
291OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream (OH_AVCodec * codec)
292```
293**Description**<br>
294Notifies a video encoder that input streams end. This API is recommended in surface mode.
295
296\@syscap SystemCapability.Multimedia.Media.VideoEncoder
297
298 **Parameters**
299
300| Name | Description |
301| -------- | -------- |
302| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
303
304**Returns**
305
306Returns **AV_ERR_OK** if the operation is successful.
307
308Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
309
310
311### OH_VideoEncoder_Prepare()
312
313
314```
315OH_AVErrCode OH_VideoEncoder_Prepare (OH_AVCodec * codec)
316```
317**Description**<br>
318Prepares internal resources for a video encoder. This API must be called after **Configure**.
319
320\@syscap SystemCapability.Multimedia.Media.VideoEncoder
321
322 **Parameters**
323
324| Name | Description |
325| -------- | -------- |
326| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
327
328**Returns**
329
330Returns **AV_ERR_OK** if the operation is successful.
331
332Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
333
334
335### OH_VideoEncoder_Reset()
336
337
338```
339OH_AVErrCode OH_VideoEncoder_Reset (OH_AVCodec * codec)
340```
341**Description**<br>
342Resets a video encoder. To continue encoding, you must call **Configure** and **Start** to configure and start the encoder again.
343
344\@syscap SystemCapability.Multimedia.Media.VideoEncoder
345
346 **Parameters**
347
348| Name | Description |
349| -------- | -------- |
350| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
351
352**Returns**
353
354Returns **AV_ERR_OK** if the operation is successful.
355
356Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
357
358
359### OH_VideoEncoder_SetCallback()
360
361
362```
363OH_AVErrCode OH_VideoEncoder_SetCallback (OH_AVCodec * codec, OH_AVCodecAsyncCallback callback, void * userData )
364```
365**Description**<br>
366Sets an asynchronous callback so that your application can respond to events generated by a video encoder. This API must be called prior to **Prepare**.
367
368\@syscap SystemCapability.Multimedia.Media.VideoEncoder
369
370 **Parameters**
371
372| Name | Description |
373| -------- | -------- |
374| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
375| callback | Indicates a collection of all callback functions. For details, see [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md).  |
376| userData | Indicates the pointer to user-specific data.  |
377
378**Returns**
379
380Returns **AV_ERR_OK** if the operation is successful.
381
382Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
383
384
385### OH_VideoEncoder_SetParameter()
386
387
388```
389OH_AVErrCode OH_VideoEncoder_SetParameter (OH_AVCodec * codec, OH_AVFormat * format )
390```
391**Description**<br>
392Sets dynamic parameters for a video encoder. This API can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure.
393
394\@syscap SystemCapability.Multimedia.Media.VideoEncoder
395
396 **Parameters**
397
398| Name | Description |
399| -------- | -------- |
400| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
401| format | Indicates the handle to an **OH_AVFormat** instance.  |
402
403**Returns**
404
405Returns **AV_ERR_OK** if the operation is successful.
406
407Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
408
409
410### OH_VideoEncoder_Start()
411
412
413```
414OH_AVErrCode OH_VideoEncoder_Start (OH_AVCodec * codec)
415```
416**Description**<br>
417Starts a video encoder. This API can be called only after the encoder is prepared successfully. After being started, the encoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event.
418
419\@syscap SystemCapability.Multimedia.Media.VideoEncoder
420
421 **Parameters**
422
423| Name | Description |
424| -------- | -------- |
425| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
426
427**Returns**
428
429Returns **AV_ERR_OK** if the operation is successful.
430
431Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
432
433
434### OH_VideoEncoder_Stop()
435
436
437```
438OH_AVErrCode OH_VideoEncoder_Stop (OH_AVCodec * codec)
439```
440**Description**<br>
441Stops a video encoder. After the encoder is stopped, you can call **Start** to start it again.
442
443\@syscap SystemCapability.Multimedia.Media.VideoEncoder
444
445 **Parameters**
446
447| Name | Description |
448| -------- | -------- |
449| codec | Indicates the pointer to an **OH_AVCodec** instance.  |
450
451**Returns**
452
453Returns **AV_ERR_OK** if the operation is successful.
454
455Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
456