harmony 鸿蒙video_processing.h

  • 2025-06-12
  • 浏览 (5)

video_processing.h

Overview

The video_processing.h file declares the video processing functions.

It provides video processing capabilities, including color space conversion, metadata generation, and video scaling.

Library: libvideo_processing.so

System capability: SystemCapability.Multimedia.VideoProcessingEngine

Since: 12

Related module: VideoProcessing

Summary

Functions

|Name|Description| |–|–| |VideoProcessing_ErrorCode OH_VideoProcessing_InitializeEnvironment(void)|Initializes the global video processing environment.
This 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.| |VideoProcessing_ErrorCode OH_VideoProcessing_DeinitializeEnvironment(void)|Releases the global video processing environment.
Before calling this API, you must call 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.| |bool OH_VideoProcessing_IsColorSpaceConversionSupported(const VideoProcessing_ColorSpaceInfo* sourceVideoInfo,const VideoProcessing_ColorSpaceInfo* destinationVideoInfo)|Checks whether color space conversion is supported during video processing.| |bool OH_VideoProcessing_IsMetadataGenerationSupported(const VideoProcessing_ColorSpaceInfo* sourceVideoInfo)|Checks whether metadata generation is supported during video processing.| |VideoProcessing_ErrorCode OH_VideoProcessing_Create(OH_VideoProcessing** videoProcessor, int type)|Creates a video processing instance.| |VideoProcessing_ErrorCode OH_VideoProcessing_Destroy(OH_VideoProcessing* videoProcessor)|Destroys a video processing instance.
Before destroying the instance, call OH_VideoProcessing_Stop to stop it.| |VideoProcessing_ErrorCode OH_VideoProcessing_RegisterCallback(OH_VideoProcessing* videoProcessor,const VideoProcessing_Callback* callback, void* userData)|Registers a callback for video processing.
The callback function should be registered before video processing starts. During video processing, it cannot be registered.| |VideoProcessing_ErrorCode OH_VideoProcessing_SetSurface(OH_VideoProcessing* videoProcessor,const OHNativeWindow* window)|Sets an output surface for video processing.
An output surface must be set before video processing starts.| |VideoProcessing_ErrorCode OH_VideoProcessing_GetSurface(OH_VideoProcessing* videoProcessor, OHNativeWindow** window)|Obtains a surface for video processing.
An input surface must be created before video processing starts, it must be destroyed by calling OH_NativeWindow_DestroyNativeWindow when it is no longer needed.| |VideoProcessing_ErrorCode OH_VideoProcessing_SetParameter(OH_VideoProcessing* videoProcessor,const OH_AVFormat* parameter)|Sets video processing parameters.| |VideoProcessing_ErrorCode OH_VideoProcessing_GetParameter(OH_VideoProcessing* videoProcessor, OH_AVFormat* parameter)|Obtains video processing parameters.| |VideoProcessing_ErrorCode OH_VideoProcessing_Start(OH_VideoProcessing* videoProcessor)|Starts video processing.
After video processing starts, the callback OH_VideoProcessingCallback_OnState reports the VIDEO_PROCESSING_STATE_RUNNING state.| |VideoProcessing_ErrorCode OH_VideoProcessing_Stop(OH_VideoProcessing* videoProcessor)|Stops video processing.
After video processing stops, the callback OH_VideoProcessingCallback_OnState reports the VIDEO_PROCESSING_STATE_STOPPED state.| |VideoProcessing_ErrorCode OH_VideoProcessing_RenderOutputBuffer(OH_VideoProcessing* videoProcessor, uint32_t index)|Renders and processes the buffer, and then outputs it.
If the callback function OH_VideoProcessingCallback_OnNewOutputBuffer is set, the buffer index is returned through the callback function after the output buffer is ready.| |VideoProcessing_ErrorCode OH_VideoProcessingCallback_Create(VideoProcessing_Callback** callback)|Creates a video processing callback object.| |VideoProcessing_ErrorCode OH_VideoProcessingCallback_Destroy(VideoProcessing_Callback* callback)|Destroys a video processing callback object. The video processing callback object can be destroyed after the callback function is registered.| |VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnError(VideoProcessing_Callback* callback,OH_VideoProcessingCallback_OnError onError)|Binds the callback function OH_VideoProcessingCallback_OnError to a video processing callback object.| |VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnState(VideoProcessing_Callback* callback,OH_VideoProcessingCallback_OnState onState)|Binds the callback function OH_VideoProcessingCallback_OnState to a video processing callback object.| |VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnNewOutputBuffer(VideoProcessing_Callback* callback,OH_VideoProcessingCallback_OnNewOutputBuffer onNewOutputBuffer)|Binds the callback function OH_VideoProcessingCallback_OnNewOutputBuffer to a video processing callback object.|

