• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.videoProcessingEngine (视频处理引擎)
2
3本模块提供图片内容的清晰度增强及缩放能力。
4
5本模块包含一个基础类:[ImageProcessor](#imageprocessor)类。
6
7> **说明:**
8>
9> 本模块首批接口从API version 18开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10
11## 导入模块
12
13```ts
14import { videoProcessingEngine } from '@kit.ImageKit';
15```
16
17## videoProcessingEngine.initializeEnvironment
18
19initializeEnvironment(): Promise\<void>
20
21初始化环境。使用Promise异步回调。
22
23**卡片能力**:从API version 18开始,该接口支持在ArkTS卡片中使用。
24
25**系统能力:** SystemCapability.Multimedia.VideoProcessingEngine
26
27**返回值:**
28
29|  类型 | 说明  |
30| ------------ | ------------ |
31|  Promise\<void> | Promise对象。无返回结果的Promise对象。  |
32
33**错误码:**
34
35以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[视频处理引擎错误码](errorcode-videoprocessingengine.md)
36
37
38| 错误码ID  | 错误信息  |
39| :------------ | :------------ |
40| 801  | Capability not supported. Function initializeEnvironment can not work correctly due to limited device capabilities.|
41| 29200002  | The global environment initialization for image processing failed, such as failure to initialize the GPU environment.  |
42| 29200006  | The operation is not permitted. This may be caused by incorrect status.  |
43| 29200007  | Out of memory.  |
44
45**示例:**
46
47```ts
48import { videoProcessingEngine } from '@kit.ImageKit';
49async function initializeEnvironment() {
50videoProcessingEngine.initializeEnvironment();
51}
52```
53
54## videoProcessingEngine.deinitializeEnvironment
55
56deinitializeEnvironment(): Promise\<void>
57
58释放处理资源。使用Promise异步回调。
59
60**卡片能力**:从API version 18开始,该接口支持在ArkTS卡片中使用。
61
62**系统能力:** SystemCapability.Multimedia.VideoProcessingEngine
63
64**返回值:**
65
66|  类型 | 说明  |
67| ------------ | ------------ |
68|  Promise\<void> | Promise对象。无返回结果的Promise对象。  |
69
70**错误码:**
71
72以下错误码的详细介绍请参见[视频处理引擎错误码](errorcode-videoprocessingengine.md)
73
74| 错误码ID  | 错误信息  |
75| :------------ | :------------ |
76| 29200006  | The operation is not permitted. This may be caused by incorrect status.  |
77
78**示例:**
79
80```ts
81import { videoProcessingEngine } from '@kit.ImageKit';
82async function deinitializeEnvironment() {
83  videoProcessingEngine.initializeEnvironment();
84  videoProcessingEngine.deinitializeEnvironment();
85}
86```
87
88## videoProcessingEngine.create
89
90create(): ImageProcessor
91
92如果操作成功,创建图片处理模块实例,否则返回null。
93
94**卡片能力**:从API version 18开始,该接口支持在ArkTS卡片中使用。
95
96**系统能力:** SystemCapability.Multimedia.VideoProcessingEngine
97
98**返回值:**
99
100|  类型 | 说明  |
101| ------------ | ------------ |
102|  [ImageProcessor](#imageprocessor) | 图片处理模块实例。  |
103
104**错误码:**
105
106以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[视频处理引擎错误码](errorcode-videoprocessingengine.md)
107
108| 错误码ID  | 错误信息  |
109| :------------ | :------------ |
110| 801  | Capability not supported. Function create can not work correctly due to limited device capabilities.|
111| 29200003  | Failed to create image processing instance. For example, the number of instances exceeds the upper limit. |
112| 29200007  | Out of memory.  |
113
114**示例:**
115
116```ts
117import { videoProcessingEngine } from '@kit.ImageKit';
118async function create() {
119videoProcessingEngine.initializeEnvironment();
120let imageProcessor = videoProcessingEngine.create() as videoProcessingEngine.ImageProcessor;
121}
122```
123
124## ImageProcessor
125
126图像处理类,提供图片内容的清晰度增强及缩放能力。根据源图像的宽度和高度进行必要的缩放操作,生成目标图像。提供不同级别的缩放方法以平衡性能和图像质量。
127
128规格约束如下:
129
130- 当前仅支持处理SDR(Standard dynamic range)图片。
131- 当前支持处理RGBA、BGRA、NV12、NV21像素格式的图片,输出格式与输入格式一致。
132
133### enhanceDetail
134
135enhanceDetail(sourceImage: image.PixelMap, width: number, height: number, level?: QualityLevel): Promise\<image.PixelMap\>
136
137细节增强处理异步方法。使用Promise异步回调。
138
139**卡片能力**:从API version 18开始,该接口支持在ArkTS卡片中使用。
140
141**系统能力:** SystemCapability.Multimedia.VideoProcessingEngine
142
143**参数:**
144
145|  参数名 | 类型  | 必填  | 说明  |
146| :------------ | :------------ | :------------ | :------------ |
147|  sourceImage | [image.PixelMap](arkts-apis-image-PixelMap.md)  | 是  | 输入图像。  |
148|  width |  number | 是  | 目标宽度(单位为像素,px)。  |
149|  height |  number | 是  |  目标高度(单位为像素,px)。 |
150|  level | [QualityLevel](#qualitylevel)| 否  |  算法档位(HIGH、MEDIUM、LOW、NONE),默认为NONE。 |
151
152**返回值:**
153
154|  类型 | 说明  |
155| ------------ | ------------ |
156| Promise\<[image.PixelMap](arkts-apis-image-PixelMap.md)\>  |  异步方法返回PixelMap的Promise实例。 |
157
158**错误码:**
159
160以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[视频处理引擎错误码](errorcode-videoprocessingengine.md)
161
162| 错误码ID  | 错误信息  |
163| :------------ | :------------ |
164| 801  | Capability not supported. Function enhanceDetail can not work correctly due to limited device capabilities.|
165|  29200007  | Out of memory.  |
166|  29200009  | Input value is invalid. This error is returned for all of the following error conditions: <br>1 - Invalid input or output image buffer - The image buffer width(height) is too large or colorspace is incorrect. <br>2 - Invalid parameter - The parameter does not contain valid information, such as detail enhancer level is incorrect. |
167
168**示例:**
169
170```ts
171import { image, videoProcessingEngine } from '@kit.ImageKit';
172async function enhanceDetail(sourceImage: image.PixelMap, width: number, height: number) {
173  videoProcessingEngine.initializeEnvironment();
174  let imageProcessor = videoProcessingEngine.create() as videoProcessingEngine.ImageProcessor;
175  let enhancedPixelmap: Promise<image.PixelMap> = imageProcessor.enhanceDetail(sourceImage, width, height, videoProcessingEngine.QualityLevel.HIGH);
176}
177```
178
179### enhanceDetail
180
181enhanceDetail(sourceImage: image.PixelMap, scale: number, level?: QualityLevel): Promise\<image.PixelMap\>
182
183细节增强处理异步方法。使用Promise异步回调。
184
185**卡片能力**:从API version 18开始,该接口支持在ArkTS卡片中使用。
186
187**系统能力:** SystemCapability.Multimedia.VideoProcessingEngine
188
189**参数:**
190
191|  参数名 | 类型  | 必填  | 说明  |
192| :------------ | :------------ | :------------ | :------------ |
193|  sourceImage | [image.PixelMap](arkts-apis-image-PixelMap.md)  | 是  | 输入图像。  |
194|  scale |  number |  是 |  目标缩放比例。 |
195|  level | [QualityLevel](#qualitylevel)| 否  |  算法档位(HIGH、MEDIUM、LOW、NONE),默认为NONE。 |
196
197**返回值:**
198
199|  类型 | 说明  |
200| ------------ | ------------ |
201| Promise\<[image.PixelMap](arkts-apis-image-PixelMap.md)\>  |  异步方法返回PixelMap的Promise实例。 |
202
203**错误码:**
204
205以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[视频处理引擎错误码](errorcode-videoprocessingengine.md)
206
207| 错误码ID  | 错误信息  |
208| :------------ | :------------ |
209| 801  | Capability not supported. Function enhanceDetail can not work correctly due to limited device capabilities.|
210|  29200007  | Out of memory.  |
211|  29200009  | Input value is invalid. This error is returned for all of the following error conditions: <br>1 - Invalid input or output image buffer - The image buffer width(height) is too large or colorspace is incorrect. <br>2 - Invalid parameter - The parameter does not contain valid information, such as detail enhancer level is incorrect.  |
212
213**示例:**
214
215```ts
216import { image, videoProcessingEngine } from '@kit.ImageKit';
217async function enhanceDetail(sourceImage: image.PixelMap, scale: number) {
218  videoProcessingEngine.initializeEnvironment();
219  let imageProcessor = videoProcessingEngine.create() as videoProcessingEngine.ImageProcessor;
220  let enhancedPixelmap: Promise<image.PixelMap> = imageProcessor.enhanceDetail(sourceImage, scale, videoProcessingEngine.QualityLevel.HIGH);
221}
222```
223
224### enhanceDetailSync
225
226enhanceDetailSync(sourceImage: image.PixelMap, width: number, height: number, level?: QualityLevel): image.PixelMap
227
228细节增强处理同步方法。
229
230**卡片能力**:从API version 18开始,该接口支持在ArkTS卡片中使用。
231
232**系统能力:** SystemCapability.Multimedia.VideoProcessingEngine
233
234**参数:**
235
236|  参数名 | 类型  | 必填  | 说明  |
237| :------------ | :------------ | :------------ | :------------ |
238|  sourceImage | [image.PixelMap](arkts-apis-image-PixelMap.md)  | 是  | 输入图像。  |
239|  width |  number | 是  | 目标宽度(单位为像素,px)。  |
240|  height |  number | 是 |  目标高度(单位为像素,px)。 |
241|  level | [QualityLevel](#qualitylevel)| 否  |  算法档位(HIGH、MEDIUM、LOW、NONE),默认为NONE。 |
242
243**返回值:**
244
245|  类型 | 说明  |
246| ------------ | ------------ |
247| [image.PixelMap](arkts-apis-image-PixelMap.md)  |  成功同步返回PixelMap对象。 |
248
249**错误码:**
250
251以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[视频处理引擎错误码](errorcode-videoprocessingengine.md)
252
253| 错误码ID  | 错误信息  |
254| :------------ | :------------ |
255| 801  | Capability not supported. Function enhanceDetailSync can not work correctly due to limited device capabilities.|
256|  29200004  | Failed to process image buffer. For example, the processing times out.  |
257|  29200007  | Out of memory.  |
258|  29200009  | Input value is invalid. This error is returned for all of the following error conditions: <br>1 - Invalid input or output image buffer - The image buffer width(height) is too large or colorspace is incorrect. <br>2 - Invalid parameter - The parameter does not contain valid information, such as detail enhancer level is incorrect. |
259
260**示例:**
261
262```ts
263import { image, videoProcessingEngine } from '@kit.ImageKit';
264async function enhanceDetailSync(sourceImage:image.PixelMap, width: number, height: number) {
265  videoProcessingEngine.initializeEnvironment();
266  let imageProcessor = videoProcessingEngine.create() as videoProcessingEngine.ImageProcessor;
267  let enhancedPixelmap: image.PixelMap = imageProcessor.enhanceDetailSync(
268sourceImage, width, height, videoProcessingEngine.QualityLevel.HIGH);
269}
270```
271
272### enhanceDetailSync
273
274enhanceDetailSync(sourceImage: image.PixelMap, scale: number, level?: QualityLevel): image.PixelMap
275
276细节增强处理同步方法。
277
278**卡片能力**:从API version 18开始,该接口支持在ArkTS卡片中使用。
279
280**系统能力:** SystemCapability.Multimedia.VideoProcessingEngine
281
282**参数:**
283
284|  参数名 | 类型  | 必填  | 说明  |
285| :------------ | :------------ | :------------ | :------------ |
286|  sourceImage | [image.PixelMap](arkts-apis-image-PixelMap.md)  | 是  | 输入图像。  |
287|  scale |  number |  是 |  目标缩放比例。 |
288|  level | [QualityLevel](#qualitylevel)| 否  |  算法档位(HIGH、MEDIUM、LOW、NONE),默认为NONE。 |
289
290**返回值:**
291
292|  类型 | 说明  |
293| ------------ | ------------ |
294| [image.PixelMap](arkts-apis-image-PixelMap.md)  |  成功同步返回PixelMap对象。 |
295
296**错误码:**
297
298以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[视频处理引擎错误码](errorcode-videoprocessingengine.md)
299
300| 错误码ID  | 错误信息  |
301| :------------ | :------------ |
302| 801  | Capability not supported. Function enhanceDetailSync can not work correctly due to limited device capabilities.|
303|  29200004  | Failed to process image buffer. For example, the processing times out.  |
304|  29200007  | Out of memory.  |
305|  29200009  | Input value is invalid. This error is returned for all of the following error conditions: <br>1 - Invalid input or output image buffer - The image buffer width(height) is too large or colorspace is incorrect. <br>2 - Invalid parameter - The parameter does not contain valid information, such as detail enhancer level is incorrect.  |
306
307**示例:**
308
309```ts
310import { image, videoProcessingEngine } from '@kit.ImageKit';
311async function enhanceDetailSync(sourceImage:image.PixelMap, scale: number) {
312  videoProcessingEngine.initializeEnvironment();
313  let imageProcessor = videoProcessingEngine.create() as videoProcessingEngine.ImageProcessor;
314  let enhancedPixelmap: image.PixelMap = imageProcessor.enhanceDetailSync(
315sourceImage, scale, videoProcessingEngine.QualityLevel.HIGH);
316}
317```
318
319## QualityLevel
320
321枚举,算法档位。
322
323**卡片能力**:从API version 18开始,该接口支持在ArkTS卡片中使用。
324
325**系统能力:** SystemCapability.Multimedia.VideoProcessingEngine
326
327| 名称  | 值  | 说明  |
328| ------------ | ------------ | ------------ |
329| NONE  | 0  | 仅适用于缩放场景,支持改变宽高比例。<br>- 输入分辨率要求(单位为像素,px):宽:[32,3000],高:[32,3000]。<br>- 输出分辨率要求(单位为像素,px):宽:[32,3000],高:[32,3000]。  |
330|  LOW |  1 | 仅适用于缩放场景,支持改变宽高比例。<br>- 输入分辨率要求(单位为像素,px):宽:[32,3000],高:[32,3000]。<br>- 输出分辨率要求(单位为像素,px):宽:[32,3000],高:[32,3000]。  |
331|  MEDIUM | 2  | 仅适用于缩放场景,支持改变宽高比例。<br>- 输入分辨率要求(单位为像素,px):宽:[32,3000],高:[32,3000]。<br>- 输出分辨率要求(单位为像素,px):宽:[32,3000],高:[32,3000]。  |
332|  HIGH |  3 |  1. 缩放场景,不支持改变宽高比例。<br>- 输入分辨率要求(单位为像素,px):宽:(32,512) (2000,8192],高:(32,512) (2000,8192]。<br>- 输出分辨率要求(单位为像素,px):宽:(32,512) (2000,8192],高:(32,512) (2000,8192]。 <br>2. 清晰度增强、缩放场景,支持改变宽高比例。<br>- 输入分辨率要求(单位为像素,px):宽:[512,2000],高:[512,2000]。<br>- 输出分辨率要求(单位为像素,px):宽:[512,2000],高:[512,2000]。 |
333