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