Function Description

OH_VideoProcessing_InitializeEnvironment()

VideoProcessing_ErrorCode OH_VideoProcessing_InitializeEnvironment(void)

Description

Initializes the global video processing environment.

This 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.

The global video processing environment must be released by calling OH_VideoProcessing_DeinitializeEnvironment.

For details about how and when to release the environment, see OH_VideoProcessing_DeinitializeEnvironment.

Since: 12

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The initialization is successful.
VIDEO_PROCESSING_ERROR_INITIALIZE_FAILED: The initialization fails.
If the operation fails, check whether the GPU works properly.|

OH_VideoProcessing_DeinitializeEnvironment()

VideoProcessing_ErrorCode OH_VideoProcessing_DeinitializeEnvironment(void)

Description

Releases the global video processing environment.

Before calling this API, you must call 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.

Since: 12

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The processing is successful.
VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED: A video processing instance is not destroyed or OH_VideoProcessing_InitializeEnvironment is not called to initialize the environment.|

OH_VideoProcessing_IsColorSpaceConversionSupported()

bool OH_VideoProcessing_IsColorSpaceConversionSupported(const VideoProcessing_ColorSpaceInfo* sourceVideoInfo,const VideoProcessing_ColorSpaceInfo* destinationVideoInfo)

Description

Checks whether color space conversion is supported during video processing.

Since: 12

Parameters

|Parameter|Description| |–|–| |const VideoProcessing_ColorSpaceInfo* sourceVideoInfo|Pointer to the color space information of the input video.| |const VideoProcessing_ColorSpaceInfo* destinationVideoInfo|Pointer to the color space information of the output video.|

Returns

|Type|Description| |–|–| |bool|Check result. The value true means that color space conversion is supported, and false means the opposite.|

OH_VideoProcessing_IsMetadataGenerationSupported()

bool OH_VideoProcessing_IsMetadataGenerationSupported(const VideoProcessing_ColorSpaceInfo* sourceVideoInfo)

Description

Checks whether metadata generation is supported during video processing.

Since: 12

Parameters

|Parameter|Description| |–|–| |const VideoProcessing_ColorSpaceInfo* sourceVideoInfo|Pointer to the color space information of the input video.|

Returns

|Type|Description| |–|–| |bool|Check result. The value true means that metadata generation is supported; false means the opposite.|

OH_VideoProcessing_Create()

VideoProcessing_ErrorCode OH_VideoProcessing_Create(OH_VideoProcessing** videoProcessor, int type)

Description

Creates a video processing instance.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing** videoProcessor| Double pointer to the video processing instance created. Before any input, *videoProcessor must be a null pointer.| |int type|Video processing type. The processing type of an instance cannot be changed.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The video processing instance is created successfully.
VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING: The processing type is not supported. For example, metadata generation is not supported.
VIDEO_PROCESSING_ERROR_CREATE_FAILED: The video processing instance fails to be created.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or the pointer to the instance is not null.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: The video processing type is invalid.|

OH_VideoProcessing_Destroy()

VideoProcessing_ErrorCode OH_VideoProcessing_Destroy(OH_VideoProcessing* videoProcessor)

Description

Destroys a video processing instance.

