1# VideoProcessing
2
3
4## Overview
5
6The VideoProcessing module provides the APIs for video processing. It provides video processing capabilities, including color space conversion, metadata generation, and video scaling.
7
8**Since**: 12
9
10
11## Summary
12
13
14### Files
15
16| Name| Description|
17| -------- | -------- |
18| [video_processing.h](video__processing_8h.md) | Declares the video processing functions.|
19| [video_processing_types.h](video__processing__types_8h.md) | Declares the video processing types.|
20
21
22### Structs
23
24| Name| Description|
25| -------- | -------- |
26| struct  [VideoProcessing_ColorSpaceInfo](_video_processing___color_space_info.md) | Describes the color space information of video processing.|
27
28
29### Types
30
31| Name| Description|
32| -------- | -------- |
33| typedef struct [OH_VideoProcessing](#oh_videoprocessing-1) [OH_VideoProcessing](#oh_videoprocessing) | Defines a struct for the video processing object.|
34| typedef struct NativeWindow [OHNativeWindow](#ohnativewindow) | Defines a struct for the NativeWindow object.|
35| typedef struct [OH_AVFormat](#oh_avformat-1) [OH_AVFormat](#oh_avformat) | Defines a struct for the OH_AVFormat object.|
36| typedef struct [VideoProcessing_ColorSpaceInfo](_video_processing___color_space_info.md) [VideoProcessing_ColorSpaceInfo](#videoprocessing_colorspaceinfo) | Defines a struct for the color space information of video processing.|
37| typedef enum [VideoDetailEnhancer_QualityLevel](#videodetailenhancer_qualitylevel-1) [VideoDetailEnhancer_QualityLevel](#videodetailenhancer_qualitylevel) | Defines an enum for the quality levels for detail enhancement.|
38| typedef enum [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1) [VideoProcessing_ErrorCode](#videoprocessing_errorcode) | Defines an enum for the video processing error codes.|
39| typedef enum [VideoProcessing_State](#videoprocessing_state-1) [VideoProcessing_State](#videoprocessing_state) | Defines an enum for the video processing states.|
40| typedef struct [VideoProcessing_Callback](#videoprocessing_callback) [VideoProcessing_Callback](#videoprocessing_callback) | Defines a struct for the video processing callback object.|
41| typedef void(\* [OH_VideoProcessingCallback_OnError](#oh_videoprocessingcallback_onerror)) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, [VideoProcessing_ErrorCode](#videoprocessing_errorcode) error, void \*userData) | Defines a pointer to the callback function for reporting an error during video processing.|
42| typedef void(\* [OH_VideoProcessingCallback_OnState](#oh_videoprocessingcallback_onstate)) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, [VideoProcessing_State](#videoprocessing_state) state, void \*userData) | Defines a pointer to the callback function for reporting the video processing state.|
43| typedef void(\* [OH_VideoProcessingCallback_OnNewOutputBuffer](#oh_videoprocessingcallback_onnewoutputbuffer)) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, uint32_t index, void \*userData) | Defines a pointer to the callback function for reporting the data filled in the output buffer.|
44
45
46### Enums
47
48| Name| Description|
49| -------- | -------- |
50| [VideoDetailEnhancer_QualityLevel](#videodetailenhancer_qualitylevel-1) {<br>VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_NONE,<br>VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_LOW,<br>VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_MEDIUM,<br>VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_HIGH } | Enumerates the quality levels for detail enhancement.|
51| [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1) {<br>VIDEO_PROCESSING_SUCCESS,<br>VIDEO_PROCESSING_ERROR_INVALID_PARAMETER = 401,<br>VIDEO_PROCESSING_ERROR_UNKNOWN = 29210001,<br>VIDEO_PROCESSING_ERROR_INITIALIZE_FAILED,<br>VIDEO_PROCESSING_ERROR_CREATE_FAILED,<br>VIDEO_PROCESSING_ERROR_PROCESS_FAILED,<br>VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING,<br>VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED,<br>VIDEO_PROCESSING_ERROR_NO_MEMORY,<br>VIDEO_PROCESSING_ERROR_INVALID_INSTANCE,<br>VIDEO_PROCESSING_ERROR_INVALID_VALUE<br>} | Enumerates the video processing error codes.|
52| [VideoProcessing_State](#videoprocessing_state-1) {<br>VIDEO_PROCESSING_STATE_RUNNING,<br>VIDEO_PROCESSING_STATE_STOPPED } | Enumerates the video processing states.|
53
54
55### Functions
56
57| Name| Description|
58| -------- | -------- |
59| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_InitializeEnvironment](#oh_videoprocessing_initializeenvironment) (void) | Initializes the global video processing environment.|
60| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_DeinitializeEnvironment](#oh_videoprocessing_deinitializeenvironment) (void) | Releases the global video processing environment.|
61| bool [OH_VideoProcessing_IsColorSpaceConversionSupported](#oh_videoprocessing_iscolorspaceconversionsupported) (const [VideoProcessing_ColorSpaceInfo](_video_processing___color_space_info.md) \*sourceVideoInfo, const [VideoProcessing_ColorSpaceInfo](_video_processing___color_space_info.md) \*destinationVideoInfo) | Checks whether color space conversion is supported during video processing.|
62| bool [OH_VideoProcessing_IsMetadataGenerationSupported](#oh_videoprocessing_ismetadatagenerationsupported) (const [VideoProcessing_ColorSpaceInfo](_video_processing___color_space_info.md) \*sourceVideoInfo) | Checks whether metadata generation is supported during video processing.|
63| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_Create](#oh_videoprocessing_create) ([OH_VideoProcessing](#oh_videoprocessing) \*\*videoProcessor, int type) | Creates a video processing instance.|
64| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_Destroy](#oh_videoprocessing_destroy) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor) | Destroys a video processing instance.|
65| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_RegisterCallback](#oh_videoprocessing_registercallback) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, const [VideoProcessing_Callback](#videoprocessing_callback) \*callback, void \*userData) | Registers a callback for video processing.|
66| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_SetSurface](#oh_videoprocessing_setsurface) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, const [OHNativeWindow](#ohnativewindow) \*window) | Sets an output surface for video processing.|
67| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_GetSurface](#oh_videoprocessing_getsurface) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, [OHNativeWindow](#ohnativewindow) \*\*window) | Obtains a surface for video processing.|
68| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_SetParameter](#oh_videoprocessing_setparameter) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, const [OH_AVFormat](#oh_avformat) \*parameter) | Sets video processing parameters.|
69| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_GetParameter](#oh_videoprocessing_getparameter) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, [OH_AVFormat](#oh_avformat) \*parameter) | Obtains video processing parameters.|
70| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_Start](#oh_videoprocessing_start) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor) | Starts video processing.|
71| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_Stop](#oh_videoprocessing_stop) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor) | Stops video processing.|
72| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessing_RenderOutputBuffer](#oh_videoprocessing_renderoutputbuffer) ([OH_VideoProcessing](#oh_videoprocessing) \*videoProcessor, uint32_t index) | Renders and processes the buffer, and then outputs it.|
73| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessingCallback_Create](#oh_videoprocessingcallback_create) ([VideoProcessing_Callback](#videoprocessing_callback) \*\*callback) | Creates a video processing callback object.|
74| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessingCallback_Destroy](#oh_videoprocessingcallback_destroy) ([VideoProcessing_Callback](#videoprocessing_callback) \*callback) | Destroys a video processing callback object.|
75| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessingCallback_BindOnError](#oh_videoprocessingcallback_bindonerror) ([VideoProcessing_Callback](#videoprocessing_callback) \*callback, [OH_VideoProcessingCallback_OnError](#oh_videoprocessingcallback_onerror) onError) | Binds the callback function [OH_VideoProcessingCallback_OnError](#oh_videoprocessingcallback_onerror) to a video processing callback object.|
76| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessingCallback_BindOnState](#oh_videoprocessingcallback_bindonstate) ([VideoProcessing_Callback](#videoprocessing_callback) \*callback, [OH_VideoProcessingCallback_OnState](#oh_videoprocessingcallback_onstate) onState) | Binds the callback function [OH_VideoProcessingCallback_OnState](#oh_videoprocessingcallback_onstate) to a video processing callback object.|
77| [VideoProcessing_ErrorCode](#videoprocessing_errorcode) [OH_VideoProcessingCallback_BindOnNewOutputBuffer](#oh_videoprocessingcallback_bindonnewoutputbuffer) ([VideoProcessing_Callback](#videoprocessing_callback) \*callback, [OH_VideoProcessingCallback_OnNewOutputBuffer](#oh_videoprocessingcallback_onnewoutputbuffer) onNewOutputBuffer) | Binds the callback function [OH_VideoProcessingCallback_OnNewOutputBuffer](#oh_videoprocessingcallback_onnewoutputbuffer) to a video processing callback object.|
78
79
80### Variables
81
82| Name| Description|
83| -------- | -------- |
84| const int32_t [VIDEO_PROCESSING_TYPE_COLOR_SPACE_CONVERSION](#video_processing_type_color_space_conversion) | Instance created for color space conversion during video processing.|
85| const int32_t [VIDEO_PROCESSING_TYPE_METADATA_GENERATION](#video_processing_type_metadata_generation) | Instance created for metadata generation during video processing.|
86| const int32_t [VIDEO_PROCESSING_TYPE_DETAIL_ENHANCER](#video_processing_type_detail_enhancer) | Instance for detail enhancement during video processing.|
87| const char \* [VIDEO_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL](#video_detail_enhancer_parameter_key_quality_level) | Pointer to the quality level of video detail enhancement.|
88
89
90## Type Description
91
92
93### OH_AVFormat
94
95```
96typedef struct OH_AVFormatOH_AVFormat
97```
98
99**Description**
100
101Defines a struct for the OH_AVFormat object.
102
103**Since**: 12
104
105
106### OH_VideoProcessing
107
108```
109typedef struct OH_VideoProcessingOH_VideoProcessing
110```
111
112**Description**
113
114Defines a struct for the video processing object.
115
116Define a null pointer to **OH_VideoProcessing**. Before [OH_VideoProcessing_Create](#oh_videoprocessing_create) is called to create a video processing instance, the pointer must be null. You can create different video processing instances with different processing types.
117
118**Since**: 12
119
120
121### OH_VideoProcessingCallback_OnError
122
123```
124typedef void(* OH_VideoProcessingCallback_OnError) (OH_VideoProcessing *videoProcessor, VideoProcessing_ErrorCode error, void *userData)
125```
126
127**Description**
128
129Defines a pointer to the callback function for reporting an error during video processing.
130
131The following error codes are defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
132
133- **VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING**: unsupported processing. For example, conversion between the color space types for input and output is not supported.
134
135- **VIDEO_PROCESSING_ERROR_INVALID_VALUE**: invalid video attribute. For example, the video color space is invalid.
136
137- **VIDEO_PROCESSING_ERROR_NO_MEMORY**: out of memory.
138
139- **VIDEO_PROCESSING_ERROR_PROCESS_FAILED**: An error occurs during the processing.
140
141**Since**: 12
142
143**Parameters**
144
145| Name| Description|
146| -------- | -------- |
147| videoProcessor | Pointer to the video processing instance.|
148| error | Error code reported.|
149| userData | Pointer to user-defined data.|
150
151
152### OH_VideoProcessingCallback_OnNewOutputBuffer
153
154```
155typedef void(* OH_VideoProcessingCallback_OnNewOutputBuffer) (OH_VideoProcessing *videoProcessor, uint32_t index, void *userData)
156```
157
158**Description**
159
160Defines a pointer to the callback function for reporting the data filled in the output buffer.
161
162After data is filled in each new output buffer, the index of the buffer is reported. Call [OH_VideoProcessing_RenderOutputBuffer](#oh_videoprocessing_renderoutputbuffer) to process rendering based on the index and output the buffer. If this callback function is not registered, the data filled in the output buffer is not reported. Instead, the data is directly processed, rendered, and output.
163
164**Since**: 12
165
166**Parameters**
167
168| Name| Description|
169| -------- | -------- |
170| videoProcessor | Pointer to the video processing instance.|
171| index | Index of the output buffer.|
172| userData | Pointer to user-defined data.|
173
174
175### OH_VideoProcessingCallback_OnState
176
177```
178typedef void(* OH_VideoProcessingCallback_OnState) (OH_VideoProcessing *videoProcessor, VideoProcessing_State state, void *userData)
179```
180
181**Description**
182
183Defines a pointer to the callback function for reporting the video processing state.
184
185After [OH_VideoProcessing_Start](#oh_videoprocessing_start) is called, the video processing state changes to VIDEO_PROCESSING_STATE_RUNNING. After [OH_VideoProcessing_Stop](#oh_videoprocessing_stop) is called and all buffers finishes processing, the state changes to VIDEO_PROCESSING_STATE_STOPPED. For details, see [VideoProcessing_State](#videoprocessing_state).
186
187**Since**: 12
188
189**Parameters**
190
191| Name| Description|
192| -------- | -------- |
193| videoProcessor | Pointer to the video processing instance.|
194| state | Video processing state. For details, see [VideoProcessing_State](#videoprocessing_state).|
195| userData | Pointer to user-defined data.|
196
197
198### OHNativeWindow
199
200```
201typedef struct NativeWindow OHNativeWindow
202```
203
204**Description**
205
206Defines a struct for the NativeWindow object.
207
208**Since**: 12
209
210
211### VideoDetailEnhancer_QualityLevel
212
213```
214typedef enum VideoDetailEnhancer_QualityLevelVideoDetailEnhancer_QualityLevel
215```
216
217**Description**
218
219Defines an enum for the quality levels for detail enhancement.
220
221For details about the enumerated values, see [VIDEO_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL](#video_detail_enhancer_parameter_key_quality_level). For details about how to set the quality level, see the development guide.
222
223**See also**: [OH_VideoProcessing_SetParameter](#oh_videoprocessing_setparameter) and [OH_VideoProcessing_GetParameter](#oh_videoprocessing_getparameter)
224
225**Since**: 12
226
227
228### VideoProcessing_Callback
229
230```
231typedef struct VideoProcessing_CallbackVideoProcessing_Callback
232```
233
234**Description**
235
236Defines a struct for the video processing callback object.
237
238Define a null pointer to **VideoProcessing_Callback**. Before [OH_VideoProcessingCallback_Create](#oh_videoprocessingcallback_create) is called to create a video processing callback object, the pointer must be null. The callback object is registered by calling [OH_VideoProcessing_RegisterCallback](#oh_videoprocessing_registercallback).
239
240**Since**: 12
241
242
243### VideoProcessing_ColorSpaceInfo
244
245```
246typedef struct VideoProcessing_ColorSpaceInfoVideoProcessing_ColorSpaceInfo
247```
248
249**Description**
250
251Defines a struct for the color space information of video processing.
252
253**See also**: [OH_VideoProcessing_IsColorSpaceConversionSupported](#oh_videoprocessing_iscolorspaceconversionsupported)
254
255**Since**: 12
256
257
258### VideoProcessing_ErrorCode
259
260```
261typedef enum VideoProcessing_ErrorCodeVideoProcessing_ErrorCode
262```
263
264**Description**
265
266Defines an enum for the video processing error codes.
267
268**Since**: 12
269
270
271### VideoProcessing_State
272
273```
274typedef enum VideoProcessing_StateVideoProcessing_State
275```
276
277**Description**
278
279Defines an enum for the video processing states.
280
281The video processing state is reported through the callback function [OH_VideoProcessingCallback_OnState](#oh_videoprocessingcallback_onstate).
282
283**Since**: 12
284
285
286## Enum Description
287
288
289### VideoDetailEnhancer_QualityLevel
290
291```
292enum VideoDetailEnhancer_QualityLevel
293```
294
295**Description**
296
297Enumerates the quality levels for detail enhancement.
298
299For details about the enumerated values, see [VIDEO_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL](#video_detail_enhancer_parameter_key_quality_level). For details about how to set the quality level, see the development guide.
300
301**See also**: [OH_VideoProcessing_SetParameter](#oh_videoprocessing_setparameter) and [OH_VideoProcessing_GetParameter](#oh_videoprocessing_getparameter)
302
303**Since**: 12
304
305| Value| Description|
306| -------- | -------- |
307| VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_NONE | No detail enhancement.|
308| VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_LOW | Low-quality detail enhancement, which features fast speed. This is the default value.|
309| VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_MEDIUM | Medium-quality detail enhancement, which features moderate speed.|
310| VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_HIGH | High-quality detail enhancement, which features slow speed.|
311
312
313### VideoProcessing_ErrorCode
314
315```
316enum VideoProcessing_ErrorCode
317```
318
319**Description**
320
321Enumerates the video processing error codes.
322
323**Since**: 12
324
325| Value| Description|
326| -------- | -------- |
327| VIDEO_PROCESSING_SUCCESS | The processing is successful.|
328| VIDEO_PROCESSING_ERROR_INVALID_PARAMETER | An input parameter is invalid. This error code is returned in the following cases:<br>1 - The input or output video buffer is either invalid or empty.<br>2 - The provided parameter is invalid or missing.<br>3 - The requested processing type is invalid.|
329| VIDEO_PROCESSING_ERROR_UNKNOWN | An unknown error occurs. For example, the GPU computing or memcpy fails.|
330| VIDEO_PROCESSING_ERROR_INITIALIZE_FAILED | The global video processing environment, for example, the GPU environment, fails to be initialized.|
331| VIDEO_PROCESSING_ERROR_CREATE_FAILED | Creating the video processing instance fails. For example, the total number of instances exceeds the upper limit.|
332| VIDEO_PROCESSING_ERROR_PROCESS_FAILED | The processing fails. For example, the processing times out.|
333| VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING | The processing type is not supported. You can call OH_VideoProcessing_Is*XXX*Supported to check whether a specific processing type is supported.|
334| VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED | The operation is not allowed. For example, the function is called in an incorrect running state.|
335| VIDEO_PROCESSING_ERROR_NO_MEMORY | Insufficient memory.|
336| VIDEO_PROCESSING_ERROR_INVALID_INSTANCE | The video processing instance is invalid, for example, a null instance.|
337| VIDEO_PROCESSING_ERROR_INVALID_VALUE | The input value is invalid. This error code is returned in the following cases:<br>1 - The width and height of the video buffer are inappropriate or the color space is incorrect.<br>2 - The parameter contains an invalid value. For example, the quality level of detail enhancement is incorrect.|
338
339
340### VideoProcessing_State
341
342```
343enum VideoProcessing_State
344```
345
346**Description**
347
348Enumerates the video processing states.
349
350The video processing state is reported through the callback function [OH_VideoProcessingCallback_OnState](#oh_videoprocessingcallback_onstate).
351
352**Since**: 12
353
354| Value| Description|
355| -------- | -------- |
356| VIDEO_PROCESSING_STATE_RUNNING | Video processing is in progress.|
357| VIDEO_PROCESSING_STATE_STOPPED | Video processing stopped.|
358
359
360## Function Description
361
362
363### OH_VideoProcessing_Create()
364
365```
366VideoProcessing_ErrorCode OH_VideoProcessing_Create (OH_VideoProcessing ** videoProcessor, int type )
367```
368
369**Description**
370
371Creates a video processing instance.
372
373**Since**: 12
374
375**Parameters**
376
377| Name| Description|
378| -------- | -------- |
379| videoProcessor |  Double pointer to the video processing instance created. Before any input, **\*videoProcessor** must be a null pointer.|
380| type | Video processing type. The processing type of an instance cannot be changed.|
381
382**Returns**
383
384Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
385
386- **VIDEO_PROCESSING_SUCCESS** if the video processing instance is created successfully.
387
388- **VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING** if the video processing type is not supported.
389  For example, if metadata generation is not supported, **VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING** is returned.
390
391- **VIDEO_PROCESSING_ERROR_CREATE_FAILED** if the video processing instance fails to be created.
392
393- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or the pointer to the instance is not null.
394
395- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if the video processing type is invalid.
396
397
398### OH_VideoProcessing_DeinitializeEnvironment()
399
400```
401VideoProcessing_ErrorCode OH_VideoProcessing_DeinitializeEnvironment (void )
402```
403
404**Description**
405
406Releases the global video processing environment.
407
408Before calling this API, you must call [OH_VideoProcessing_InitializeEnvironment](#oh_videoprocessing_initializeenvironment) to initialize the environment. Generally, this function is called when the main process is about to exit. Do not call this function when a video processing instance is running.
409
410**Since**: 12
411
412**Returns**
413
414Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
415
416- **VIDEO_PROCESSING_SUCCESS** if the processing is successful.
417
418- **VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED** if a video processing instance is not destroyed or [OH_VideoProcessing_InitializeEnvironment](#oh_videoprocessing_initializeenvironment) is not called to initialize the environment.
419
420
421### OH_VideoProcessing_Destroy()
422
423```
424VideoProcessing_ErrorCode OH_VideoProcessing_Destroy (OH_VideoProcessing * videoProcessor)
425```
426
427**Description**
428
429Destroys a video processing instance.
430
431Before destroying the instance, call [OH_VideoProcessing_Stop](#oh_videoprocessing_stop) to stop it.
432
433**Since**: 12
434
435**Parameters**
436
437| Name| Description|
438| -------- | -------- |
439| videoProcessor | Pointer to the video processing instance. You are advised to set the pointer to a null pointer after the instance is destroyed.|
440
441**Returns**
442
443Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
444
445- **VIDEO_PROCESSING_SUCCESS** if the instance is destroyed.
446
447- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
448
449- **VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED** if the instance is still running.
450
451
452### OH_VideoProcessing_GetParameter()
453
454```
455VideoProcessing_ErrorCode OH_VideoProcessing_GetParameter (OH_VideoProcessing * videoProcessor, OH_AVFormat * parameter )
456```
457
458**Description**
459
460Obtains video processing parameters.
461
462**Since**: 12
463
464**Parameters**
465
466| Name| Description|
467| -------- | -------- |
468| videoProcessor | Pointer to a video processing instance.|
469| parameter | Pointer to the video processing parameters.|
470
471**Returns**
472
473Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
474
475- **VIDEO_PROCESSING_SUCCESS** if the parameters are obtained.
476
477- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
478
479- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if the parameter is empty.
480
481
482### OH_VideoProcessing_GetSurface()
483
484```
485VideoProcessing_ErrorCode OH_VideoProcessing_GetSurface (OH_VideoProcessing * videoProcessor, OHNativeWindow ** window )
486```
487
488**Description**
489
490Obtains a surface for video processing.
491
492An input surface must be created before video processing starts, and it must be destroyed by calling [OH_NativeWindow_DestroyNativeWindow](../apis-arkgraphics2d/_native_window.md#oh_nativewindow_destroynativewindow) when it is no longer needed.
493
494**Since**: 12
495
496**Parameters**
497
498| Name| Description|
499| -------- | -------- |
500| videoProcessor | Pointer to a video processing instance.|
501| window | Double pointer to the input surface. For example, the input surface pointer can point to an output surface of the video decoder.|
502
503**Returns**
504
505Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
506
507- **VIDEO_PROCESSING_SUCCESS** if the processing is successful.
508
509- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
510
511- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if the window is a null pointer or the pointer to the window is not null.
512
513- **VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED** if the surface fails to be created, an input surface has been created, or the video processing instance is running.
514
515
516### OH_VideoProcessing_InitializeEnvironment()
517
518```
519VideoProcessing_ErrorCode OH_VideoProcessing_InitializeEnvironment (void )
520```
521
522**Description**
523
524Initializes the global video processing environment.
525
526This function is optional. It is called only once when the main process is started to initialize the global video processing environment. This reduces the duration for running [OH_VideoProcessing_Create](#oh_videoprocessing_create). The global video processing environment must be released by calling [OH_VideoProcessing_DeinitializeEnvironment](#oh_videoprocessing_deinitializeenvironment). For details about how and when to release the environment, see [OH_VideoProcessing_DeinitializeEnvironment](#oh_videoprocessing_deinitializeenvironment).
527
528**Since**: 12
529
530**Returns**
531
532Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
533
534- **VIDEO_PROCESSING_SUCCESS** if the initialization is successful.
535- **VIDEO_PROCESSING_ERROR_INITIALIZE_FAILED** if the initialization fails.
536
537If the operation fails, check whether the GPU works properly.
538
539
540### OH_VideoProcessing_IsColorSpaceConversionSupported()
541
542```
543bool OH_VideoProcessing_IsColorSpaceConversionSupported (const VideoProcessing_ColorSpaceInfo * sourceVideoInfo, const VideoProcessing_ColorSpaceInfo * destinationVideoInfo )
544```
545
546**Description**
547
548Checks whether color space conversion is supported during video processing.
549
550**Since**: 12
551
552**Parameters**
553
554| Name| Description|
555| -------- | -------- |
556| sourceVideoInfo | Pointer to the color space information of the input video.|
557| destinationVideoInfo | Pointer to the color space information of the output video.|
558
559**Returns**
560
561Returns **true** if color space conversion is supported; returns **false** otherwise.
562
563
564### OH_VideoProcessing_IsMetadataGenerationSupported()
565
566```
567bool OH_VideoProcessing_IsMetadataGenerationSupported (const VideoProcessing_ColorSpaceInfo * sourceVideoInfo)
568```
569
570**Description**
571
572Checks whether metadata generation is supported during video processing.
573
574**Since**: 12
575
576**Parameters**
577
578| Name| Description|
579| -------- | -------- |
580| sourceVideoInfo | Pointer to the color space information of the input video.|
581
582**Returns**
583
584Returns **true** if metadata generation is supported; returns **false** otherwise.
585
586
587### OH_VideoProcessing_RegisterCallback()
588
589```
590VideoProcessing_ErrorCode OH_VideoProcessing_RegisterCallback (OH_VideoProcessing * videoProcessor, const VideoProcessing_Callback * callback, void * userData )
591```
592
593**Description**
594
595Registers a callback for video processing.
596
597The callback function should be registered before video processing starts. During video processing, it cannot be registered.
598
599**Since**: 12
600
601**Parameters**
602
603| Name| Description|
604| -------- | -------- |
605| videoProcessor | Pointer to a video processing instance.|
606| callback | Pointer to the callback function.|
607| userData | Pointer to user-defined data.|
608
609**Returns**
610
611Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
612
613- **VIDEO_PROCESSING_SUCCESS** if the callback function is registered.
614
615- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
616
617- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if the callback function pointer is null.
618
619- **VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED** if the instance is still running.
620
621
622### OH_VideoProcessing_RenderOutputBuffer()
623
624```
625VideoProcessing_ErrorCode OH_VideoProcessing_RenderOutputBuffer (OH_VideoProcessing * videoProcessor, uint32_t index )
626```
627
628**Description**
629
630Renders and processes the buffer, and then outputs it.
631
632If the callback function [OH_VideoProcessingCallback_OnNewOutputBuffer](#oh_videoprocessingcallback_onnewoutputbuffer) is set, the buffer index is returned through the callback function after the output buffer is ready.
633
634**Since**: 12
635
636**Parameters**
637
638| Name| Description|
639| -------- | -------- |
640| videoProcessor | Pointer to a video processing instance.|
641| index | Index of the output buffer.|
642
643**Returns**
644
645Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
646
647- **VIDEO_PROCESSING_SUCCESS** if the processing is successful.
648
649- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
650
651- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if the index is invalid.
652
653- **VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED** if the callback function [OH_VideoProcessingCallback_OnNewOutputBuffer](#oh_videoprocessingcallback_onnewoutputbuffer) is not set or the instance is stopped.
654
655
656### OH_VideoProcessing_SetParameter()
657
658```
659VideoProcessing_ErrorCode OH_VideoProcessing_SetParameter (OH_VideoProcessing * videoProcessor, const OH_AVFormat * parameter )
660```
661
662**Description**
663
664Sets video processing parameters.
665
666**Since**: 12
667
668**Parameters**
669
670| Name| Description|
671| -------- | -------- |
672| videoProcessor | Pointer to a video processing instance.|
673| parameter | Pointer to a video processing parameter instance.|
674
675**Returns**
676
677Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
678
679- **VIDEO_PROCESSING_SUCCESS** if the parameters are successfully set.
680
681- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
682
683- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if the parameter is empty.
684
685- **VIDEO_PROCESSING_ERROR_INVALID_VALUE** if some attributes of a parameter are invalid, for example, unsupported parameter value.
686
687- **VIDEO_PROCESSING_ERROR_NO_MEMORY** if memory allocation fails.
688
689
690### OH_VideoProcessing_SetSurface()
691
692```
693VideoProcessing_ErrorCode OH_VideoProcessing_SetSurface (OH_VideoProcessing * videoProcessor, const OHNativeWindow * window )
694```
695
696**Description**
697
698Sets an output surface for video processing.
699
700An output surface must be set before video processing starts.
701
702**Since**: 12
703
704**Parameters**
705
706| Name| Description|
707| -------- | -------- |
708| videoProcessor | Pointer to a video processing instance.|
709| window | Pointer to the output surface.|
710
711**Returns**
712
713Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
714
715- **VIDEO_PROCESSING_SUCCESS** if the output surface is successfully set.
716
717- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
718
719- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if the window is a null pointer.
720
721
722### OH_VideoProcessing_Start()
723
724```
725VideoProcessing_ErrorCode OH_VideoProcessing_Start (OH_VideoProcessing * videoProcessor)
726```
727
728**Description**
729
730Starts video processing.
731
732After video processing starts, the callback [OH_VideoProcessingCallback_OnState](#oh_videoprocessingcallback_onstate) reports the **VIDEO_PROCESSING_STATE_RUNNING** state. For details, see [VideoProcessing_State](#videoprocessing_state).
733
734**Since**: 12
735
736**Parameters**
737
738| Name| Description|
739| -------- | -------- |
740| videoProcessor | Pointer to a video processing instance.|
741
742**Returns**
743
744Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
745
746- **VIDEO_PROCESSING_SUCCESS** if the processing is successful.
747
748- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
749
750- **VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED** if no output surface is set, no input surface is created, or the instance is running.
751
752
753### OH_VideoProcessing_Stop()
754
755```
756VideoProcessing_ErrorCode OH_VideoProcessing_Stop (OH_VideoProcessing * videoProcessor)
757```
758
759**Description**
760
761Stops video processing.
762
763After video processing stops, the callback [OH_VideoProcessingCallback_OnState](#oh_videoprocessingcallback_onstate) reports the **VIDEO_PROCESSING_STATE_STOPPED** state. For details, see [VideoProcessing_State](#videoprocessing_state).
764
765**Since**: 12
766
767**Parameters**
768
769| Name| Description|
770| -------- | -------- |
771| videoProcessor | Pointer to a video processing instance.|
772
773**Returns**
774
775Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
776
777- **VIDEO_PROCESSING_SUCCESS** if the processing is successful.
778
779- **VIDEO_PROCESSING_ERROR_INVALID_INSTANCE** if the instance is null or is not a video processing instance.
780
781- **VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED** if the instance is stopped.
782
783
784### OH_VideoProcessingCallback_BindOnError()
785
786```
787VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnError (VideoProcessing_Callback * callback, OH_VideoProcessingCallback_OnError onError )
788```
789
790**Description**
791
792Binds the callback function [OH_VideoProcessingCallback_OnError](#oh_videoprocessingcallback_onerror) to a video processing callback object.
793
794**Since**: 12
795
796**Parameters**
797
798| Name| Description|
799| -------- | -------- |
800| callback | Pointer to a callback object.|
801| onError | Callback function to bind.|
802
803**Returns**
804
805Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
806
807- **VIDEO_PROCESSING_SUCCESS** if the binding is successful.
808
809- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if **callback** or **onError** is null.
810
811
812### OH_VideoProcessingCallback_BindOnNewOutputBuffer()
813
814```
815VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnNewOutputBuffer (VideoProcessing_Callback * callback, OH_VideoProcessingCallback_OnNewOutputBuffer onNewOutputBuffer )
816```
817
818**Description**
819
820Binds the callback function [OH_VideoProcessingCallback_OnNewOutputBuffer](#oh_videoprocessingcallback_onnewoutputbuffer) to a video processing callback object.
821
822**Since**: 12
823
824**Parameters**
825
826| Name| Description|
827| -------- | -------- |
828| callback | Pointer to a callback object.|
829| onNewOutputBuffer | Callback function to bind.|
830
831**Returns**
832
833Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
834
835- **VIDEO_PROCESSING_SUCCESS** if the binding is successful.
836
837- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if **callback** is null.
838
839
840### OH_VideoProcessingCallback_BindOnState()
841
842```
843VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnState (VideoProcessing_Callback * callback, OH_VideoProcessingCallback_OnState onState )
844```
845
846**Description**
847
848Binds the callback function [OH_VideoProcessingCallback_OnState](#oh_videoprocessingcallback_onstate) to a video processing callback object.
849
850**Since**: 12
851
852**Parameters**
853
854| Name| Description|
855| -------- | -------- |
856| callback | Pointer to a callback object.|
857| onState | Callback function to bind.|
858
859**Returns**
860
861Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
862
863- **VIDEO_PROCESSING_SUCCESS** if the binding is successful.
864
865- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if **callback** or **onState** is null.
866
867
868### OH_VideoProcessingCallback_Create()
869
870```
871VideoProcessing_ErrorCode OH_VideoProcessingCallback_Create (VideoProcessing_Callback ** callback)
872```
873
874**Description**
875
876Creates a video processing callback object.
877
878**Since**: 12
879
880**Parameters**
881
882| Name| Description|
883| -------- | -------- |
884| callback |  Double pointer to the video processing callback object. Before creating a callback object, **\*callback** must be a null pointer.|
885
886**Returns**
887
888Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
889
890- **VIDEO_PROCESSING_SUCCESS** if the callback object is created.
891
892- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if **callback** is null or **\*callback** is not null.
893
894- **VIDEO_PROCESSING_ERROR_NO_MEMORY** if the memory is insufficient.
895
896
897### OH_VideoProcessingCallback_Destroy()
898
899```
900VideoProcessing_ErrorCode OH_VideoProcessingCallback_Destroy (VideoProcessing_Callback * callback)
901```
902
903**Description**
904
905Destroys a video processing callback object.
906
907The video processing callback object can be destroyed after the callback function is registered.
908
909**Since**: 12
910
911**Parameters**
912
913| Name| Description|
914| -------- | -------- |
915| callback | Pointer to the callback object. You are advised to set the pointer to a null pointer after the callback object is destroyed.|
916
917**Returns**
918
919Returns one of the following error codes defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1):
920
921- **VIDEO_PROCESSING_SUCCESS** if the callback object is destroyed.
922
923- **VIDEO_PROCESSING_ERROR_INVALID_PARAMETER** if **callback** is null.
924
925
926## Variable Description
927
928
929### VIDEO_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL
930
931```
932const char* VIDEO_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL
933```
934
935**Description**
936
937Pointer to the quality level of video detail enhancement.
938
939For details about the available options, see [VideoDetailEnhancer_QualityLevel](#videodetailenhancer_qualitylevel). You can call [OH_VideoProcessing_SetParameter](#oh_videoprocessing_setparameter) to set the quality level, and call [OH_VideoProcessing_GetParameter](#oh_videoprocessing_getparameter) to obtain the quality level.
940
941**Since**: 12
942
943
944### VIDEO_PROCESSING_TYPE_COLOR_SPACE_CONVERSION
945
946```
947const int32_t VIDEO_PROCESSING_TYPE_COLOR_SPACE_CONVERSION
948```
949
950**Description**
951
952Instance created for color space conversion during video processing.
953
954Call [OH_VideoProcessing_Create](#oh_videoprocessing_create) to create such an instance for color space conversion. If color space conversion is not supported, **VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING** defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1) is returned.
955
956**Since**: 12
957
958
959### VIDEO_PROCESSING_TYPE_DETAIL_ENHANCER
960
961```
962const int32_t VIDEO_PROCESSING_TYPE_DETAIL_ENHANCER
963```
964
965**Description**
966
967Instance for detail enhancement during video processing.
968
969Call [OH_VideoProcessing_Create](#oh_videoprocessing_create) to create such an instance for detail enhancement. If detail enhancement is not supported, **VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING** defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1) is returned.
970
971**Since**: 12
972
973
974### VIDEO_PROCESSING_TYPE_METADATA_GENERATION
975
976```
977const int32_t VIDEO_PROCESSING_TYPE_METADATA_GENERATION
978```
979
980**Description**
981
982Instance created for metadata generation during video processing.
983
984Call [OH_VideoProcessing_Create](#oh_videoprocessing_create) to create such an instance for metadata generation. If metadata generation is not supported, **VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING** defined in [VideoProcessing_ErrorCode](#videoprocessing_errorcode-1) is returned.
985
986**Since**: 12
987