Before destroying the instance, call OH_VideoProcessing_Stop to stop it.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance. You are advised to set the pointer to a null pointer after the instance is destroyed.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The instance is destroyed.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED: The instance is still running.|

OH_VideoProcessing_RegisterCallback()

VideoProcessing_ErrorCode OH_VideoProcessing_RegisterCallback(OH_VideoProcessing* videoProcessor,const VideoProcessing_Callback* callback, void* userData)

Description

Registers a callback for video processing.

The callback function should be registered before video processing starts. During video processing, it cannot be registered.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance.| |const VideoProcessing_Callback* callback|Pointer to the callback function.| |void* userData|Pointer to user-defined data.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The callback function is registered.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: The callback function pointer is null.
VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED: The instance is still running.|

OH_VideoProcessing_SetSurface()

VideoProcessing_ErrorCode OH_VideoProcessing_SetSurface(OH_VideoProcessing* videoProcessor,const OHNativeWindow* window)

Description

Sets an output surface for video processing.

An output surface must be set before video processing starts.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance.| |const OHNativeWindow* window|Pointer to the output surface.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The output surface is successfully set.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: The window is a null pointer.|

OH_VideoProcessing_GetSurface()

VideoProcessing_ErrorCode OH_VideoProcessing_GetSurface(OH_VideoProcessing* videoProcessor, OHNativeWindow** window)

Description

Obtains a surface for video processing.

An input surface must be created before video processing starts, and it must be destroyed by calling OH_NativeWindow_DestroyNativeWindow when it is no longer needed.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance.| |OHNativeWindow** window|Double pointer to the input surface. For example, the input surface pointer can point to an output surface of the video decoder.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The processing is successful.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: The window is a null pointer or the pointer to the window is not null.
VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED: The surface fails to be created, an input surface has been created, or the video processing instance is running.|

OH_VideoProcessing_SetParameter()

VideoProcessing_ErrorCode OH_VideoProcessing_SetParameter(OH_VideoProcessing* videoProcessor,const OH_AVFormat* parameter)

Description

Sets video processing parameters.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance.| |const OH_AVFormat* parameter|Pointer to the video processing parameter instance.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The parameters are successfully set.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: The parameter is empty.
VIDEO_PROCESSING_ERROR_INVALID_VALUE: Some attributes of a parameter are invalid, for example, unsupported parameter value.
VIDEO_PROCESSING_ERROR_NO_MEMORY: Memory allocation fails.|

OH_VideoProcessing_GetParameter()

VideoProcessing_ErrorCode OH_VideoProcessing_GetParameter(OH_VideoProcessing* videoProcessor, OH_AVFormat* parameter)

Description

Obtains video processing parameters.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance.| |OH_AVFormat* parameter|Pointer to the video processing parameter instance.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The parameters are obtained.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: The parameter is empty.|

OH_VideoProcessing_Start()

VideoProcessing_ErrorCode OH_VideoProcessing_Start(OH_VideoProcessing* videoProcessor)

Description

Starts video processing.

After video processing starts, the callback OH_VideoProcessingCallback_OnState reports the VideoProcessing_State.VIDEO_PROCESSING_STATE_RUNNING state.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The processing is successful.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED: No output surface is set, no input surface is created, or the instance is running.|

OH_VideoProcessing_Stop()

VideoProcessing_ErrorCode OH_VideoProcessing_Stop(OH_VideoProcessing* videoProcessor)

Description

Stops video processing.

After video processing stops, the callback OH_VideoProcessingCallback_OnState reports the VideoProcessing_State.VIDEO_PROCESSING_STATE_STOPPED state.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The processing is successful.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED: The instance is stopped.|

OH_VideoProcessing_RenderOutputBuffer()

VideoProcessing_ErrorCode OH_VideoProcessing_RenderOutputBuffer(OH_VideoProcessing* videoProcessor, uint32_t index)

Description

Renders and processes the buffer, and then outputs it.

If the callback function OH_VideoProcessingCallback_OnNewOutputBuffer is set, the buffer index is returned through the callback function after the output buffer is ready.

Since: 12

Parameters

|Parameter|Description| |–|–| |OH_VideoProcessing* videoProcessor|Pointer to the video processing instance.| |uint32_t index|Index of the output buffer.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The processing is successful.
VIDEO_PROCESSING_ERROR_INVALID_INSTANCE: The instance is null or is not a video processing instance.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: The index is invalid.
VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED: The callback function OH_VideoProcessingCallback_OnNewOutputBuffer is not set or the instance is stopped.|

OH_VideoProcessingCallback_Create()

VideoProcessing_ErrorCode OH_VideoProcessingCallback_Create(VideoProcessing_Callback** callback)

Description

Creates a video processing callback object.

Since: 12

Parameters

|Parameter|Description| |–|–| |VideoProcessing_Callback** callback| Double pointer to the video processing callback object. Before creating a callback object, *callback must be a null pointer.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The callback object is created.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: callback is null or callback is not null.
VIDEO_PROCESSING_ERROR_NO_MEMORY: The memory is insufficient.|

OH_VideoProcessingCallback_Destroy()

VideoProcessing_ErrorCode OH_VideoProcessingCallback_Destroy(VideoProcessing_Callback* callback)

Description

Destroys a video processing callback object. The video processing callback object can be destroyed after the callback function is registered.

Since: 12

Parameters

|Parameter|Description| |–|–| |VideoProcessing_Callback* callback|Pointer to the callback object. You are advised to set the pointer to a null pointer after the callback object is destroyed.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The callback object is destroyed.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: callback is null.|

OH_VideoProcessingCallback_BindOnError()

VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnError(VideoProcessing_Callback* callback,OH_VideoProcessingCallback_OnError onError)

Description

Binds the callback function OH_VideoProcessingCallback_OnError to a video processing callback object.

Since: 12

Parameters

|Parameter|Description| |–|–| |VideoProcessing_Callback* callback|Pointer to the callback object.| |OH_VideoProcessingCallback_OnError onError|Callback function to bind.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The binding is successful.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: callback or onError is null.|

OH_VideoProcessingCallback_BindOnState()

VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnState(VideoProcessing_Callback* callback,OH_VideoProcessingCallback_OnState onState)

Description

Binds the callback function OH_VideoProcessingCallback_OnState to a video processing callback object.

Since: 12

Parameters

|Parameter|Description| |–|–| |VideoProcessing_Callback* callback|Pointer to the callback object.| |OH_VideoProcessingCallback_OnState onState|Callback function to bind.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The binding is successful.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: callback or onState is null.|

OH_VideoProcessingCallback_BindOnNewOutputBuffer()

VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnNewOutputBuffer(VideoProcessing_Callback* callback,OH_VideoProcessingCallback_OnNewOutputBuffer onNewOutputBuffer)

Description

Binds the callback function OH_VideoProcessingCallback_OnNewOutputBuffer to a video processing callback object.

Since: 12

Parameters

|Parameter|Description| |–|–| |VideoProcessing_Callback* callback|Pointer to the callback object.| |OH_VideoProcessingCallback_OnNewOutputBuffer onNewOutputBuffer|Callback function to bind.|

Returns

|Type|Description| |–|–| |VideoProcessing_ErrorCode|VIDEO_PROCESSING_SUCCESS: The binding is successful.
VIDEO_PROCESSING_ERROR_INVALID_PARAMETER: callback is null.|

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Media Kit

harmony 鸿蒙AVImageGenerator

harmony 鸿蒙AVMetadataExtractor

harmony 鸿蒙AVPlayer

harmony 鸿蒙AVPlayerCallback

harmony 鸿蒙AVRecorder

harmony 鸿蒙AVScreenCapture

harmony 鸿蒙OH_AVRecorder_Config

harmony 鸿蒙OH_AVRecorder_EncoderInfo

harmony 鸿蒙OH_AVRecorder_Location

0  赞